aboutsummaryrefslogtreecommitdiff
path: root/src/parsec_server/include/e_packethandler.h
blob: bd283a147cef0e45a6c2e9c34992719b930462f2 (plain)
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
/*
* PARSEC HEADER: e_packethandler.h
*/

#ifndef _E_PACKETHANDLER_H_
#define _E_PACKETHANDLER_H_


// forward decls --------------------------------------------------------------
//
struct PacketChainBlock;
class NET_PacketDriver;
class E_ClientChallengeInfo;
class E_ClientConnectInfo;
class E_REList;

// needed includes ------------------------------------------------------------
//
#include "e_connmanager.h"
#include "MasterServerItem.h"

#ifndef _NET_GAME_H_
	//FIXME: we MUST not depend on client module NET_GAME
	//#include "net_game_sv.h"
#endif // _NET_GAME_H_


// Server packet handler class ------------------------------------------------
//
class E_PacketHandler
{
protected:

	E_PacketHandler()
	{
	}

public:

	// SINGLETON pattern
	static E_PacketHandler* GetPacketHandler()
	{
		static E_PacketHandler _ThePacketHandler;
		return &_ThePacketHandler;
	}
	
	// main packet handling function
	void HandlePacket( PacketChainBlock* block );

	// send a challenge response back to a client
	void SendChallengeResponse( E_ClientChallengeInfo* pChallengeInfo, node_t* clientnode );

	// send a connect response back to a client
	int SendConnectResponse( E_ConnManager::ConnResults rc, E_ClientConnectInfo* pClientConnectInfo );

	// send a disconnect response back to a client
	int SendDisconnectResponse( E_ConnManager::DisconnResults rc, node_t* clientnode, int nClientID );

	// send a namechange response back to the client
	int SendNameChangeRepsponse( E_ConnManager::NameChangeResults rc, node_t* clientnode, int nClientID );

	// send a PING response back to the client
	int SendPingResponse( refframe_t client_ping_send_frame, node_t* clientnode, int nClientID );

	// send a INFO response back to the client
	int SendInfoResponse( refframe_t client_ping_send_frame, node_t* clientnode, int nClientID );

	// send IPV4 info to the client after a master server list command
	int SendIPV4Response( node_t* clientnode, int nClientID, int serverid );

	// notify a client that another client is connected
	void SendNotifyConnected( int nDestSlot, int nClientSlot );
	
	// notify a client that another client is disconnected
	void SendNotifyDisconnected( int nDestSlot, int nClientSlot );
	
	// notify a client that another client's name changed
	void SendNotifyNameChange( int nDestSlot, int nClientSlot );


	// send a STREAM packet to a client
	size_t Send_STREAM( int nClientID, E_REList* pReliable, E_REList* pUnreliable );

	// send a server command to a node
	int Send_COMMAND( char* clientcommand, node_t* node, int nClientID, int reliable );

	// send a datagram to a node
	int Send_STREAM_Datagram( E_REList* relist, node_t* node, int nClientID );

	// send a datagram command to a specific client node
	int Send_COMMAND_Datagram( const char* clientcommand, node_t* node, int nClientID );

	// multicast a packet to all connected clients
	//void Multicast_Packet( NetPacket_GMSV* gamepacket, int nSenderClientID );
	
protected:

	// handle a command packet
	void _Handle_COMMAND( NetPacket_GMSV* gamepacket, int bufid );

	// handle a packet containing a command from the masterserver
	void _Handle_COMMAND_MASV( NetPacket_GMSV* gamepacket, int bufid );

	// handle a packet containing a command FOR the master server.
	void _Handle_COMMAND_MASTER( NetPacket_GMSV* gamepacket, int bufid );

	// handle a stream packet
	void _Handle_STREAM( NetPacket_GMSV* gamepacket );

	// handle a stream packet for the master server
	void _Handle_STREAM_MASTER( NetPacket_GMSV* gamepacket, int bufid );

	void _Send_STREAM();

	// do safe parsing of challenge request
	int _ParseChallengeRequest( char* recvline );

	// do safe parsing of connect request
	int _ParseConnectRequest( char* recvline, E_ClientConnectInfo* pClientConnectInfo );

	// do safe parsing of disconnect request
	int _ParseDisconnectRequest( char* recvline );

	// do safe parsing of namechange request
	int _ParseNameChangeRequest( char* recvline, char* playername );

	// do safe parsing of PING request
	int _ParsePingRequest( char* recvline, refframe_t* client_ping_send_frame );

	// do safe parsing of INFO request
	int _ParseInfoRequest( char* recvline, refframe_t* client_ping_send_frame );

	// do safe parsing of LIST requests for Master Server Mode.
	int _ParseListRequest_MASTER( char* recvline, int *serverid);

	// do safe parsing of heartbeat packets for the Master Server.
	int _ParseHBPacket_MASTER(char* recvline);

	// check whether the sender node matches the node for the senderid
	int _IsLegitSender( NetPacket_GMSV* gamepacket, int bufid );

	// do safe parsing of new challenge from MASV
	int _ParseMASVChallenge( char* recvline, int* pChallenge );
};


#endif // _E_PACKETHANDLER_H_