plugins/basebans/ban.sp
author David Anderson <dvander@alliedmods.net>
Sun Nov 25 18:50:13 2007 +0000 (2007-11-25)
changeset 1725 ea875bcbc286
parent 1672 92764e877da1
child 1789 55172f6df9a4
permissions -rw-r--r--
small clarification to param2 in MenuAction_End
     1 PrepareBan(client, target, time, const String:reason[])
     2 {
     3 	decl String:authid[64], String:name[32];
     4 	GetClientAuthString(target, authid, sizeof(authid));
     5 	GetClientName(target, name, sizeof(name));
     6 
     7 	if (!time)
     8 	{
     9 		if (reason[0] == '\0')
    10 		{
    11 			ShowActivity(client, "%t", "Permabanned player", name);
    12 		} else {
    13 			ShowActivity(client, "%t", "Permabanned player reason", name, reason);
    14 		}
    15 	} else {
    16 		if (reason[0] == '\0')
    17 		{
    18 			ShowActivity(client, "%t", "Banned player", name, time);
    19 		} else {
    20 			ShowActivity(client, "%t", "Banned player reason", name, time, reason);
    21 		}
    22 	}
    23 
    24 	LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
    25 
    26 	if (reason[0] == '\0')
    27 	{
    28 		BanClient(target, time, BANFLAG_AUTO, "Banned", "Banned", "sm_ban", client);
    29 	}
    30 	else
    31 	{
    32 		BanClient(target, time, BANFLAG_AUTO, reason, reason, "sm_ban", client);
    33 	}
    34 }
    35 
    36 DisplayBanTargetMenu(client)
    37 {
    38 	new Handle:menu = CreateMenu(MenuHandler_BanPlayerList);
    39 	
    40 	decl String:title[100];
    41 	Format(title, sizeof(title), "%T:", "Ban player", client);
    42 	SetMenuTitle(menu, title);
    43 	SetMenuExitBackButton(menu, true);
    44 	
    45 	AddTargetsToMenu(menu, client, false, false);
    46 	
    47 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    48 }
    49 
    50 DisplayBanTimeMenu(client)
    51 {
    52 	new Handle:menu = CreateMenu(MenuHandler_BanTimeList);
    53 	
    54 	decl String:title[100];
    55 	Format(title, sizeof(title), "%T:", "Ban player", client);
    56 	SetMenuTitle(menu, title);
    57 	SetMenuExitBackButton(menu, true);
    58 	
    59 	AddMenuItem(menu, "0", "Permanent");
    60 	AddMenuItem(menu, "10", "10 Minutes");
    61 	AddMenuItem(menu, "30", "30 Minutes");
    62 	AddMenuItem(menu, "60", "1 Hour");
    63 	AddMenuItem(menu, "240", "4 Hours");
    64 	AddMenuItem(menu, "1440", "1 Day");
    65 	AddMenuItem(menu, "10080", "1 Week");
    66 	
    67 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    68 }
    69 
    70 DisplayBanReasonMenu(client)
    71 {
    72 	new Handle:menu = CreateMenu(MenuHandler_BanReasonList);
    73 	
    74 	decl String:title[100];
    75 	Format(title, sizeof(title), "%T:", "Ban reason", client);
    76 	SetMenuTitle(menu, title);
    77 	SetMenuExitBackButton(menu, true);
    78 	
    79 	/* :TODO: we should either remove this or make it configurable */
    80 	
    81 	AddMenuItem(menu, "Abusive", "Abusive");
    82 	AddMenuItem(menu, "Racism", "Racism");
    83 	AddMenuItem(menu, "General cheating/exploits", "General cheating/exploits");
    84 	AddMenuItem(menu, "Wallhack", "Wallhack");
    85 	AddMenuItem(menu, "Aimbot", "Aimbot");
    86 	AddMenuItem(menu, "Speedhacking", "Speedhacking");
    87 	AddMenuItem(menu, "Mic spamming", "Mic spamming");
    88 	AddMenuItem(menu, "Admin disrepect", "Admin disrepect");
    89 	AddMenuItem(menu, "Camping", "Camping");
    90 	AddMenuItem(menu, "Team killing", "Team killing");
    91 	AddMenuItem(menu, "Unacceptable Spray", "Unacceptable Spray");
    92 	AddMenuItem(menu, "Breaking Server Rules", "Breaking Server Rules");
    93 	AddMenuItem(menu, "Other", "Other");
    94 	
    95 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    96 }
    97 
    98 public AdminMenu_Ban(Handle:topmenu, 
    99 							  TopMenuAction:action,
   100 							  TopMenuObject:object_id,
   101 							  param,
   102 							  String:buffer[],
   103 							  maxlength)
   104 {
   105 	if (action == TopMenuAction_DisplayOption)
   106 	{
   107 		Format(buffer, maxlength, "%T", "Ban player", param);
   108 	}
   109 	else if (action == TopMenuAction_SelectOption)
   110 	{
   111 		DisplayBanTargetMenu(param);
   112 	}
   113 }
   114 
   115 public MenuHandler_BanReasonList(Handle:menu, MenuAction:action, param1, param2)
   116 {
   117 	if (action == MenuAction_End)
   118 	{
   119 		CloseHandle(menu);
   120 	}
   121 	else if (action == MenuAction_Cancel)
   122 	{
   123 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   124 		{
   125 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   126 		}
   127 	}
   128 	else if (action == MenuAction_Select)
   129 	{
   130 		decl String:info[64];
   131 		
   132 		GetMenuItem(menu, param2, info, sizeof(info));
   133 	
   134 		PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info);
   135 	}
   136 }
   137 
   138 public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
   139 {
   140 	if (action == MenuAction_End)
   141 	{
   142 		CloseHandle(menu);
   143 	}
   144 	else if (action == MenuAction_Cancel)
   145 	{
   146 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   147 		{
   148 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   149 		}
   150 	}
   151 	else if (action == MenuAction_Select)
   152 	{
   153 		decl String:info[32], String:name[32];
   154 		new userid, target;
   155 		
   156 		GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
   157 		userid = StringToInt(info);
   158 
   159 		if ((target = GetClientOfUserId(userid)) == 0)
   160 		{
   161 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   162 		}
   163 		else if (!CanUserTarget(param1, target))
   164 		{
   165 			PrintToChat(param1, "[SM] %t", "Unable to target");
   166 		}
   167 		else
   168 		{
   169 			g_BanTarget[param1] = target;
   170 			DisplayBanTimeMenu(param1);
   171 		}
   172 	}
   173 }
   174 
   175 public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
   176 {
   177 	if (action == MenuAction_End)
   178 	{
   179 		CloseHandle(menu);
   180 	}
   181 	else if (action == MenuAction_Cancel)
   182 	{
   183 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   184 		{
   185 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   186 		}
   187 	}
   188 	else if (action == MenuAction_Select)
   189 	{
   190 		decl String:info[32];
   191 		
   192 		GetMenuItem(menu, param2, info, sizeof(info));
   193 		g_BanTime[param1] = StringToInt(info);
   194 		
   195 		DisplayBanReasonMenu(param1);
   196 	}
   197 }
   198 
   199 
   200 public Action:Command_Ban(client, args)
   201 {
   202 	if (args < 2)
   203 	{
   204 		ReplyToCommand(client, "[SM] Usage: sm_ban <#userid|name> <minutes|0> [reason]");
   205 		return Plugin_Handled;
   206 	}
   207 	
   208 	decl len, next_len;
   209 	decl String:Arguments[256];
   210 	GetCmdArgString(Arguments, sizeof(Arguments));
   211 
   212 	decl String:arg[65];	
   213 	len = BreakString(Arguments, arg, sizeof(arg));
   214 
   215 	new target = FindTarget(client, arg, true);
   216 	if (target == -1)
   217 	{
   218 		return Plugin_Handled;
   219 	}
   220 
   221 	decl String:s_time[12];
   222 	if ((next_len = BreakString(Arguments[len], s_time, sizeof(s_time))) != -1)
   223 	{
   224 		len += next_len;
   225 	}
   226 	else
   227 	{
   228 		len = 0;
   229 		Arguments[0] = '\0';
   230 	}
   231 
   232 	new time = StringToInt(s_time);
   233 
   234 	PrepareBan(client, target, time, Arguments[len]);
   235 
   236 	return Plugin_Handled;
   237 }