added password support

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401166
This commit is contained in:
David Anderson 2007-07-24 17:05:46 +00:00
parent 9c44d29b23
commit 9ef04b07e7
3 changed files with 33 additions and 2 deletions

View File

@ -46,4 +46,10 @@
* String to use as the silent chat trigger. Set an empty string to disable.
*/
"SilentChatTrigger" "/"
/**
* Password setinfo key that clients must set. You must change this in order for
* passwords to work, for security reasons.
*/
"PassInfoVar" "_password"
}

View File

@ -98,6 +98,23 @@ void PlayerManager::OnSourceModShutdown()
delete [] m_Players;
}
ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key,
const char *value,
ConfigSource source,
char *error,
size_t maxlength)
{
if (strcmp(key, "PassInfoVar") == 0)
{
if (strcmp(value, "_password") != 0)
{
m_PassInfoVar.assign(value);
}
return ConfigResult_Accept;
}
return ConfigResult_Ignore;
}
void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
{
if (m_FirstPass)
@ -119,13 +136,18 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl
SM_ExecuteAllConfigs();
}
bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
{
const char *password = g_Admins.GetAdminPassword(id);
if (password != NULL)
{
if (m_PassInfoVar.size() < 1)
{
return false;
}
/* Whoa... the user needs a password! */
const char *given = engine->GetClientConVarValue(index, "_password");
const char *given = engine->GetClientConVarValue(index, m_PassInfoVar.c_str());
if (!given || strcmp(given, password) != 0)
{
return false;

View File

@ -76,6 +76,7 @@ public: //SMGlobalClass
void OnSourceModAllInitialized();
void OnSourceModShutdown();
void OnSourceModLevelEnd();
ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
public:
CPlayer *GetPlayerByIndex(int client) const;
void RunAuthChecks();
@ -108,6 +109,7 @@ public:
}
private:
void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
private:
List<IClientListener *> m_hooks;
IForward *m_clconnect;
@ -125,6 +127,7 @@ private:
int m_PlayerCount;
bool m_FirstPass;
unsigned int *m_AuthQueue;
String m_PassInfoVar;
};
extern PlayerManager g_Players;