1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//===========================================================================//
#ifndef INETWORKSYSTEM_H
#define INETWORKSYSTEM_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/platform.h"
#include "appframework/IAppSystem.h"
//-----------------------------------------------------------------------------
// Forward declarations:
//-----------------------------------------------------------------------------
class INetworkMessageHandler;
class INetworkMessage;
class INetChannel;
class INetworkMessageFactory;
class bf_read;
class bf_write;
typedef struct netadr_s netadr_t;
class CNetPacket;
//-----------------------------------------------------------------------------
// Default ports
//-----------------------------------------------------------------------------
enum
{
NETWORKSYSTEM_DEFAULT_SERVER_PORT = 27001,
NETWORKSYSTEM_DEFAULT_CLIENT_PORT = 27002
};
//-----------------------------------------------------------------------------
// This interface encompasses a one-way communication path between two
//-----------------------------------------------------------------------------
typedef int ConnectionHandle_t;
enum ConnectionStatus_t
{
CONNECTION_STATE_DISCONNECTED = 0,
CONNECTION_STATE_CONNECTING,
CONNECTION_STATE_CONNECTION_FAILED,
CONNECTION_STATE_CONNECTED,
};
//-----------------------------------------------------------------------------
// This interface encompasses a one-way communication path between two machines
//-----------------------------------------------------------------------------
abstract_class INetChannel
{
public:
// virtual INetworkMessageHandler *GetMsgHandler( void ) const = 0;
virtual const netadr_t &GetRemoteAddress( void ) const = 0;
// send a net message
// NOTE: There are special connect/disconnect messages?
virtual bool AddNetMsg( INetworkMessage *msg, bool bForceReliable = false ) = 0;
// virtual bool RegisterMessage( INetworkMessage *msg ) = 0;
virtual ConnectionStatus_t GetConnectionState( ) = 0;
/*
virtual ConnectTo( const netadr_t& to ) = 0;
virtual Disconnect() = 0;
virtual const netadr_t& GetLocalAddress() = 0;
virtual const netadr_t& GetRemoteAddress() = 0;
*/
};
//-----------------------------------------------------------------------------
// Network event types + structures
//-----------------------------------------------------------------------------
enum NetworkEventType_t
{
NETWORK_EVENT_CONNECTED = 0,
NETWORK_EVENT_DISCONNECTED,
NETWORK_EVENT_MESSAGE_RECEIVED,
};
struct NetworkEvent_t
{
NetworkEventType_t m_nType;
};
struct NetworkConnectionEvent_t : public NetworkEvent_t
{
INetChannel *m_pChannel;
};
struct NetworkDisconnectionEvent_t : public NetworkEvent_t
{
INetChannel *m_pChannel;
};
struct NetworkMessageReceivedEvent_t : public NetworkEvent_t
{
INetChannel *m_pChannel;
INetworkMessage *m_pNetworkMessage;
};
//-----------------------------------------------------------------------------
// Main interface for low-level networking (packet sending). This is a low-level interface
//-----------------------------------------------------------------------------
#define NETWORKSYSTEM_INTERFACE_VERSION "NetworkSystemVersion001"
abstract_class INetworkSystem : public IAppSystem
{
public:
// Installs network message factories to be used with all connections
virtual bool RegisterMessage( INetworkMessage *msg ) = 0;
// Start, shutdown a server
virtual bool StartServer( unsigned short nServerListenPort = NETWORKSYSTEM_DEFAULT_SERVER_PORT ) = 0;
virtual void ShutdownServer( ) = 0;
// Process server-side network messages
virtual void ServerReceiveMessages() = 0;
virtual void ServerSendMessages() = 0;
// Start, shutdown a client
virtual bool StartClient( unsigned short nClientListenPort = NETWORKSYSTEM_DEFAULT_CLIENT_PORT ) = 0;
virtual void ShutdownClient( ) = 0;
// Process client-side network messages
virtual void ClientSendMessages() = 0;
virtual void ClientReceiveMessages() = 0;
// Connect, disconnect a client to a server
virtual INetChannel* ConnectClientToServer( const char *pServer, int nServerListenPort = NETWORKSYSTEM_DEFAULT_SERVER_PORT ) = 0;
virtual void DisconnectClientFromServer( INetChannel* pChan ) = 0;
// Event queue
virtual NetworkEvent_t *FirstNetworkEvent( ) = 0;
virtual NetworkEvent_t *NextNetworkEvent( ) = 0;
// Returns the local host name
virtual const char* GetLocalHostName( void ) const = 0;
virtual const char* GetLocalAddress( void ) const = 0;
/*
// NOTE: Server methods
// NOTE: There's only 1 client INetChannel ever
// There can be 0-N server INetChannels.
virtual INetChannel* CreateConnection( bool bIsClientConnection ) = 0;
// Add methods for setting unreliable payloads
*/
};
#endif // INETWORKSYSTEM_H
|