1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-26 08:41:13 +02:00
vcmi/server/CGameHandler.h

52 lines
1.2 KiB
C
Raw Normal View History

#pragma once
#include "../global.h"
#include <set>
#include "../CGameState.h"
#include "../lib/Connection.h"
class CVCMIServer;
class CGameState;
//class CConnection;
struct StartInfo;
2008-07-30 20:51:19 +03:00
class CCPPObjectScript;
class CScriptCallback;
template <typename T> struct CPack;
class CGameHandler
{
2008-07-30 20:51:19 +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
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);
public:
CGameHandler(void);
~CGameHandler(void);
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);
}
void run();
void newTurn();
friend class CVCMIServer;
2008-07-30 20:51:19 +03:00
friend class CScriptCallback;
};