1.1 --- a/core/smn_player.cpp Thu Feb 08 21:41:28 2007 +0000
1.2 +++ b/core/smn_player.cpp Fri Feb 09 01:08:59 2007 +0000
1.3 @@ -12,6 +12,7 @@
1.4 */
1.5
1.6 #include "CPlayerManager.h"
1.7 +#include "AdminCache.h"
1.8 #include "sm_stringutil.h"
1.9
1.10 static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
1.11 @@ -230,6 +231,150 @@
1.12 return 1;
1.13 }
1.14
1.15 +static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params)
1.16 +{
1.17 + int client = params[1];
1.18 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.19 + if (!pPlayer)
1.20 + {
1.21 + return pContext->ThrowNativeError("Invalid client index %d.", client);
1.22 + }
1.23 + if (!pPlayer->IsConnected())
1.24 + {
1.25 + return pContext->ThrowNativeError("Client %d is not connected.", client);
1.26 + }
1.27 + if (!g_Admins.IsValidAdmin(params[2]))
1.28 + {
1.29 + return pContext->ThrowNativeError("AdminId %x is not valid.", params[2]);
1.30 + }
1.31 +
1.32 + pPlayer->SetAdminId(params[2], params[3] ? true : false);
1.33 +
1.34 + return 1;
1.35 +}
1.36 +
1.37 +static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params)
1.38 +{
1.39 + int client = params[1];
1.40 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.41 + if (!pPlayer)
1.42 + {
1.43 + return pContext->ThrowNativeError("Invalid client index %d.", client);
1.44 + }
1.45 + if (!pPlayer->IsConnected())
1.46 + {
1.47 + return pContext->ThrowNativeError("Client %d is not connected.", client);
1.48 + }
1.49 +
1.50 + return pPlayer->GetAdminId();
1.51 +}
1.52 +
1.53 +static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params)
1.54 +{
1.55 + int client = params[1];
1.56 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.57 + if (!pPlayer)
1.58 + {
1.59 + return pContext->ThrowNativeError("Invalid client index %d.", client);
1.60 + }
1.61 + if (!pPlayer->IsConnected())
1.62 + {
1.63 + return pContext->ThrowNativeError("Client %d is not connected.", client);
1.64 + }
1.65 +
1.66 + AdminId id;
1.67 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.68 + {
1.69 + id = g_Admins.CreateAdmin(NULL);
1.70 + pPlayer->SetAdminId(id, true);
1.71 + }
1.72 +
1.73 + cell_t *addr;
1.74 + for (int i=2; i<=params[0]; i++)
1.75 + {
1.76 + pContext->LocalToPhysAddr(params[i], &addr);
1.77 + g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true);
1.78 + }
1.79 +
1.80 + return 1;
1.81 +}
1.82 +
1.83 +static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
1.84 +{
1.85 + int client = params[1];
1.86 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.87 + if (!pPlayer)
1.88 + {
1.89 + return pContext->ThrowNativeError("Invalid client index %d.", client);
1.90 + }
1.91 + if (!pPlayer->IsConnected())
1.92 + {
1.93 + return pContext->ThrowNativeError("Client %d is not connected.", client);
1.94 + }
1.95 +
1.96 + AdminId id;
1.97 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.98 + {
1.99 + return 0;
1.100 + }
1.101 +
1.102 + cell_t *addr;
1.103 + for (int i=2; i<=params[0]; i++)
1.104 + {
1.105 + pContext->LocalToPhysAddr(params[i], &addr);
1.106 + g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false);
1.107 + }
1.108 +
1.109 + return 1;
1.110 +}
1.111 +
1.112 +static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params)
1.113 +{
1.114 + int client = params[1];
1.115 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.116 + if (!pPlayer)
1.117 + {
1.118 + return pContext->ThrowNativeError("Invalid client index %d.", client);
1.119 + }
1.120 + if (!pPlayer->IsConnected())
1.121 + {
1.122 + return pContext->ThrowNativeError("Client %d is not connected.", client);
1.123 + }
1.124 +
1.125 + AdminId id;
1.126 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.127 + {
1.128 + id = g_Admins.CreateAdmin(NULL);
1.129 + pPlayer->SetAdminId(id, true);
1.130 + }
1.131 +
1.132 + g_Admins.SetAdminFlags(id, Access_Effective, params[2]);
1.133 +
1.134 + return 1;
1.135 +}
1.136 +
1.137 +static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
1.138 +{
1.139 + int client = params[1];
1.140 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.141 + if (!pPlayer)
1.142 + {
1.143 + return pContext->ThrowNativeError("Invalid client index %d.", client);
1.144 + }
1.145 + if (!pPlayer->IsConnected())
1.146 + {
1.147 + return pContext->ThrowNativeError("Client %d is not connected.", client);
1.148 + }
1.149 +
1.150 + AdminId id;
1.151 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.152 + {
1.153 + return 0;
1.154 + }
1.155 +
1.156 + return g_Admins.GetAdminFlags(id, Access_Effective);
1.157 +}
1.158 +
1.159 REGISTER_NATIVES(playernatives)
1.160 {
1.161 {"GetMaxClients", sm_GetMaxClients},
1.162 @@ -244,6 +389,11 @@
1.163 {"PrintToServer", sm_PrintToServer},
1.164 {"PrintToConsole", sm_PrintToConsole},
1.165 {"GetClientInfo", sm_GetClientInfo},
1.166 + {"SetUserAdmin", SetUserAdmin},
1.167 + {"AddUserFlags", AddUserFlags},
1.168 + {"RemoveUserFlags", RemoveUserFlags},
1.169 + {"SetUserFlagBits", SetUserFlagBits},
1.170 + {"GetUserFlagBits", GetUserFlagBits},
1.171 {NULL, NULL}
1.172 };
1.173