B2SX

[ANY] Tournament WhiteList

Oct 12th, 2018
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.90 KB | None | 0 0
  1. #include <sourcemod>
  2.  
  3. char KVPath[64];
  4. // Flags to join without having to be in the list
  5. #define Flags ADMFLAG_ROOT
  6.  
  7. public Plugin myinfo =
  8. {
  9.     name = "[ANY] Tournament WhiteList",
  10.     author = "BaroNN",
  11.     description = "Tournament WhiteList",
  12.     version = "1.0",
  13.     url = "http://steamcommunity.com/id/BaRoNN-Main"
  14. }
  15.  
  16. public void OnPluginStart()
  17. {
  18.     RegAdminCmd("sm_players", Command_ShowListed, Flags);
  19.     CreateDirectory("addons/sourcemod/data/whitelist", 3);
  20.     BuildPath(Path_SM, KVPath, sizeof(KVPath), "data/whitelist/list.txt");
  21. }
  22.  
  23. public void OnClientPutInServer(int client)
  24. {
  25.     char steamid[128], ip[128];
  26.     char usersteamid[128], userip[128], username[32];
  27.     Handle data = CreateKeyValues("players");
  28.     FileToKeyValues(data, KVPath);
  29.    
  30.     if(IsValidClient(client))
  31.     {
  32.         KvGetString(data, "ip", ip, sizeof(ip));
  33.         GetClientIP(client, userip, sizeof(userip));
  34.         GetClientName(client, username, sizeof(username));
  35.         KvGetString(data, "steamid", steamid, sizeof(steamid));
  36.         GetClientAuthId(client, AuthId_SteamID64, usersteamid, sizeof(usersteamid));
  37.        
  38.         if(StrEqual(steamid, usersteamid, true))
  39.         {
  40.             PrintToServer("[WhiteList] %s joined the server with the name %s", steamid, username);
  41.         }
  42.         else if(StrEqual(ip, userip, true))
  43.         {
  44.             PrintToServer("[WhiteList] %s joined the server with the name %s", steamid, username);
  45.         }
  46.         else
  47.         {  
  48.             if (CheckCommandAccess(client, "sm_admin", Flags))PrintToServer("[WhiteList] A unlisted user by the name of %s (%s) joined the server", username, steamid);
  49.             else KickClient(client, "You are not whitelisted");
  50.         }
  51.     }
  52. }
  53.  
  54. public Action Command_ShowListed(int client, int args)
  55. {
  56.     if (IsValidClient(client))
  57.     {
  58.         int count = 0;
  59.         char form[512], name[128], steamid[128];
  60.         Handle data = CreateKeyValues("players");
  61.         FileToKeyValues(data, KVPath);
  62.        
  63.         if (!KvGotoFirstSubKey(data))return Plugin_Handled;
  64.         do count++;
  65.         while (KvGotoNextKey(data));
  66.         KvRewind(data);
  67.        
  68.         Menu menu = new Menu(showplayersmenu);
  69.         menu.SetTitle("[WhiteList] Whitelisted Players");
  70.        
  71.         for (int i = 0; i < count; i++)
  72.         {
  73.             KvGetString(data, "steamid", steamid, sizeof(steamid));
  74.             KvGetString(data, "name", name, sizeof(name));
  75.             Format(form, sizeof(form), "%s [%s]", name, steamid);
  76.             menu.AddItem("-1", form);
  77.             KvGotoNextKey(data);
  78.         }
  79.        
  80.         menu.ExitButton = true;
  81.         menu.Display(client, MENU_TIME_FOREVER);
  82.        
  83.         KvRewind(data);
  84.         KeyValuesToFile(data, KVPath);
  85.         CloseHandle(data);
  86.     }
  87.     return Plugin_Handled;
  88. }
  89.  
  90. stock bool IsValidClient(int client, bool bAlive = false)
  91. {
  92.     if (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client) && !IsClientSourceTV(client) && (bAlive == false || IsPlayerAlive(client)))return true;
  93.     return false;
  94. }
  95.  
  96. public showplayersmenu(Handle menu, MenuAction action, client, param2)
  97. {
  98.     if (action == MenuAction_Select)Command_ShowListed(client, 0);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment