Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include "include/autoexecconfig"
- #include "include/messagebot"
- #include "include/calladmin"
- #include "include/system2"
- #include <regex>
- #undef REQUIRE_PLUGIN
- #include "include/updater"
- #pragma semicolon 1
- #pragma newdecls required
- #pragma dynamic 32768
- #define MAX_ITEMS 150
- ConVar g_hVersion;
- ConVar g_hSteamUsername;
- char g_sSteamUsername[128];
- ConVar g_hSteamPassword;
- char g_sSteamPassword[128];
- Regex g_hSteamID2Regex;
- Regex g_hSteamID3Regex;
- Regex g_hCommunityIDRegex;
- char g_sSteamIDConfigFile[PLATFORM_MAX_PATH];
- char g_sGroupIDConfigFile[PLATFORM_MAX_PATH];
- int g_iLastReportID;
- enum AuthStringType
- {
- AuthString_SteamID2,
- AuthString_SteamID3,
- AuthString_CommunityID,
- AuthString_Unknown
- }
- ArrayList g_hRecipientAdt;
- #define UPDATER_URL "http://plugins.gugyclan.eu/calladmin/calladmin_steam.txt"
- public Plugin myinfo =
- {
- name = "CallAdmin: Steam module",
- author = "Impact, dordnung",
- description = "The steammodule for CallAdmin",
- version = CALLADMIN_VERSION,
- url = "http://gugyclan.eu"
- }
- public void OnPluginStart()
- {
- BuildPath(Path_SM, g_sSteamIDConfigFile, sizeof(g_sSteamIDConfigFile), "configs/calladmin_steam_steamidlist.cfg");
- if (!FileExists(g_sSteamIDConfigFile))
- {
- CreateSteamIDList();
- }
- BuildPath(Path_SM, g_sGroupIDConfigFile, sizeof(g_sGroupIDConfigFile), "configs/calladmin_steam_groupidlist.cfg");
- if (!FileExists(g_sGroupIDConfigFile))
- {
- CreateGroupIDList();
- }
- g_hSteamID2Regex = new Regex("^STEAM_[0-1]{1}:[0-1]{1}:[0-9]+$");
- g_hSteamID3Regex = new Regex("^\\[U:1:[0-9]{3,11}+\\]$");
- g_hCommunityIDRegex = new Regex("^[0-9]{4,17}+$");
- g_hRecipientAdt = new ArrayList(ByteCountToCells(21));
- MessageBot_ClearRecipients();
- ParseSteamIDList();
- ParseGroupIDList();
- RegConsoleCmd("sm_calladmin_steam_reload", Command_Reload);
- RegConsoleCmd("sm_calladmin_steam_listrecipients", Command_ListRecipients);
- AutoExecConfig_SetFile("plugin.calladmin_steam");
- g_hVersion = AutoExecConfig_CreateConVar("sm_calladmin_steam_version", CALLADMIN_VERSION, "Plugin version", FCVAR_NOTIFY|FCVAR_DONTRECORD);
- g_hSteamUsername = AutoExecConfig_CreateConVar("sm_calladmin_steam_username", "", "Your steam username", FCVAR_PROTECTED);
- g_hSteamPassword = AutoExecConfig_CreateConVar("sm_calladmin_steam_password", "", "Your steam password", FCVAR_PROTECTED);
- AutoExecConfig(true, "plugin.calladmin_steam");
- AutoExecConfig_CleanFile();
- g_hVersion.SetString(CALLADMIN_VERSION, false, false);
- g_hVersion.AddChangeHook(OnCvarChanged);
- g_hSteamUsername.GetString(g_sSteamUsername, sizeof(g_sSteamUsername));
- g_hSteamUsername.AddChangeHook(OnCvarChanged);
- g_hSteamPassword.GetString(g_sSteamPassword, sizeof(g_sSteamPassword));
- g_hSteamPassword.AddChangeHook(OnCvarChanged);
- }
- public void OnMessageResultReceived(MessageBotResult result, MessageBotError error)
- {
- static char resultString[][] = {"No error", "Error while trying to login", "Operation timed out",
- "No recipients were setup prior to sending a message", "Couldn't send to any recipient"};
- if (result != RESULT_NO_ERROR)
- {
- CallAdmin_LogMessage("Failed to send steam message: (result: %d [%s] | error: %d)", result, resultString[result], error);
- }
- }
- void CreateSteamIDList()
- {
- File hFile;
- hFile = OpenFile(g_sSteamIDConfigFile, "w");
- if (hFile == null)
- {
- CallAdmin_LogMessage("Failed to open configfile 'calladmin_steam_steamidlist.cfg' for writing");
- SetFailState("Failed to open configfile 'calladmin_steam_steamidlist.cfg' for writing");
- }
- hFile.WriteLine("// List of steamids or communityids, seperated by a new line");
- hFile.WriteLine("// STEAM_0:0:1");
- hFile.WriteLine("// 76561197960265730");
- delete hFile;
- }
- void ParseSteamIDList()
- {
- File hFile;
- hFile = OpenFile(g_sSteamIDConfigFile, "r");
- if (hFile == null)
- {
- CallAdmin_LogMessage("Failed to open configfile 'calladmin_steam_steamidlist.cfg' for reading");
- SetFailState("Failed to open configfile 'calladmin_steam_steamidlist.cfg' for reading");
- }
- char sReadBuffer[128];
- int len;
- while (!hFile.EndOfFile() && hFile.ReadLine(sReadBuffer, sizeof(sReadBuffer)))
- {
- if (sReadBuffer[0] == '/' || IsCharSpace(sReadBuffer[0]))
- {
- continue;
- }
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), "\n", "");
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), "\r", "");
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), "\t", "");
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), " ", "");
- len = strlen(sReadBuffer);
- for (int i; i < len; i++)
- {
- if (sReadBuffer[i] == ' ' || sReadBuffer[i] == '/')
- {
- sReadBuffer[i] = '\0';
- break;
- }
- }
- AuthStringType type = GetAuthIDType(sReadBuffer);
- if (type == AuthString_SteamID2)
- {
- g_hSteamID2Regex.GetSubString(1, sReadBuffer, sizeof(sReadBuffer));
- }
- else if (type == AuthString_SteamID3)
- {
- g_hSteamID3Regex.GetSubString(1, sReadBuffer, sizeof(sReadBuffer));
- SteamID3ToSteamId2(sReadBuffer, sReadBuffer, sizeof(sReadBuffer));
- }
- else if (type == AuthString_CommunityID)
- {
- g_hCommunityIDRegex.GetSubString(1, sReadBuffer, sizeof(sReadBuffer));
- }
- else
- {
- continue;
- }
- MessageBot_AddRecipient(sReadBuffer);
- g_hRecipientAdt.PushString(sReadBuffer);
- }
- hFile.Close();
- }
- void CreateGroupIDList()
- {
- File hFile;
- hFile = OpenFile(g_sGroupIDConfigFile, "w");
- if (hFile == null)
- {
- CallAdmin_LogMessage("Failed to open configfile 'calladmin_steam_groupidlist.cfg' for writing");
- SetFailState("Failed to open configfile 'calladmin_steam_groupidlist.cfg' for writing");
- }
- hFile.WriteLine("// List of group names (custom group name), separated by a new line");
- hFile.WriteLine("// So for example if your community link is: http://steamcommunity.com/groups/Valve then write in a new line: Valve");
- hFile.WriteLine("// YourGroupName");
- hFile.Close();
- }
- void ParseGroupIDList()
- {
- File hFile;
- hFile = OpenFile(g_sGroupIDConfigFile, "r");
- if (hFile == null)
- {
- CallAdmin_LogMessage("Failed to open configfile 'calladmin_steam_groupidlist.cfg' for reading");
- SetFailState("Failed to open configfile 'calladmin_steam_groupidlist.cfg' for reading");
- }
- char sReadBuffer[128];
- int len;
- while (! hFile.EndOfFile() && hFile.ReadLine(sReadBuffer, sizeof(sReadBuffer)))
- {
- if (sReadBuffer[0] == '/' || IsCharSpace(sReadBuffer[0]))
- {
- continue;
- }
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), "\n", "");
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), "\r", "");
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), "\t", "");
- ReplaceString(sReadBuffer, sizeof(sReadBuffer), " ", "");
- len = strlen(sReadBuffer);
- for (int i; i < len; i++)
- {
- if (sReadBuffer[i] == ' ' || sReadBuffer[i] == '/')
- {
- sReadBuffer[i] = '\0';
- len = strlen(sReadBuffer);
- break;
- }
- }
- if (len < 3 || len > 64)
- {
- continue;
- }
- FetchGroupMembers(sReadBuffer);
- }
- hFile.Close();
- }
- public void OnCvarChanged(Handle cvar, const char[] oldValue, const char[] newValue)
- {
- if (cvar == g_hVersion)
- {
- g_hVersion.SetString(CALLADMIN_VERSION, false, false);
- }
- else if (cvar == g_hSteamUsername)
- {
- g_hSteamUsername.GetString(g_sSteamUsername, sizeof(g_sSteamUsername));
- }
- else if (cvar == g_hSteamPassword)
- {
- g_hSteamPassword.GetString(g_sSteamPassword, sizeof(g_sSteamPassword));
- }
- }
- public Action Command_Reload(int client, int args)
- {
- if (!CheckCommandAccess(client, "sm_calladmin_admin", ADMFLAG_BAN, false))
- {
- ReplyToCommand(client, " \x10[HR] \x0E%t", "CallAdmin_NoAdmin");
- return Plugin_Handled;
- }
- MessageBot_ClearRecipients();
- g_hRecipientAdt.Clear();
- ParseSteamIDList();
- ParseGroupIDList();
- return Plugin_Handled;
- }
- public Action Command_ListRecipients(int client, int args)
- {
- if (!CheckCommandAccess(client, "sm_calladmin_admin", ADMFLAG_BAN, false))
- {
- ReplyToCommand(client, " \x10[HR] \x0E%t", "CallAdmin_NoAdmin");
- return Plugin_Handled;
- }
- int count = g_hRecipientAdt.Length;
- char sRecipientBuffer[21];
- if (count)
- {
- for (int i; i < count; i++)
- {
- g_hRecipientAdt.GetString(i, sRecipientBuffer, sizeof(sRecipientBuffer));
- ReplyToCommand(client, "Recipient %d: %s%s", i + 1, sRecipientBuffer, MessageBot_IsRecipient(sRecipientBuffer) ? "" : " (Not In Messagebot's list)");
- }
- }
- else
- {
- ReplyToCommand(client, "Recipient list is empty");
- }
- return Plugin_Handled;
- }
- public void OnAllPluginsLoaded()
- {
- if (LibraryExists("updater"))
- {
- Updater_AddPlugin(UPDATER_URL);
- }
- }
- public void OnLibraryAdded(const char[] name)
- {
- if (StrEqual(name, "updater"))
- {
- Updater_AddPlugin(UPDATER_URL);
- }
- }
- public void CallAdmin_OnReportPost(int client, int target, const char[] reason)
- {
- MessageBot_SetLoginData(g_sSteamUsername, g_sSteamPassword);
- char sClientName[MAX_NAME_LENGTH];
- char sClientID[21];
- char sTargetName[MAX_NAME_LENGTH];
- char sTargetID[21];
- char sServerIP[16];
- int serverPort;
- char sServerName[128];
- CallAdmin_GetHostIP(sServerIP, sizeof(sServerIP));
- serverPort = CallAdmin_GetHostPort();
- CallAdmin_GetHostName(sServerName, sizeof(sServerName));
- if (client == REPORTER_CONSOLE)
- {
- strcopy(sClientName, sizeof(sClientName), "Server/Console");
- strcopy(sClientID, sizeof(sClientID), "Server/Console");
- }
- else
- {
- GetClientName(client, sClientName, sizeof(sClientName));
- if (!GetClientAuthId(client, AuthId_Steam2, sClientID, sizeof(sClientID)))
- {
- CallAdmin_LogMessage("Failed to get authentication for client %d (%s)", client, sClientName);
- return;
- }
- }
- GetClientName(target, sTargetName, sizeof(sTargetName));
- if (!GetClientAuthId(target, AuthId_Steam2, sTargetID, sizeof(sTargetID)))
- {
- CallAdmin_LogMessage("Failed to get authentication for client %d (%s)", client, sTargetName);
- return;
- }
- g_iLastReportID = CallAdmin_GetReportID();
- char sMessage[4096];
- Format(sMessage, sizeof(sMessage), "-\nÚj jelentés a szerveren: Herbál Reality | JailBreak\nJelentésID: %d\nJelentő: %s\nGyanúsított: %s\nIndok: %s\nHa játékban vagy, írd be /handle %d a chat ablakba, hogy kezeld ezt a jelentést!", g_iLastReportID, sClientName, sTargetName, reason, g_iLastReportID);
- MessageBot_SendMessage(OnMessageResultReceived, sMessage);
- }
- public void CallAdmin_OnReportHandled(int client, int id)
- {
- if (id != g_iLastReportID)
- {
- return;
- }
- char sMessage[1024];
- Format(sMessage, sizeof(sMessage), "\nAz utolsó jelentést (%d) kezelte: %N", g_iLastReportID, client);
- MessageBot_SendMessage(OnMessageResultReceived, sMessage);
- }
- void FetchGroupMembers(const char[] groupID)
- {
- char sGroupID[64 * 4];
- System2_URLEncode(sGroupID, sizeof(sGroupID), groupID);
- System2HTTPRequest httpRequest = new System2HTTPRequest(OnHTTPReceive, "https://steamcommunity.com/groups/%s/memberslistxml?xml=1", sGroupID);
- httpRequest.Timeout = 10;
- httpRequest.GET();
- delete httpRequest;
- }
- public void OnHTTPReceive(bool success, const char[] error, System2HTTPRequest request, System2HTTPResponse response, HTTPRequestMethod method)
- {
- if (!success)
- {
- CallAdmin_LogMessage("Error on fetching group members: %s", error);
- return;
- }
- if (response.StatusCode != 200)
- {
- CallAdmin_LogMessage("Error on fetching group members: HTTP status code %d", response.StatusCode);
- return;
- }
- char[] data = new char[response.ContentLength + 1];
- response.GetContent(data, response.ContentLength + 1);
- static int SPLITSIZE1 = MAX_ITEMS + 50;
- static int SPLITSIZE2 = 64;
- char[][] Split = new char[SPLITSIZE1][SPLITSIZE2];
- char sTempID[21];
- int startindex = 0;
- if ( (startindex = StrContains(data, "<members>", true)) == -1)
- {
- startindex = 0;
- }
- int endindex = strlen(data);
- if ( (endindex = StrContains(data, "</members>", true)) != -1)
- {
- data[endindex] = '\0';
- }
- ExplodeString(data[startindex], "<steamID64>", Split, SPLITSIZE1, SPLITSIZE2);
- int splitsize = SPLITSIZE1;
- int index;
- for (int i; i < splitsize; i++)
- {
- if (strlen(Split[i]) > 0)
- {
- if ( (index = StrContains(Split[i], "</steamID64>", true)) != -1)
- {
- Split[i][index] = '\0';
- }
- if (GetAuthIDType(Split[i]) != AuthString_CommunityID)
- {
- continue;
- }
- strcopy(sTempID, sizeof(sTempID), Split[i]);
- MessageBot_AddRecipient(sTempID);
- g_hRecipientAdt.PushString(sTempID);
- }
- }
- }
- stock AuthStringType GetAuthIDType(const char[] auth)
- {
- if (g_hSteamID2Regex.Match(auth) == 1)
- {
- return AuthString_SteamID2;
- }
- else if (g_hSteamID3Regex.Match(auth) == 1)
- {
- return AuthString_SteamID3;
- }
- else if (g_hCommunityIDRegex.Match(auth) == 1)
- {
- return AuthString_CommunityID;
- }
- return AuthString_Unknown;
- }
- stock void SteamID3ToSteamId2(const char[] steamID3, char[] dest, int max_len)
- {
- char sTemp[21];
- strcopy(sTemp, sizeof(sTemp), steamID3);
- sTemp[strlen(sTemp)] = '\0';
- int temp = StringToInt(sTemp[5]);
- Format(dest, max_len, "STEAM_0:%d:%d", temp & 1, temp >> 1);
- }
Add Comment
Please, Sign In to add comment