Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- char KVPath[64];
- // Flags to join without having to be in the list
- #define Flags ADMFLAG_ROOT
- public Plugin myinfo =
- {
- name = "[ANY] Tournament WhiteList",
- author = "BaroNN",
- description = "Tournament WhiteList",
- version = "1.0",
- url = "http://steamcommunity.com/id/BaRoNN-Main"
- }
- public void OnPluginStart()
- {
- RegAdminCmd("sm_players", Command_ShowListed, Flags);
- CreateDirectory("addons/sourcemod/data/whitelist", 3);
- BuildPath(Path_SM, KVPath, sizeof(KVPath), "data/whitelist/list.txt");
- }
- public void OnClientPutInServer(int client)
- {
- char steamid[128], ip[128];
- char usersteamid[128], userip[128], username[32];
- Handle data = CreateKeyValues("players");
- FileToKeyValues(data, KVPath);
- if(IsValidClient(client))
- {
- KvGetString(data, "ip", ip, sizeof(ip));
- GetClientIP(client, userip, sizeof(userip));
- GetClientName(client, username, sizeof(username));
- KvGetString(data, "steamid", steamid, sizeof(steamid));
- GetClientAuthId(client, AuthId_SteamID64, usersteamid, sizeof(usersteamid));
- if(StrEqual(steamid, usersteamid, true))
- {
- PrintToServer("[WhiteList] %s joined the server with the name %s", steamid, username);
- }
- else if(StrEqual(ip, userip, true))
- {
- PrintToServer("[WhiteList] %s joined the server with the name %s", steamid, username);
- }
- else
- {
- if (CheckCommandAccess(client, "sm_admin", Flags))PrintToServer("[WhiteList] A unlisted user by the name of %s (%s) joined the server", username, steamid);
- else KickClient(client, "You are not whitelisted");
- }
- }
- }
- public Action Command_ShowListed(int client, int args)
- {
- if (IsValidClient(client))
- {
- int count = 0;
- char form[512], name[128], steamid[128];
- Handle data = CreateKeyValues("players");
- FileToKeyValues(data, KVPath);
- if (!KvGotoFirstSubKey(data))return Plugin_Handled;
- do count++;
- while (KvGotoNextKey(data));
- KvRewind(data);
- Menu menu = new Menu(showplayersmenu);
- menu.SetTitle("[WhiteList] Whitelisted Players");
- for (int i = 0; i < count; i++)
- {
- KvGetString(data, "steamid", steamid, sizeof(steamid));
- KvGetString(data, "name", name, sizeof(name));
- Format(form, sizeof(form), "%s [%s]", name, steamid);
- menu.AddItem("-1", form);
- KvGotoNextKey(data);
- }
- menu.ExitButton = true;
- menu.Display(client, MENU_TIME_FOREVER);
- KvRewind(data);
- KeyValuesToFile(data, KVPath);
- CloseHandle(data);
- }
- return Plugin_Handled;
- }
- stock bool IsValidClient(int client, bool bAlive = false)
- {
- if (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsFakeClient(client) && !IsClientSourceTV(client) && (bAlive == false || IsPlayerAlive(client)))return true;
- return false;
- }
- public showplayersmenu(Handle menu, MenuAction action, client, param2)
- {
- if (action == MenuAction_Select)Command_ShowListed(client, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment