-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from mEldevlp/dev
add: User access, admin levels (amxmodx)
- Loading branch information
Showing
39 changed files
with
254 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#include "precompiled.h" | ||
|
||
surfmod::CUsers g_SurfModUsers; | ||
|
||
void surfmod::CUsers::ServerActivate() | ||
{ | ||
this->m_Data.clear(); | ||
this->m_Flag.clear(); | ||
|
||
CMemScript* lpMemScript = new CMemScript; | ||
|
||
if (!lpMemScript->SetBuffer(ADMIN_LIST_AMXMODX_PATH)) | ||
{ | ||
LOG_CONSOLE(PLID, "[%s] cannot SetBufer (%s)", __func__, ADMIN_LIST_AMXMODX_PATH); | ||
|
||
delete lpMemScript; | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
while (true) | ||
{ | ||
if (lpMemScript->GetToken() == eTokenResult::TOKEN_END) | ||
{ | ||
break; | ||
} | ||
|
||
P_ADMIN_INFO Info = { }; | ||
|
||
Info.Name = lpMemScript->GetString(); | ||
|
||
Info.Auth = lpMemScript->GetAsString(); | ||
|
||
Info.Flag = lpMemScript->GetAsString(); | ||
|
||
this->m_Data.insert(std::make_pair(Info.Auth, Info)); | ||
} | ||
} | ||
catch (...) | ||
{ | ||
LOG_CONSOLE(PLID, "[%s] %s", __func__, lpMemScript->GetError().c_str()); | ||
} | ||
|
||
delete lpMemScript; | ||
} | ||
|
||
int surfmod::CUsers::ReadFlags(const char* Flags) | ||
{ | ||
int Result = ACCES_ADMIN::ALL; | ||
|
||
while (*Flags) | ||
{ | ||
Result |= BIT(*Flags++ - 'a'); | ||
} | ||
|
||
return Result; | ||
} | ||
|
||
bool surfmod::CUsers::PlayerConnect(edict_t* pEntity, const char* pszName, const char* pszAddress, char szRejectReason[128]) | ||
{ | ||
if (!FNullEnt(pEntity)) | ||
{ | ||
auto EntityIndex = ENTINDEX(pEntity); | ||
|
||
this->m_Flag[EntityIndex] = ACCES_ADMIN::ALL; | ||
|
||
this->m_Flag[EntityIndex] |= this->ReadFlags("z"); | ||
|
||
auto Auth = g_engfuncs.pfnGetPlayerAuthId(pEntity); | ||
|
||
if (this->m_Data.find(Auth) != this->m_Data.end()) | ||
{ | ||
this->m_Flag[EntityIndex] |= this->ReadFlags(this->m_Data[Auth].Flag.c_str()); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
int surfmod::CUsers::GetFlags(int EntityIndex) | ||
{ | ||
return this->m_Flag[EntityIndex]; | ||
} | ||
|
||
std::string surfmod::CUsers::GetFlags(edict_t* pEdict) | ||
{ | ||
auto Auth = g_engfuncs.pfnGetPlayerAuthId(pEdict); | ||
|
||
if (Auth) | ||
{ | ||
if (this->m_Data.find(Auth) != this->m_Data.end()) | ||
{ | ||
return this->m_Data[Auth].Flag; | ||
} | ||
} | ||
|
||
return "z"; | ||
} | ||
|
||
int surfmod::CUsers::Access(int EntityIndex, ACCES_ADMIN Level) | ||
{ | ||
if (Level & ACCES_ADMIN::ADMIN) | ||
{ | ||
return (this->m_Flag[EntityIndex] > ACCES_ADMIN::ALL && !(this->m_Flag[EntityIndex] & ACCES_ADMIN::USER)); | ||
} | ||
else if (Level & ACCES_ADMIN::ALL) | ||
{ | ||
return 1; | ||
} | ||
|
||
return (this->m_Flag[EntityIndex] & Level); | ||
} | ||
|
||
int surfmod::CUsers::Access(std::string Auth, ACCES_ADMIN Level) | ||
{ | ||
auto Admin = this->m_Data.find(Auth); | ||
|
||
if (Admin != this->m_Data.end()) | ||
{ | ||
auto Flags = this->ReadFlags(Admin->second.Flag.c_str()); | ||
|
||
if (Level & ACCES_ADMIN::ADMIN) | ||
{ | ||
return (Flags > ACCES_ADMIN::ALL && !(Flags & ACCES_ADMIN::USER)); | ||
} | ||
else if (Level & ACCES_ADMIN::ALL) | ||
{ | ||
return 1; | ||
} | ||
|
||
return (Flags & Level); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#pragma once | ||
|
||
#define ADMIN_LIST_AMXMODX_PATH "cstrike/addons/SurfMod/configs/admins.ini" | ||
|
||
namespace surfmod { | ||
|
||
typedef struct S_ADMIN_INFO | ||
{ | ||
std::string Auth; | ||
std::string Name; | ||
std::string Flag; | ||
} P_ADMIN_INFO, * LP_ADMIN_INFO; | ||
|
||
enum ACCES_ADMIN | ||
{ | ||
ALL = 0, | ||
IMMUNITY = BIT(0), // flag - a | ||
RESERVATION = BIT(1), // flag - b | ||
KICK = BIT(2), // flag - c | ||
BAN = BIT(3), // flag - d | ||
SLAY = BIT(4), // flag - e | ||
MAP = BIT(5), // flag - f | ||
CVAR = BIT(6), // flag - g | ||
CFG = BIT(7), // flag - h | ||
CHAT = BIT(8), // flag - i | ||
VOTE = BIT(9), // flag - j | ||
PASSWORD = BIT(10), // flag - k | ||
RCON = BIT(11), // flag - l | ||
LEVEL_A = BIT(12), // flag - m | ||
LEVEL_B = BIT(13), // flag - n | ||
LEVEL_C = BIT(14), // flag - o | ||
LEVEL_D = BIT(15), // flag - p | ||
LEVEL_E = BIT(16), // flag - q | ||
LEVEL_F = BIT(17), // flag - r | ||
LEVEL_G = BIT(18), // flag - s | ||
LEVEL_H = BIT(19), // flag - t | ||
MENU = BIT(20), // flag - u | ||
BAN_TEMP = BIT(21), // flag - v | ||
|
||
ADMIN = BIT(24), // flag - y | ||
USER = BIT(25) // flag - z | ||
}; | ||
|
||
class CUsers | ||
{ | ||
public: | ||
void ServerActivate(); | ||
|
||
int ReadFlags(const char* Flags); | ||
|
||
bool PlayerConnect(edict_t* pEntity, const char* pszName, const char* pszAddress, char szRejectReason[128]); | ||
|
||
int GetFlags(int EntityIndex); | ||
|
||
std::string GetFlags(edict_t* pEdict); | ||
|
||
int Access(int EntityIndex, ACCES_ADMIN Level); | ||
|
||
int Access(std::string Auth, ACCES_ADMIN Level); | ||
|
||
private: | ||
std::unordered_map<std::string, P_ADMIN_INFO> m_Data; | ||
|
||
std::unordered_map<int, int> m_Flag; | ||
}; | ||
|
||
}; /* namespace surfmod */ | ||
|
||
extern surfmod::CUsers g_SurfModUsers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.