forked from mirror/openmw-tes3mp
[Server] Add ability to set password to server from config & scripts
This commit is contained in:
parent
3e50cf60e7
commit
158e9b3b09
7 changed files with 24 additions and 2 deletions
|
@ -16,6 +16,7 @@
|
|||
#include "Networking.hpp"
|
||||
#include "MasterClient.hpp"
|
||||
#include "Cell.hpp"
|
||||
#include <components/openmw-mp/Version.hpp>
|
||||
|
||||
using namespace mwmp;
|
||||
using namespace std;
|
||||
|
@ -43,6 +44,8 @@ Networking::Networking(RakNet::RakPeerInterface *peer)
|
|||
exitCode = 0;
|
||||
|
||||
Script::Call<Script::CallbackIdentity("OnServerInit")>();
|
||||
|
||||
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(),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"))
|
||||
{
|
||||
|
|
|
@ -8,4 +8,6 @@
|
|||
#define TES3MP_VERSION "0.5.0"
|
||||
#define TES3MP_PROTO_VERSION 6
|
||||
|
||||
#define TES3MP_DEFAULT_PASSW "SuperPassword"
|
||||
|
||||
#endif //OPENMW_VERSION_HPP
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue