18 #include "precompiled.h"
31 m_Client(client), m_FileTransferer(this), m_Host(NULL),
m_Server(NULL), m_Stats(NULL)
63 if (enet_address_set_host(&addr, server.c_str()) < 0)
86 enet_peer_disconnect_now(
m_Server, reason);
104 while (enet_host_service(
m_Host, &event, 0) > 0)
108 case ENET_EVENT_TYPE_CONNECT:
113 char hostname[256] =
"(error)";
114 enet_address_get_host_ip(&event.peer->address, hostname,
ARRAY_SIZE(hostname));
115 LOGMESSAGE(L
"Net client: Connected to %hs:%u", hostname, (
unsigned int)event.peer->address.port);
122 case ENET_EVENT_TYPE_DISCONNECT:
131 case ENET_EVENT_TYPE_RECEIVE:
143 enet_packet_destroy(event.packet);
148 case ENET_EVENT_TYPE_NONE:
174 m_Server(server), m_FileTransferer(this), m_Peer(peer)
182 enet_peer_disconnect(
m_Peer, reason);
187 enet_peer_disconnect_now(
m_Peer, reason);
ScriptInterface & GetScriptInterface()
Get the script interface associated with this network client, which is equivalent to the one used by ...
CNetFileTransferer m_FileTransferer
void DisconnectNow(u32 reason)
Sends an unreliable disconnection notification to the client.
void Poll()
Process queued incoming messages.
virtual bool SendMessage(const CNetMessage *message)
Send a message to the client.
CNetServerWorker & m_Server
static const int CHANNEL_COUNT
void Disconnect(u32 reason)
Sends a disconnection notification to the client, and sends a NMT_CONNECTION_LOST message to the sess...
struct _ENetPeer ENetPeer
static bool SendMessage(const CNetMessage *message, ENetPeer *peer, const char *peerName)
Transmit a message to the given peer.
void HandleConnect()
Call when the network connection has been successfully initiated.
CNetClientSession(CNetClient &client)
CNetServerSession(CNetServerWorker &server, ENetPeer *peer)
void HandleDisconnect(u32 reason)
Call when the network connection has been lost.
CNetServerWorker & m_Server
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
virtual bool SendMessage(const CNetMessage *message)
Send a message to the server.
void Flush()
Flush queued outgoing network messages.
#define SAFE_DELETE(p)
delete memory ensuing from new and set the pointer to zero (thus making double-frees safe / a no-op) ...
ENet connection statistics profiler table.
static bool IsInitialised()
bool Update(unsigned int eventType, void *pEventData)
The base class for all network messages exchanged within the game.
bool HandleMessage(CNetMessage *message)
Call when a message has been received from the network.
void Poll()
Call frequently (e.g.
virtual size_t GetSerializedLength() const
Retrieves the size in bytes of the serialized message.
struct _ENetHost ENetHost
Network client/server sessions.
bool SendMessage(ENetPeer *peer, const CNetMessage *message)
Send a message to the given network peer.
void Disconnect(u32 reason)
Disconnect from the server.
Network server worker thread.
bool Connect(u16 port, const CStr &server)
static CNetMessage * CreateMessage(const void *pData, size_t dataSize, ScriptInterface &scriptInterface)
Factory method which creates a message object based on the given data.
virtual CStr ToString() const
Returns a string representation for the message.