extensions/batsupport/extension.cpp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/extensions/batsupport/extension.cpp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,270 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod BAT Support Extension
     1.8 - * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     1.9 - * =============================================================================
    1.10 - *
    1.11 - * This program is free software; you can redistribute it and/or modify it under
    1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.13 - * Free Software Foundation.
    1.14 - * 
    1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.18 - * details.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License along with
    1.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.22 - *
    1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.30 - * or <http://www.sourcemod.net/license.php>.
    1.31 - *
    1.32 - * Version: $Id$
    1.33 - */
    1.34 -
    1.35 -#include <IAdminSystem.h>
    1.36 -#include <IPlayerHelpers.h>
    1.37 -#include "extension.h"
    1.38 -
    1.39 -/**
    1.40 - * @file extension.cpp
    1.41 - * @brief Implements BAT Support extension code.
    1.42 - */
    1.43 -
    1.44 -BatSupport g_BatSupport;		/**< Global singleton for your extension's main interface */
    1.45 -IAdminSystem *admins = NULL;
    1.46 -IPlayerManager *players = NULL;
    1.47 -SMEXT_LINK(&g_BatSupport);
    1.48 -
    1.49 -bool BatSupport::SDK_OnLoad(char *error, size_t maxlength, bool late)
    1.50 -{
    1.51 -	SM_GET_IFACE(ADMINSYS, admins);
    1.52 -	SM_GET_IFACE(PLAYERMANAGER, players);
    1.53 -
    1.54 -	players->AddClientListener(this);
    1.55 -
    1.56 -	return true;
    1.57 -}
    1.58 -
    1.59 -void BatSupport::SDK_OnUnload()
    1.60 -{
    1.61 -	players->RemoveClientListener(this);
    1.62 -
    1.63 -	List<AdminInterfaceListner *>::iterator iter;
    1.64 -	AdminInterfaceListner *hook;
    1.65 -
    1.66 -	for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
    1.67 -	{
    1.68 -		hook = (*iter);
    1.69 -		hook->OnAdminInterfaceUnload();
    1.70 -	}
    1.71 -
    1.72 -	/* In case plugins don't do this */
    1.73 -	m_hooks.clear();
    1.74 -}
    1.75 -
    1.76 -bool BatSupport::SDK_OnMetamodLoad(char *error, size_t maxlength, bool late)
    1.77 -{
    1.78 -	g_SMAPI->AddListener(this, this);
    1.79 -
    1.80 -	return true;
    1.81 -}
    1.82 -
    1.83 -void BatSupport::OnClientAuthorized(int client, const char *authstring)
    1.84 -{
    1.85 -	List<AdminInterfaceListner *>::iterator iter;
    1.86 -	AdminInterfaceListner *hook;
    1.87 -
    1.88 -	for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
    1.89 -	{
    1.90 -		hook = (*iter);
    1.91 -		hook->Client_Authorized(client);
    1.92 -	}
    1.93 -}
    1.94 -
    1.95 -const char *BatSupport::GetModName()
    1.96 -{
    1.97 -	return "SourceMod";
    1.98 -}
    1.99 -
   1.100 -int BatSupport::GetInterfaceVersion()
   1.101 -{
   1.102 -	return ADMININTERFACE_VERSION;
   1.103 -}
   1.104 -
   1.105 -void *BatSupport::OnMetamodQuery(const char *iface, int *ret)
   1.106 -{
   1.107 -	if (strcmp(iface, "AdminInterface") == 0)
   1.108 -	{
   1.109 -		AdminInterface *pThis = this;
   1.110 -		if (ret)
   1.111 -		{
   1.112 -			*ret = IFACE_OK;
   1.113 -		}
   1.114 -		return pThis;
   1.115 -	}
   1.116 -
   1.117 -	if (ret)
   1.118 -	{
   1.119 -		*ret = IFACE_FAILED;
   1.120 -	}
   1.121 -	
   1.122 -	return NULL;
   1.123 -}
   1.124 -
   1.125 -bool BatSupport::RegisterFlag(const char *Class,const char *Flag,const char *Description)
   1.126 -{
   1.127 -	/* No empty flags */
   1.128 -	if (Flag[0] == '\0')
   1.129 -	{
   1.130 -		g_pSM->LogError(myself, "BAT AdminInterface support tried to register a blank flag");
   1.131 -		return false;
   1.132 -	}
   1.133 -
   1.134 -	/* We only support up to 6 custom flags for SourceMod */
   1.135 -	if (m_flags.size() >= 6)
   1.136 -	{
   1.137 -		g_pSM->LogError(myself, "BAT AdminInterface support reached maximum number of custom flags");
   1.138 -		return false;
   1.139 -	}
   1.140 -
   1.141 -	List<CustomFlag>::iterator iter;
   1.142 -	for (iter=m_flags.begin(); iter!=m_flags.end(); iter++)
   1.143 -	{
   1.144 -		CustomFlag &cf = (*iter);
   1.145 -		/* Ignore already registered, in case plugin is reloading */
   1.146 -		if (cf.name.compare(Flag) == 0)
   1.147 -		{
   1.148 -			return true;
   1.149 -		}
   1.150 -	}
   1.151 -
   1.152 -	g_pSM->LogMessage(myself, 
   1.153 -		"BAT AdminInterface support registered Admin_Custom%d (class \"%s\") (flag \"%s\") (descr \"%s\")",
   1.154 -		m_flags.size() + 1,
   1.155 -		Class,
   1.156 -		Flag,
   1.157 -		Description);
   1.158 -
   1.159 -	unsigned int f = (unsigned int)Admin_Custom1;
   1.160 -	f += m_flags.size();
   1.161 -
   1.162 -	CustomFlag cf;
   1.163 -	cf.bit = (1<<f);
   1.164 -	cf.flag = (AdminFlag)f;
   1.165 -	cf.name.assign(Flag);
   1.166 -
   1.167 -	m_flags.push_back(cf);
   1.168 -
   1.169 -	return true;
   1.170 -}
   1.171 -
   1.172 -bool BatSupport::IsClient(int id)
   1.173 -{
   1.174 -	IGamePlayer *pPlayer = players->GetGamePlayer(id);
   1.175 -	
   1.176 -	if (!pPlayer)
   1.177 -	{
   1.178 -		return false;
   1.179 -	}
   1.180 -
   1.181 -	if (!pPlayer->IsConnected())
   1.182 -	{
   1.183 -		return false;
   1.184 -	}
   1.185 -
   1.186 -	if (pPlayer->IsFakeClient())
   1.187 -	{
   1.188 -		return false;
   1.189 -	}
   1.190 -
   1.191 -	return true;
   1.192 -}
   1.193 -
   1.194 -void BatSupport::AddEventListner(AdminInterfaceListner *ptr)
   1.195 -{
   1.196 -	m_hooks.push_back(ptr);
   1.197 -}
   1.198 -
   1.199 -void BatSupport::RemoveListner(AdminInterfaceListner *ptr)
   1.200 -{
   1.201 -	m_hooks.remove(ptr);
   1.202 -}
   1.203 -
   1.204 -bool BatSupport::HasFlag(int id,const char *Flag)
   1.205 -{
   1.206 -	IGamePlayer *pPlayer = players->GetGamePlayer(id);
   1.207 -
   1.208 -	if (!pPlayer || !pPlayer->IsConnected())
   1.209 -	{
   1.210 -		return false;
   1.211 -	}
   1.212 -
   1.213 -	AdminId admin = pPlayer->GetAdminId();
   1.214 -	if (admin == INVALID_ADMIN_ID)
   1.215 -	{
   1.216 -		return false;
   1.217 -	}
   1.218 -
   1.219 -	FlagBits bits = admins->GetAdminFlags(admin, Access_Effective);
   1.220 -
   1.221 -	/* Root has it all... except for immunity */
   1.222 -	if ((strcmp(Flag, "immunity") != 0)
   1.223 -	    && ((bits & ADMFLAG_ROOT) == ADMFLAG_ROOT))
   1.224 -	{
   1.225 -		return true;
   1.226 -	}
   1.227 -
   1.228 -	if (!strcmp(Flag, "any"))
   1.229 -	{
   1.230 -		return ((bits & ~ADMFLAG_RESERVATION) != 0);
   1.231 -	} else if (!strcmp(Flag, "kick")) {
   1.232 -		return ((bits & ADMFLAG_KICK) == ADMFLAG_KICK);
   1.233 -	} else if (!strcmp(Flag, "slap")) {
   1.234 -		return ((bits & ADMFLAG_SLAY) == ADMFLAG_SLAY);
   1.235 -	} else if (!strcmp(Flag, "slay")) {
   1.236 -		return ((bits & ADMFLAG_SLAY) == ADMFLAG_SLAY);
   1.237 -	} else if (!strcmp(Flag, "ban")) {
   1.238 -		return ((bits & ADMFLAG_BAN) == ADMFLAG_BAN);
   1.239 -	} else if (!strcmp(Flag, "chat")) {
   1.240 -		return ((bits & ADMFLAG_CHAT) == ADMFLAG_CHAT);
   1.241 -	} else if (!strcmp(Flag, "rcon")) {
   1.242 -		return ((bits & ADMFLAG_RCON) == ADMFLAG_RCON);
   1.243 -	} else if (!strcmp(Flag, "map")) {
   1.244 -		return ((bits & ADMFLAG_CHANGEMAP) == ADMFLAG_CHANGEMAP);
   1.245 -	} else if (!strcmp(Flag, "reservedslots")) {
   1.246 -		return ((bits & ADMFLAG_RESERVATION) == ADMFLAG_RESERVATION);
   1.247 -	} else if (!strcmp(Flag, "immunuty")) {
   1.248 -		/* This is a bit different... */
   1.249 -		unsigned int count = admins->GetAdminGroupCount(admin);
   1.250 -		for (unsigned int i=0; i<count; i++)
   1.251 -		{
   1.252 -			GroupId gid = admins->GetAdminGroup(admin, i, NULL);
   1.253 -			if (admins->GetGroupGenericImmunity(gid, Immunity_Default)
   1.254 -				|| admins->GetGroupGenericImmunity(gid, Immunity_Global))
   1.255 -			{
   1.256 -				return true;
   1.257 -			}
   1.258 -		}
   1.259 -		return false;
   1.260 -	}
   1.261 -
   1.262 -	List<CustomFlag>::iterator iter;
   1.263 -	for (iter=m_flags.begin(); iter!=m_flags.end(); iter++)
   1.264 -	{
   1.265 -		CustomFlag &cf = (*iter);
   1.266 -		if (cf.name.compare(Flag) == 0)
   1.267 -		{
   1.268 -			return ((bits & cf.bit) == cf.bit);
   1.269 -		}
   1.270 -	}
   1.271 -
   1.272 -	return false;
   1.273 -}