1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Gracefully ending.

This commit is contained in:
Michał W. Urbańczyk 2011-09-29 13:42:07 +00:00
parent b69f18df41
commit 1282ad4573
2 changed files with 20 additions and 4 deletions

View File

@ -638,6 +638,12 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
{
pack = c.retreivePack();
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
if(packType != typeList.getTypeID<QueryReply>()
&&(packType != typeList.getTypeID<ArrangeStacks>() || !isAllowedArrangePack((ArrangeStacks*)pack)) // for dialogs like garrison

View File

@ -500,7 +500,9 @@ void CVCMIServer::loadGame()
void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI, const std::string &rightAI)
{
//we need three connections
boost::thread* threads[3] = {0};
CConnection *conns[3] = {0};
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;
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");
@ -559,7 +561,13 @@ void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI
tlog0 << "Battle over!\n";
delNull(gh);
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";
exit(0);
}
@ -581,8 +589,10 @@ int main(int argc, char** argv)
{
io_service io_service;
CVCMIServer server;
assert(argc == 4);
server.startDuel(argv[1], argv[2], argv[3]);
if(argc == 4)
server.startDuel(argv[1], argv[2], argv[3]);
else
server.startDuel("b1.json", "StupidAI", "StupidAI");
while(!end2)
{