1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Zmiany do Programming challenge.

This commit is contained in:
Michał W. Urbańczyk
2011-09-27 21:54:40 +00:00
parent 5d4cfc0d0f
commit bdd66b6537
21 changed files with 588 additions and 82 deletions

View File

@@ -335,7 +335,6 @@ CGameHandler * CVCMIServer::initGhFromHostingConnection(CConnection &c)
c << ui8(0); //OK!
}
gh->init(&si,std::time(NULL));
c.addStdVecItems(gh->gs);
gh->conns.insert(&c);
@@ -499,6 +498,51 @@ void CVCMIServer::loadGame()
gh.run(true);
}
void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI, const std::string &rightAI)
{
//we need three connections
CConnection *conns[3] = {0};
for (int i = 0; i < 3 ; i++)
{
boost::system::error_code error;
tcp::socket * s = new tcp::socket(acceptor->get_io_service());
acceptor->accept(*s, error);
if (error)
{
tlog2<<"Got connection but there is an error " << std::endl << error;
i--;
delNull(s);
}
else
{
tlog0<<"We've accepted someone... " << std::endl;
conns[i] = new CConnection(s, NAME);
tlog0<<"Got connection!" << std::endl;
}
}
StartInfo si;
si.mode = StartInfo::DUEL;
si.mapname = battle;
CGameHandler *gh = new CGameHandler();
gh->init(&si,std::time(NULL));
BOOST_FOREACH(CConnection *c, conns)
{
c->addStdVecItems(gh->gs, VLC);
gh->connections[gh->conns.size()] = c;
gh->conns.insert(c);
}
gh->runBattle();
delNull(gh);
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
exit(0);
}
#ifndef __GNUC__
int _tmain(int argc, _TCHAR* argv[])
#else
@@ -523,6 +567,9 @@ int main(int argc, char** argv)
{
io_service io_service;
CVCMIServer server;
assert(argc == 4);
server.startDuel(argv[1], argv[2], argv[3]);
while(!end2)
{
server.start();