1
0
forked from 0ad/0ad
0ad/source/ps/Network/Client.h
olsner 7bcc12373b - Created JSMap
- Changed player colour JS interface: setColour(...) instead of a colour
property
- Introduced a network log and replaced most network LOG() calls with
NET_LOG()
- Moved to a slot-based system for Pre-Game and extended a lot of the JS
APIs to networking stuff
- A bit of cleanup in the low-level network code (Unix parts)
- Clients now keep track of all other connected clients on the server
(And exposes this info to JS)
- Split out GameAttributes to its own file
- Removed unused class AttributeMap
- Changed CJSObject to use T* pointers in JS_SetPrivate (needed to make
ToScript work with multiple inheritance)

This was SVN commit r1929.
2005-02-21 17:13:31 +00:00

79 lines
1.8 KiB
C++
Executable File

#ifndef _Network_NetClient_H
#define _Network_NetClient_H
#include <CStr.h>
#include <Network/Session.h>
#include "TurnManager.h"
#include "Game.h"
#include "scripting/ScriptableObject.h"
#include "scripting/JSMap.h"
#include <map>
class CPlayer;
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);
// JS Interface Functions
bool JSI_BeginConnect(JSContext *cx, uintN argc, jsval *argv);
static void ScriptingInit();
protected:
virtual void NewTurn();
virtual void QueueLocalCommand(CNetMessage *pMsg);
void StartGame();
public:
CNetClient(CGame *pGame, CGameAttributes *pGameAttribs);
virtual ~CNetClient();
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 //_Network_NetClient_H