Re-enabled PDB files.
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "sm_globals.h"
33 #include "sm_stringutil.h"
34 #include "HalfLife2.h"
35 #include "PlayerManager.h"
36 #include "ForwardSys.h"
38 #define BANFLAG_AUTO (1<<0) /**< Auto-detects whether to ban by steamid or IP */
39 #define BANFLAG_IP (1<<1) /**< Always ban by IP address */
40 #define BANFLAG_AUTHID (1<<2) /**< Ban by SteamID */
41 #define BANFLAG_NOKICK (1<<3) /**< Does not kick the client */
42 #define BANFLAG_NOWRITE (1<<4) /**< Ban is not written to SourceDS's files if permanent */
44 IForward *g_pOnBanClient = NULL;
45 IForward *g_pOnBanIdentity = NULL;
46 IForward *g_pOnRemoveBan = NULL;
48 class BanNativeHelpers : public SMGlobalClass
51 void OnSourceModAllInitialized()
53 g_pOnBanClient = g_Forwards.CreateForward(
65 g_pOnBanIdentity = g_Forwards.CreateForward(
76 g_pOnRemoveBan = g_Forwards.CreateForward(
86 void OnSourceModShutdown()
88 g_Forwards.ReleaseForward(g_pOnBanClient);
89 g_Forwards.ReleaseForward(g_pOnBanIdentity);
90 g_Forwards.ReleaseForward(g_pOnRemoveBan);
92 g_pOnBanClient = NULL;
93 g_pOnBanIdentity = NULL;
94 g_pOnRemoveBan = NULL;
99 static cell_t BanIdentity(IPluginContext *pContext, const cell_t *params)
101 char *r_identity, *ban_reason, *ban_cmd;
102 int ban_time, ban_flags, ban_source;
104 pContext->LocalToString(params[1], &r_identity);
105 pContext->LocalToString(params[4], &ban_reason);
106 pContext->LocalToString(params[5], &ban_cmd);
107 ban_time = params[2];
108 ban_flags = params[3];
109 ban_source = params[6];
111 /* Make sure we can ban by one of the two methods! */
112 bool ban_by_ip = ((ban_flags & BANFLAG_IP) == BANFLAG_IP);
113 if (!ban_by_ip && ((ban_flags & BANFLAG_AUTHID) != BANFLAG_AUTHID))
115 return pContext->ThrowNativeError("No valid ban flags specified");
118 /* Sanitize the input */
120 strncopy(identity, r_identity, sizeof(identity));
121 UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
124 if (ban_cmd[0] != '\0' && g_pOnBanIdentity->GetFunctionCount() > 0)
126 g_pOnBanIdentity->PushString(identity);
127 g_pOnBanIdentity->PushCell(ban_time);
128 g_pOnBanIdentity->PushCell(ban_flags);
129 g_pOnBanIdentity->PushString(ban_reason);
130 g_pOnBanIdentity->PushString(ban_cmd);
131 g_pOnBanIdentity->PushCell(ban_source);
132 g_pOnBanIdentity->Execute(&handled);
137 bool write_ban = ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE);
148 engine->ServerCommand(command);
150 if (write_ban && ban_time == 0)
152 engine->ServerCommand("writeip\n");
155 else if (!g_HL2.IsLANServer())
163 engine->ServerCommand(command);
165 if (write_ban && ban_time == 0)
167 engine->ServerCommand("writeid\n");
179 static cell_t RemoveBan(IPluginContext *pContext, const cell_t *params)
181 char *r_identity, *ban_cmd;
182 int ban_flags, ban_source;
184 pContext->LocalToString(params[1], &r_identity);
185 pContext->LocalToString(params[3], &ban_cmd);
186 ban_flags = params[2];
187 ban_source = params[4];
189 /* Make sure we can ban by one of the two methods! */
190 bool ban_by_ip = ((ban_flags & BANFLAG_IP) == BANFLAG_IP);
191 if (!ban_by_ip && ((ban_flags & BANFLAG_AUTHID) != BANFLAG_AUTHID))
193 return pContext->ThrowNativeError("No valid ban flags specified");
197 strncopy(identity, r_identity, sizeof(identity));
198 UTIL_ReplaceAll(identity, sizeof(identity), ";", "");
201 if (ban_cmd[0] != '\0' && g_pOnRemoveBan->GetFunctionCount() > 0)
203 g_pOnRemoveBan->PushString(identity);
204 g_pOnRemoveBan->PushCell(ban_flags);
205 g_pOnRemoveBan->PushString(ban_cmd);
206 g_pOnRemoveBan->PushCell(ban_source);
207 g_pOnRemoveBan->Execute(&handled);
220 engine->ServerCommand(command);
221 engine->ServerCommand("writeip\n");
224 else if (!g_HL2.IsLANServer())
233 engine->ServerCommand(command);
234 engine->ServerCommand("writeid\n");
245 static cell_t BanClient(IPluginContext *pContext, const cell_t *params)
247 const char *kick_message;
248 char *ban_reason, *ban_cmd;
249 int client, ban_flags, ban_source, ban_time;
251 client = g_HL2.ReferenceToIndex(params[1]);
253 CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
254 if (!pPlayer || !pPlayer->IsConnected())
256 return pContext->ThrowNativeError("Client index %d is invalid", client);
259 if (pPlayer->IsFakeClient())
261 return pContext->ThrowNativeError("Cannot ban fake client %d", client);
264 pContext->LocalToString(params[4], &ban_reason);
265 pContext->LocalToString(params[5], (char **)&kick_message);
266 pContext->LocalToString(params[6], &ban_cmd);
267 ban_time = params[2];
268 ban_flags = params[3];
269 ban_source = params[7];
271 #if SOURCE_ENGINE != SE_DARKMESSIAH
272 /* Check how we should ban the player */
273 if ((ban_flags & BANFLAG_AUTO) == BANFLAG_AUTO)
275 if (g_HL2.IsLANServer() || !pPlayer->IsAuthorized())
277 ban_flags |= BANFLAG_IP;
278 ban_flags &= ~BANFLAG_AUTHID;
282 ban_flags |= BANFLAG_AUTHID;
283 ban_flags &= ~BANFLAG_IP;
286 else if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
288 ban_flags |= BANFLAG_IP;
289 ban_flags &= ~BANFLAG_AUTHID;
291 else if ((ban_flags & BANFLAG_AUTHID) == BANFLAG_AUTHID)
293 if (pPlayer->IsAuthorized())
295 ban_flags |= BANFLAG_AUTHID;
296 ban_flags &= ~BANFLAG_IP;
305 return pContext->ThrowNativeError("No valid ban method flags specified");
308 /* Dark Messiah doesn't have Steam IDs so there is only one ban method to choose */
309 ban_flags |= BANFLAG_IP;
310 ban_flags &= ~BANFLAG_AUTHID;
314 if (ban_cmd[0] != '\0' && g_pOnBanClient->GetFunctionCount() > 0)
316 g_pOnBanClient->PushCell(client);
317 g_pOnBanClient->PushCell(ban_time);
318 g_pOnBanClient->PushCell(ban_flags);
319 g_pOnBanClient->PushString(ban_reason);
320 g_pOnBanClient->PushString(kick_message);
321 g_pOnBanClient->PushString(ban_cmd);
322 g_pOnBanClient->PushCell(ban_source);
323 g_pOnBanClient->Execute(&handled);
326 /* Sanitize the kick message */
327 if (kick_message[0] == '\0')
329 kick_message = "Kicked";
334 if ((ban_flags & BANFLAG_IP) == BANFLAG_IP)
336 /* Get the IP address and strip the port */
338 strncopy(ip, pPlayer->GetIPAddress(), sizeof(ip));
339 if ((ptr = strchr(ip, ':')) != NULL)
344 /* Tell the server to ban the ip */
354 if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
356 pPlayer->Kick(kick_message);
358 engine->ServerCommand(command);
360 /* Physically write the ban */
361 if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
363 engine->ServerCommand("writeip\n");
366 else if ((ban_flags & BANFLAG_AUTHID) == BANFLAG_AUTHID)
368 /* Tell the server to ban the auth string */
375 pPlayer->GetAuthString());
378 if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
380 g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), kick_message);
382 engine->ServerCommand(command);
384 /* Physically write the ban if it's permanent */
385 if ((ban_time == 0) && ((ban_flags & BANFLAG_NOWRITE) != BANFLAG_NOWRITE))
387 engine->ServerCommand("writeid\n");
391 else if ((ban_flags & BANFLAG_NOKICK) != BANFLAG_NOKICK)
393 g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), kick_message);
400 REGISTER_NATIVES(banNatives)
402 {"BanClient", BanClient},
403 {"BanIdentity", BanIdentity},
404 {"RemoveBan", RemoveBan},