Advertisement
Guest User

bandiscnt

a guest
Jul 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <adminmenu>
  5.  
  6. #pragma newdecls required
  7.  
  8. #define PLUGIN_VERSION "1.0"
  9. #define TAG "[SM] "
  10.  
  11. Handle g_hTopMenu = null;
  12.  
  13. ConVar gcv_iArraySize = null;
  14.  
  15. ArrayList ga_Names;
  16. ArrayList ga_SteamIds;
  17. ArrayList ga_IPs;
  18.  
  19. public Plugin myinfo =
  20. {
  21. name = "[CSGO] SourceBans - Disconnected Ban",
  22. author = "HeadLine, MadHamster, Cherry, edited by somebody.",
  23. description = "SourceBans - Disconnected Ban",
  24. version = PLUGIN_VERSION,
  25. url = "http://sourcemod.net"
  26. };
  27.  
  28. public void OnPluginStart()
  29. {
  30. CreateConVar("hl_bandisconnected_version", PLUGIN_VERSION, "Headline's ban disconnected plugin", FCVAR_DONTRECORD);
  31.  
  32. gcv_iArraySize = CreateConVar("hl_bandisconnected_max", "100", "List size of ban disconnected players menu");
  33.  
  34. RegAdminCmd("sm_bandisconnected", Command_BanDisconnected, ADMFLAG_BAN, "Ban a player after they have disconnected!");
  35. RegAdminCmd("sm_listdisconnected", Command_ListDisconnected, ADMFLAG_BAN, "List all disconnected players!");
  36. RegAdminCmd("sm_bandisconnectedip", Command_BanDisconnectedip, ADMFLAG_BAN, "Ban a player after they have disconnected!");
  37.  
  38. AddCommandListener(xdd, "sm_dcbanehe");
  39. HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_Pre);
  40.  
  41. Handle topmenu;
  42. if(LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
  43. {
  44. OnAdminMenuReady(topmenu);
  45. }
  46. LoadADTArray();
  47. }
  48.  
  49. public Action xdd(int client, const char[] cmd, int argc)
  50. {
  51. return Plugin_Handled;
  52. }
  53.  
  54.  
  55. public void OnClientPostAdminCheck(int client)
  56. {
  57. char sSteamID[32];
  58. GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID));
  59.  
  60. char clientIP[32];
  61. GetClientIP(client, clientIP, sizeof(clientIP));
  62.  
  63. if (FindStringInArray(ga_SteamIds, sSteamID) != -1 || FindStringInArray(ga_IPs, clientIP) != -1)
  64. {
  65. ga_Names.Erase(ga_SteamIds.FindString(sSteamID));
  66. ga_SteamIds.Erase(ga_SteamIds.FindString(sSteamID));
  67. ga_IPs.Erase(ga_IPs.FindString(clientIP));
  68. }
  69. }
  70.  
  71. public Action Event_PlayerDisconnect(Event hEvent, char[] name, bool bDontBroadcast)
  72. {
  73. int client = GetClientOfUserId(hEvent.GetInt("userid"));
  74. if (IsValidClient(client))
  75. {
  76. char sName[MAX_NAME_LENGTH];
  77. GetClientName(client, sName, sizeof(sName));
  78.  
  79. char sDisconnectedSteamID[32];
  80. GetClientAuthId(client, AuthId_Steam2, sDisconnectedSteamID, sizeof(sDisconnectedSteamID));
  81.  
  82. char clientIP[32];
  83. GetClientIP(client, clientIP, sizeof(clientIP));
  84.  
  85. if (FindStringInArray(ga_SteamIds, sDisconnectedSteamID) == -1 || FindStringInArray(ga_IPs, clientIP) == -1 )
  86. {
  87. PushToArrays(sName, sDisconnectedSteamID,clientIP);
  88. }
  89. }
  90. }
  91.  
  92. void PushToArrays(const char[] clientName, const char[] clientSteam, const char[] clientIP)
  93. {
  94. if (ga_Names.Length == 0)
  95. {
  96. ga_Names.PushString(clientName);
  97. ga_SteamIds.PushString(clientSteam);
  98. ga_IPs.PushString(clientIP);
  99. }
  100. else
  101. {
  102. ga_Names.ShiftUp(0);
  103. ga_SteamIds.ShiftUp(0);
  104. ga_IPs.ShiftUp(0);
  105.  
  106. ga_Names.SetString(0, clientName);
  107. ga_SteamIds.SetString(0, clientSteam);
  108. ga_IPs.SetString(0, clientIP);
  109. }
  110.  
  111. /* Trucate Arrays */
  112. if (ga_Names.Length >= gcv_iArraySize.IntValue && gcv_iArraySize.IntValue > 0)
  113. {
  114. ga_Names.Resize(gcv_iArraySize.IntValue);
  115. ga_SteamIds.Resize(gcv_iArraySize.IntValue);
  116. ga_IPs.Resize(gcv_iArraySize.IntValue);
  117. }
  118. }
  119.  
  120. public Action Command_BanDisconnected(int client, int args)
  121. {
  122. if (args != 3)
  123. {
  124. ReplyToCommand(client, " %sUsage: sm_bandisconnected <\"steamid\"> <minutes|0> [\"reason\"]", TAG);
  125. return Plugin_Handled;
  126. }
  127. else
  128. {
  129. char steamid[20], minutes[10], reason[256];
  130. GetCmdArg(1, steamid, sizeof(steamid));
  131. GetCmdArg(2, minutes, sizeof(minutes));
  132. GetCmdArg(3, reason, sizeof(reason));
  133. CheckAndPerformBan(client, steamid, StringToInt(minutes), reason);
  134. }
  135. return Plugin_Handled;
  136. }
  137.  
  138. public Action Command_BanDisconnectedip(int client, int args)
  139. {
  140. if (args != 3)
  141. {
  142. ReplyToCommand(client, " %sUsage: sm_bandisconnected <\"ip\"> <minutes|0> [\"reason\"]", TAG);
  143. return Plugin_Handled;
  144. }
  145. else
  146. {
  147. char ipp[20], minutes[10], reason[256];
  148. GetCmdArg(1, ipp, sizeof(ipp));
  149. GetCmdArg(2, minutes, sizeof(minutes));
  150. GetCmdArg(3, reason, sizeof(reason));
  151. FakeClientCommand(client, "sm_banip \"%s\" %d %s", ipp, StringToInt(minutes), reason);
  152. }
  153. return Plugin_Handled;
  154. }
  155.  
  156.  
  157. public Action Command_ListDisconnected(int client, int args)
  158. {
  159. if (ga_Names.Length >= 10)
  160. {
  161. PrintToConsole(client, "************ LAST 10 DISCONNECTED PLAYERS *****************");
  162. for (int i = 0; i <= 10; i++)
  163. {
  164. char sName[MAX_TARGET_LENGTH], sSteamID[32], clientIP[32];
  165.  
  166. ga_Names.GetString(i, sName, sizeof(sName));
  167. ga_SteamIds.GetString(i, sSteamID, sizeof(sSteamID));
  168. ga_IPs.GetString(i, clientIP, sizeof(clientIP));
  169.  
  170. PrintToConsole(client, "NAME : %s STEAMID : %s IP : %s", sName, sSteamID, clientIP);
  171. }
  172. PrintToConsole(client, "************ LAST 10 DISCONNECTED PLAYERS *****************");
  173. }
  174. else
  175. {
  176. if (ga_Names.Length == 0)
  177. {
  178. PrintToConsole(client, "[SM] Jelenleg nincsenek lelépett játékosok a listában!");
  179. }
  180. else
  181. {
  182. PrintToConsole(client, "************ LAST %i DISCONNECTED PLAYERS *****************", GetArraySize(ga_Names) - 1);
  183. for (int i = 0; i < ga_Names.Length; i++)
  184. {
  185. char sName[MAX_TARGET_LENGTH], sSteamID[32], clientIP[32];
  186.  
  187. ga_Names.GetString(i, sName, sizeof(sName));
  188. ga_SteamIds.GetString(i, sSteamID, sizeof(sSteamID));
  189. ga_IPs.GetString(i, clientIP, sizeof(clientIP));
  190.  
  191. PrintToConsole(client, "** %s | %s | %s **", sName, sSteamID, clientIP);
  192. }
  193. PrintToConsole(client, "************ LAST %i DISCONNECTED PLAYERS *****************", GetArraySize(ga_Names) - 1);
  194. }
  195. }
  196. return Plugin_Handled;
  197. }
  198.  
  199. void CheckAndPerformBan(int client, char[] steamid, int minutes, char[] reason)
  200. {
  201. AdminId admClient = GetUserAdmin(client);
  202. AdminId admTarget;
  203. if ((admTarget = FindAdminByIdentity(AUTHMETHOD_STEAM, steamid)) == INVALID_ADMIN_ID || CanAdminTarget(admClient, admTarget))
  204. {
  205. bool hasRoot = GetAdminFlag(admClient, Admin_Root);
  206. SetAdminFlag(admClient, Admin_Root, true);
  207. FakeClientCommand(client, "sm_addban %d \"%s\" %s", minutes, steamid, reason);
  208. SetAdminFlag(admClient, Admin_Root, hasRoot);
  209. }
  210. else
  211. {
  212. ReplyToCommand(client, " %sYou can't ban an admin with higher immunity than yourself", TAG);
  213. }
  214. }
  215.  
  216. public void OnAdminMenuReady(Handle hTopMenu)
  217. {
  218. if(hTopMenu == g_hTopMenu)
  219. {
  220. return;
  221. }
  222.  
  223. g_hTopMenu = hTopMenu;
  224.  
  225. TopMenuObject MenuObject = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
  226. if(MenuObject == INVALID_TOPMENUOBJECT)
  227. {
  228. return;
  229. }
  230. AddToTopMenu(hTopMenu, "sm_bandisconnected", TopMenuObject_Item, AdminMenu_Ban, MenuObject, "sm_bandisconnected", ADMFLAG_BAN, "Ban Disconnected Player");
  231. }
  232.  
  233. public void AdminMenu_Ban(Handle hTopMenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength)
  234. {
  235. if (action == TopMenuAction_DisplayOption)
  236. {
  237. Format(buffer, maxlength, "Játékos kitiltása [lelépett]");
  238. }
  239. else if (action == TopMenuAction_SelectOption)
  240. {
  241. DisplayTargetsMenu(param);
  242. }
  243. }
  244.  
  245. public void DisplayTargetsMenu(int client)
  246. {
  247. if (ga_SteamIds.Length == 0)
  248. {
  249. ReplyToCommand(client, "[SM] Jelenleg nincsenek lelépett játékosok a listában!");
  250. return;
  251. }
  252.  
  253. Menu MainMenu = new Menu(TargetsMenu_CallBack, MenuAction_Select | MenuAction_End);
  254. MainMenu.SetTitle("Válassz játékost:");
  255.  
  256. char sDisplayBuffer[128], sSteamID[32], clientIP[32], sName[MAX_NAME_LENGTH], steamipbuffer[64];
  257. for (int i = 0; i < ga_SteamIds.Length; i++)
  258. {
  259. ga_Names.GetString(i, sName, sizeof(sName));
  260.  
  261. ga_SteamIds.GetString(i, sSteamID, sizeof(sSteamID));
  262.  
  263. ga_IPs.GetString(i, clientIP, sizeof(clientIP));
  264.  
  265. Format(sDisplayBuffer, sizeof(sDisplayBuffer), "%s (%s)", sName, sSteamID);
  266.  
  267. Format(steamipbuffer, sizeof(steamipbuffer), "%s,%s,%s", sSteamID, clientIP,sName);
  268.  
  269. MainMenu.AddItem(steamipbuffer, sDisplayBuffer);
  270. }
  271. SetMenuExitBackButton(MainMenu, true);
  272. DisplayMenu(MainMenu, client, MENU_TIME_FOREVER);
  273. }
  274.  
  275. public int TargetsMenu_CallBack(Menu MainMenu, MenuAction action, int param1, int param2)
  276. {
  277. switch (action)
  278. {
  279. case MenuAction_Select:
  280. {
  281. char sInfo[128];
  282. GetMenuItem(MainMenu, param2, sInfo, sizeof(sInfo));
  283.  
  284. DisplayBanTimeMenu(param1, sInfo);
  285. }
  286. case MenuAction_Cancel:
  287. {
  288. if (param2 == MenuCancel_ExitBack && g_hTopMenu != INVALID_HANDLE)
  289. {
  290. DisplayTopMenu(g_hTopMenu, param1, TopMenuPosition_LastCategory);
  291. }
  292. }
  293. case MenuAction_End:
  294. {
  295. CloseHandle(MainMenu);
  296. }
  297. }
  298. }
  299.  
  300. public void DisplayBanTimeMenu(int client, char[] sInfo)
  301. {
  302. Menu BanTimeMenu = new Menu(BanTime_CallBack, MenuAction_Select | MenuAction_End);
  303. BanTimeMenu.SetTitle("Időtartam:");
  304. char sInfoBuffer[128];
  305.  
  306. Format(sInfoBuffer, sizeof(sInfoBuffer), "%s,0", sInfo);
  307. BanTimeMenu.AddItem(sInfoBuffer, "Végleges");
  308.  
  309. SetMenuExitBackButton(BanTimeMenu, true);
  310. DisplayMenu(BanTimeMenu, client, MENU_TIME_FOREVER);
  311. }
  312.  
  313. public int BanTime_CallBack(Handle BanTimeMenu, MenuAction action, int param1, int param2)
  314. {
  315. switch (action)
  316. {
  317. case MenuAction_Select:
  318. {
  319. char sInfo[128];
  320. GetMenuItem(BanTimeMenu, param2, sInfo, sizeof(sInfo));
  321.  
  322. DisplayBanReasonMenu(param1, sInfo);
  323. }
  324. case MenuAction_Cancel:
  325. {
  326. if (param2 == MenuCancel_ExitBack && g_hTopMenu != INVALID_HANDLE)
  327. {
  328. DisplayTopMenu(g_hTopMenu, param1, TopMenuPosition_LastCategory);
  329. }
  330. }
  331. case MenuAction_End:
  332. {
  333. CloseHandle(BanTimeMenu);
  334. }
  335. }
  336. }
  337.  
  338. void DisplayBanReasonMenu(int client, char[] sInfo)
  339. {
  340. Menu BanReasonMenu = new Menu(BanReason_CallBack, MenuAction_Select | MenuAction_End);
  341. BanReasonMenu.SetTitle("Indok:");
  342. char sInfoBuffer[128];
  343.  
  344. Format(sInfoBuffer, sizeof(sInfoBuffer), "%s,Offline Kitiltás", sInfo);
  345. BanReasonMenu.AddItem(sInfoBuffer, "Offline Kitiltás");
  346.  
  347. SetMenuExitBackButton(BanReasonMenu, true);
  348. DisplayMenu(BanReasonMenu, client, MENU_TIME_FOREVER);
  349. }
  350.  
  351. public int BanReason_CallBack(Handle BanReasonMenu, MenuAction action, int param1, int param2)
  352. {
  353. switch (action)
  354. {
  355. case MenuAction_Select:
  356. {
  357. char sInfo[128], sTempArray[5][64]; // Steamid,time,reason is the format of sInfo
  358.  
  359. GetMenuItem(BanReasonMenu, param2, sInfo, sizeof(sInfo));
  360. ExplodeString(sInfo, ",", sTempArray, 5, 64);
  361. FakeClientCommand(param1, "sm_dcbanehe \"%s\" \"%s\" \"%s\" %d \"%s\"", sTempArray[0], sTempArray[1],sTempArray[2], StringToInt(sTempArray[3]), sTempArray[4]);
  362. }
  363. case MenuAction_Cancel:
  364. {
  365. if (param2 == MenuCancel_ExitBack && g_hTopMenu != INVALID_HANDLE)
  366. {
  367. DisplayTopMenu(g_hTopMenu, param1, TopMenuPosition_LastCategory);
  368. }
  369. }
  370. case MenuAction_End:
  371. {
  372. CloseHandle(BanReasonMenu);
  373. }
  374. }
  375. }
  376.  
  377. void LoadADTArray()
  378. {
  379. ga_Names = new ArrayList(MAX_TARGET_LENGTH);
  380. ga_SteamIds = new ArrayList(32);
  381. ga_IPs = new ArrayList(32);
  382. }
  383.  
  384. bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
  385. {
  386. if(!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
  387. {
  388. return false;
  389. }
  390. return true;
  391. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement