1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D is free software; you can redistribute it and/or modify
7 //    it under the terms of the GNU General Public License as published by
8 //    the Free Software Foundation; either version 2 of the License, or
9 //    (at your option) any later version.
10 //
11 //    Scorched3D is distributed in the hope that it will be useful,
12 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //    GNU General Public License for more details.
15 //
16 //    You should have received a copy of the GNU General Public License along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(__INCLUDE_ServerSyncCheckh_INCLUDE__)
22 #define __INCLUDE_ServerSyncCheckh_INCLUDE__
23 
24 #include <time.h>
25 #include <coms/ComsSyncCheckMessage.h>
26 #include <coms/ComsMessageHandler.h>
27 #include <map>
28 #include <set>
29 
30 class ServerSyncCheck : public ComsMessageHandlerI
31 {
32 public:
33 	ServerSyncCheck(ComsMessageHandler &comsMessageHandler);
34 	virtual ~ServerSyncCheck();
35 
36 	void enterState();
37 	void simulate();
38 
39 	void addServerSyncCheck(ComsSyncCheckMessage *message);
40 	void sendAutoSyncCheck();
41 	void sendSyncCheck();
42 	void sentSyncCheck(unsigned int syncId);
43 
44 	// Inherited from ComsMessageHandlerI
45 	virtual bool processMessage(
46 		NetMessage &message,
47 		const char *messageType,
48 		NetBufferReader &reader);
49 
50 protected:
51 	static ServerSyncCheck *instance_;
52 	time_t lastTime_;
53 
54 	struct SyncContext
55 	{
56 		SyncContext();
57 		~SyncContext();
58 
59 		ComsSyncCheckMessage *serverMessage;
60 		std::map<unsigned int, ComsSyncCheckMessage*> clientMessages;
61 		std::set<unsigned int> clientDestinations;
62 	};
63 	std::map<unsigned int, SyncContext*> contexts_;
64 
65 	bool checkContext(SyncContext *context);
66 	bool compareSyncChecks(ComsSyncCheckMessage *server,
67 		unsigned int destinationId, ComsSyncCheckMessage *client);
68 	bool compareHeightMaps(unsigned int destinationId, unsigned int syncId,
69 		const char *mapName,
70 		NetBuffer &serverBuffer, NetBuffer &clientBuffer);
71 
72 };
73 
74 #endif
75