Fix line-endings.

This commit is contained in:
David Anderson 2014-10-30 21:25:23 -07:00
parent 613b06f6c0
commit 9c6c0f37ed

View File

@ -1,306 +1,306 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 :
* ============================================================================= * =============================================================================
* SourceMod Basecommands * SourceMod Basecommands
* Functionality related to banning. * Functionality related to banning.
* *
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
PrepareBan(client, target, time, const String:reason[]) PrepareBan(client, target, time, const String:reason[])
{ {
new originalTarget = GetClientOfUserId(g_BanTargetUserId[client]); new originalTarget = GetClientOfUserId(g_BanTargetUserId[client]);
if (originalTarget != target) if (originalTarget != target)
{ {
if (client == 0) if (client == 0)
{ {
PrintToServer("[SM] %t", "Player no longer available"); PrintToServer("[SM] %t", "Player no longer available");
} }
else else
{ {
PrintToChat(client, "[SM] %t", "Player no longer available"); PrintToChat(client, "[SM] %t", "Player no longer available");
} }
return; return;
} }
new String:name[32]; new String:name[32];
GetClientName(target, name, sizeof(name)); GetClientName(target, name, sizeof(name));
if (!time) if (!time)
{ {
if (reason[0] == '\0') if (reason[0] == '\0')
{ {
ShowActivity(client, "%t", "Permabanned player", name); ShowActivity(client, "%t", "Permabanned player", name);
} else { } else {
ShowActivity(client, "%t", "Permabanned player reason", name, reason); ShowActivity(client, "%t", "Permabanned player reason", name, reason);
} }
} else { } else {
if (reason[0] == '\0') if (reason[0] == '\0')
{ {
ShowActivity(client, "%t", "Banned player", name, time); ShowActivity(client, "%t", "Banned player", name, time);
} else { } else {
ShowActivity(client, "%t", "Banned player reason", name, time, reason); ShowActivity(client, "%t", "Banned player reason", name, time, reason);
} }
} }
LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason); LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
if (reason[0] == '\0') if (reason[0] == '\0')
{ {
BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client); BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client);
} }
else else
{ {
BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client); BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
} }
} }
DisplayBanTargetMenu(client) DisplayBanTargetMenu(client)
{ {
new Handle:menu = CreateMenu(MenuHandler_BanPlayerList); new Handle:menu = CreateMenu(MenuHandler_BanPlayerList);
decl String:title[100]; decl String:title[100];
Format(title, sizeof(title), "%T:", "Ban player", client); Format(title, sizeof(title), "%T:", "Ban player", client);
SetMenuTitle(menu, title); SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true); SetMenuExitBackButton(menu, true);
AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED); AddTargetsToMenu2(menu, client, COMMAND_FILTER_NO_BOTS|COMMAND_FILTER_CONNECTED);
DisplayMenu(menu, client, MENU_TIME_FOREVER); DisplayMenu(menu, client, MENU_TIME_FOREVER);
} }
DisplayBanTimeMenu(client) DisplayBanTimeMenu(client)
{ {
new Handle:menu = CreateMenu(MenuHandler_BanTimeList); new Handle:menu = CreateMenu(MenuHandler_BanTimeList);
decl String:title[100]; decl String:title[100];
Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]); Format(title, sizeof(title), "%T: %N", "Ban player", client, g_BanTarget[client]);
SetMenuTitle(menu, title); SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true); SetMenuExitBackButton(menu, true);
AddMenuItem(menu, "0", "Permanent"); AddMenuItem(menu, "0", "Permanent");
AddMenuItem(menu, "10", "10 Minutes"); AddMenuItem(menu, "10", "10 Minutes");
AddMenuItem(menu, "30", "30 Minutes"); AddMenuItem(menu, "30", "30 Minutes");
AddMenuItem(menu, "60", "1 Hour"); AddMenuItem(menu, "60", "1 Hour");
AddMenuItem(menu, "240", "4 Hours"); AddMenuItem(menu, "240", "4 Hours");
AddMenuItem(menu, "1440", "1 Day"); AddMenuItem(menu, "1440", "1 Day");
AddMenuItem(menu, "10080", "1 Week"); AddMenuItem(menu, "10080", "1 Week");
DisplayMenu(menu, client, MENU_TIME_FOREVER); DisplayMenu(menu, client, MENU_TIME_FOREVER);
} }
DisplayBanReasonMenu(client) DisplayBanReasonMenu(client)
{ {
new Handle:menu = CreateMenu(MenuHandler_BanReasonList); new Handle:menu = CreateMenu(MenuHandler_BanReasonList);
decl String:title[100]; decl String:title[100];
Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]); Format(title, sizeof(title), "%T: %N", "Ban reason", client, g_BanTarget[client]);
SetMenuTitle(menu, title); SetMenuTitle(menu, title);
SetMenuExitBackButton(menu, true); SetMenuExitBackButton(menu, true);
//Add custom chat reason entry first //Add custom chat reason entry first
AddMenuItem(menu, "", "Custom reason (type in chat)"); AddMenuItem(menu, "", "Custom reason (type in chat)");
//Loading configurable entries from the kv-file //Loading configurable entries from the kv-file
decl String:reasonName[100]; decl String:reasonName[100];
decl String:reasonFull[255]; decl String:reasonFull[255];
//Iterate through the kv-file //Iterate through the kv-file
KvGotoFirstSubKey(g_hKvBanReasons, false); KvGotoFirstSubKey(g_hKvBanReasons, false);
do do
{ {
KvGetSectionName(g_hKvBanReasons, reasonName, sizeof(reasonName)); KvGetSectionName(g_hKvBanReasons, reasonName, sizeof(reasonName));
KvGetString(g_hKvBanReasons, NULL_STRING, reasonFull, sizeof(reasonFull)); KvGetString(g_hKvBanReasons, NULL_STRING, reasonFull, sizeof(reasonFull));
//Add entry //Add entry
AddMenuItem(menu, reasonFull, reasonName); AddMenuItem(menu, reasonFull, reasonName);
} while (KvGotoNextKey(g_hKvBanReasons, false)); } while (KvGotoNextKey(g_hKvBanReasons, false));
//Reset kvHandle //Reset kvHandle
KvRewind(g_hKvBanReasons); KvRewind(g_hKvBanReasons);
DisplayMenu(menu, client, MENU_TIME_FOREVER); DisplayMenu(menu, client, MENU_TIME_FOREVER);
} }
public AdminMenu_Ban(Handle:topmenu, public AdminMenu_Ban(Handle:topmenu,
TopMenuAction:action, TopMenuAction:action,
TopMenuObject:object_id, TopMenuObject:object_id,
param, param,
String:buffer[], String:buffer[],
maxlength) maxlength)
{ {
//Reset chat reason first //Reset chat reason first
g_IsWaitingForChatReason[param] = false; g_IsWaitingForChatReason[param] = false;
if (action == TopMenuAction_DisplayOption) if (action == TopMenuAction_DisplayOption)
{ {
Format(buffer, maxlength, "%T", "Ban player", param); Format(buffer, maxlength, "%T", "Ban player", param);
} }
else if (action == TopMenuAction_SelectOption) else if (action == TopMenuAction_SelectOption)
{ {
DisplayBanTargetMenu(param); DisplayBanTargetMenu(param);
} }
} }
public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2) public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
{ {
if (action == MenuAction_End) if (action == MenuAction_End)
{ {
CloseHandle(menu); CloseHandle(menu);
} }
else if (action == MenuAction_Cancel) else if (action == MenuAction_Cancel)
{ {
if (param2 == MenuCancel_ExitBack && hTopMenu) if (param2 == MenuCancel_ExitBack && hTopMenu)
{ {
hTopMenu.Display(param1, TopMenuPosition_LastCategory); hTopMenu.Display(param1, TopMenuPosition_LastCategory);
} }
} }
else if (action == MenuAction_Select) else if (action == MenuAction_Select)
{ {
if(param2 == 0) if(param2 == 0)
{ {
//Chat reason //Chat reason
g_IsWaitingForChatReason[param1] = true; g_IsWaitingForChatReason[param1] = true;
PrintToChat(param1, "[SM] %t", "Custom ban reason explanation", "sm_abortban"); PrintToChat(param1, "[SM] %t", "Custom ban reason explanation", "sm_abortban");
} }
else else
{ {
decl String:info[64]; decl String:info[64];
GetMenuItem(menu, param2, info, sizeof(info)); GetMenuItem(menu, param2, info, sizeof(info));
PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info); PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
} }
} }
} }
public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2) public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
{ {
if (action == MenuAction_End) if (action == MenuAction_End)
{ {
CloseHandle(menu); CloseHandle(menu);
} }
else if (action == MenuAction_Cancel) else if (action == MenuAction_Cancel)
{ {
if (param2 == MenuCancel_ExitBack && hTopMenu) if (param2 == MenuCancel_ExitBack && hTopMenu)
{ {
hTopMenu.Display(param1, TopMenuPosition_LastCategory); hTopMenu.Display(param1, TopMenuPosition_LastCategory);
} }
} }
else if (action == MenuAction_Select) else if (action == MenuAction_Select)
{ {
decl String:info[32], String:name[32]; decl String:info[32], String:name[32];
new userid, target; new userid, target;
GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name)); GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
userid = StringToInt(info); userid = StringToInt(info);
if ((target = GetClientOfUserId(userid)) == 0) if ((target = GetClientOfUserId(userid)) == 0)
{ {
PrintToChat(param1, "[SM] %t", "Player no longer available"); PrintToChat(param1, "[SM] %t", "Player no longer available");
} }
else if (!CanUserTarget(param1, target)) else if (!CanUserTarget(param1, target))
{ {
PrintToChat(param1, "[SM] %t", "Unable to target"); PrintToChat(param1, "[SM] %t", "Unable to target");
} }
else else
{ {
g_BanTarget[param1] = target; g_BanTarget[param1] = target;
g_BanTargetUserId[param1] = userid; g_BanTargetUserId[param1] = userid;
DisplayBanTimeMenu(param1); DisplayBanTimeMenu(param1);
} }
} }
} }
public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2) public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
{ {
if (action == MenuAction_End) if (action == MenuAction_End)
{ {
CloseHandle(menu); CloseHandle(menu);
} }
else if (action == MenuAction_Cancel) else if (action == MenuAction_Cancel)
{ {
if (param2 == MenuCancel_ExitBack && hTopMenu) if (param2 == MenuCancel_ExitBack && hTopMenu)
{ {
hTopMenu.Display(param1, TopMenuPosition_LastCategory); hTopMenu.Display(param1, TopMenuPosition_LastCategory);
} }
} }
else if (action == MenuAction_Select) else if (action == MenuAction_Select)
{ {
decl String:info[32]; decl String:info[32];
GetMenuItem(menu, param2, info, sizeof(info)); GetMenuItem(menu, param2, info, sizeof(info));
g_BanTime[param1] = StringToInt(info); g_BanTime[param1] = StringToInt(info);
DisplayBanReasonMenu(param1); DisplayBanReasonMenu(param1);
} }
} }
public Action:Command_Ban(client, args) public Action:Command_Ban(client, args)
{ {
if (args < 2) if (args < 2)
{ {
ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]"); ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
return Plugin_Handled; return Plugin_Handled;
} }
decl len, next_len; decl len, next_len;
decl String:Arguments[256]; decl String:Arguments[256];
GetCmdArgString(Arguments, sizeof(Arguments)); GetCmdArgString(Arguments, sizeof(Arguments));
decl String:arg[65]; decl String:arg[65];
len = BreakString(Arguments, arg, sizeof(arg)); len = BreakString(Arguments, arg, sizeof(arg));
new target = FindTarget(client, arg, true); new target = FindTarget(client, arg, true);
if (target == -1) if (target == -1)
{ {
return Plugin_Handled; return Plugin_Handled;
} }
decl String:s_time[12]; decl String:s_time[12];
if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1) if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
{ {
len += next_len; len += next_len;
} }
else else
{ {
len = 0; len = 0;
Arguments[0] = '\0'; Arguments[0] = '\0';
} }
new time = StringToInt(s_time); new time = StringToInt(s_time);
g_BanTargetUserId[client] = GetClientUserId(target); g_BanTargetUserId[client] = GetClientUserId(target);
PrepareBan(client, target, time, Arguments[len]); PrepareBan(client, target, time, Arguments[len]);
return Plugin_Handled; return Plugin_Handled;
} }