Minor styling tidy up

This commit is contained in:
Antz 2017-02-13 21:54:53 +00:00 committed by Antz
parent f959ae40b6
commit 63e73a18fa
2 changed files with 183 additions and 55 deletions

View file

@ -128,16 +128,24 @@ World::World(): mail_timer(0), mail_timer_expires(0), m_NextMonthlyQuestReset(0)
m_availableDbcLocaleMask = 0;
for (int i = 0; i < CONFIG_UINT32_VALUE_COUNT; ++i)
{ m_configUint32Values[i] = 0; }
{
m_configUint32Values[i] = 0;
}
for (int i = 0; i < CONFIG_INT32_VALUE_COUNT; ++i)
{ m_configInt32Values[i] = 0; }
{
m_configInt32Values[i] = 0;
}
for (int i = 0; i < CONFIG_FLOAT_VALUE_COUNT; ++i)
{ m_configFloatValues[i] = 0.0f; }
{
m_configFloatValues[i] = 0.0f;
}
for (int i = 0; i < CONFIG_BOOL_VALUE_COUNT; ++i)
{ m_configBoolValues[i] = false; }
{
m_configBoolValues[i] = false;
}
}
/// World destructor
@ -197,9 +205,13 @@ WorldSession* World::FindSession(uint32 id) const
SessionMap::const_iterator itr = m_sessions.find(id);
if (itr != m_sessions.end())
{ return itr->second; } // also can return NULL for kicked session
{
return itr->second;
} // also can return NULL for kicked session
else
{ return NULL; }
{
return NULL;
}
}
/// Remove a given session
@ -211,7 +223,9 @@ bool World::RemoveSession(uint32 id)
if (itr != m_sessions.end() && itr->second)
{
if (itr->second->PlayerLoading())
{ return false; }
{
return false;
}
itr->second->KickPlayer();
}
@ -253,7 +267,11 @@ World::AddSession_(WorldSession* s)
{
// prevent decrease sessions count if session queued
if (RemoveQueuedSession(old->second))
{ decrease_session = false; }
{
decrease_session = false;
}
// not remove replaced session form queue if listed
delete old->second;
}
}
@ -266,7 +284,9 @@ World::AddSession_(WorldSession* s)
// so we don't count the user trying to
// login as a session and queue the socket that we are using
if (decrease_session)
{ --Sessions; }
{
--Sessions;
}
if (pLimit > 0 && Sessions >= pLimit && s->GetSecurity() == SEC_PLAYER)
{
@ -323,7 +343,9 @@ int32 World::GetQueuedSessionPos(WorldSession* sess)
for (Queue::const_iterator iter = m_QueuedSessions.begin(); iter != m_QueuedSessions.end(); ++iter, ++position)
if ((*iter) == sess)
{ return position; }
{
return position;
}
return 0;
}
@ -379,7 +401,9 @@ bool World::RemoveQueuedSession(WorldSession* sess)
// if session not queued then we need decrease sessions count
if (!found && sessions)
{ --sessions; }
{
--sessions;
}
// accept first in queue
if ((!m_playerLimit || (int32)sessions < m_playerLimit) && !m_QueuedSessions.empty())
@ -406,7 +430,9 @@ bool World::RemoveQueuedSession(WorldSession* sess)
// update position from iter to end()
// iter point to first not updated socket, position store new position
for (; iter != m_QueuedSessions.end(); ++iter, ++position)
{ (*iter)->SendAuthWaitQue(position); }
{
(*iter)->SendAuthWaitQue(position);
}
return found;
}
@ -551,22 +577,32 @@ void World::LoadConfigSettings(bool reload)
setConfigMin(CONFIG_UINT32_INTERVAL_GRIDCLEAN, "GridCleanUpDelay", 5 * MINUTE * IN_MILLISECONDS, MIN_GRID_DELAY);
if (reload)
{ sMapMgr.SetGridCleanUpDelay(getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN)); }
{
sMapMgr.SetGridCleanUpDelay(getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN));
}
setConfigMin(CONFIG_UINT32_INTERVAL_MAPUPDATE, "MapUpdateInterval", 100, MIN_MAP_UPDATE_DELAY);
if (reload)
{ sMapMgr.SetMapUpdateInterval(getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE)); }
{
sMapMgr.SetMapUpdateInterval(getConfig(CONFIG_UINT32_INTERVAL_MAPUPDATE));
}
setConfig(CONFIG_UINT32_INTERVAL_CHANGEWEATHER, "ChangeWeatherInterval", 10 * MINUTE * IN_MILLISECONDS);
if (configNoReload(reload, CONFIG_UINT32_PORT_WORLD, "WorldServerPort", DEFAULT_WORLDSERVER_PORT))
{ setConfig(CONFIG_UINT32_PORT_WORLD, "WorldServerPort", DEFAULT_WORLDSERVER_PORT); }
{
setConfig(CONFIG_UINT32_PORT_WORLD, "WorldServerPort", DEFAULT_WORLDSERVER_PORT);
}
if (configNoReload(reload, CONFIG_UINT32_GAME_TYPE, "GameType", 0))
{ setConfig(CONFIG_UINT32_GAME_TYPE, "GameType", 0); }
{
setConfig(CONFIG_UINT32_GAME_TYPE, "GameType", 0);
}
if (configNoReload(reload, CONFIG_UINT32_REALM_ZONE, "RealmZone", REALM_ZONE_DEVELOPMENT))
{ setConfig(CONFIG_UINT32_REALM_ZONE, "RealmZone", REALM_ZONE_DEVELOPMENT); }
{
setConfig(CONFIG_UINT32_REALM_ZONE, "RealmZone", REALM_ZONE_DEVELOPMENT);
}
setConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_ACCOUNTS, "AllowTwoSide.Accounts", true);
setConfig(CONFIG_BOOL_ALLOW_TWO_SIDE_INTERACTION_CHAT, "AllowTwoSide.Interaction.Chat", false);
@ -601,7 +637,9 @@ void World::LoadConfigSettings(bool reload)
setConfigMinMax(CONFIG_UINT32_SKIP_CINEMATICS, "SkipCinematics", 0, 0, 2);
if (configNoReload(reload, CONFIG_UINT32_MAX_PLAYER_LEVEL, "MaxPlayerLevel", DEFAULT_MAX_LEVEL))
{ setConfigMinMax(CONFIG_UINT32_MAX_PLAYER_LEVEL, "MaxPlayerLevel", DEFAULT_MAX_LEVEL, 1, DEFAULT_MAX_LEVEL); }
{
setConfigMinMax(CONFIG_UINT32_MAX_PLAYER_LEVEL, "MaxPlayerLevel", DEFAULT_MAX_LEVEL, 1, DEFAULT_MAX_LEVEL);
}
setConfigMinMax(CONFIG_UINT32_START_PLAYER_LEVEL, "StartPlayerLevel", 1, 1, (uint32)getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL));
setConfigMinMax(CONFIG_UINT32_START_HEROIC_PLAYER_LEVEL, "StartHeroicPlayerLevel", 55, 1, getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL));
@ -889,9 +927,13 @@ void World::LoadConfigSettings(bool reload)
setConfig(CONFIG_UINT32_CHARDELETE_KEEP_DAYS, "CharDelete.KeepDays", 30);
if (configNoReload(reload, CONFIG_UINT32_GUID_RESERVE_SIZE_CREATURE, "GuidReserveSize.Creature", 100))
{ setConfig(CONFIG_UINT32_GUID_RESERVE_SIZE_CREATURE, "GuidReserveSize.Creature", 100); }
{
setConfig(CONFIG_UINT32_GUID_RESERVE_SIZE_CREATURE, "GuidReserveSize.Creature", 100);
}
if (configNoReload(reload, CONFIG_UINT32_GUID_RESERVE_SIZE_GAMEOBJECT, "GuidReserveSize.GameObject", 100))
{ setConfig(CONFIG_UINT32_GUID_RESERVE_SIZE_GAMEOBJECT, "GuidReserveSize.GameObject", 100); }
{
setConfig(CONFIG_UINT32_GUID_RESERVE_SIZE_GAMEOBJECT, "GuidReserveSize.GameObject", 100);
}
setConfig(CONFIG_UINT32_MIN_LEVEL_FOR_RAID, "Raid.MinLevel", 10);
@ -900,15 +942,21 @@ void World::LoadConfigSettings(bool reload)
// for empty string use current dir as for absent case
if (dataPath.empty())
{ dataPath = "./"; }
{
dataPath = "./";
}
// normalize dir path to path/ or path\ form
else if (dataPath.at(dataPath.length() - 1) != '/' && dataPath.at(dataPath.length() - 1) != '\\')
{ dataPath.append("/"); }
{
dataPath.append("/");
}
if (reload)
{
if (dataPath != m_dataPath)
{ sLog.outError("DataDir option can't be changed at mangosd.conf reload, using current value (%s).", m_dataPath.c_str()); }
{
sLog.outError("DataDir option can't be changed at mangosd.conf reload, using current value (%s).", m_dataPath.c_str());
}
}
else
{
@ -922,7 +970,9 @@ void World::LoadConfigSettings(bool reload)
std::string ignoreSpellIds = sConfig.GetStringDefault("vmap.ignoreSpellIds", "");
if (!enableHeight)
{ sLog.outError("VMAP height use disabled! Creatures movements and other things will be in broken state."); }
{
sLog.outError("VMAP height use disabled! Creatures movements and other things will be in broken state.");
}
VMAP::VMapFactory::createOrGetVMapManager()->setEnableLineOfSightCalc(enableLOS);
VMAP::VMapFactory::createOrGetVMapManager()->setEnableHeightCalc(enableHeight);
@ -1595,9 +1645,13 @@ void World::Update(uint32 diff)
for (int i = 0; i < WUPDATE_COUNT; ++i)
{
if (m_timers[i].GetCurrent() >= 0)
{ m_timers[i].Update(diff); }
{
m_timers[i].Update(diff);
}
else
{ m_timers[i].SetCurrent(0); }
{
m_timers[i].SetCurrent(0);
}
}
///- Update the game time and check for shutdown time
@ -1728,10 +1782,17 @@ namespace MaNGOS
do_helper(data_list, &str[0]);
}
else
{
do_helper(data_list, (char*)text);
}
}
private:
char* lineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = NULL; return start; }
char* lineFromMessage(char*& pos)
{
char* start = strtok(pos, "\n");
pos = NULL;
return start;
}
void do_helper(WorldPacketList& data_list, char* text)
{
char* pos = text;
@ -1763,7 +1824,9 @@ void World::SendWorldText(int32 string_id, ...)
{
Player* player = session->GetPlayer();
if (player && player->IsInWorld())
{
wt_do(player);
}
}
}
@ -1779,7 +1842,9 @@ void World::SendGlobalMessage(WorldPacket* packet)
{
Player* player = session->GetPlayer();
if (player && player->IsInWorld())
{
session->SendPacket(packet);
}
}
}
}
@ -1792,9 +1857,13 @@ void World::SendServerMessage(ServerMessageType type, const char* text /*=""*/,
data << text;
if (player)
{
player->GetSession()->SendPacket(&data);
}
else
{
SendGlobalMessage(&data);
}
}
/// Sends a zone under attack message to all players not in an instance
@ -1809,7 +1878,9 @@ void World::SendZoneUnderAttackMessage(uint32 zoneId, Team team)
{
Player* player = session->GetPlayer();
if (player && player->IsInWorld() && player->GetTeam() == team && !player->GetMap()->Instanceable())
{
itr->second->SendPacket(&data);
}
}
}
}
@ -1844,7 +1915,9 @@ void World::KickAll()
// session not removed at kick and will removed in next update tick
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
{
itr->second->KickPlayer();
}
}
/// Kick (and save) all players with security level less `sec`
@ -1854,7 +1927,9 @@ void World::KickAllLess(AccountTypes sec)
for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
if (WorldSession* session = itr->second)
if (session->GetSecurity() < sec)
{
session->KickPlayer();
}
}
/// Ban an account or ban an IP address, duration_secs if it is positive used, otherwise permban
@ -1890,9 +1965,13 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, uint32 duration_
if (!resultAccounts)
{
if (mode == BAN_IP)
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
{
return BAN_SUCCESS;
} // ip correctly banned but nobody affected (yet)
else
return BAN_NOTFOUND; // Nobody to ban
{
return BAN_NOTFOUND;
} // Nobody to ban
}
///- Disconnect all affected players (for IP it can be several)
@ -1910,15 +1989,15 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, uint32 duration_
if (WorldSession* sess = FindSession(account))
if (std::string(sess->GetPlayerName()) != author)
{
sess->KickPlayer();
}
while (resultAccounts->NextRow());
}
} while (resultAccounts->NextRow());
delete resultAccounts;
return BAN_SUCCESS;
}
/// Remove a ban from an account or IP address
bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
{
@ -1931,12 +2010,18 @@ bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
{
uint32 account = 0;
if (mode == BAN_ACCOUNT)
{
account = sAccountMgr.GetId(nameOrIP);
}
else if (mode == BAN_CHARACTER)
{
account = sObjectMgr.GetPlayerAccountIdByPlayerName(nameOrIP);
}
if (!account)
{
return false;
}
// NO SQL injection as account is uint32
LoginDatabase.PExecute("UPDATE account_banned SET active = '0' WHERE id = '%u'", account);
@ -1959,9 +2044,13 @@ void World::_UpdateGameTime()
if (m_ShutdownTimer <= elapsed)
{
if (!(m_ShutdownMask & SHUTDOWN_MASK_IDLE) || GetActiveAndQueuedSessionCount() == 0)
m_stopEvent = true; // exist code already set
{
m_stopEvent = true;
} // exist code already set
else
m_ShutdownTimer = 1; // minimum timer value to wait idle state
{
m_ShutdownTimer = 1;
} // minimum timer value to wait idle state
}
///- ... else decrease it and if necessary display a shutdown countdown to the users
else
@ -1978,7 +2067,9 @@ void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
{
// ignore if server shutdown at next tick
if (m_stopEvent)
{
return;
}
m_ShutdownMask = options;
m_ExitCode = exitcode;
@ -1989,7 +2080,9 @@ void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
if (!(options & SHUTDOWN_MASK_IDLE) || GetActiveAndQueuedSessionCount() == 0)
m_stopEvent = true; // exist code already set
else
m_ShutdownTimer = 1; // So that the session count is re-evaluated at next world tick
{
m_ShutdownTimer = 1;
} // So that the session count is re-evaluated at next world tick
}
///- Else set the shutdown timer and warn users
else
@ -1997,6 +2090,7 @@ void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
m_ShutdownTimer = time;
ShutdownMsg(true);
}
///- Used by Eluna
#ifdef ENABLE_ELUNA
sEluna->OnShutdownInitiate(ShutdownExitCode(exitcode), ShutdownMask(options));
@ -2008,15 +2102,17 @@ void World::ShutdownMsg(bool show /*= false*/, Player* player /*= NULL*/)
{
// not show messages for idle shutdown mode
if (m_ShutdownMask & SHUTDOWN_MASK_IDLE)
{ return; }
{
return;
}
///- Display a message every 12 hours, 1 hour, 5 minutes, 1 minute and 15 seconds
if (show ||
(m_ShutdownTimer < 5 * MINUTE && (m_ShutdownTimer % 15) == 0) || // < 5 min; every 15 sec
(m_ShutdownTimer < 15 * MINUTE && (m_ShutdownTimer % MINUTE) == 0) || // < 15 min; every 1 min
(m_ShutdownTimer < 30 * MINUTE && (m_ShutdownTimer % (5 * MINUTE)) == 0) || // < 30 min; every 5 min
(m_ShutdownTimer < 12 * HOUR && (m_ShutdownTimer % HOUR) == 0) || // < 12 h; every 1 h
(m_ShutdownTimer >= 12 * HOUR && (m_ShutdownTimer % (12 * HOUR)) == 0)) // >= 12 h; every 12 h
(m_ShutdownTimer < 5 * MINUTE && (m_ShutdownTimer % 15) == 0) || // < 5 min; every 15 sec
(m_ShutdownTimer < 15 * MINUTE && (m_ShutdownTimer % MINUTE) == 0) || // < 15 min; every 1 min
(m_ShutdownTimer < 30 * MINUTE && (m_ShutdownTimer % (5 * MINUTE)) == 0) || // < 30 min; every 5 min
(m_ShutdownTimer < 12 * HOUR && (m_ShutdownTimer % HOUR) == 0) || // < 12 h; every 1 h
(m_ShutdownTimer >= 12 * HOUR && (m_ShutdownTimer % (12 * HOUR)) == 0)) // >= 12 h; every 12 h
{
std::string str = secsToTimeString(m_ShutdownTimer);
@ -2032,7 +2128,9 @@ void World::ShutdownCancel()
{
// nothing cancel or too later
if (!m_ShutdownTimer || m_stopEvent)
{ return; }
{
return;
}
ServerMessageType msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_CANCELLED : SERVER_MSG_SHUTDOWN_CANCELLED;
@ -2095,7 +2193,9 @@ void World::ProcessCliCommands()
handler.ParseCommands(command->m_command);
if (command->m_commandFinished)
{
command->m_commandFinished(callbackArg, !handler.HasSentErrorMessage());
}
delete command;
}
@ -2375,7 +2475,9 @@ void World::ResetCurrencyWeekCounts()
void World::SetPlayerLimit(int32 limit, bool needUpdate)
{
if (limit < -SEC_ADMINISTRATOR)
{
limit = -SEC_ADMINISTRATOR;
}
// lock update need
bool db_update_need = needUpdate || (limit < 0) != (m_playerLimit < 0) || (limit < 0 && m_playerLimit < 0 && limit != m_playerLimit);
@ -2415,7 +2517,9 @@ void World::LoadDBVersion()
}
if (m_DBVersion.empty())
{ m_DBVersion = "Unknown world database."; }
{
m_DBVersion = "Unknown world database.";
}
}
void World::setConfig(eConfigUInt64Values index, char const* fieldname, uint64 defvalue)
@ -2596,11 +2700,15 @@ void World::setConfigMinMax(eConfigFloatValues index, char const* fieldname, flo
bool World::configNoReload(bool reload, eConfigUInt32Values index, char const* fieldname, uint32 defvalue)
{
if (!reload)
{ return true; }
{
return true;
}
uint32 val = sConfig.GetIntDefault(fieldname, defvalue);
if (val != getConfig(index))
{ sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%u).", fieldname, getConfig(index)); }
{
sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%u).", fieldname, getConfig(index));
}
return false;
}
@ -2608,11 +2716,15 @@ bool World::configNoReload(bool reload, eConfigUInt32Values index, char const* f
bool World::configNoReload(bool reload, eConfigInt32Values index, char const* fieldname, int32 defvalue)
{
if (!reload)
{ return true; }
{
return true;
}
int32 val = sConfig.GetIntDefault(fieldname, defvalue);
if (val != getConfig(index))
{ sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%i).", fieldname, getConfig(index)); }
{
sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%i).", fieldname, getConfig(index));
}
return false;
}
@ -2620,11 +2732,15 @@ bool World::configNoReload(bool reload, eConfigInt32Values index, char const* fi
bool World::configNoReload(bool reload, eConfigFloatValues index, char const* fieldname, float defvalue)
{
if (!reload)
{ return true; }
{
return true;
}
float val = sConfig.GetFloatDefault(fieldname, defvalue);
if (val != getConfig(index))
{ sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%f).", fieldname, getConfig(index)); }
{
sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%f).", fieldname, getConfig(index));
}
return false;
}
@ -2632,11 +2748,15 @@ bool World::configNoReload(bool reload, eConfigFloatValues index, char const* fi
bool World::configNoReload(bool reload, eConfigBoolValues index, char const* fieldname, bool defvalue)
{
if (!reload)
{ return true; }
{
return true;
}
bool val = sConfig.GetBoolDefault(fieldname, defvalue);
if (val != getConfig(index))
{ sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%s).", fieldname, getConfig(index) ? "'true'" : "'false'"); }
{
sLog.outError("%s option can't be changed at mangosd.conf reload, using current value (%s).", fieldname, getConfig(index) ? "'true'" : "'false'");
}
return false;
}