diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 352756f53..6fc12a321 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -16,6 +16,7 @@ #include "Networking.hpp" #include "MasterClient.hpp" #include "Cell.hpp" +#include using namespace mwmp; using namespace std; @@ -43,6 +44,8 @@ Networking::Networking(RakNet::RakPeerInterface *peer) exitCode = 0; Script::Call(); + + serverPassword = TES3MP_DEFAULT_PASSW; } Networking::~Networking() @@ -56,6 +59,11 @@ Networking::~Networking() LOG_QUIT(); } +void Networking::setServerPassword(std::string passw) noexcept +{ + serverPassword = passw.empty() ? TES3MP_DEFAULT_PASSW : passw; +} + void Networking::processPlayerPacket(RakNet::Packet *packet) { Player *player = Players::getPlayer(packet->guid); @@ -64,7 +72,6 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) if (packet->data[0] == ID_HANDSHAKE) { - string passw = "SuperPassword"; myPacket->Read(player); @@ -77,7 +84,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) return; } - if (player->passw != passw) + if (player->passw != serverPassword) { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Wrong server password for player %d, name: %s (pass: %s)", player->getId(), diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 24bac7775..6aa8e1f77 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -40,11 +40,13 @@ namespace mwmp MasterClient *getMasterClient(); void InitQuery(std::string queryAddr, unsigned short queryPort, std::string serverAddr, unsigned short serverPort); + void setServerPassword(std::string passw) noexcept; static const Networking &get(); static Networking *getPtr(); private: + std::string serverPassword; static Networking *sThis; RakNet::RakPeerInterface *peer; RakNet::BitStream bsOut; diff --git a/apps/openmw-mp/Script/ScriptFunctions.cpp b/apps/openmw-mp/Script/ScriptFunctions.cpp index 42f9ec557..a4032238c 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.cpp +++ b/apps/openmw-mp/Script/ScriptFunctions.cpp @@ -139,3 +139,8 @@ void ScriptFunctions::SetHostname(const char *name) noexcept { mwmp::Networking::getPtr()->getMasterClient()->SetHostname(name); } + +void ScriptFunctions::SetServerPassword(const char *passw) noexcept +{ + mwmp::Networking::getPtr()->setServerPassword(passw); +} diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 2233f6c99..9d8817597 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -66,6 +66,7 @@ public: static int GetAvgPing(unsigned short pid) noexcept; static void SetModname(const char* name) noexcept; static void SetHostname(const char* name) noexcept; + static void SetServerPassword(const char *passw) noexcept; static constexpr ScriptFunctionData functions[]{ {"CreateTimer", ScriptFunctions::CreateTimer}, @@ -88,6 +89,7 @@ public: {"GetAvgPing", ScriptFunctions::GetAvgPing}, {"SetModname", ScriptFunctions::SetModname}, {"SetHostname", ScriptFunctions::SetHostname}, + {"SetServerPassword", ScriptFunctions::SetServerPassword}, POSITIONAPI, CELLAPI, diff --git a/apps/openmw-mp/main.cpp b/apps/openmw-mp/main.cpp index ee6b7e558..4ac4ce764 100644 --- a/apps/openmw-mp/main.cpp +++ b/apps/openmw-mp/main.cpp @@ -183,6 +183,8 @@ int main(int argc, char *argv[]) string addr = mgr.getString("address", "General"); int port = mgr.getInt("port", "General"); + string passw = mgr.getString("password", "General"); + string plugin_home = mgr.getString("home", "Plugins"); string moddir = Utils::convertPath(plugin_home + "/data"); @@ -227,6 +229,7 @@ int main(int argc, char *argv[]) peer->SetMaximumIncomingConnections((unsigned short)(players)); Networking networking(peer); + networking.setServerPassword(passw); if ( mgr.getBool("enabled", "MasterServer")) { diff --git a/components/openmw-mp/Version.hpp b/components/openmw-mp/Version.hpp index 99336ef42..587b86056 100644 --- a/components/openmw-mp/Version.hpp +++ b/components/openmw-mp/Version.hpp @@ -8,4 +8,6 @@ #define TES3MP_VERSION "0.5.0" #define TES3MP_PROTO_VERSION 6 +#define TES3MP_DEFAULT_PASSW "SuperPassword" + #endif //OPENMW_VERSION_HPP diff --git a/files/tes3mp/tes3mp-server-default.cfg b/files/tes3mp/tes3mp-server-default.cfg index 85566f089..759c050a8 100644 --- a/files/tes3mp/tes3mp-server-default.cfg +++ b/files/tes3mp/tes3mp-server-default.cfg @@ -5,6 +5,7 @@ players = 64 hostname = My TES3MP server # 0 - Verbose (spam), 1 - Info, 2 - Warnings, 3 - Errors, 4 - Only fatal errors loglevel = 1 +password = [Plugins] #home = ~/local/openmw/tes3mp