[General] Fix warnings and errors found by PVS Studio in Server

experimental-mono
Koncord 6 years ago
parent 1248741da6
commit 6b3b5cdab4

@ -223,4 +223,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;
timeout = rate; else
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 passw) noexcept void Networking::setServerPassword(const std::string &passw) noexcept
{ {
serverPassword = passw.empty() ? TES3MP_DEFAULT_PASSW : passw; serverPassword = passw.empty() ? TES3MP_DEFAULT_PASSW : passw;
} }
@ -239,7 +239,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
@ -311,7 +311,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);
@ -321,27 +321,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);
@ -357,7 +357,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)
@ -452,7 +452,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);
} }
@ -532,7 +532,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);
} }
@ -557,7 +557,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);
} }
@ -572,7 +572,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;
}; };

@ -80,7 +80,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;

@ -10,27 +10,27 @@
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;
end = true; end = 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;
end = true; end = true;
} }
#endif #endif
#ifdef ENABLE_MONO #ifdef ENABLE_MONO
Timer::Timer(MonoObject *callback, long msec, const std::string &def, std::vector<boost::any> args) : ScriptFunction(callback, 'v', def) Timer::Timer(MonoObject *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;
end = true; end = true;
} }
#endif #endif
@ -125,7 +125,7 @@ int TimerAPI::CreateTimerMono(MonoObject *callback, long msec, const std::string
} }
#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;

@ -40,9 +40,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 end; bool end;
}; };
@ -55,7 +55,7 @@ namespace mwmp
#if defined(ENABLE_MONO) #if defined(ENABLE_MONO)
static int CreateTimerMono(MonoObject *callback, long msec, const std::string& def, std::vector<boost::any> args); static int CreateTimerMono(MonoObject *callback, long msec, const std::string& def, std::vector<boost::any> args);
#endif #endif
static int CreateTimer(ScriptFunc callback, long msec, const std::string& def, std::vector<boost::any> args); static int CreateTimer(ScriptFunc callback, long msec, const std::string& def, const std::vector<boost::any> &args);
static void FreeTimer(int timerid); static void FreeTimer(int timerid);
static void ResetTimer(int timerid, long msec); static void ResetTimer(int timerid, long msec);
static void StartTimer(int timerid); static void StartTimer(int timerid);

@ -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;

@ -223,7 +223,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]);
} }
} }
@ -275,7 +275,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;
} }

@ -191,7 +191,7 @@ MonoObject *LangMono::AnyToObject(boost::any any, char ret_type)
} }
default: default:
throw std::runtime_error("Mono call: Unknown argument identifier " + ret_type); throw std::runtime_error(std::string("Mono call: Unknown argument identifier ") + ret_type);
} }
return object; return object;
} }
@ -366,6 +366,7 @@ boost::any LangMono::Call(const char *name, const char *argl, int buf, ...)
int n_args = (int) (strlen(argl)); int n_args = (int) (strlen(argl));
std::vector<void *> vec(n_args); std::vector<void *> vec(n_args);
TMonoArgsStore argsStore(n_args);
for (int index = 0; index < n_args; index++) for (int index = 0; index < n_args; index++)
{ {
@ -373,38 +374,32 @@ boost::any LangMono::Call(const char *name, const char *argl, int buf, ...)
{ {
case 'i': case 'i':
{ {
auto val = va_arg(vargs, unsigned int); vec[index] = MonoStoreAndGetPtr<unsigned int>(argsStore, vargs, index);
vec[index] = (void *) &val;
break; break;
} }
case 'q': case 'q':
{ {
auto val = va_arg(vargs, signed int); vec[index] = MonoStoreAndGetPtr<signed int>(argsStore, vargs, index);
vec[index] = (void *) &val;
break; break;
} }
case 'l': case 'l':
{ {
auto val = va_arg(vargs, unsigned long long); vec[index] = MonoStoreAndGetPtr<unsigned long long>(argsStore, vargs, index);
vec[index] = (void *) &val;
break; break;
} }
case 'w': case 'w':
{ {
auto val = va_arg(vargs, signed long long); vec[index] = MonoStoreAndGetPtr<signed long long>(argsStore, vargs, index);
vec[index] = (void *) &val;
break; break;
} }
case 'f': case 'f':
{ {
auto val = va_arg(vargs, double); vec[index] = MonoStoreAndGetPtr<double>(argsStore, vargs, index);
vec[index] = (void *) &val;
break; break;
} }
case 'p': case 'p':
{ {
auto val = va_arg(vargs, void*); vec[index] = MonoStoreAndGetPtr<void *>(argsStore, vargs, index);
vec[index] = (void *) &val;
break; break;
} }
case 's': case 's':
@ -414,13 +409,12 @@ boost::any LangMono::Call(const char *name, const char *argl, int buf, ...)
} }
case 'b': case 'b':
{ {
auto val = va_arg(vargs, int); vec[index] = MonoStoreAndGetPtr<int>(argsStore, vargs, index);
vec[index] = (void *) &val;
break; break;
} }
default: default:
throw std::runtime_error("Mono call: Unknown argument identifier " + argl[index]); throw std::runtime_error(std::string("Mono call: Unknown argument identifier ") + argl[index]);
} }
} }
@ -452,6 +446,7 @@ boost::any LangMono::Call(const char *name, const char *argl, const std::vector<
int n_args = args.size(); int n_args = args.size();
std::vector<void *> vec(n_args); std::vector<void *> vec(n_args);
TMonoArgsStore argsStore(n_args);
for (int index = 0; index < n_args; index++) for (int index = 0; index < n_args; index++)
{ {
@ -459,38 +454,32 @@ boost::any LangMono::Call(const char *name, const char *argl, const std::vector<
{ {
case 'i': case 'i':
{ {
auto val = boost::any_cast<unsigned int>(args.at(index)); vec[index] = MonoStoreAndGetPtr<unsigned int>(argsStore, args, index);
vec[index] = ((void *) &val);
break; break;
} }
case 'q': case 'q':
{ {
auto val = boost::any_cast<signed int>(args.at(index)); vec[index] = MonoStoreAndGetPtr<signed int>(argsStore, args, index);
vec[index] = ((void *) &val);
break; break;
} }
case 'l': case 'l':
{ {
auto val = boost::any_cast<unsigned long long>(args.at(index)); vec[index] = MonoStoreAndGetPtr<unsigned long long>(argsStore, args, index);
vec[index] = ((void *) &val);
break; break;
} }
case 'w': case 'w':
{ {
auto val = boost::any_cast<signed long long>(args.at(index)); vec[index] = MonoStoreAndGetPtr<signed long long>(argsStore, args, index);
vec[index] = ((void *) &val);
break; break;
} }
case 'f': case 'f':
{ {
auto val = boost::any_cast<double>(args.at(index)); vec[index] = MonoStoreAndGetPtr<double>(argsStore, args, index);
vec[index] = ((void *) &val);
break; break;
} }
case 'p': case 'p':
{ {
auto val = boost::any_cast<void *>(args.at(index)); vec[index] = MonoStoreAndGetPtr<void *>(argsStore, args, index);
vec[index] = ((void *) &val);
break; break;
} }
case 's': case 's':
@ -501,13 +490,12 @@ boost::any LangMono::Call(const char *name, const char *argl, const std::vector<
} }
case 'b': case 'b':
{ {
auto val = boost::any_cast<int>(args.at(index)); vec[index] = MonoStoreAndGetPtr<int>(argsStore, args, index);
vec[index] = ((void *) &val);
break; break;
} }
default: default:
throw std::runtime_error("Mono call: Unknown argument identifier " + argl[index]); throw std::runtime_error(std::string("Mono call: Unknown argument identifier ") + argl[index]);
} }
} }

@ -8,6 +8,25 @@
#include <Script/SystemInterface.hpp> #include <Script/SystemInterface.hpp>
#include <unordered_map> #include <unordered_map>
#include <mono/metadata/object.h> #include <mono/metadata/object.h>
#include <boost/variant.hpp>
typedef boost::variant<unsigned int, signed int, unsigned long long, signed long long, double, void*> TMonoArgVariant;
typedef std::vector<TMonoArgVariant> TMonoArgsStore;
template<typename T>
void *MonoStoreAndGetPtr(TMonoArgsStore &argsStore, va_list &vargs, size_t index)
{
argsStore[index] = va_arg(vargs, T);
return (void *) &boost::get<T&>(argsStore[index]);
}
template<typename T>
void *MonoStoreAndGetPtr(TMonoArgsStore &argsStore, const std::vector<boost::any> &args, size_t index)
{
argsStore[index] = boost::any_cast<T>(args.at(index));
return (void *) &boost::get<T&>(argsStore[index]);
}
struct MethodKey struct MethodKey
{ {
@ -16,10 +35,8 @@ struct MethodKey
return other.paramsCnt == paramsCnt && other.name == name; return other.paramsCnt == paramsCnt && other.name == name;
} }
MethodKey(const std::string &name, int paramsCnt) MethodKey(const std::string &name, int paramsCnt): name(name), paramsCnt(paramsCnt)
{ {
this->name = name;
this->paramsCnt = paramsCnt;
} }
std::string name; std::string name;

@ -91,7 +91,7 @@ lib_t LangNative::GetInterface()
} }
LangNative::LangNative() LangNative::LangNative(): lib(nullptr)
{ {
} }

@ -78,8 +78,8 @@ boost::any ScriptFunction::Call(const vector<boost::any> &args)
#if defined (ENABLE_MONO) #if defined (ENABLE_MONO)
else if (script_type == SCRIPT_MONO) else if (script_type == SCRIPT_MONO)
{ {
std::vector<void *> argList; std::vector<void *> argList(args.size());
argList.resize(args.size()); TMonoArgsStore argsStore(args.size());
for (size_t index = 0; index < args.size(); index++) for (size_t index = 0; index < args.size(); index++)
{ {
@ -87,38 +87,32 @@ boost::any ScriptFunction::Call(const vector<boost::any> &args)
{ {
case 'i': case 'i':
{ {
auto val = boost::any_cast<unsigned int>(args.at(index)); argList[index] = MonoStoreAndGetPtr<unsigned int>(argsStore, args, index);
argList[index] = ((void *) &val);
break; break;
} }
case 'q': case 'q':
{ {
auto val = boost::any_cast<signed int>(args.at(index)); argList[index] = MonoStoreAndGetPtr<signed int>(argsStore, args, index);
argList[index] = ((void *) &val);
break; break;
} }
case 'l': case 'l':
{ {
auto val = boost::any_cast<unsigned long long>(args.at(index)); argList[index] = MonoStoreAndGetPtr<unsigned long long>(argsStore, args, index);
argList[index] = ((void *) &val);
break; break;
} }
case 'w': case 'w':
{ {
auto val = boost::any_cast<signed long long>(args.at(index)); argList[index] = MonoStoreAndGetPtr<signed long long>(argsStore, args, index);
argList[index] = ((void *) &val);
break; break;
} }
case 'f': case 'f':
{ {
auto val = boost::any_cast<double>(args.at(index)); argList[index] = MonoStoreAndGetPtr<double>(argsStore, args, index);
argList[index] = ((void *) &val);
break; break;
} }
case 'p': case 'p':
{ {
auto val = boost::any_cast<void *>(args.at(index)); argList[index] = MonoStoreAndGetPtr<void *>(argsStore, args, index);
argList[index] = ((void *) &val);
break; break;
} }
case 's': case 's':
@ -133,8 +127,7 @@ boost::any ScriptFunction::Call(const vector<boost::any> &args)
} }
case 'b': case 'b':
{ {
auto val = boost::any_cast<int>(args.at(index)); argList[index] = MonoStoreAndGetPtr<int>(argsStore, args, index);
argList[index] = ((void *) &val);
break; break;
} }

@ -56,7 +56,7 @@ void ScriptFunctions::GetArguments(std::vector<boost::any> &params, 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)

@ -321,13 +321,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);
masterClient->SetMaxPlayers((unsigned) players);
masterClient->SetUpdateRate((unsigned) updateRate);
string hostname = mgr.getString("hostname", "General"); string hostname = mgr.getString("hostname", "General");
networking.getMasterClient()->SetHostname(hostname); masterClient->SetHostname(hostname);
networking.getMasterClient()->SetRuleString("CommitHash", version.mCommitHash.substr(0, 10)); masterClient->SetRuleString("CommitHash", version.mCommitHash.substr(0, 10));
networking.getMasterClient()->Start(); 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…
Cancel
Save