1 /*****************************************************************************
2  * PokerTH - The open source texas holdem engine                             *
3  * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May          *
4  *                                                                           *
5  * This program is free software: you can redistribute it and/or modify      *
6  * it under the terms of the GNU Affero General Public License as            *
7  * published by the Free Software Foundation, either version 3 of the        *
8  * License, or (at your option) any later version.                           *
9  *                                                                           *
10  * This program is distributed in the hope that it will be useful,           *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
13  * GNU Affero General Public License for more details.                       *
14  *                                                                           *
15  * You should have received a copy of the GNU Affero General Public License  *
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.     *
17  *                                                                           *
18  *                                                                           *
19  * Additional permission under GNU AGPL version 3 section 7                  *
20  *                                                                           *
21  * If you modify this program, or any covered work, by linking or            *
22  * combining it with the OpenSSL project's OpenSSL library (or a             *
23  * modified version of that library), containing parts covered by the        *
24  * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH           *
25  * (Felix Hammer, Florian Thauer, Lothar May) grant you additional           *
26  * permission to convey the resulting work.                                  *
27  * Corresponding Source for a non-source form of such a combination          *
28  * shall include the source code for the parts of OpenSSL used as well       *
29  * as that of the covered work.                                              *
30  *****************************************************************************/
31 /* PokerTH network packet. */
32 
33 #ifndef _NETPACKET_H_
34 #define _NETPACKET_H_
35 
36 #include <string>
37 #include <list>
38 
39 #include <third_party/protobuf/pokerth.pb.h>
40 #include <gamedata.h>
41 
42 #define NET_VERSION_MAJOR			5
43 #define NET_VERSION_MINOR			1
44 
45 #define NET_HEADER_SIZE				4
46 
47 #define MAX_FILE_DATA_SIZE			256
48 #define MAX_PACKET_SIZE				384
49 #define MAX_CHAT_TEXT_SIZE			128
50 
51 /*#define MIN_PACKET_SIZE				4
52 #define MAX_NAME_SIZE				64
53 #define MAX_PASSWORD_SIZE			64
54 #define MAX_NUM_MANUAL_BLINDS		30
55 #define MAX_NUM_PLAYER_RESULTS		MAX_NUMBER_OF_PLAYERS
56 #define MAX_NUM_PLAYER_CARDS		MAX_NUMBER_OF_PLAYERS*/
57 
58 // This is just a wrapper class for the protocol buffer.
59 class NetPacket
60 {
61 public:
62 	NetPacket();
63 	NetPacket(PokerTHMessage *msg);
64 	~NetPacket();
65 
66 	static boost::shared_ptr<NetPacket> Create(const char *data, size_t dataSize);
67 
GetMsg()68 	const PokerTHMessage *GetMsg() const
69 	{
70 		return m_msg;
71 	}
GetMsg()72 	PokerTHMessage *GetMsg()
73 	{
74 		return m_msg;
75 	}
76 
77 	bool IsClientActivity() const;
78 
79 	std::string ToString() const;
80 
81 	static void SetGameData(const GameData &inData, NetGameInfo &outData);
82 	static void GetGameData(const NetGameInfo &inData, GameData &outData);
83 
84 	static int NetErrorToGameError(ErrorMessage::ErrorReason netErrorReason);
85 	static ErrorMessage::ErrorReason GameErrorToNetError(int gameErrorReason);
86 
87 private:
88 	PokerTHMessage *m_msg;
89 };
90 
91 typedef std::list<boost::shared_ptr<NetPacket> > NetPacketList;
92 
93 #endif
94 
95