MCPcopy Create free account
hub / github.com/ddnet/ddnet / ConAuthAddHashed

Method ConAuthAddHashed

src/engine/server/server.cpp:3656–3705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3654}
3655
3656void CServer::ConAuthAddHashed(IConsole::IResult *pResult, void *pUser)
3657{
3658 CServer *pThis = (CServer *)pUser;
3659 CAuthManager *pManager = &pThis->m_AuthManager;
3660
3661 const char *pIdent = pResult->GetString(0);
3662 const char *pLevel = pResult->GetString(1);
3663 const char *pPw = pResult->GetString(2);
3664 const char *pSalt = pResult->GetString(3);
3665
3666 if(!pManager->IsValidIdent(pIdent))
3667 {
3668 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "ident is invalid");
3669 return;
3670 }
3671
3672 int Level = GetAuthLevel(pLevel);
3673 if(Level == -1)
3674 {
3675 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "level can be one of {\"admin\", \"mod(erator)\", \"helper\"}");
3676 return;
3677 }
3678 // back compat to change "mod", "modder" and so on as parameters to "moderator"
3679 pLevel = CAuthManager::AuthLevelToRoleName(Level);
3680
3681 MD5_DIGEST Hash;
3682 unsigned char aSalt[SALT_BYTES];
3683
3684 if(md5_from_str(&Hash, pPw))
3685 {
3686 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "Malformed password hash");
3687 return;
3688 }
3689 if(str_hex_decode(aSalt, sizeof(aSalt), pSalt))
3690 {
3691 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "Malformed salt hash");
3692 return;
3693 }
3694
3695 bool NeedUpdate = !pManager->NumNonDefaultKeys();
3696
3697 if(pManager->AddKeyHash(pIdent, Hash, aSalt, pLevel) < 0)
3698 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "ident already exists");
3699 else
3700 {
3701 if(NeedUpdate)
3702 pThis->SendRconType(-1, true);
3703 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "key added");
3704 }
3705}
3706
3707void CServer::ConAuthUpdate(IConsole::IResult *pResult, void *pUser)
3708{

Callers

nothing calls this directly

Calls 10

GetAuthLevelFunction · 0.85
md5_from_strFunction · 0.85
str_hex_decodeFunction · 0.85
IsValidIdentMethod · 0.80
NumNonDefaultKeysMethod · 0.80
AddKeyHashMethod · 0.80
SendRconTypeMethod · 0.80
GetStringMethod · 0.45
PrintMethod · 0.45
ConsoleMethod · 0.45

Tested by

no test coverage detected