0ad/source/network/Client.h
Matei 207d1367ec # A number of network synchronization fixes.
- The server will no longer send a new turn until the previous one has
been "acknowledged". (TODO: this may create lag between turns in its
current form; investigate and possibly allow executing two turns while
the third is being negotiated).
- Mutexes are now being used in NetServer and NetClient to ensure
commands go into the right batches.
- Commented out some orders in the GUI code that should not be there and
are not 100% working anyway (they were part of the follow/formation
system).
- Units that spawn or are created by scripts now have net-safe position
and orientation.
- Added a debug flag that can be turned on to print details about when
commands are received and executed (DEBUG_SYNCHRONIZATION). This is
especially useful if you diff the stdouts of two running games. There
should be no differences if everything is in synch.

This was SVN commit r5463.
2007-11-18 09:09:06 +00:00

98 lines
2.4 KiB
C++

#ifndef INCLUDED_NETWORK_CLIENT
#define INCLUDED_NETWORK_CLIENT
#include "Session.h"
#include "simulation/TurnManager.h"
#include "simulation/ScriptObject.h"
#include "scripting/ScriptableObject.h"
#include "ps/CStr.h"
#include "ps/ThreadUtil.h"
#include "ps/scripting/JSMap.h"
#include <map>
class CPlayerSlot;
class CPlayer;
class CGame;
class CGameAttributes;
class CNetClient: public CNetSession, protected CTurnManager, public CJSObject<CNetClient>
{
class CServerSession: public CJSObject<CServerSession>
{
static void ScriptingInit();
public:
CServerSession(int sessionID, const CStrW& name);
int m_SessionID;
CStrW m_Name;
};
typedef std::map<int, CServerSession *> SessionMap;
SessionMap m_ServerSessions;
CJSMap<SessionMap> m_JSI_ServerSessions;
CStrW m_Password;
int m_SessionID;
CPlayerSlot *m_pLocalPlayerSlot;
CGame *m_pGame;
CGameAttributes *m_pGameAttributes;
// JS event scripts
CScriptObject m_OnStartGame;
CScriptObject m_OnChat;
CScriptObject m_OnConnectComplete;
CScriptObject m_OnDisconnect;
CScriptObject m_OnClientConnect;
CScriptObject m_OnClientDisconnect;
void OnClientConnect(int sessionID, const CStrW& name);
void OnClientDisconnect(int sessionID);
void OnStartGameMessage();
void QueueIncomingMessage(CNetMessage *pMsg);
// JS Interface Functions
bool JSI_BeginConnect(JSContext *cx, uintN argc, jsval *argv);
static void ScriptingInit();
// Are we currently in a locally-yet-unsimulated turn?
// This is set to true when we receive a command batch and cleared in NewTurn().
// The server also ensures that it does not send a new turn until we ack one.
bool m_TurnPending;
// Mutex for accessing batches
CMutex m_Mutex;
protected:
virtual bool NewTurnReady();
virtual void NewTurn();
virtual void QueueLocalCommand(CNetMessage *pMsg);
public:
CNetClient(CGame *pGame, CGameAttributes *pGameAttribs);
virtual ~CNetClient();
// Launch a game through this client
int StartGame();
// Get a pointer to our player
CPlayer* GetLocalPlayer();
static MessageHandler ConnectHandler;
static MessageHandler BaseHandler; // Common to all connected states
static MessageHandler HandshakeHandler;
static MessageHandler AuthenticateHandler;
static MessageHandler ChatHandler; // Common to pre-game and later
static MessageHandler PreGameHandler;
static MessageHandler InGameHandler;
};
extern CNetClient *g_NetClient;
#endif //INCLUDED_NETWORK_CLIENT