[General] Remove 'using namespace std' from multiplayer components

pull/593/head
David Cernat 4 years ago
parent b3c40913f6
commit 4940687455

@ -5,7 +5,6 @@
using namespace mwmp; using namespace mwmp;
using namespace RakNet; using namespace RakNet;
using namespace std;
PacketMasterAnnounce::PacketMasterAnnounce(RakNet::RakPeerInterface *peer) : BasePacket(peer) PacketMasterAnnounce::PacketMasterAnnounce(RakNet::RakPeerInterface *peer) : BasePacket(peer)
{ {

@ -6,7 +6,6 @@
using namespace mwmp; using namespace mwmp;
using namespace std;
using namespace RakNet; using namespace RakNet;
PacketMasterQuery::PacketMasterQuery(RakNet::RakPeerInterface *peer) : BasePacket(peer) PacketMasterQuery::PacketMasterQuery(RakNet::RakPeerInterface *peer) : BasePacket(peer)
@ -26,12 +25,12 @@ void PacketMasterQuery::Packet(RakNet::BitStream *newBitstream, bool send)
RW(serversCount, send); RW(serversCount, send);
map<SystemAddress, QueryData>::iterator serverIt; std::map<SystemAddress, QueryData>::iterator serverIt;
if (send) if (send)
serverIt = servers->begin(); serverIt = servers->begin();
QueryData server; QueryData server;
string addr; std::string addr;
uint16_t port; uint16_t port;
while (serversCount--) while (serversCount--)
{ {
@ -55,12 +54,12 @@ void PacketMasterQuery::Packet(RakNet::BitStream *newBitstream, bool send)
if (send) if (send)
serverIt++; serverIt++;
else else
servers->insert(pair<SystemAddress, QueryData>(SystemAddress(addr.c_str(), port), server)); servers->insert(std::pair<SystemAddress, QueryData>(SystemAddress(addr.c_str(), port), server));
} }
} }
void PacketMasterQuery::SetServers(map<SystemAddress, QueryData> *serverMap) void PacketMasterQuery::SetServers(std::map<SystemAddress, QueryData> *serverMap)
{ {
servers = serverMap; servers = serverMap;
} }

@ -3,7 +3,6 @@
#include "ProxyMasterPacket.hpp" #include "ProxyMasterPacket.hpp"
using namespace mwmp; using namespace mwmp;
using namespace std;
using namespace RakNet; using namespace RakNet;
PacketMasterUpdate::PacketMasterUpdate(RakNet::RakPeerInterface *peer) : BasePacket(peer) PacketMasterUpdate::PacketMasterUpdate(RakNet::RakPeerInterface *peer) : BasePacket(peer)
@ -19,7 +18,7 @@ void PacketMasterUpdate::Packet(RakNet::BitStream *newBitstream, bool send)
if (send) if (send)
bs->Write(packetID); bs->Write(packetID);
string addr = server->first.ToString(false); std::string addr = server->first.ToString(false);
uint16_t port = server->first.GetPort(); uint16_t port = server->first.GetPort();
RW(addr, send); RW(addr, send);

@ -22,22 +22,20 @@ namespace mwmp
template<class Packet> template<class Packet>
static void addServer(Packet *packet, QueryData &server, bool send) static void addServer(Packet *packet, QueryData &server, bool send)
{ {
using namespace std;
int32_t rulesSize = server.rules.size(); int32_t rulesSize = server.rules.size();
packet->RW(rulesSize, send); packet->RW(rulesSize, send);
if (rulesSize > QueryData::maxRules) if (rulesSize > QueryData::maxRules)
rulesSize = 0; rulesSize = 0;
map<string, ServerRule>::iterator ruleIt; std::map<std::string, ServerRule>::iterator ruleIt;
if (send) if (send)
ruleIt = server.rules.begin(); ruleIt = server.rules.begin();
while (rulesSize--) while (rulesSize--)
{ {
ServerRule *rule = nullptr; ServerRule *rule = nullptr;
string key; std::string key;
if (send) if (send)
{ {
key = ruleIt->first; key = ruleIt->first;
@ -47,7 +45,7 @@ namespace mwmp
packet->RW(key, send, false, QueryData::maxStringLength); packet->RW(key, send, false, QueryData::maxStringLength);
if (!send) if (!send)
{ {
ruleIt = server.rules.insert(pair<string, ServerRule>(key, ServerRule())).first; ruleIt = server.rules.insert(std::pair<std::string, ServerRule>(key, ServerRule())).first;
rule = &ruleIt->second; rule = &ruleIt->second;
} }
@ -62,7 +60,7 @@ namespace mwmp
ruleIt++; ruleIt++;
} }
vector<string>::iterator plIt; std::vector<std::string>::iterator plIt;
int32_t playersCount = server.players.size(); int32_t playersCount = server.players.size();
packet->RW(playersCount, send); packet->RW(playersCount, send);

@ -1,7 +1,6 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerBook.hpp" #include "PacketPlayerBook.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerBook::PacketPlayerBook(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerBook::PacketPlayerBook(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -1,7 +1,6 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerFaction.hpp" #include "PacketPlayerFaction.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerFaction::PacketPlayerFaction(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerFaction::PacketPlayerFaction(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -1,7 +1,6 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerInventory.hpp" #include "PacketPlayerInventory.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerInventory::PacketPlayerInventory(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerInventory::PacketPlayerInventory(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -1,7 +1,6 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerJournal.hpp" #include "PacketPlayerJournal.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerJournal::PacketPlayerJournal(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerJournal::PacketPlayerJournal(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -1,7 +1,6 @@
#include "PacketPlayerPosition.hpp" #include "PacketPlayerPosition.hpp"
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerPosition::PacketPlayerPosition(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerPosition::PacketPlayerPosition(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -1,7 +1,6 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerQuickKeys.hpp" #include "PacketPlayerQuickKeys.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerQuickKeys::PacketPlayerQuickKeys(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerQuickKeys::PacketPlayerQuickKeys(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -1,7 +1,6 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerSpellbook.hpp" #include "PacketPlayerSpellbook.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerSpellbook::PacketPlayerSpellbook(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerSpellbook::PacketPlayerSpellbook(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -1,7 +1,6 @@
#include <components/openmw-mp/NetworkMessages.hpp> #include <components/openmw-mp/NetworkMessages.hpp>
#include "PacketPlayerTopic.hpp" #include "PacketPlayerTopic.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketPlayerTopic::PacketPlayerTopic(RakNet::RakPeerInterface *peer) : PlayerPacket(peer) PacketPlayerTopic::PacketPlayerTopic(RakNet::RakPeerInterface *peer) : PlayerPacket(peer)

@ -2,7 +2,6 @@
#include <components/openmw-mp/TimedLog.hpp> #include <components/openmw-mp/TimedLog.hpp>
#include "PacketWorldMap.hpp" #include "PacketWorldMap.hpp"
using namespace std;
using namespace mwmp; using namespace mwmp;
PacketWorldMap::PacketWorldMap(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer) PacketWorldMap::PacketWorldMap(RakNet::RakPeerInterface *peer) : WorldstatePacket(peer)

@ -8,8 +8,6 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include "TimedLog.hpp" #include "TimedLog.hpp"
using namespace std;
TimedLog *TimedLog::sTimedLog = nullptr; TimedLog *TimedLog::sTimedLog = nullptr;
TimedLog::TimedLog(int logLevel) : logLevel(logLevel) TimedLog::TimedLog(int logLevel) : logLevel(logLevel)
@ -99,15 +97,15 @@ void TimedLog::print(int level, bool hasPrefix, const char *file, int line, cons
sstr << '\n'; sstr << '\n';
va_list args; va_list args;
va_start(args, message); va_start(args, message);
vector<char> buf((unsigned long) (vsnprintf(nullptr, 0, sstr.str().c_str(), args) + 1)); std::vector<char> buf((unsigned long) (vsnprintf(nullptr, 0, sstr.str().c_str(), args) + 1));
va_end(args); va_end(args);
va_start(args, message); va_start(args, message);
vsnprintf(buf.data(), buf.size(), sstr.str().c_str(), args); vsnprintf(buf.data(), buf.size(), sstr.str().c_str(), args);
va_end(args); va_end(args);
cout << buf.data() << flush; std::cout << buf.data() << std::flush;
} }
string TimedLog::getFilenameTimestamp() std::string TimedLog::getFilenameTimestamp()
{ {
time_t rawtime = time(0); time_t rawtime = time(0);
struct tm *timeinfo = localtime(&rawtime); struct tm *timeinfo = localtime(&rawtime);

@ -11,8 +11,6 @@
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <iomanip> #include <iomanip>
using namespace std;
#ifdef _WIN32 #ifdef _WIN32
int setenv(const char *name, const char *value, int overwrite) int setenv(const char *name, const char *value, int overwrite)
{ {
@ -117,15 +115,15 @@ std::string Utils::toString(int num)
return stream.str(); return stream.str();
} }
std::string Utils::replaceString(const string& source, const char* find, const char* replace) std::string Utils::replaceString(const std::string& source, const char* find, const char* replace)
{ {
unsigned int find_len = strlen(find); unsigned int find_len = strlen(find);
unsigned int replace_len = strlen(replace); unsigned int replace_len = strlen(replace);
size_t pos = 0; size_t pos = 0;
string dest = source; std::string dest = source;
while ((pos = dest.find(find, pos)) != string::npos) while ((pos = dest.find(find, pos)) != std::string::npos)
{ {
dest.replace(pos, find_len, replace); dest.replace(pos, find_len, replace);
pos += replace_len; pos += replace_len;
@ -134,7 +132,7 @@ std::string Utils::replaceString(const string& source, const char* find, const c
return dest; return dest;
} }
string& Utils::removeExtension(string& file) std::string& Utils::removeExtension(std::string& file)
{ {
size_t pos = file.find_last_of('.'); size_t pos = file.find_last_of('.');
@ -211,23 +209,23 @@ std::string Utils::getVersionInfo(std::string appName, std::string version, std:
{ {
std::stringstream stream; std::stringstream stream;
stream << appName << " " << version << " (" << getOperatingSystemType() << " " << getArchitectureType() << ")" << endl; stream << appName << " " << version << " (" << getOperatingSystemType() << " " << getArchitectureType() << ")" << std::endl;
stream << "Protocol version: " << protocol << endl; stream << "Protocol version: " << protocol << std::endl;
stream << "Oldest compatible commit hash: " << commitHash.substr(0, 10) << endl; stream << "Oldest compatible commit hash: " << commitHash.substr(0, 10) << std::endl;
stream << "------------------------------------------------------------" << endl; stream << "------------------------------------------------------------" << std::endl;
return stream.str(); return stream.str();
} }
void Utils::printWithWidth(ostringstream &sstr, string str, size_t width) void Utils::printWithWidth(std::ostringstream &sstr, std::string str, size_t width)
{ {
sstr << left << setw(width) << setfill(' ') << str; sstr << std::left << std::setw(width) << std::setfill(' ') << str;
} }
string Utils::intToHexStr(unsigned val) std::string Utils::intToHexStr(unsigned val)
{ {
ostringstream sstr; std::ostringstream sstr;
sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val; sstr << "0x" << std::setfill('0') << std::setw(8) << std::uppercase << std::hex << val;
return sstr.str(); return sstr.str();
} }

Loading…
Cancel
Save