mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
If no rcon password is set, generate one
After the generation (using the OS random number generator), the password is displayed to the user on stdout.
This commit is contained in:
parent
903878f4a2
commit
7af6e6ae5b
|
@ -285,6 +285,8 @@ CServer::CServer() : m_DemoRecorder(&m_SnapshotDelta)
|
||||||
m_RconClientID = IServer::RCON_CID_SERV;
|
m_RconClientID = IServer::RCON_CID_SERV;
|
||||||
m_RconAuthLevel = AUTHED_ADMIN;
|
m_RconAuthLevel = AUTHED_ADMIN;
|
||||||
|
|
||||||
|
m_GeneratedRconPassword = 0;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,6 +510,36 @@ int CServer::MaxClients() const
|
||||||
return m_NetServer.MaxClients();
|
return m_NetServer.MaxClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CServer::InitRconPasswordIfEmpty()
|
||||||
|
{
|
||||||
|
if(g_Config.m_SvRconPassword[0])
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char VALUES[] = "ABCDEFGHKLMNPRSTUVWXYZabcdefghjkmnopqt23456789";
|
||||||
|
static const size_t NUM_VALUES = sizeof(VALUES) - 1; // Disregard the '\0'.
|
||||||
|
static const size_t PASSWORD_LENGTH = 6;
|
||||||
|
dbg_assert(NUM_VALUES * NUM_VALUES >= 2048, "need at least 2048 possibilities for 2-character sequences");
|
||||||
|
// With 6 characters, we get a password entropy of log(2048) * 6/2 = 33bit.
|
||||||
|
|
||||||
|
dbg_assert(PASSWORD_LENGTH % 2 == 0, "need an even password length");
|
||||||
|
unsigned short aRandom[PASSWORD_LENGTH / 2];
|
||||||
|
char aRandomPassword[PASSWORD_LENGTH+1];
|
||||||
|
aRandomPassword[PASSWORD_LENGTH] = 0;
|
||||||
|
|
||||||
|
secure_random_fill(aRandom, sizeof(aRandom));
|
||||||
|
for(size_t i = 0; i < PASSWORD_LENGTH / 2; i++)
|
||||||
|
{
|
||||||
|
unsigned short RandomNumber = aRandom[i] % 2048;
|
||||||
|
aRandomPassword[2 * i + 0] = VALUES[RandomNumber / NUM_VALUES];
|
||||||
|
aRandomPassword[2 * i + 1] = VALUES[RandomNumber % NUM_VALUES];
|
||||||
|
}
|
||||||
|
|
||||||
|
str_copy(g_Config.m_SvRconPassword, aRandomPassword, sizeof(g_Config.m_SvRconPassword));
|
||||||
|
m_GeneratedRconPassword = 1;
|
||||||
|
}
|
||||||
|
|
||||||
int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID)
|
int CServer::SendMsg(CMsgPacker *pMsg, int Flags, int ClientID)
|
||||||
{
|
{
|
||||||
CNetChunk Packet;
|
CNetChunk Packet;
|
||||||
|
@ -1296,6 +1328,13 @@ int CServer::Run()
|
||||||
// process pending commands
|
// process pending commands
|
||||||
m_pConsole->StoreCommands(false);
|
m_pConsole->StoreCommands(false);
|
||||||
|
|
||||||
|
if(m_GeneratedRconPassword)
|
||||||
|
{
|
||||||
|
dbg_msg("server", "+-------------------------+");
|
||||||
|
dbg_msg("server", "| rcon password: '%s' |", g_Config.m_SvRconPassword);
|
||||||
|
dbg_msg("server", "+-------------------------+");
|
||||||
|
}
|
||||||
|
|
||||||
// start game
|
// start game
|
||||||
{
|
{
|
||||||
int64 ReportTime = time_get();
|
int64 ReportTime = time_get();
|
||||||
|
@ -1741,6 +1780,8 @@ int main(int argc, const char **argv) // ignore_convention
|
||||||
|
|
||||||
pEngine->InitLogfile();
|
pEngine->InitLogfile();
|
||||||
|
|
||||||
|
pServer->InitRconPasswordIfEmpty();
|
||||||
|
|
||||||
// run the server
|
// run the server
|
||||||
dbg_msg("server", "starting...");
|
dbg_msg("server", "starting...");
|
||||||
pServer->Run();
|
pServer->Run();
|
||||||
|
|
|
@ -161,6 +161,8 @@ public:
|
||||||
int m_CurrentMapSize;
|
int m_CurrentMapSize;
|
||||||
int m_MapChunksPerRequest;
|
int m_MapChunksPerRequest;
|
||||||
|
|
||||||
|
int m_GeneratedRconPassword;
|
||||||
|
|
||||||
CDemoRecorder m_DemoRecorder;
|
CDemoRecorder m_DemoRecorder;
|
||||||
CRegister m_Register;
|
CRegister m_Register;
|
||||||
CMapChecker m_MapChecker;
|
CMapChecker m_MapChecker;
|
||||||
|
@ -183,6 +185,8 @@ public:
|
||||||
|
|
||||||
int Init();
|
int Init();
|
||||||
|
|
||||||
|
void InitRconPasswordIfEmpty();
|
||||||
|
|
||||||
void SetRconCID(int ClientID);
|
void SetRconCID(int ClientID);
|
||||||
bool IsAuthed(int ClientID) const;
|
bool IsAuthed(int ClientID) const;
|
||||||
bool IsBanned(int ClientID) const;
|
bool IsBanned(int ClientID) const;
|
||||||
|
|
Loading…
Reference in a new issue