2011-12-14 00:23:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CVCMIServer.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
|
|
|
|
2010-10-24 14:35:14 +03:00
|
|
|
class CMapInfo;
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
class CConnection;
|
2010-10-31 00:53:41 +03:00
|
|
|
struct CPackForSelectionScreen;
|
2010-10-24 14:35:14 +03:00
|
|
|
class CGameHandler;
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
namespace asio
|
|
|
|
{
|
|
|
|
namespace ip
|
|
|
|
{
|
|
|
|
class tcp;
|
|
|
|
}
|
2010-10-24 14:35:14 +03:00
|
|
|
class io_service;
|
|
|
|
|
|
|
|
template <typename Protocol> class stream_socket_service;
|
|
|
|
template <typename Protocol,typename StreamSocketService>
|
|
|
|
class basic_stream_socket;
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
template <typename Protocol> class socket_acceptor_service;
|
|
|
|
template <typename Protocol,typename SocketAcceptorService>
|
|
|
|
class basic_socket_acceptor;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-24 14:35:14 +03:00
|
|
|
typedef boost::asio::basic_socket_acceptor<boost::asio::ip::tcp, boost::asio::socket_acceptor_service<boost::asio::ip::tcp> > TAcceptor;
|
|
|
|
typedef boost::asio::basic_stream_socket < boost::asio::ip::tcp , boost::asio::stream_socket_service<boost::asio::ip::tcp> > TSocket;
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
class CVCMIServer
|
|
|
|
{
|
|
|
|
boost::asio::io_service *io;
|
2010-10-24 14:35:14 +03:00
|
|
|
TAcceptor * acceptor;
|
|
|
|
|
|
|
|
CConnection *firstConnection;
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2009-05-07 20:20:41 +03:00
|
|
|
CVCMIServer(); //c-tor
|
|
|
|
~CVCMIServer(); //d-tor
|
2010-10-24 14:35:14 +03:00
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
void start();
|
2010-10-24 14:35:14 +03:00
|
|
|
CGameHandler *initGhFromHostingConnection(CConnection &c);
|
|
|
|
|
|
|
|
void newGame();
|
|
|
|
void loadGame();
|
|
|
|
void newPregame();
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2010-10-24 14:35:14 +03:00
|
|
|
|
|
|
|
class CPregameServer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CConnection *host;
|
|
|
|
int listeningThreads;
|
|
|
|
std::set<CConnection *> connections;
|
|
|
|
std::list<CPackForSelectionScreen*> toAnnounce;
|
|
|
|
boost::recursive_mutex mx;
|
|
|
|
|
|
|
|
//std::vector<CMapInfo> maps;
|
|
|
|
TAcceptor *acceptor;
|
|
|
|
TSocket *upcomingConnection;
|
|
|
|
|
|
|
|
const CMapInfo *curmap;
|
|
|
|
StartInfo *curStartInfo;
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
CPregameServer(CConnection *Host, TAcceptor *Acceptor = nullptr);
|
2010-10-24 14:35:14 +03:00
|
|
|
~CPregameServer();
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
|
|
|
void processPack(CPackForSelectionScreen * pack);
|
|
|
|
void handleConnection(CConnection *cpc);
|
|
|
|
void connectionAccepted(const boost::system::error_code& ec);
|
|
|
|
void initConnection(CConnection *c);
|
|
|
|
|
|
|
|
void start_async_accept();
|
|
|
|
|
|
|
|
enum { INVALID, RUNNING, ENDING_WITHOUT_START, ENDING_AND_STARTING_GAME
|
|
|
|
} state;
|
|
|
|
|
|
|
|
void announceTxt(const std::string &txt, const std::string &playerName = "system");
|
|
|
|
void announcePack(const CPackForSelectionScreen &pack);
|
|
|
|
|
|
|
|
void sendPack(CConnection * pc, const CPackForSelectionScreen & pack);
|
|
|
|
void startListeningThread(CConnection * pc);
|
|
|
|
};
|
2013-06-21 23:59:32 +03:00
|
|
|
|
|
|
|
extern boost::program_options::variables_map cmdLineOptions;
|