3 * ===============================================================
4 * SourceMod BAT Support Extension
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ===============================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include <IAdminSystem.h>
25 #include <IPlayerHelpers.h>
26 #include "extension.h"
30 * @brief Implements BAT Support extension code.
33 BatSupport g_BatSupport; /**< Global singleton for your extension's main interface */
34 IAdminSystem *admins = NULL;
35 IPlayerManager *players = NULL;
36 SMEXT_LINK(&g_BatSupport);
38 bool BatSupport::SDK_OnLoad(char *error, size_t maxlength, bool late)
40 SM_GET_IFACE(ADMINSYS, admins);
41 SM_GET_IFACE(PLAYERMANAGER, players);
43 players->AddClientListener(this);
48 void BatSupport::SDK_OnUnload()
50 players->RemoveClientListener(this);
52 List<AdminInterfaceListner *>::iterator iter;
53 AdminInterfaceListner *hook;
55 for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
58 hook->OnAdminInterfaceUnload();
61 /* In case plugins don't do this */
65 bool BatSupport::SDK_OnMetamodLoad(char *error, size_t maxlength, bool late)
67 g_SMAPI->AddListener(this, this);
72 void BatSupport::OnClientAuthorized(int client, const char *authstring)
74 List<AdminInterfaceListner *>::iterator iter;
75 AdminInterfaceListner *hook;
77 for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
80 hook->Client_Authorized(client);
84 const char *BatSupport::GetModName()
89 int BatSupport::GetInterfaceVersion()
91 return ADMININTERFACE_VERSION;
94 void *BatSupport::OnMetamodQuery(const char *iface, int *ret)
96 if (strcmp(iface, "AdminInterface") == 0)
98 AdminInterface *pThis = this;
114 bool BatSupport::RegisterFlag(const char *Class,const char *Flag,const char *Description)
119 g_pSM->LogError(myself, "BAT AdminInterface support tried to register a blank flag");
123 /* We only support up to 6 custom flags for SourceMod */
124 if (m_flags.size() >= 6)
126 g_pSM->LogError(myself, "BAT AdminInterface support reached maximum number of custom flags");
130 List<CustomFlag>::iterator iter;
131 for (iter=m_flags.begin(); iter!=m_flags.end(); iter++)
133 CustomFlag &cf = (*iter);
134 /* Ignore already registered, in case plugin is reloading */
135 if (cf.name.compare(Flag) == 0)
141 g_pSM->LogMessage(myself,
142 "BAT AdminInterface support registered Admin_Custom%d (class \"%s\") (flag \"%s\") (descr \"%s\")",
148 unsigned int f = (unsigned int)Admin_Custom1;
153 cf.flag = (AdminFlag)f;
154 cf.name.assign(Flag);
156 m_flags.push_back(cf);
161 bool BatSupport::IsClient(int id)
163 IGamePlayer *pPlayer = players->GetGamePlayer(id);
170 if (!pPlayer->IsConnected())
175 if (pPlayer->IsFakeClient())
183 void BatSupport::AddEventListner(AdminInterfaceListner *ptr)
185 m_hooks.push_back(ptr);
188 void BatSupport::RemoveListner(AdminInterfaceListner *ptr)
193 bool BatSupport::HasFlag(int id,const char *Flag)
195 IGamePlayer *pPlayer = players->GetGamePlayer(id);
197 if (!pPlayer || !pPlayer->IsConnected())
202 AdminId admin = pPlayer->GetAdminId();
203 if (admin == INVALID_ADMIN_ID)
208 FlagBits bits = admins->GetAdminFlags(admin, Access_Effective);
210 /* Root has it all... except for immunity */
211 if ((strcmp(Flag, "immunity") != 0)
212 && ((bits & ADMFLAG_ROOT) == ADMFLAG_ROOT))
217 if (!strcmp(Flag, "any"))
219 return ((bits & ~ADMFLAG_RESERVATION) != 0);
220 } else if (!strcmp(Flag, "kick")) {
221 return ((bits & ADMFLAG_KICK) == ADMFLAG_KICK);
222 } else if (!strcmp(Flag, "slap")) {
223 return ((bits & ADMFLAG_SLAY) == ADMFLAG_SLAY);
224 } else if (!strcmp(Flag, "slay")) {
225 return ((bits & ADMFLAG_SLAY) == ADMFLAG_SLAY);
226 } else if (!strcmp(Flag, "ban")) {
227 return ((bits & ADMFLAG_BAN) == ADMFLAG_BAN);
228 } else if (!strcmp(Flag, "chat")) {
229 return ((bits & ADMFLAG_CHAT) == ADMFLAG_CHAT);
230 } else if (!strcmp(Flag, "rcon")) {
231 return ((bits & ADMFLAG_RCON) == ADMFLAG_RCON);
232 } else if (!strcmp(Flag, "map")) {
233 return ((bits & ADMFLAG_CHANGEMAP) == ADMFLAG_CHANGEMAP);
234 } else if (!strcmp(Flag, "reservedslots")) {
235 return ((bits & ADMFLAG_RESERVATION) == ADMFLAG_RESERVATION);
236 } else if (!strcmp(Flag, "immunuty")) {
237 /* This is a bit different... */
238 unsigned int count = admins->GetAdminGroupCount(admin);
239 for (unsigned int i=0; i<count; i++)
241 GroupId gid = admins->GetAdminGroup(admin, i, NULL);
242 if (admins->GetGroupGenericImmunity(gid, Immunity_Default)
243 || admins->GetGroupGenericImmunity(gid, Immunity_Global))
251 List<CustomFlag>::iterator iter;
252 for (iter=m_flags.begin(); iter!=m_flags.end(); iter++)
254 CustomFlag &cf = (*iter);
255 if (cf.name.compare(Flag) == 0)
257 return ((bits & cf.bit) == cf.bit);