|
@@ -937,7 +937,7 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
|
|
|
|
|
|
packType = typeList.getTypeID(pack); //get the id of type
|
|
packType = typeList.getTypeID(pack); //get the id of type
|
|
|
|
|
|
- logGlobal->traceStream() << boost::format("Received client message (request %d by player %d) of type with ID=%d (%s).\n")
|
|
|
|
|
|
+ logGlobal->traceStream() << boost::format("Received client message (request %d by player %d) of type with ID=%d (%s).\n")
|
|
% requestID % player.getNum() % packType % typeid(*pack).name();
|
|
% requestID % player.getNum() % packType % typeid(*pack).name();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -964,7 +964,7 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
|
|
if(!result)
|
|
if(!result)
|
|
{
|
|
{
|
|
complain((boost::format("Got false in applying %s... that request must have been fishy!")
|
|
complain((boost::format("Got false in applying %s... that request must have been fishy!")
|
|
- % typeid(*pack).name()).str());
|
|
|
|
|
|
+ % typeid(*pack).name()).str());
|
|
}
|
|
}
|
|
logGlobal->traceStream() << "Message successfully applied (result=" << result << ")!";
|
|
logGlobal->traceStream() << "Message successfully applied (result=" << result << ")!";
|
|
sendPackageResponse(true);
|
|
sendPackageResponse(true);
|
|
@@ -981,7 +981,7 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
|
|
catch(boost::system::system_error &e) //for boost errors just log, not crash - probably client shut down connection
|
|
catch(boost::system::system_error &e) //for boost errors just log, not crash - probably client shut down connection
|
|
{
|
|
{
|
|
assert(!c.connected); //make sure that connection has been marked as broken
|
|
assert(!c.connected); //make sure that connection has been marked as broken
|
|
- logGlobal->errorStream() << e.what();
|
|
|
|
|
|
+ logGlobal->errorStream() << e.what();
|
|
end2 = true;
|
|
end2 = true;
|
|
}
|
|
}
|
|
catch(...)
|
|
catch(...)
|
|
@@ -991,7 +991,7 @@ void CGameHandler::handleConnection(std::set<PlayerColor> players, CConnection &
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
- logGlobal->errorStream() << "Ended handling connection";
|
|
|
|
|
|
+ logGlobal->errorStream() << "Ended handling connection";
|
|
}
|
|
}
|
|
|
|
|
|
int CGameHandler::moveStack(int stack, BattleHex dest)
|
|
int CGameHandler::moveStack(int stack, BattleHex dest)
|
|
@@ -1328,9 +1328,9 @@ void CGameHandler::init(StartInfo *si)
|
|
}
|
|
}
|
|
|
|
|
|
gs = new CGameState();
|
|
gs = new CGameState();
|
|
- logGlobal->infoStream() << "Gamestate created!";
|
|
|
|
|
|
+ logGlobal->infoStream() << "Gamestate created!";
|
|
gs->init(si);
|
|
gs->init(si);
|
|
- logGlobal->infoStream() << "Gamestate initialized!";
|
|
|
|
|
|
+ logGlobal->infoStream() << "Gamestate initialized!";
|
|
|
|
|
|
// reset seed, so that clients can't predict any following random values
|
|
// reset seed, so that clients can't predict any following random values
|
|
gs->getRandomGenerator().resetSeed();
|
|
gs->getRandomGenerator().resetSeed();
|
|
@@ -1343,7 +1343,7 @@ void CGameHandler::init(StartInfo *si)
|
|
|
|
|
|
static bool evntCmp(const CMapEvent &a, const CMapEvent &b)
|
|
static bool evntCmp(const CMapEvent &a, const CMapEvent &b)
|
|
{
|
|
{
|
|
- return a.earlierThan(b);
|
|
|
|
|
|
+ return a.earlierThan(b);
|
|
}
|
|
}
|
|
|
|
|
|
void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=false, bool clear = false)
|
|
void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=false, bool clear = false)
|
|
@@ -1351,7 +1351,7 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa
|
|
const PlayerState *p = gs->getPlayer(town->tempOwner);
|
|
const PlayerState *p = gs->getPlayer(town->tempOwner);
|
|
if(!p)
|
|
if(!p)
|
|
{
|
|
{
|
|
- logGlobal->warnStream() << "There is no player owner of town " << town->name << " at " << town->pos;
|
|
|
|
|
|
+ logGlobal->warnStream() << "There is no player owner of town " << town->name << " at " << town->pos;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1389,7 +1389,7 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa
|
|
|
|
|
|
void CGameHandler::newTurn()
|
|
void CGameHandler::newTurn()
|
|
{
|
|
{
|
|
- logGlobal->traceStream() << "Turn " << gs->day+1;
|
|
|
|
|
|
+ logGlobal->traceStream() << "Turn " << gs->day+1;
|
|
NewTurn n;
|
|
NewTurn n;
|
|
n.specialWeek = NewTurn::NO_ACTION;
|
|
n.specialWeek = NewTurn::NO_ACTION;
|
|
n.creatureid = CreatureID::NONE;
|
|
n.creatureid = CreatureID::NONE;
|
|
@@ -1702,7 +1702,7 @@ void CGameHandler::newTurn()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- logGlobal->traceStream() << "Info about turn " << n.day << "has been sent!";
|
|
|
|
|
|
+ logGlobal->traceStream() << "Info about turn " << n.day << "has been sent!";
|
|
handleTimeEvents();
|
|
handleTimeEvents();
|
|
//call objects
|
|
//call objects
|
|
for(auto & elem : gs->map->objects)
|
|
for(auto & elem : gs->map->objects)
|
|
@@ -1747,17 +1747,17 @@ void CGameHandler::run(bool resume)
|
|
std::set<PlayerColor> players;
|
|
std::set<PlayerColor> players;
|
|
(*cc) >> players; //how many players will be handled at that client
|
|
(*cc) >> players; //how many players will be handled at that client
|
|
|
|
|
|
- std::stringstream sbuffer;
|
|
|
|
- sbuffer << "Connection " << cc->connectionID << " will handle " << players.size() << " player: ";
|
|
|
|
|
|
+ std::stringstream sbuffer;
|
|
|
|
+ sbuffer << "Connection " << cc->connectionID << " will handle " << players.size() << " player: ";
|
|
for(PlayerColor color : players)
|
|
for(PlayerColor color : players)
|
|
{
|
|
{
|
|
- sbuffer << color << " ";
|
|
|
|
|
|
+ sbuffer << color << " ";
|
|
{
|
|
{
|
|
boost::unique_lock<boost::recursive_mutex> lock(gsm);
|
|
boost::unique_lock<boost::recursive_mutex> lock(gsm);
|
|
connections[color] = cc;
|
|
connections[color] = cc;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- logGlobal->infoStream() << sbuffer.str();
|
|
|
|
|
|
+ logGlobal->infoStream() << sbuffer.str();
|
|
|
|
|
|
cc->addStdVecItems(gs);
|
|
cc->addStdVecItems(gs);
|
|
cc->enableStackSendingByID();
|
|
cc->enableStackSendingByID();
|
|
@@ -1931,7 +1931,7 @@ bool CGameHandler::removeObject( const CGObjectInstance * obj )
|
|
{
|
|
{
|
|
if(!obj || !getObj(obj->id))
|
|
if(!obj || !getObj(obj->id))
|
|
{
|
|
{
|
|
- logGlobal->errorStream() << "Something wrong, that object already has been removed or hasn't existed!";
|
|
|
|
|
|
+ logGlobal->errorStream() << "Something wrong, that object already has been removed or hasn't existed!";
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1956,16 +1956,16 @@ bool CGameHandler::moveHero( ObjectInstanceID hid, int3 dst, ui8 teleporting, bo
|
|
if(!h || (asker != PlayerColor::NEUTRAL && (teleporting || h->getOwner() != gs->currentPlayer)) //not turn of that hero or player can't simply teleport hero (at least not with this function)
|
|
if(!h || (asker != PlayerColor::NEUTRAL && (teleporting || h->getOwner() != gs->currentPlayer)) //not turn of that hero or player can't simply teleport hero (at least not with this function)
|
|
)
|
|
)
|
|
{
|
|
{
|
|
- logGlobal->errorStream() << "Illegal call to move hero!";
|
|
|
|
|
|
+ logGlobal->errorStream() << "Illegal call to move hero!";
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- logGlobal->traceStream() << "Player " << asker << " wants to move hero "<< hid.getNum() << " from "<< h->pos << " to " << dst;
|
|
|
|
|
|
+ logGlobal->traceStream() << "Player " << asker << " wants to move hero "<< hid.getNum() << " from "<< h->pos << " to " << dst;
|
|
const int3 hmpos = CGHeroInstance::convertPosition(dst, false);
|
|
const int3 hmpos = CGHeroInstance::convertPosition(dst, false);
|
|
|
|
|
|
if(!gs->map->isInTheMap(hmpos))
|
|
if(!gs->map->isInTheMap(hmpos))
|
|
{
|
|
{
|
|
- logGlobal->errorStream() << "Destination tile is outside the map!";
|
|
|
|
|
|
+ logGlobal->errorStream() << "Destination tile is outside the map!";
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2142,7 +2142,7 @@ bool CGameHandler::teleportHero(ObjectInstanceID hid, ObjectInstanceID dstid, ui
|
|
const CGTownInstance *t = getTown(dstid);
|
|
const CGTownInstance *t = getTown(dstid);
|
|
|
|
|
|
if ( !h || !t || h->getOwner() != gs->currentPlayer )
|
|
if ( !h || !t || h->getOwner() != gs->currentPlayer )
|
|
- logGlobal->errorStream()<<"Invalid call to teleportHero!";
|
|
|
|
|
|
+ logGlobal->errorStream() << "Invalid call to teleportHero!";
|
|
|
|
|
|
const CGTownInstance *from = h->visitedTown;
|
|
const CGTownInstance *from = h->visitedTown;
|
|
if(((h->getOwner() != t->getOwner())
|
|
if(((h->getOwner() != t->getOwner())
|
|
@@ -2519,7 +2519,7 @@ void CGameHandler::heroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2)
|
|
|
|
|
|
void CGameHandler::sendToAllClients( CPackForClient * info )
|
|
void CGameHandler::sendToAllClients( CPackForClient * info )
|
|
{
|
|
{
|
|
- logGlobal->traceStream() << "Sending to all clients a package of type " << typeid(*info).name();
|
|
|
|
|
|
+ logGlobal->traceStream() << "Sending to all clients a package of type " << typeid(*info).name();
|
|
for(auto & elem : conns)
|
|
for(auto & elem : conns)
|
|
{
|
|
{
|
|
boost::unique_lock<boost::mutex> lock(*(elem)->wmx);
|
|
boost::unique_lock<boost::mutex> lock(*(elem)->wmx);
|
|
@@ -2565,13 +2565,13 @@ void CGameHandler::sendAndApply( NewStructures * info )
|
|
|
|
|
|
void CGameHandler::save(const std::string & filename )
|
|
void CGameHandler::save(const std::string & filename )
|
|
{
|
|
{
|
|
- logGlobal->infoStream() << "Saving to " << filename;
|
|
|
|
|
|
+ logGlobal->infoStream() << "Saving to " << filename;
|
|
const auto stem = FileInfo::GetPathStem(filename);
|
|
const auto stem = FileInfo::GetPathStem(filename);
|
|
const auto savefname = stem.to_string() + ".vsgm1";
|
|
const auto savefname = stem.to_string() + ".vsgm1";
|
|
CResourceHandler::get("local")->createResource(savefname);
|
|
CResourceHandler::get("local")->createResource(savefname);
|
|
|
|
|
|
{
|
|
{
|
|
- logGlobal->infoStream() << "Ordering clients to serialize...";
|
|
|
|
|
|
+ logGlobal->infoStream() << "Ordering clients to serialize...";
|
|
SaveGame sg(savefname);
|
|
SaveGame sg(savefname);
|
|
sendToAllClients(&sg);
|
|
sendToAllClients(&sg);
|
|
}
|
|
}
|
|
@@ -2589,20 +2589,20 @@ void CGameHandler::save(const std::string & filename )
|
|
{
|
|
{
|
|
CSaveFile save(*CResourceHandler::get("local")->getResourceName(ResourceID(stem.to_string(), EResType::SERVER_SAVEGAME)));
|
|
CSaveFile save(*CResourceHandler::get("local")->getResourceName(ResourceID(stem.to_string(), EResType::SERVER_SAVEGAME)));
|
|
saveCommonState(save);
|
|
saveCommonState(save);
|
|
- logGlobal->infoStream() << "Saving server state";
|
|
|
|
|
|
+ logGlobal->infoStream() << "Saving server state";
|
|
save << *this;
|
|
save << *this;
|
|
}
|
|
}
|
|
- logGlobal->infoStream() << "Game has been successfully saved!";
|
|
|
|
|
|
+ logGlobal->infoStream() << "Game has been successfully saved!";
|
|
}
|
|
}
|
|
catch(std::exception &e)
|
|
catch(std::exception &e)
|
|
{
|
|
{
|
|
- logGlobal->errorStream() << "Failed to save game: " << e.what();
|
|
|
|
|
|
+ logGlobal->errorStream() << "Failed to save game: " << e.what();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void CGameHandler::close()
|
|
void CGameHandler::close()
|
|
{
|
|
{
|
|
- logGlobal->infoStream() << "We have been requested to close.";
|
|
|
|
|
|
+ logGlobal->infoStream() << "We have been requested to close.";
|
|
|
|
|
|
if(gs->initialOpts->mode == StartInfo::DUEL)
|
|
if(gs->initialOpts->mode == StartInfo::DUEL)
|
|
{
|
|
{
|
|
@@ -3784,7 +3784,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
|
BattleHex startingPos = stack->position;
|
|
BattleHex startingPos = stack->position;
|
|
int distance = moveStack(ba.stackNumber, ba.destinationTile);
|
|
int distance = moveStack(ba.stackNumber, ba.destinationTile);
|
|
|
|
|
|
- logGlobal->traceStream() << stack->nodeName() << " will attack " << destinationStack->nodeName();
|
|
|
|
|
|
+ logGlobal->traceStream() << stack->nodeName() << " will attack " << destinationStack->nodeName();
|
|
|
|
|
|
if(stack->position != ba.destinationTile //we wasn't able to reach destination tile
|
|
if(stack->position != ba.destinationTile //we wasn't able to reach destination tile
|
|
&& !(stack->doubleWide()
|
|
&& !(stack->doubleWide()
|
|
@@ -3793,7 +3793,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
|
)
|
|
)
|
|
{
|
|
{
|
|
std::string problem = "We cannot move this stack to its destination " + stack->getCreature()->namePl;
|
|
std::string problem = "We cannot move this stack to its destination " + stack->getCreature()->namePl;
|
|
- logGlobal->warnStream() << problem;
|
|
|
|
|
|
+ logGlobal->warnStream() << problem;
|
|
complain(problem);
|
|
complain(problem);
|
|
ok = false;
|
|
ok = false;
|
|
sendAndApply(&end_action);
|
|
sendAndApply(&end_action);
|
|
@@ -4024,7 +4024,7 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
|
attack.destinationTile = gs->curB->wallPartToBattleHex(EWallPart::EWallPart(attack.attackedPart));
|
|
attack.destinationTile = gs->curB->wallPartToBattleHex(EWallPart::EWallPart(attack.attackedPart));
|
|
|
|
|
|
logGlobal->traceStream() << "Catapult attacks " << (int)attack.attackedPart
|
|
logGlobal->traceStream() << "Catapult attacks " << (int)attack.attackedPart
|
|
- << " dealing " << (int)attack.damageDealt << " damage";
|
|
|
|
|
|
+ << " dealing " << (int)attack.damageDealt << " damage";
|
|
|
|
|
|
//removing creatures in turrets / keep if one is destroyed
|
|
//removing creatures in turrets / keep if one is destroyed
|
|
if(attack.damageDealt > 0 && (attackedPart == EWallPart::KEEP ||
|
|
if(attack.damageDealt > 0 && (attackedPart == EWallPart::KEEP ||
|
|
@@ -4370,12 +4370,12 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
|
|
const CGHeroInstance *h = gs->curB->battleGetFightingHero(ba.side);
|
|
const CGHeroInstance *h = gs->curB->battleGetFightingHero(ba.side);
|
|
if(!h)
|
|
if(!h)
|
|
{
|
|
{
|
|
- logGlobal->warnStream() << "Wrong caster!";
|
|
|
|
|
|
+ logGlobal->warnStream() << "Wrong caster!";
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
if(ba.additionalInfo >= VLC->spellh->objects.size())
|
|
if(ba.additionalInfo >= VLC->spellh->objects.size())
|
|
{
|
|
{
|
|
- logGlobal->warnStream() << "Wrong spell id (" << ba.additionalInfo << ")!";
|
|
|
|
|
|
+ logGlobal->warnStream() << "Wrong spell id (" << ba.additionalInfo << ")!";
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4702,7 +4702,7 @@ void CGameHandler::handleTimeEvents()
|
|
|
|
|
|
ev.firstOccurence += ev.nextOccurence;
|
|
ev.firstOccurence += ev.nextOccurence;
|
|
auto it = gs->map->events.begin();
|
|
auto it = gs->map->events.begin();
|
|
- while ( it !=gs->map->events.end() && it->earlierThanOrEqual(ev))
|
|
|
|
|
|
+ while(it != gs->map->events.end() && it->earlierThanOrEqual(ev))
|
|
it++;
|
|
it++;
|
|
gs->map->events.insert(it, ev);
|
|
gs->map->events.insert(it, ev);
|
|
}
|
|
}
|
|
@@ -4785,7 +4785,7 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n)
|
|
|
|
|
|
ev.firstOccurence += ev.nextOccurence;
|
|
ev.firstOccurence += ev.nextOccurence;
|
|
auto it = town->events.begin();
|
|
auto it = town->events.begin();
|
|
- while ( it != town->events.end() && it->earlierThanOrEqual(ev))
|
|
|
|
|
|
+ while(it != town->events.end() && it->earlierThanOrEqual(ev))
|
|
it++;
|
|
it++;
|
|
town->events.insert(it, ev);
|
|
town->events.insert(it, ev);
|
|
}
|
|
}
|
|
@@ -4805,7 +4805,7 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n)
|
|
bool CGameHandler::complain( const std::string &problem )
|
|
bool CGameHandler::complain( const std::string &problem )
|
|
{
|
|
{
|
|
sendMessageToAll("Server encountered a problem: " + problem);
|
|
sendMessageToAll("Server encountered a problem: " + problem);
|
|
- logGlobal->errorStream() << problem;
|
|
|
|
|
|
+ logGlobal->errorStream() << problem;
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -5760,8 +5760,8 @@ void CGameHandler::runBattle()
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- logGlobal->traceStream() << "Activating " << next->nodeName();
|
|
|
|
- auto nextId = next->ID;
|
|
|
|
|
|
+ logGlobal->traceStream() << "Activating " << next->nodeName();
|
|
|
|
+ auto nextId = next->ID;
|
|
BattleSetActiveStack sas;
|
|
BattleSetActiveStack sas;
|
|
sas.stack = nextId;
|
|
sas.stack = nextId;
|
|
sendAndApply(&sas);
|
|
sendAndApply(&sas);
|
|
@@ -5935,12 +5935,12 @@ void CGameHandler::spawnWanderingMonsters(CreatureID creatureID)
|
|
getFreeTiles(tiles);
|
|
getFreeTiles(tiles);
|
|
ui32 amount = tiles.size() / 200; //Chance is 0.5% for each tile
|
|
ui32 amount = tiles.size() / 200; //Chance is 0.5% for each tile
|
|
std::random_shuffle(tiles.begin(), tiles.end());
|
|
std::random_shuffle(tiles.begin(), tiles.end());
|
|
- logGlobal->traceStream() << "Spawning wandering monsters. Found " << tiles.size() << " free tiles. Creature type: " << creatureID;
|
|
|
|
|
|
+ logGlobal->traceStream() << "Spawning wandering monsters. Found " << tiles.size() << " free tiles. Creature type: " << creatureID;
|
|
const CCreature *cre = VLC->creh->creatures.at(creatureID);
|
|
const CCreature *cre = VLC->creh->creatures.at(creatureID);
|
|
for (int i = 0; i < amount; ++i)
|
|
for (int i = 0; i < amount; ++i)
|
|
{
|
|
{
|
|
tile = tiles.begin();
|
|
tile = tiles.begin();
|
|
- logGlobal->traceStream() << "\tSpawning monster at " << *tile;
|
|
|
|
|
|
+ logGlobal->traceStream() << "\tSpawning monster at " << *tile;
|
|
putNewMonster(creatureID, cre->getRandomAmount(std::rand), *tile);
|
|
putNewMonster(creatureID, cre->getRandomAmount(std::rand), *tile);
|
|
tiles.erase(tile); //not use it again
|
|
tiles.erase(tile); //not use it again
|
|
}
|
|
}
|
|
@@ -6134,7 +6134,7 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl
|
|
{
|
|
{
|
|
if(st->alive() && st->count > 0)
|
|
if(st->alive() && st->count > 0)
|
|
{
|
|
{
|
|
- logGlobal->debugStream() << "Permanently summoned " + st->count << " units.";
|
|
|
|
|
|
+ logGlobal->debugStream() << "Permanently summoned " << st->count << " units.";
|
|
const CreatureID summonedType = st->type->idNumber;
|
|
const CreatureID summonedType = st->type->idNumber;
|
|
summoned[summonedType] += st->count;
|
|
summoned[summonedType] += st->count;
|
|
}
|
|
}
|