2008-07-01 11:01:02 +03:00
|
|
|
#pragma once
|
2008-07-25 20:28:28 +03:00
|
|
|
#include "../global.h"
|
|
|
|
#include <set>
|
2008-08-04 12:05:52 +03:00
|
|
|
#include "../CGameState.h"
|
|
|
|
#include "../lib/Connection.h"
|
2008-07-25 20:28:28 +03:00
|
|
|
class CVCMIServer;
|
|
|
|
class CGameState;
|
2008-08-04 12:05:52 +03:00
|
|
|
//class CConnection;
|
2008-07-25 20:28:28 +03:00
|
|
|
struct StartInfo;
|
2008-07-30 20:51:19 +03:00
|
|
|
class CCPPObjectScript;
|
|
|
|
class CScriptCallback;
|
2008-07-26 16:57:32 +03:00
|
|
|
template <typename T> struct CPack;
|
|
|
|
|
2008-07-01 11:01:02 +03:00
|
|
|
class CGameHandler
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
|
2008-07-25 20:28:28 +03:00
|
|
|
CGameState *gs;
|
2008-07-30 20:51:19 +03:00
|
|
|
std::set<CCPPObjectScript *> cppscripts; //C++ scripts
|
|
|
|
//std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
|
|
|
|
|
2008-07-25 20:28:28 +03:00
|
|
|
CVCMIServer *s;
|
|
|
|
std::map<int,CConnection*> connections;
|
|
|
|
std::set<CConnection*> conns;
|
2008-07-30 20:51:19 +03:00
|
|
|
|
|
|
|
void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
|
|
|
|
|
2008-07-01 11:01:02 +03:00
|
|
|
public:
|
|
|
|
CGameHandler(void);
|
|
|
|
~CGameHandler(void);
|
2008-07-25 20:28:28 +03:00
|
|
|
void init(StartInfo *si, int Seed);
|
|
|
|
void handleConnection(std::set<int> players, CConnection &c);
|
2008-07-30 20:51:19 +03:00
|
|
|
template <typename T>void sendToAllClients(CPack<T> * info)
|
|
|
|
{
|
|
|
|
for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
|
|
|
|
{
|
|
|
|
(*i)->rmx->lock();
|
|
|
|
**i << info->getType() << *info->This();
|
|
|
|
(*i)->rmx->unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
template <typename T>void sendAndApply(CPack<T> * info)
|
|
|
|
{
|
|
|
|
gs->apply(info);
|
|
|
|
sendToAllClients(info);
|
|
|
|
}
|
2008-07-25 20:28:28 +03:00
|
|
|
void run();
|
|
|
|
void newTurn();
|
|
|
|
|
|
|
|
friend class CVCMIServer;
|
2008-07-30 20:51:19 +03:00
|
|
|
friend class CScriptCallback;
|
2008-07-01 11:01:02 +03:00
|
|
|
};
|