mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
[General] Fix warnings and errors found by PVS Studio in Server
This commit is contained in:
parent
7ab7c4c9c2
commit
5519572b22
32 changed files with 108 additions and 103 deletions
|
@ -206,4 +206,4 @@ endif (MSVC)
|
||||||
pvs_studio_add_target(TARGET tes3mp-server.analyze ALL
|
pvs_studio_add_target(TARGET tes3mp-server.analyze ALL
|
||||||
OUTPUT FORMAT errorfile
|
OUTPUT FORMAT errorfile
|
||||||
ANALYZE tes3mp-server
|
ANALYZE tes3mp-server
|
||||||
LOG target.err)
|
LOG target_tes3mp-server.err)
|
||||||
|
|
|
@ -55,7 +55,7 @@ void Cell::addPlayer(Player *player)
|
||||||
|
|
||||||
void Cell::removePlayer(Player *player, bool cleanPlayer)
|
void Cell::removePlayer(Player *player, bool cleanPlayer)
|
||||||
{
|
{
|
||||||
for (Iterator it = begin(); it != end(); it++)
|
for (auto it = begin(); it != end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it == player)
|
if (*it == player)
|
||||||
{
|
{
|
||||||
|
@ -161,7 +161,7 @@ void Cell::removeActors(const mwmp::BaseActorList *newActorList)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundActor)
|
if (!foundActor)
|
||||||
it++;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
cellActorList.count = cellActorList.baseActors.size();
|
cellActorList.count = cellActorList.baseActors.size();
|
||||||
|
|
|
@ -64,7 +64,7 @@ Cell *CellController::getCellByXY(int x, int y)
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *CellController::getCellByName(std::string cellName)
|
Cell *CellController::getCellByName(const std::string &cellName)
|
||||||
{
|
{
|
||||||
auto it = find_if(cells.begin(), cells.end(), [cellName](const Cell *c)
|
auto it = find_if(cells.begin(), cells.end(), [cellName](const Cell *c)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ Cell *CellController::getCellByName(std::string cellName)
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cell *CellController::addCell(ESM::Cell cellData)
|
Cell *CellController::addCell(const ESM::Cell &cellData)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_INFO, "- Loaded cells: %d", cells.size());
|
LOG_APPEND(Log::LOG_INFO, "- Loaded cells: %d", cells.size());
|
||||||
auto it = find_if(cells.begin(), cells.end(), [cellData](const Cell *c) {
|
auto it = find_if(cells.begin(), cells.end(), [cellData](const Cell *c) {
|
||||||
|
|
|
@ -27,14 +27,14 @@ public:
|
||||||
typedef std::deque<Cell*> TContainer;
|
typedef std::deque<Cell*> TContainer;
|
||||||
typedef TContainer::iterator TIter;
|
typedef TContainer::iterator TIter;
|
||||||
|
|
||||||
Cell * addCell(ESM::Cell cell);
|
Cell * addCell(const ESM::Cell &cell);
|
||||||
void removeCell(Cell *);
|
void removeCell(Cell *);
|
||||||
|
|
||||||
void deletePlayer(Player *player);
|
void deletePlayer(Player *player);
|
||||||
|
|
||||||
Cell *getCell(ESM::Cell *esmCell);
|
Cell *getCell(ESM::Cell *esmCell);
|
||||||
Cell *getCellByXY(int x, int y);
|
Cell *getCellByXY(int x, int y);
|
||||||
Cell *getCellByName(std::string cellName);
|
Cell *getCellByName(const std::string &cellName);
|
||||||
|
|
||||||
void update(Player *player);
|
void update(Player *player);
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ void MasterClient::SetMaxPlayers(unsigned pl)
|
||||||
mutexData.unlock();
|
mutexData.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterClient::SetHostname(std::string hostname)
|
void MasterClient::SetHostname(const std::string &hostname)
|
||||||
{
|
{
|
||||||
mutexData.lock();
|
mutexData.lock();
|
||||||
string substr = hostname.substr(0, 200);
|
string substr = hostname.substr(0, 200);
|
||||||
|
@ -63,7 +63,7 @@ void MasterClient::SetHostname(std::string hostname)
|
||||||
mutexData.unlock();
|
mutexData.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterClient::SetModname(std::string modname)
|
void MasterClient::SetModname(const std::string &modname)
|
||||||
{
|
{
|
||||||
mutexData.lock();
|
mutexData.lock();
|
||||||
string substr = modname.substr(0, 200);
|
string substr = modname.substr(0, 200);
|
||||||
|
@ -75,7 +75,7 @@ void MasterClient::SetModname(std::string modname)
|
||||||
mutexData.unlock();
|
mutexData.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterClient::SetRuleString(std::string key, std::string value)
|
void MasterClient::SetRuleString(const std::string &key, std::string value)
|
||||||
{
|
{
|
||||||
mutexData.lock();
|
mutexData.lock();
|
||||||
if (queryData.rules.find(key) == queryData.rules.end() || queryData.rules[key].type != 's'
|
if (queryData.rules.find(key) == queryData.rules.end() || queryData.rules[key].type != 's'
|
||||||
|
@ -90,7 +90,7 @@ void MasterClient::SetRuleString(std::string key, std::string value)
|
||||||
mutexData.unlock();
|
mutexData.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterClient::SetRuleValue(std::string key, double value)
|
void MasterClient::SetRuleValue(const std::string &key, double value)
|
||||||
{
|
{
|
||||||
mutexData.lock();
|
mutexData.lock();
|
||||||
if (queryData.rules.find(key) == queryData.rules.end() || queryData.rules[key].type != 'v'
|
if (queryData.rules.find(key) == queryData.rules.end() || queryData.rules[key].type != 'v'
|
||||||
|
@ -105,7 +105,7 @@ void MasterClient::SetRuleValue(std::string key, double value)
|
||||||
mutexData.unlock();
|
mutexData.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterClient::PushPlugin(Plugin plugin)
|
void MasterClient::PushPlugin(const Plugin &plugin)
|
||||||
{
|
{
|
||||||
mutexData.lock();
|
mutexData.lock();
|
||||||
queryData.plugins.push_back(plugin);
|
queryData.plugins.push_back(plugin);
|
||||||
|
@ -208,7 +208,7 @@ void MasterClient::Thread()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = 0; pIt != players->end(); i++, pIt++)
|
for (int i = 0; pIt != players->end(); i++, ++pIt)
|
||||||
{
|
{
|
||||||
if (queryData.players[i] != pIt->second->npc.mName)
|
if (queryData.players[i] != pIt->second->npc.mName)
|
||||||
{
|
{
|
||||||
|
@ -258,5 +258,6 @@ void MasterClient::SetUpdateRate(unsigned int rate)
|
||||||
timeout = min_rate;
|
timeout = min_rate;
|
||||||
else if (timeout > max_rate)
|
else if (timeout > max_rate)
|
||||||
timeout = max_rate;
|
timeout = max_rate;
|
||||||
|
else
|
||||||
timeout = rate;
|
timeout = rate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,11 @@ public:
|
||||||
MasterClient(RakNet::RakPeerInterface *peer, std::string queryAddr, unsigned short queryPort);
|
MasterClient(RakNet::RakPeerInterface *peer, std::string queryAddr, unsigned short queryPort);
|
||||||
void SetPlayers(unsigned pl);
|
void SetPlayers(unsigned pl);
|
||||||
void SetMaxPlayers(unsigned pl);
|
void SetMaxPlayers(unsigned pl);
|
||||||
void SetHostname(std::string hostname);
|
void SetHostname(const std::string &hostname);
|
||||||
void SetModname(std::string hostname);
|
void SetModname(const std::string &hostname);
|
||||||
void SetRuleString(std::string key, std::string value);
|
void SetRuleString(const std::string &key, std::string value);
|
||||||
void SetRuleValue(std::string key, double value);
|
void SetRuleValue(const std::string &key, double value);
|
||||||
void PushPlugin(Plugin plugin);
|
void PushPlugin(const Plugin &plugin);
|
||||||
|
|
||||||
bool Process(RakNet::Packet *packet);
|
bool Process(RakNet::Packet *packet);
|
||||||
void Start();
|
void Start();
|
||||||
|
|
|
@ -75,7 +75,7 @@ Networking::~Networking()
|
||||||
delete worldstatePacketController;
|
delete worldstatePacketController;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::setServerPassword(std::string password) noexcept
|
void Networking::setServerPassword(const std::string &passw) noexcept
|
||||||
{
|
{
|
||||||
serverPassword = password.empty() ? TES3MP_DEFAULT_PASSW : password;
|
serverPassword = password.empty() ? TES3MP_DEFAULT_PASSW : password;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ bool Networking::preInit(RakNet::Packet *packet, RakNet::BitStream &bsIn)
|
||||||
auto plugin = plugins.begin();
|
auto plugin = plugins.begin();
|
||||||
if (samples.size() == plugins.size())
|
if (samples.size() == plugins.size())
|
||||||
{
|
{
|
||||||
for (int i = 0; plugin != plugins.end(); plugin++, i++)
|
for (int i = 0; plugin != plugins.end(); ++plugin, i++)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_VERBOSE, "- %X\t%s", plugin->second[0], plugin->first.c_str());
|
LOG_APPEND(Log::LOG_VERBOSE, "- %X\t%s", plugin->second[0], plugin->first.c_str());
|
||||||
// Check if the filenames match, ignoring case
|
// Check if the filenames match, ignoring case
|
||||||
|
@ -317,7 +317,7 @@ void Networking::update(RakNet::Packet *packet, RakNet::BitStream &bsIn)
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled RakNet packet with identifier %i has arrived", packet->data[0]);
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Unhandled RakNet packet with identifier %i has arrived", packet->data[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::newPlayer(RakNet::RakNetGUID guid)
|
void Networking::newPlayer(const RakNet::RakNetGUID &guid)
|
||||||
{
|
{
|
||||||
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->RequestData(guid);
|
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->RequestData(guid);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(guid);
|
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(guid);
|
||||||
|
@ -327,27 +327,27 @@ void Networking::newPlayer(RakNet::RakNetGUID guid)
|
||||||
|
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Sending info about other players to %lu", guid.g);
|
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Sending info about other players to %lu", guid.g);
|
||||||
|
|
||||||
for (TPlayers::iterator pl = players->begin(); pl != players->end(); pl++) //sending other players to new player
|
for (auto &player : *players) //sending other players to new player
|
||||||
{
|
{
|
||||||
// If we are iterating over the new player, don't send the packets below
|
// If we are iterating over the new player, don't send the packets below
|
||||||
if (pl->first == guid) continue;
|
if (player.first == guid) continue;
|
||||||
|
|
||||||
// If an invalid key makes it into the Players map, ignore it
|
// If an invalid key makes it into the Players map, ignore it
|
||||||
else if (pl->first == RakNet::UNASSIGNED_CRABNET_GUID) continue;
|
else if (player.first == RakNet::UNASSIGNED_CRABNET_GUID) continue;
|
||||||
|
|
||||||
// if player not fully connected
|
// if player not fully connected
|
||||||
else if (pl->second == nullptr) continue;
|
else if (player.second == nullptr) continue;
|
||||||
|
|
||||||
// If we are iterating over a player who has inputted their name, proceed
|
// If we are iterating over a player who has inputted their name, proceed
|
||||||
else if (pl->second->getLoadState() == Player::POSTLOADED)
|
else if (player.second->getLoadState() == Player::POSTLOADED)
|
||||||
{
|
{
|
||||||
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->setPlayer(pl->second);
|
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->setPlayer(player.second);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(pl->second);
|
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player.second);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(pl->second);
|
playerPacketController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(player.second);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_SKILL)->setPlayer(pl->second);
|
playerPacketController->GetPacket(ID_PLAYER_SKILL)->setPlayer(player.second);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_POSITION)->setPlayer(pl->second);
|
playerPacketController->GetPacket(ID_PLAYER_POSITION)->setPlayer(player.second);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(pl->second);
|
playerPacketController->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(player.second);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(pl->second);
|
playerPacketController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(player.second);
|
||||||
|
|
||||||
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->Send(guid);
|
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->Send(guid);
|
||||||
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(guid);
|
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(guid);
|
||||||
|
@ -363,7 +363,7 @@ void Networking::newPlayer(RakNet::RakNetGUID guid)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::disconnectPlayer(RakNet::RakNetGUID guid)
|
void Networking::disconnectPlayer(const RakNet::RakNetGUID &guid)
|
||||||
{
|
{
|
||||||
Player *player = Players::getPlayer(guid);
|
Player *player = Players::getPlayer(guid);
|
||||||
if (!player)
|
if (!player)
|
||||||
|
@ -458,7 +458,7 @@ Networking *Networking::getPtr()
|
||||||
return sThis;
|
return sThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
RakNet::SystemAddress Networking::getSystemAddress(RakNet::RakNetGUID guid)
|
RakNet::SystemAddress Networking::getSystemAddress(const RakNet::RakNetGUID &guid)
|
||||||
{
|
{
|
||||||
return peer->GetSystemAddressFromGuid(guid);
|
return peer->GetSystemAddressFromGuid(guid);
|
||||||
}
|
}
|
||||||
|
@ -538,7 +538,7 @@ int Networking::mainLoop()
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::kickPlayer(RakNet::RakNetGUID guid, bool sendNotification)
|
void Networking::kickPlayer(const RakNet::RakNetGUID &guid, bool sendNotification)
|
||||||
{
|
{
|
||||||
peer->CloseConnection(guid, sendNotification);
|
peer->CloseConnection(guid, sendNotification);
|
||||||
}
|
}
|
||||||
|
@ -563,7 +563,7 @@ unsigned int Networking::maxConnections() const
|
||||||
return peer->GetMaximumIncomingConnections();
|
return peer->GetMaximumIncomingConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Networking::getAvgPing(RakNet::AddressOrGUID addr) const
|
int Networking::getAvgPing(const RakNet::AddressOrGUID &addr) const
|
||||||
{
|
{
|
||||||
return peer->GetAveragePing(addr);
|
return peer->GetAveragePing(addr);
|
||||||
}
|
}
|
||||||
|
@ -578,7 +578,7 @@ MasterClient *Networking::getMasterClient()
|
||||||
return mclient;
|
return mclient;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Networking::InitQuery(std::string queryAddr, unsigned short queryPort)
|
void Networking::InitQuery(const std::string &queryAddr, unsigned short queryPort)
|
||||||
{
|
{
|
||||||
mclient = new MasterClient(peer, queryAddr, queryPort);
|
mclient = new MasterClient(peer, queryAddr, queryPort);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,13 @@ namespace mwmp
|
||||||
Networking(RakNet::RakPeerInterface *peer);
|
Networking(RakNet::RakPeerInterface *peer);
|
||||||
~Networking();
|
~Networking();
|
||||||
|
|
||||||
void newPlayer(RakNet::RakNetGUID guid);
|
void newPlayer(const RakNet::RakNetGUID &guid);
|
||||||
void disconnectPlayer(RakNet::RakNetGUID guid);
|
void disconnectPlayer(const RakNet::RakNetGUID &guid);
|
||||||
void kickPlayer(RakNet::RakNetGUID guid, bool sendNotification = true);
|
void kickPlayer(const RakNet::RakNetGUID &guid, bool sendNotification = true);
|
||||||
|
|
||||||
void banAddress(const char *ipAddress);
|
void banAddress(const char *ipAddress);
|
||||||
void unbanAddress(const char *ipAddress);
|
void unbanAddress(const char *ipAddress);
|
||||||
RakNet::SystemAddress getSystemAddress(RakNet::RakNetGUID guid);
|
RakNet::SystemAddress getSystemAddress(const RakNet::RakNetGUID &guid);
|
||||||
|
|
||||||
void processPlayerPacket(RakNet::Packet *packet);
|
void processPlayerPacket(RakNet::Packet *packet);
|
||||||
void processActorPacket(RakNet::Packet *packet);
|
void processActorPacket(RakNet::Packet *packet);
|
||||||
|
@ -33,7 +33,7 @@ namespace mwmp
|
||||||
|
|
||||||
unsigned short numberOfConnections() const;
|
unsigned short numberOfConnections() const;
|
||||||
unsigned int maxConnections() const;
|
unsigned int maxConnections() const;
|
||||||
int getAvgPing(RakNet::AddressOrGUID) const;
|
int getAvgPing(const RakNet::AddressOrGUID &) const;
|
||||||
unsigned short getPort() const;
|
unsigned short getPort() const;
|
||||||
|
|
||||||
int mainLoop();
|
int mainLoop();
|
||||||
|
@ -60,8 +60,8 @@ namespace mwmp
|
||||||
void setScriptErrorIgnoringState(bool state);
|
void setScriptErrorIgnoringState(bool state);
|
||||||
|
|
||||||
MasterClient *getMasterClient();
|
MasterClient *getMasterClient();
|
||||||
void InitQuery(std::string queryAddr, unsigned short queryPort);
|
void InitQuery(const std::string &queryAddr, unsigned short queryPort);
|
||||||
void setServerPassword(std::string passw) noexcept;
|
void setServerPassword(const std::string &passw) noexcept;
|
||||||
bool isPassworded() const;
|
bool isPassworded() const;
|
||||||
|
|
||||||
static const Networking &get();
|
static const Networking &get();
|
||||||
|
|
|
@ -10,7 +10,7 @@ TSlots Players::slots;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void Players::deletePlayer(RakNet::RakNetGUID guid)
|
void Players::deletePlayer(const RakNet::RakNetGUID &guid)
|
||||||
{
|
{
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu", guid.g);
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Deleting player with guid %lu", guid.g);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void Players::deletePlayer(RakNet::RakNetGUID guid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Players::newPlayer(RakNet::RakNetGUID guid)
|
void Players::newPlayer(const RakNet::RakNetGUID &guid)
|
||||||
{
|
{
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Creating new player with guid %lu", guid.g);
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Creating new player with guid %lu", guid.g);
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid)
|
||||||
|
|
||||||
for (unsigned int i = 0; i < mwmp::Networking::get().maxConnections(); i++)
|
for (unsigned int i = 0; i < mwmp::Networking::get().maxConnections(); i++)
|
||||||
{
|
{
|
||||||
if (slots[i] == 0)
|
if (slots[i] == nullptr)
|
||||||
{
|
{
|
||||||
LOG_APPEND(Log::LOG_INFO, "- Storing in slot %i", i);
|
LOG_APPEND(Log::LOG_INFO, "- Storing in slot %i", i);
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player *Players::getPlayer(RakNet::RakNetGUID guid)
|
Player *Players::getPlayer(const RakNet::RakNetGUID &guid)
|
||||||
{
|
{
|
||||||
auto it = players.find(guid);
|
auto it = players.find(guid);
|
||||||
if (it == players.end())
|
if (it == players.end())
|
||||||
|
@ -70,7 +70,7 @@ unsigned short Players::getLastPlayerId()
|
||||||
return slots.rbegin()->first;
|
return slots.rbegin()->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player::Player(RakNet::RakNetGUID guid) : BasePlayer(guid)
|
Player::Player(const RakNet::RakNetGUID &guid) : BasePlayer(guid), id(InvalidID)
|
||||||
{
|
{
|
||||||
handshakeCounter = 0;
|
handshakeCounter = 0;
|
||||||
loadState = NOTLOADED;
|
loadState = NOTLOADED;
|
||||||
|
@ -81,7 +81,7 @@ Player::~Player()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short Player::getId()
|
unsigned int Player::getId()
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ void Player::forEachLoaded(std::function<void(Player *pl, Player *other)> func)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Players::doesPlayerExist(RakNet::RakNetGUID guid)
|
bool Players::doesPlayerExist(const RakNet::RakNetGUID &guid)
|
||||||
{
|
{
|
||||||
return players.find(guid) != players.end();
|
return players.find(guid) != players.end();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ typedef std::map<unsigned short, Player*> TSlots;
|
||||||
class Players
|
class Players
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void newPlayer(RakNet::RakNetGUID guid);
|
static void newPlayer(const RakNet::RakNetGUID &guid);
|
||||||
static void deletePlayer(RakNet::RakNetGUID guid);
|
static void deletePlayer(const RakNet::RakNetGUID &guid);
|
||||||
static Player *getPlayer(RakNet::RakNetGUID guid);
|
static Player *getPlayer(const RakNet::RakNetGUID &guid);
|
||||||
static Player *getPlayer(unsigned short id);
|
static Player *getPlayer(unsigned short id);
|
||||||
static TPlayers *getPlayers();
|
static TPlayers *getPlayers();
|
||||||
static unsigned short getLastPlayerId();
|
static unsigned short getLastPlayerId();
|
||||||
static bool doesPlayerExist(RakNet::RakNetGUID guid);
|
static bool doesPlayerExist(const RakNet::RakNetGUID &guid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static TPlayers players;
|
static TPlayers players;
|
||||||
|
@ -44,9 +44,8 @@ private:
|
||||||
class Player : public mwmp::BasePlayer
|
class Player : public mwmp::BasePlayer
|
||||||
{
|
{
|
||||||
friend class Cell;
|
friend class Cell;
|
||||||
unsigned short id;
|
|
||||||
public:
|
public:
|
||||||
|
const unsigned int InvalidID = (unsigned int) -1;
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
NOTLOADED=0,
|
NOTLOADED=0,
|
||||||
|
@ -54,9 +53,9 @@ public:
|
||||||
POSTLOADED,
|
POSTLOADED,
|
||||||
KICKED
|
KICKED
|
||||||
};
|
};
|
||||||
Player(RakNet::RakNetGUID guid);
|
Player(const RakNet::RakNetGUID &guid);
|
||||||
|
|
||||||
unsigned short getId();
|
unsigned int getId();
|
||||||
void setId(unsigned short id);
|
void setId(unsigned short id);
|
||||||
|
|
||||||
bool isHandshaked();
|
bool isHandshaked();
|
||||||
|
@ -78,6 +77,7 @@ private:
|
||||||
CellController::TContainer cells;
|
CellController::TContainer cells;
|
||||||
int loadState;
|
int loadState;
|
||||||
int handshakeCounter;
|
int handshakeCounter;
|
||||||
|
unsigned int id;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ bool Public::IsLua(const std::string &name)
|
||||||
|
|
||||||
void Public::DeleteAll()
|
void Public::DeleteAll()
|
||||||
{
|
{
|
||||||
for (auto it = publics.begin(); it != publics.end(); it++)
|
for (auto it = publics.begin(); it != publics.end(); ++it)
|
||||||
{
|
{
|
||||||
Public *_public = it->second;
|
Public *_public = it->second;
|
||||||
delete _public;
|
delete _public;
|
||||||
|
|
|
@ -6,18 +6,18 @@
|
||||||
using namespace mwmp;
|
using namespace mwmp;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Timer::Timer(ScriptFunc callback, long msec, const std::string& def, std::vector<boost::any> args) : ScriptFunction(callback, 'v', def)
|
Timer::Timer(ScriptFunc callback, long msec, const std::string& def, std::vector<boost::any> args) : ScriptFunction(callback, 'v', def), args(args)
|
||||||
{
|
{
|
||||||
|
startTime = 0;
|
||||||
targetMsec = msec;
|
targetMsec = msec;
|
||||||
this->args = args;
|
|
||||||
isEnded = true;
|
isEnded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ENABLE_LUA)
|
#if defined(ENABLE_LUA)
|
||||||
Timer::Timer(lua_State *lua, ScriptFuncLua callback, long msec, const std::string& def, std::vector<boost::any> args): ScriptFunction(callback, lua, 'v', def)
|
Timer::Timer(lua_State *lua, ScriptFuncLua callback, long msec, const std::string& def, std::vector<boost::any> args): ScriptFunction(callback, lua, 'v', def), args(args)
|
||||||
{
|
{
|
||||||
|
startTime = 0;
|
||||||
targetMsec = msec;
|
targetMsec = msec;
|
||||||
this->args = args;
|
|
||||||
isEnded = true;
|
isEnded = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -90,7 +90,7 @@ int TimerAPI::CreateTimerLua(lua_State *lua, ScriptFuncLua callback, long msec,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int TimerAPI::CreateTimer(ScriptFunc callback, long msec, const std::string &def, std::vector<boost::any> args)
|
int TimerAPI::CreateTimer(ScriptFunc callback, long msec, const std::string &def, const std::vector<boost::any> &args)
|
||||||
{
|
{
|
||||||
int id = -1;
|
int id = -1;
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ namespace mwmp
|
||||||
void Restart(int msec);
|
void Restart(int msec);
|
||||||
private:
|
private:
|
||||||
double startTime, targetMsec;
|
double startTime, targetMsec;
|
||||||
std::string publ, arg_types;
|
//std::string publ, arg_types;
|
||||||
std::vector<boost::any> args;
|
std::vector<boost::any> args;
|
||||||
Script *scr;
|
//Script *scr;
|
||||||
bool isEnded;
|
bool isEnded;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ extern "C" const char *CellFunctions::GetCell(unsigned short pid) noexcept
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
tempCellDescription = player->cell.getDescription().c_str();
|
tempCellDescription = player->cell.getDescription();
|
||||||
return tempCellDescription.c_str();
|
return tempCellDescription.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ extern "C" void CharClassFunctions::SetClassName(unsigned short pid, const char
|
||||||
GET_PLAYER(pid, player,);
|
GET_PLAYER(pid, player,);
|
||||||
|
|
||||||
player->charClass.mName = name;
|
player->charClass.mName = name;
|
||||||
player->charClass.mId = "";
|
player->charClass.mId.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void CharClassFunctions::SetClassDesc(unsigned short pid, const char *desc) noexcept
|
extern "C" void CharClassFunctions::SetClassDesc(unsigned short pid, const char *desc) noexcept
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern "C" const char *MechanicsFunctions::GetMarkCell(unsigned short pid) noexc
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
tempCellDescription = player->cell.getDescription().c_str();
|
tempCellDescription = player->cell.getDescription();
|
||||||
return tempCellDescription.c_str();
|
return tempCellDescription.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ extern "C" void ServerFunctions::AddPluginHash(const char *pluginName, const cha
|
||||||
|
|
||||||
unsigned hash = 0;
|
unsigned hash = 0;
|
||||||
|
|
||||||
if (strlen(hashStr) != 0)
|
if (hashStr[0] != '\0')
|
||||||
{
|
{
|
||||||
hash = (unsigned) std::stoul(hashStr);
|
hash = (unsigned) std::stoul(hashStr);
|
||||||
hashList.push_back(hash);
|
hashList.push_back(hash);
|
||||||
|
|
|
@ -239,7 +239,7 @@ extern "C" int StatsFunctions::GetSkillIncrease(unsigned short pid, unsigned int
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player, 0);
|
GET_PLAYER(pid, player, 0);
|
||||||
|
|
||||||
if (attributeId > Attribute::Length)
|
if (attributeId >= Attribute::Length)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return player->npcStats.mSkillIncrease[attributeId];
|
return player->npcStats.mSkillIncrease[attributeId];
|
||||||
|
@ -484,7 +484,7 @@ extern "C" void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned in
|
||||||
Player *player;
|
Player *player;
|
||||||
GET_PLAYER(pid, player,);
|
GET_PLAYER(pid, player,);
|
||||||
|
|
||||||
if (attributeId > Attribute::Length)
|
if (attributeId >= Attribute::Length)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
player->npcStats.mSkillIncrease[attributeId] = value;
|
player->npcStats.mSkillIncrease[attributeId] = value;
|
||||||
|
|
|
@ -252,7 +252,7 @@ boost::any LangLua::Call(const char *name, const char *argl, int buf, ...)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw runtime_error("C++ call: Unknown argument identifier " + argl[index]);
|
throw runtime_error(std::string("C++ call: Unknown argument identifier ") + argl[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ boost::any LangLua::Call(const char *name, const char *argl, const std::vector<b
|
||||||
luabridge::Stack<bool>::push(lua, boost::any_cast<int>(args.at(index)));
|
luabridge::Stack<bool>::push(lua, boost::any_cast<int>(args.at(index)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw runtime_error("Lua call: Unknown argument identifier " + argl[index]);
|
throw runtime_error(std::string("Lua call: Unknown argument identifier ") + argl[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
inline vector<boost::any> DefToVec(lua_State *lua, string types, int args_begin, int args_n)
|
inline vector<boost::any> DefToVec(lua_State *lua, const string &types, int args_begin, int args_n)
|
||||||
{
|
{
|
||||||
vector<boost::any> args;
|
vector<boost::any> args;
|
||||||
|
|
||||||
|
@ -93,13 +93,15 @@ int LangLua::CallPublic(lua_State *lua)
|
||||||
if (result.empty())
|
if (result.empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (result.type().hash_code() == typeid(signed int).hash_code())
|
auto retTypeHash = result.type().hash_code();
|
||||||
|
|
||||||
|
if (retTypeHash == typeid(signed int).hash_code())
|
||||||
luabridge::Stack<signed int>::push(lua, boost::any_cast<signed int>(result));
|
luabridge::Stack<signed int>::push(lua, boost::any_cast<signed int>(result));
|
||||||
else if (result.type().hash_code() == typeid(unsigned int).hash_code())
|
else if (retTypeHash == typeid(unsigned int).hash_code())
|
||||||
luabridge::Stack<unsigned int>::push(lua, boost::any_cast<unsigned int>(result));
|
luabridge::Stack<unsigned int>::push(lua, boost::any_cast<unsigned int>(result));
|
||||||
else if (result.type().hash_code() == typeid(double).hash_code())
|
else if (retTypeHash == typeid(double).hash_code())
|
||||||
luabridge::Stack<double>::push(lua, boost::any_cast<double>(result));
|
luabridge::Stack<double>::push(lua, boost::any_cast<double>(result));
|
||||||
else if (result.type().hash_code() == typeid(const char*).hash_code())
|
else if (retTypeHash == typeid(const char*).hash_code())
|
||||||
luabridge::Stack<const char*>::push(lua, boost::any_cast<const char*>(result));
|
luabridge::Stack<const char*>::push(lua, boost::any_cast<const char*>(result));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ lib_t LangNative::GetInterface()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LangNative::LangNative()
|
LangNative::LangNative(): lib(nullptr)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ void ScriptFunctions::GetArguments(std::vector<boost::any> ¶ms, va_list args
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw runtime_error("C++ call: Unknown argument identifier " + c);
|
throw runtime_error(std::string("C++ call: Unknown argument identifier ") + c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ const vector<string> Utils::split(const string &str, int delimiter)
|
||||||
else if (!buffer.empty())
|
else if (!buffer.empty())
|
||||||
{
|
{
|
||||||
result.push_back(move(buffer));
|
result.push_back(move(buffer));
|
||||||
buffer.clear();
|
|
||||||
}
|
}
|
||||||
if (!buffer.empty())
|
if (!buffer.empty())
|
||||||
result.push_back(move(buffer));
|
result.push_back(move(buffer));
|
||||||
|
@ -25,7 +24,7 @@ const vector<string> Utils::split(const string &str, int delimiter)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::Cell Utils::getCellFromDescription(std::string cellDescription)
|
ESM::Cell Utils::getCellFromDescription(const std::string &cellDescription)
|
||||||
{
|
{
|
||||||
ESM::Cell cell;
|
ESM::Cell cell;
|
||||||
cell.blank();
|
cell.blank();
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Utils
|
||||||
{
|
{
|
||||||
const std::vector<std::string> split(const std::string &str, int delimiter);
|
const std::vector<std::string> split(const std::string &str, int delimiter);
|
||||||
|
|
||||||
ESM::Cell getCellFromDescription(std::string cellDescription);
|
ESM::Cell getCellFromDescription(const std::string &cellDescription);
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
constexpr unsigned int hash(const char(&str)[N], size_t I = N)
|
constexpr unsigned int hash(const char(&str)[N], size_t I = N)
|
||||||
|
|
|
@ -309,13 +309,15 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
networking.InitQuery(masterAddr, (unsigned short) masterPort);
|
networking.InitQuery(masterAddr, (unsigned short) masterPort);
|
||||||
networking.getMasterClient()->SetMaxPlayers((unsigned) players);
|
auto masterClient = networking.getMasterClient();
|
||||||
networking.getMasterClient()->SetUpdateRate((unsigned) updateRate);
|
|
||||||
string hostname = mgr.getString("hostname", "General");
|
|
||||||
networking.getMasterClient()->SetHostname(hostname);
|
|
||||||
networking.getMasterClient()->SetRuleString("CommitHash", version.mCommitHash.substr(0, 10));
|
|
||||||
|
|
||||||
networking.getMasterClient()->Start();
|
masterClient->SetMaxPlayers((unsigned) players);
|
||||||
|
masterClient->SetUpdateRate((unsigned) updateRate);
|
||||||
|
string hostname = mgr.getString("hostname", "General");
|
||||||
|
masterClient->SetHostname(hostname);
|
||||||
|
masterClient->SetRuleString("CommitHash", version.mCommitHash.substr(0, 10));
|
||||||
|
|
||||||
|
masterClient->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
networking.postInit();
|
networking.postInit();
|
||||||
|
|
|
@ -31,7 +31,7 @@ bool ActorProcessor::Process(RakNet::Packet &packet, BaseActorList &actorList) n
|
||||||
if (!processor.second->avoidReading)
|
if (!processor.second->avoidReading)
|
||||||
myPacket->Read();
|
myPacket->Read();
|
||||||
|
|
||||||
if (actorList.isValid)
|
if (actorList.isValid) // -V547
|
||||||
processor.second->Do(*myPacket, *player, actorList);
|
processor.second->Do(*myPacket, *player, actorList);
|
||||||
else
|
else
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
||||||
|
|
|
@ -31,7 +31,7 @@ bool ObjectProcessor::Process(RakNet::Packet &packet, BaseObjectList &objectList
|
||||||
if (!processor.second->avoidReading)
|
if (!processor.second->avoidReading)
|
||||||
myPacket->Read();
|
myPacket->Read();
|
||||||
|
|
||||||
if (objectList.isValid)
|
if (objectList.isValid) // -V547
|
||||||
processor.second->Do(*myPacket, *player, objectList);
|
processor.second->Do(*myPacket, *player, objectList);
|
||||||
else
|
else
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
||||||
|
|
|
@ -28,7 +28,7 @@ bool WorldstateProcessor::Process(RakNet::Packet &packet, BaseWorldstate &worlds
|
||||||
if (!processor.second->avoidReading)
|
if (!processor.second->avoidReading)
|
||||||
myPacket->Read();
|
myPacket->Read();
|
||||||
|
|
||||||
if (worldstate.isValid)
|
if (worldstate.isValid) // -V547
|
||||||
processor.second->Do(*myPacket, *player, worldstate);
|
processor.second->Do(*myPacket, *player, worldstate);
|
||||||
else
|
else
|
||||||
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BaseActorList()
|
BaseActorList(): count(0), action(0), isValid(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,12 +81,13 @@ namespace mwmp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BaseObjectList(RakNet::RakNetGUID guid) : guid(guid)
|
BaseObjectList(RakNet::RakNetGUID guid) : guid(guid), baseObjectCount(0), packetOrigin(0), action(0),
|
||||||
|
containerSubAction(0), isValid(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseObjectList()
|
BaseObjectList(): baseObjectCount(0), packetOrigin(0), action(0), containerSubAction(0), isValid(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,15 +43,15 @@ struct QueryData
|
||||||
QueryData()
|
QueryData()
|
||||||
{
|
{
|
||||||
rules["name"].type = ServerRule::Type::string;
|
rules["name"].type = ServerRule::Type::string;
|
||||||
rules["name"].str = "";
|
rules["name"].str.clear();
|
||||||
rules["version"].type = ServerRule::Type::string;
|
rules["version"].type = ServerRule::Type::string;
|
||||||
rules["version"].str = "";
|
rules["version"].str.clear();
|
||||||
rules["players"].type = ServerRule::Type::number;
|
rules["players"].type = ServerRule::Type::number;
|
||||||
rules["players"].val = 0;
|
rules["players"].val = 0;
|
||||||
rules["maxPlayers"].type = ServerRule::Type::number;
|
rules["maxPlayers"].type = ServerRule::Type::number;
|
||||||
rules["maxPlayers"].val = 0;
|
rules["maxPlayers"].val = 0;
|
||||||
rules["gamemode"].type = ServerRule::Type::string;
|
rules["gamemode"].type = ServerRule::Type::string;
|
||||||
rules["gamemode"].str = "";
|
rules["gamemode"].str.clear();
|
||||||
rules["passw"].type = ServerRule::Type::number;
|
rules["passw"].type = ServerRule::Type::number;
|
||||||
rules["passw"].val = 0;
|
rules["passw"].val = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ namespace mwmp
|
||||||
str = rstr.C_String();
|
str = rstr.C_String();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
str = std::string();
|
str.clear();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue