1
0
forked from 0ad/0ad
0ad/source/network/Client.h
Matei 92578ae553 # Some initial work on networking, fixing session setup, game startup, and command queueing.
- Fixed outdated / buggy networking code in the GUI scripts.
- Finished the API to CNetClient so that it's possible to start a CGame
from it.
- Some enhancements for debugging networking: Enabled updates while the
game is minimized/out-of-focus if it's in a network session. Also
reduced the turn length to something slightly more manageable but still
unplayable (1 sec versus 3 sec).
- Fixed a bug where IssueCommand used to access the order it creates
after queueing it, which is bad if the order gets deleted while being
queued (e.g. in CNetClient).

This was SVN commit r5139.
2007-06-04 07:41:05 +00:00

87 lines
2.0 KiB
C++

#ifndef INCLUDED_NETWORK_CLIENT
#define INCLUDED_NETWORK_CLIENT
#include "ps/CStr.h"
#include "Session.h"
#include "simulation/TurnManager.h"
#include "simulation/ScriptObject.h"
#include "scripting/ScriptableObject.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();
// JS Interface Functions
bool JSI_BeginConnect(JSContext *cx, uintN argc, jsval *argv);
static void ScriptingInit();
protected:
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