[Server] Make style for new methods consistent with rest of project

pull/158/head
David Cernat 8 years ago
parent fd36ec7613
commit 887b436ee7

@ -12,19 +12,19 @@ using namespace std;
void Cell::addPlayer(Player *player) void Cell::addPlayer(Player *player)
{ {
auto it = find(player->cells.begin(), player->cells.end(), this); auto it = find(player->cells.begin(), player->cells.end(), this);
if(it == player->cells.end()) if (it == player->cells.end())
player->cells.push_back(this); player->cells.push_back(this);
players.push_back(player); players.push_back(player);
} }
void Cell::removePlayer(Player *player) void Cell::removePlayer(Player *player)
{ {
for(Iterator it = begin(); it != end(); it++) for (Iterator it = begin(); it != end(); it++)
{ {
if(*it == player) if (*it == player)
{ {
auto it2 = find(player->cells.begin(), player->cells.end(), this); auto it2 = find(player->cells.begin(), player->cells.end(), this);
if(it2 != player->cells.end()) if (it2 != player->cells.end())
player->cells.erase(it2); player->cells.erase(it2);
players.erase(it); players.erase(it);
return; return;
@ -73,7 +73,7 @@ Cell *CellController::getCellByXY(int x, int y)
auto it = find_if(cells.begin(), cells.end(), [x, y](const Cell *c) { auto it = find_if(cells.begin(), cells.end(), [x, y](const Cell *c) {
return c->cell.mData.mX == x && c->cell.mData.mY == y; return c->cell.mData.mX == x && c->cell.mData.mY == y;
}); });
if(it == cells.end()) if (it == cells.end())
return nullptr; return nullptr;
return *it; return *it;
} }
@ -83,7 +83,7 @@ Cell *CellController::getCellByID(std::string cellid)
auto it = find_if(cells.begin(), cells.end(), [cellid](const Cell *c) { auto it = find_if(cells.begin(), cells.end(), [cellid](const Cell *c) {
return c->cell.mName == cellid; return c->cell.mName == cellid;
}); });
if(it == cells.end()) if (it == cells.end())
return nullptr; return nullptr;
return *it; return *it;
} }
@ -98,7 +98,7 @@ Cell *CellController::addCell(ESM::Cell cellData)
c->cell.mCellId.mWorldspace == cellData.mCellId.mWorldspace; c->cell.mCellId.mWorldspace == cellData.mCellId.mWorldspace;
}); });
Cell *cell; Cell *cell;
if(it == cells.end()) if (it == cells.end())
{ {
cell = new Cell(cellData); cell = new Cell(cellData);
cells.push_back(cell); cells.push_back(cell);
@ -112,11 +112,11 @@ Cell *CellController::addCell(ESM::Cell cellData)
void CellController::removeCell(Cell *cell) void CellController::removeCell(Cell *cell)
{ {
if(cell == nullptr) if (cell == nullptr)
return; return;
for (auto it = cells.begin(); it != cells.end();) for (auto it = cells.begin(); it != cells.end();)
{ {
if(*it != nullptr && *it == cell) if (*it != nullptr && *it == cell)
{ {
delete *it; delete *it;
it = cells.erase(it); it = cells.erase(it);
@ -131,7 +131,7 @@ void CellController::removePlayer(Cell *cell, Player *player)
cell->removePlayer(player); cell->removePlayer(player);
if(cell->players.empty()) if (cell->players.empty())
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Deleting empty cell from memory: %s", player->npc.mName, player->getId(), cell->cell.getDescription().c_str()); LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Deleting empty cell from memory: %s", player->npc.mName, player->getId(), cell->cell.getDescription().c_str());
auto it = find(cells.begin(), cells.end(), cell); auto it = find(cells.begin(), cells.end(), cell);
@ -156,9 +156,9 @@ void CellController::deletePlayer(Player *player)
void CellController::update(Player *player) void CellController::update(Player *player)
{ {
for(auto cell : player->cellStateChanges.cellStates) for (auto cell : player->cellStateChanges.cellStates)
{ {
if(cell.type == mwmp::CellState::LOAD) if (cell.type == mwmp::CellState::LOAD)
{ {
Cell *c = addCell(cell.cell); Cell *c = addCell(cell.cell);
c->addPlayer(player); c->addPlayer(player);
@ -167,12 +167,12 @@ void CellController::update(Player *player)
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player %s (%d) unloaded cell: %s", player->npc.mName, player->getId(), cell.cell.getDescription().c_str()); LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player %s (%d) unloaded cell: %s", player->npc.mName, player->getId(), cell.cell.getDescription().c_str());
Cell *c; Cell *c;
if(!cell.cell.isExterior()) if (!cell.cell.isExterior())
c = getCellByID(cell.cell.mName); c = getCellByID(cell.cell.mName);
else else
c = getCellByXY(cell.cell.getGridX(), cell.cell.getGridY()); c = getCellByXY(cell.cell.getGridX(), cell.cell.getGridY());
if(c != nullptr) if (c != nullptr)
removePlayer(c, player); removePlayer(c, player);
} }
} }

@ -152,7 +152,7 @@ void MasterClient::Update()
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Update rate is too low, and the master server has deleted information about" LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Update rate is too low, and the master server has deleted information about"
" the server. Trying low rate..."); " the server. Trying low rate...");
if((timeout - step_rate) >= step_rate) if ((timeout - step_rate) >= step_rate)
SetUpdateRate(timeout - step_rate); SetUpdateRate(timeout - step_rate);
update = false; update = false;
} }
@ -177,10 +177,10 @@ void MasterClient::Start()
void MasterClient::Stop() void MasterClient::Stop()
{ {
if(!sRun) if (!sRun)
return; return;
sRun = false; sRun = false;
if(thrQuery.joinable()) if (thrQuery.joinable())
thrQuery.join(); thrQuery.join();
} }

@ -857,7 +857,7 @@ int Networking::mainLoop()
RakNet::BitStream bs; RakNet::BitStream bs;
bs.Write((unsigned char) ID_MASTER_QUERY); bs.Write((unsigned char) ID_MASTER_QUERY);
bs.Write(Players::getPlayers()->size()); bs.Write(Players::getPlayers()->size());
for(auto player : *Players::getPlayers()) for (auto player : *Players::getPlayers())
bs.Write(RakNet::RakString(player.second->npc.mName.c_str())); bs.Write(RakNet::RakString(player.second->npc.mName.c_str()));
bs.Write(0); // plugins bs.Write(0); // plugins
peer->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false); peer->Send(&bs, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->systemAddress, false);

@ -54,7 +54,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid)
Player *Players::getPlayer(RakNet::RakNetGUID guid) Player *Players::getPlayer(RakNet::RakNetGUID guid)
{ {
if(players.count(guid) == 0) if (players.count(guid) == 0)
return nullptr; return nullptr;
return players[guid]; return players[guid];
} }
@ -147,16 +147,16 @@ void Player::sendToLoaded(mwmp::PlayerPacket *myPacket)
{ {
std::list <Player*> plList; std::list <Player*> plList;
for(auto cell : getCells()) for (auto cell : getCells())
for (auto pl : *cell) for (auto pl : *cell)
plList.push_back(pl); plList.push_back(pl);
plList.sort(); plList.sort();
plList.unique(); plList.unique();
for(auto pl : plList) for (auto pl : plList)
{ {
if(pl == this) continue; if (pl == this) continue;
myPacket->Send(this, pl->guid); myPacket->Send(this, pl->guid);
} }
} }
@ -165,16 +165,16 @@ void Player::forEachLoaded(std::function<void(Player *pl, Player *other)> func)
{ {
std::list <Player*> plList; std::list <Player*> plList;
for(auto cell : getCells()) for (auto cell : getCells())
for (auto pl : *cell) for (auto pl : *cell)
plList.push_back(pl); plList.push_back(pl);
plList.sort(); plList.sort();
plList.unique(); plList.unique();
for(auto pl : plList) for (auto pl : plList)
{ {
if(pl == this) continue; if (pl == this) continue;
func(this, pl); func(this, pl);
} }
} }

Loading…
Cancel
Save