mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-19 21:10:12 +02:00
Gracefully ending.
This commit is contained in:
parent
b69f18df41
commit
1282ad4573
@ -638,6 +638,12 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
|
|||||||
{
|
{
|
||||||
pack = c.retreivePack();
|
pack = c.retreivePack();
|
||||||
int packType = typeList.getTypeID(pack); //get the id of type
|
int packType = typeList.getTypeID(pack); //get the id of type
|
||||||
|
if(packType == typeList.getTypeID<CloseServer>())
|
||||||
|
{
|
||||||
|
tlog0 << "Ending listening thread for side " << *players.begin() << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CBaseForGHApply *apply = applier->apps[packType]; //and appropriae applier object
|
CBaseForGHApply *apply = applier->apps[packType]; //and appropriae applier object
|
||||||
if(packType != typeList.getTypeID<QueryReply>()
|
if(packType != typeList.getTypeID<QueryReply>()
|
||||||
&&(packType != typeList.getTypeID<ArrangeStacks>() || !isAllowedArrangePack((ArrangeStacks*)pack)) // for dialogs like garrison
|
&&(packType != typeList.getTypeID<ArrangeStacks>() || !isAllowedArrangePack((ArrangeStacks*)pack)) // for dialogs like garrison
|
||||||
|
@ -500,7 +500,9 @@ void CVCMIServer::loadGame()
|
|||||||
|
|
||||||
void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI, const std::string &rightAI)
|
void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI, const std::string &rightAI)
|
||||||
{
|
{
|
||||||
|
|
||||||
//we need three connections
|
//we need three connections
|
||||||
|
boost::thread* threads[3] = {0};
|
||||||
CConnection *conns[3] = {0};
|
CConnection *conns[3] = {0};
|
||||||
for (int i = 0; i < 3 ; i++)
|
for (int i = 0; i < 3 ; i++)
|
||||||
{
|
{
|
||||||
@ -545,7 +547,7 @@ void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI
|
|||||||
|
|
||||||
std::set<int> pom;
|
std::set<int> pom;
|
||||||
pom.insert(player);
|
pom.insert(player);
|
||||||
boost::thread(boost::bind(&CGameHandler::handleConnection,gh,pom,boost::ref(*c)));
|
threads[player] = new boost::thread(boost::bind(&CGameHandler::handleConnection, gh, pom, boost::ref(*c)));
|
||||||
}
|
}
|
||||||
|
|
||||||
tlog0 << boost::format("Sending start info to connections!\n");
|
tlog0 << boost::format("Sending start info to connections!\n");
|
||||||
@ -559,7 +561,13 @@ void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI
|
|||||||
tlog0 << "Battle over!\n";
|
tlog0 << "Battle over!\n";
|
||||||
delNull(gh);
|
delNull(gh);
|
||||||
tlog0 << "Removed gh!\n";
|
tlog0 << "Removed gh!\n";
|
||||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
tlog0 << "Waiting for connections to close\n";
|
||||||
|
BOOST_FOREACH(boost::thread *t, threads)
|
||||||
|
{
|
||||||
|
t->join();
|
||||||
|
delNull(t);
|
||||||
|
}
|
||||||
|
|
||||||
tlog0 << "Dying...\n";
|
tlog0 << "Dying...\n";
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -581,8 +589,10 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
io_service io_service;
|
io_service io_service;
|
||||||
CVCMIServer server;
|
CVCMIServer server;
|
||||||
assert(argc == 4);
|
if(argc == 4)
|
||||||
server.startDuel(argv[1], argv[2], argv[3]);
|
server.startDuel(argv[1], argv[2], argv[3]);
|
||||||
|
else
|
||||||
|
server.startDuel("b1.json", "StupidAI", "StupidAI");
|
||||||
|
|
||||||
while(!end2)
|
while(!end2)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user