Skip to content

Commit

Permalink
Merge pull request #11 from mEldevlp/dev
Browse files Browse the repository at this point in the history
add: User access, admin levels (amxmodx)
  • Loading branch information
Daniel Kondrashoff authored Sep 19, 2023
2 parents 3431158 + ad1f092 commit 4a3a75a
Show file tree
Hide file tree
Showing 39 changed files with 254 additions and 6 deletions.
Binary file modified Release/SurfMod_mm.dll
Binary file not shown.
14 changes: 14 additions & 0 deletions SurfMod/MetaDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS* pFunctionTable, int* interfaceVersi
gDLL_FunctionTable_Pre.pfnCmdEnd = DLL_PRE_CmdEnd;

gDLL_FunctionTable_Pre.pfnClientDisconnect = DLL_PRE_ClientDisconnect;
gDLL_FunctionTable_Pre.pfnClientConnect = DLL_PRE_ClientConnect;

memcpy(pFunctionTable, &gDLL_FunctionTable_Pre, sizeof(DLL_FUNCTIONS));

Expand Down Expand Up @@ -49,6 +50,18 @@ void DLL_PRE_ClientDisconnect(edict_t* player)

RETURN_META(MRES_IGNORED);
}

BOOL DLL_PRE_ClientConnect(edict_t* pEntity, const char* pszName, const char* pszAddress, char szRejectReason[128])
{
if (!g_SurfModUsers.PlayerConnect(pEntity, pszName, pszAddress, szRejectReason))
{
RETURN_META_VALUE(MRES_SUPERCEDE, FALSE);
return FALSE;
}

RETURN_META_VALUE(MRES_IGNORED, TRUE);
return TRUE;
}
#pragma endregion

#pragma region DLL_POST
Expand All @@ -69,6 +82,7 @@ C_DLLEXPORT int GetEntityAPI2_Post(DLL_FUNCTIONS* pFunctionTable, int* interface

void DLL_POST_ServerActivate(edict_t* pEdictList, int edictCount, int clientMax)
{
g_SurfModUsers.ServerActivate();
g_SurfModCommand.ServerActivate();
g_SurfModTask.ServerActivate();

Expand Down
1 change: 1 addition & 0 deletions SurfMod/MetaDLL.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
void DLL_PRE_CmdStart(const edict_t* player, const struct usercmd_s* cmd, unsigned int random_seed);
void DLL_PRE_CmdEnd(const edict_t* player);
void DLL_PRE_ClientDisconnect(edict_t* player);
BOOL DLL_PRE_ClientConnect(edict_t* pEntity, const char* pszName, const char* pszAddress, char szRejectReason[128]);
#pragma endregion

#pragma region DLL_POST
Expand Down
Binary file modified SurfMod/Release/MetaDLL.obj
Binary file not shown.
Binary file modified SurfMod/Release/MetaEngine.obj
Binary file not shown.
Binary file modified SurfMod/Release/MetaMod.obj
Binary file not shown.
Binary file modified SurfMod/Release/ReAPI.obj
Binary file not shown.
Binary file modified SurfMod/Release/ReGameDLL.obj
Binary file not shown.
4 changes: 2 additions & 2 deletions SurfMod/Release/SurfMod.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
 SurfModDuels.cpp
 SurfModBox.cpp
Creating library C:\Users\mEl\Desktop\Surf-Mod-mm\Release\SurfMod_mm.lib and object C:\Users\mEl\Desktop\Surf-Mod-mm\Release\SurfMod_mm.exp
Generating code
0 of 701 functions ( 0.0%) were compiled, the rest were copied from previous compilation.
0 of 1306 functions ( 0.0%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
0 functions had inline decision re-evaluated but remain unchanged
Finished generating code
Expand Down
Binary file modified SurfMod/Release/SurfMod.tlog/CL.command.1.tlog
Binary file not shown.
Binary file modified SurfMod/Release/SurfMod.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified SurfMod/Release/SurfMod.tlog/CL.write.1.tlog
Binary file not shown.
1 change: 1 addition & 0 deletions SurfMod/Release/SurfMod.tlog/Cl.items.tlog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\MetaMod.cpp;C:\Users\mEl\Desktop\Surf-M
C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\precompiled.cpp;C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\Release\precompiled.obj
C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\ReAPI.cpp;C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\Release\ReAPI.obj
C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\ReGameDLL.cpp;C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\Release\ReGameDLL.obj
C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\SurfModUsers.cpp;C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\Release\SurfModUsers.obj
C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\SurfModBox.cpp;C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\Release\SurfModBox.obj
C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\SurfModCommand.cpp;C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\Release\SurfModCommand.obj
C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\SurfModDuels.cpp;C:\Users\mEl\Desktop\Surf-Mod-mm\SurfMod\Release\SurfModDuels.obj
Expand Down
Binary file modified SurfMod/Release/SurfMod.tlog/link.command.1.tlog
Binary file not shown.
Binary file modified SurfMod/Release/SurfMod.tlog/link.read.1.tlog
Binary file not shown.
Binary file modified SurfMod/Release/SurfMod.tlog/link.write.1.tlog
Binary file not shown.
Binary file modified SurfMod/Release/SurfModCommand.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfModDuels.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfModFix.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfModMenu.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfModPlayer.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfModPlayerMenu.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfModTask.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfModUtils.obj
Binary file not shown.
Binary file modified SurfMod/Release/SurfMod_mm.iobj
Binary file not shown.
Binary file modified SurfMod/Release/SurfMod_mm.ipdb
Binary file not shown.
Binary file modified SurfMod/Release/SurfMod_mm.pch
Binary file not shown.
Binary file modified SurfMod/Release/precompiled.obj
Binary file not shown.
Binary file modified SurfMod/Release/vc143.pdb
Binary file not shown.
2 changes: 2 additions & 0 deletions SurfMod/SurfMod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<ClInclude Include="precompiled.h" />
<ClInclude Include="ReAPI.h" />
<ClInclude Include="ReGameDLL.h" />
<ClInclude Include="SurfModUsers.h" />
<ClInclude Include="SurfModBox.h" />
<ClInclude Include="SurfModCommand.h" />
<ClInclude Include="SurfModDuels.h" />
Expand All @@ -123,6 +124,7 @@
</ClCompile>
<ClCompile Include="ReAPI.cpp" />
<ClCompile Include="ReGameDLL.cpp" />
<ClCompile Include="SurfModUsers.cpp" />
<ClCompile Include="SurfModBox.cpp" />
<ClCompile Include="SurfModCommand.cpp" />
<ClCompile Include="SurfModDuels.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions SurfMod/SurfMod.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<Filter Include="SurfMod\SurfBox">
<UniqueIdentifier>{bafb44e3-d0ba-465b-ab4e-44a6eee63463}</UniqueIdentifier>
</Filter>
<Filter Include="SurfMod\SurfUsers">
<UniqueIdentifier>{53690b4e-9ec6-4d9d-9e87-5224a67e897a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MetaMod.h">
Expand Down Expand Up @@ -99,6 +102,9 @@
<ClInclude Include="SurfModBox.h">
<Filter>SurfMod\SurfBox</Filter>
</ClInclude>
<ClInclude Include="SurfModUsers.h">
<Filter>SurfMod\SurfUsers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MetaMod.cpp">
Expand Down Expand Up @@ -146,5 +152,8 @@
<ClCompile Include="SurfModBox.cpp">
<Filter>SurfMod\SurfBox</Filter>
</ClCompile>
<ClCompile Include="SurfModUsers.cpp">
<Filter>SurfMod\SurfUsers</Filter>
</ClCompile>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion SurfMod/SurfModBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ edict_t* surfmod::CBox::box_Create(std::string szClass, std::string szId, const
{
edict_t* pBox = g_engfuncs.pfnCreateNamedEntity(MAKE_STRING("info_target"));

if (!pBox || !pBox->pvPrivateData) [[unlikely]]
if (!pBox || !pBox->pvPrivateData)
{
if (pBox)
g_engfuncs.pfnRemoveEntity(pBox);
Expand Down
8 changes: 8 additions & 0 deletions SurfMod/SurfModDuels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ surfmod::CDuel g_SurfModDuel;

void surfmod::CDuel::JudgeMenuMain(int EntityIndex)
{
auto Flags = g_SurfModUsers.GetFlags(EntityIndex);

if (!(Flags & ACCES_ADMIN::MENU))
{
g_SurfModUtility.SayText(INDEXENT(EntityIndex), PRINT_TEAM_RED, "^3You can not do this!");
return;
}

std::string title = g_SurfModUtility.FormatString("^rJudge Panel\n\n");
bool isduel = this->m_pDuel_info.is_now_duel;
bool ispreparing = this->m_pDuel_info.state == DUEL_STATE::PREPARING;
Expand Down
6 changes: 4 additions & 2 deletions SurfMod/SurfModDuels.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace surfmod
{
enum DUEL_STATE {
enum DUEL_STATE
{
NOTHING,
PREPARING,
PAUSE,
Expand All @@ -11,7 +12,8 @@ namespace surfmod
WINING
};

enum Team {
enum Team
{
TER = 1,
CT,
WINNER = 10
Expand Down
136 changes: 136 additions & 0 deletions SurfMod/SurfModUsers.cpp
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;
}
69 changes: 69 additions & 0 deletions SurfMod/SurfModUsers.h
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;
3 changes: 3 additions & 0 deletions SurfMod/SurfModUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ void surfmod::CUtility::SayText(edict_t* pEntity, int Sender, const char* Format
char Buffer[MAX_LINE_TXT_MSG] = { 0 };

va_list ArgList;

va_start(ArgList, Format);

Q_vsnprintf(Buffer, sizeof(Buffer), Format, ArgList);

va_end(ArgList);

char Temp[MAX_LINE_TXT_MSG] = { 0 };
Expand Down
2 changes: 2 additions & 0 deletions SurfMod/SurfModUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ constexpr auto MAX_LINE_TXT_MSG = 191;

namespace surfmod
{
#define BIT(n) (1 << (n))

class CUtility
{
public:
Expand Down
Loading

0 comments on commit 4a3a75a

Please sign in to comment.