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
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <boost/program_options.hpp>
|
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;
|
2017-06-04 14:59:11 +02:00
|
|
|
struct SharedMemory;
|
2010-10-24 14:35:14 +03:00
|
|
|
|
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
|
|
|
|
{
|
2016-12-04 11:54:26 +02:00
|
|
|
ui16 port;
|
2009-04-16 14:14:13 +03:00
|
|
|
boost::asio::io_service *io;
|
2010-10-24 14:35:14 +03:00
|
|
|
TAcceptor * acceptor;
|
2017-06-04 14:59:11 +02:00
|
|
|
SharedMemory * shared;
|
2010-10-24 14:35:14 +03:00
|
|
|
|
|
|
|
CConnection *firstConnection;
|
2009-04-16 14:14:13 +03:00
|
|
|
public:
|
2017-07-17 23:04:00 +02:00
|
|
|
CVCMIServer();
|
|
|
|
~CVCMIServer();
|
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();
|
2017-05-25 19:57:20 +02:00
|
|
|
|
|
|
|
#ifdef VCMI_ANDROID
|
|
|
|
static void create();
|
|
|
|
#endif
|
2009-04-16 14:14:13 +03:00
|
|
|
};
|
2010-10-24 14:35:14 +03:00
|
|
|
|
2017-05-25 19:57:20 +02:00
|
|
|
struct StartInfo;
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-11-28 20:00:56 +02:00
|
|
|
extern boost::program_options::variables_map cmdLineOptions;
|