From e0c32eab493ad3ba39177637b2691040b1f01116 Mon Sep 17 00:00:00 2001 From: neon Date: Mon, 23 Jul 2018 11:04:35 +0200 Subject: [PATCH] added customization --- .../connect_announce/custom-messages.cfg | 175 ++++++++++ .../configs/connect_announce/settings.cfg | 1 + ConnectAnnounce/scripting/ConnectAnnounce.sp | 320 +++++++++++++++++- 3 files changed, 482 insertions(+), 14 deletions(-) create mode 100644 ConnectAnnounce/configs/connect_announce/custom-messages.cfg create mode 100644 ConnectAnnounce/configs/connect_announce/settings.cfg diff --git a/ConnectAnnounce/configs/connect_announce/custom-messages.cfg b/ConnectAnnounce/configs/connect_announce/custom-messages.cfg new file mode 100644 index 00000000..04445dbf --- /dev/null +++ b/ConnectAnnounce/configs/connect_announce/custom-messages.cfg @@ -0,0 +1,175 @@ +"custom_messages" +{ + "STEAM_0:0:161265777" + { + "message" "admin pleaseeeee" + } + "STEAM_0:1:32247009" + { + "message" "ff0000Nff4000eff7f00offbf00n 80ff00i00ff00s 00ffffh0080ffe0000ffr4600ffe8b00ff!" + } + "STEAM_0:0:22286324" + { + "message" "{purple}HERE COMES DRUNK DOGAN" + } + "STEAM_0:1:1115569" + { + "message" "{black}Noob Elite" + } + "STEAM_0:1:47447437" + { + "message" "{Purple}CANCER {Orange}CONNECTED {Darkblue}FROM {Green}NORWAY" + } + "STEAM_0:1:79535030" + { + "message" "{orangered} !nominate ze_paranoid_rezurrection_v11_9 {cyan} !nominate ze_paranoid_rezurrection_v11_9" + } + "STEAM_0:0:15776136" + { + "message" "{red} Phoony loves camel meat" + } + "STEAM_0:0:20936525" + { + "message" "{cyan} | bhop GOD is coming boys! " + } + "STEAM_0:1:69650476" + { + "message" "{cyan} to abuse unloze.ru" + } + "STEAM_0:1:112369958" + { + "message" "{white}came as fast as {hotpink}Lightning." + } + "STEAM_0:0:83045997" + { + "message" "{fullred}❤ {white}ΣZΣ | Crush" + } + "STEAM_0:1:15654243" + { + "message" "{springgreen} and he's definitely a trap." + "Definitely" "a" + "Definitely" "a" + } + "STEAM_0:1:49642555" + { + "message" "{white}I'm here to abuse you again !" + "I'm" "here" + "to" "abuse" + "you" "again" + } + "STEAM_0:0:38786924" + { + "message" "right from the Kremlin" + } + "STEAM_0:0:41303250" + { + "message" "\" + "server" "killer\" + } + "STEAM_0:0:86995925" + { + "message" "{cyan}-͜- ching chong -͜-" + "-͜-" "ching" + "chong" "-͜-\" + } + "STEAM_0:0:42794022" + { + "message" "ALL GREENNNNNNNNNNNNNNNNNNNNNNNNN" + } + "STEAM_0:0:15263982" + { + "message" "Sharmuta Kebab" + } + "STEAM_0:0:419740855" + { + "message" "{darkblue}In {red}spec {orange} till {purple}lasers" + } + "STEAM_0:0:42114365" + { + "message" "{hotpink}Autism {deeppink}Furry {lightpink}Nigger" + } + "STEAM_0:0:75183065" + { + "message" "test" + } + "STEAM_0:0:191740833" + { + "message" "'s nosteam camp" + } + "STEAM_0:0:1327015326" + { + "message" "AA" + } + "STEAM_0:0:53949117" + { + "message" "To call people niggers despite being shit himself" + } + "STEAM_0:1:19765234" + { + "message" "the Lightbringer is coming" + } + "STEAM_0:1:68295521" + { + "message" ", the Emerald Isle." + } + "STEAM_0:0:26975345" + { + "message" "reset" + } + "STEAM_0:1:119073089" + { + "message" "\" + "Arrays" "start" + "from" "0\" + } + "*" " + } +} +" + "STEAM_0:0:61503660" + { + "message" "Tom Is Gay" + } + "STEAM_0:0:44028386" + { + "message" "{gold}to dodge some lasers {red}and {blue}meme a fucking lot" + } + "STEAM_0:0:95388502" + { + "message" "miau" + } + "STEAM_0:0:39673815" + { + "message" "I'm actually from Lithuania" + } + "STEAM_0:0:147147908" + { + "message" "Bhopper just arrived." + } + "STEAM_0:1:23546931" + { + "message" "{Azure}Ambassador of the weebs" + "Ambassador" "of" + "the" "weebs\" + } + "Ambassador" "of" + "the" "weebs\" + "STEAM_0:0:31075155" + { + "message" "yeah boi" + } + "STEAM_0:0:39805726" + { + "message" "nigger" + } + "STEAM_0:0:30963326" + { + "message" "\" + "CONNECTED" "FROM" + "ISLE" "OF" + } + "STEAM_0:1:62094773" + { + "message" "{fullred}Probably Playing Doto" + } +} diff --git a/ConnectAnnounce/configs/connect_announce/settings.cfg b/ConnectAnnounce/configs/connect_announce/settings.cfg new file mode 100644 index 00000000..af76c7ae --- /dev/null +++ b/ConnectAnnounce/configs/connect_announce/settings.cfg @@ -0,0 +1 @@ +{WHITE}{PLAYERTYPE}{GREEN} {NAME} {BLUE}{RANK}{green}[{lightgreen}{STEAMID}{NOSTEAM}{green}] connected{COUNTRY} \ No newline at end of file diff --git a/ConnectAnnounce/scripting/ConnectAnnounce.sp b/ConnectAnnounce/scripting/ConnectAnnounce.sp index 3d658b96..114f2254 100644 --- a/ConnectAnnounce/scripting/ConnectAnnounce.sp +++ b/ConnectAnnounce/scripting/ConnectAnnounce.sp @@ -3,34 +3,326 @@ #include #include #include +#include #pragma newdecls required +char g_sDataFile[128]; +char g_sCustomMessageFile[128]; + +Database g_hDatabase; + +Handle g_hCustomMessageFile; +Handle g_hCustomMessageFile2; + + +#define MSGLENGTH 100 + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public Plugin myinfo = { name = "Connect Announce", - author = "BotoX", - description = "Simple connect announcer", - version = "1.1", + author = "Neon + Botox", + description = "Connect Announcer", + version = "2.0", url = "" } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnPluginStart() +{ + BuildPath(Path_SM, g_sCustomMessageFile, sizeof(g_sCustomMessageFile), "configs/connect_announce/custom-messages.cfg"); + BuildPath(Path_SM, g_sDataFile, sizeof(g_sDataFile), "configs/connect_announce/settings.cfg"); + + char error[255]; + + if (SQL_CheckConfig("hlstatsx")) + { + g_hDatabase = SQL_Connect("hlstatsx", true, error, sizeof(error)); + } + + if (g_hDatabase == null) + { + LogError("Could not connect to database: %s", error); + } + + RegAdminCmd("sm_joinmsg", Command_JoinMsg, ADMFLAG_CUSTOM1, "Sets a custom message which will be shown upon connecting to the server"); + RegAdminCmd("sm_resetjoinmsg", Command_ResetJoinMsg, ADMFLAG_CUSTOM1, "Resets your custom connect message"); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action Command_JoinMsg(int client, int args) +{ + if (!client) + { + ReplyToCommand(client, "[ConnectAnnounce] Cannot use command from server console"); + return Plugin_Handled; + } + + char sAuth[32]; + GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth)); + + if (g_hCustomMessageFile != null) + CloseHandle(g_hCustomMessageFile); + + g_hCustomMessageFile = CreateKeyValues("custom_messages"); + + if (!FileToKeyValues(g_hCustomMessageFile, g_sCustomMessageFile)) + { + SetFailState("[ConnectAnnounce] Config file missing!"); + return Plugin_Handled; + } + + KvRewind(g_hCustomMessageFile); + + if (args < 1) + { + if (KvJumpToKey(g_hCustomMessageFile, sAuth)) + { + char sCustomMessage[256]; + KvGetString(g_hCustomMessageFile, "message", sCustomMessage, sizeof(sCustomMessage), ""); + if (StrEqual(sCustomMessage, "reset")) + { + CPrintToChat(client, "[ConnectAnnounce] No Join Message set! Use sm_joinmsg to set one."); + return Plugin_Handled; + } + CPrintToChat(client, "[ConnectAnnounce] Your Join Message is: %s", sCustomMessage); + } + else + CPrintToChat(client, "[ConnectAnnounce] No Join Message set! Use sm_joinmsg to set one."); + } + else + { + char sArg[512]; + int iLength; + iLength = GetCmdArgString(sArg, sizeof(sArg)); + + if(iLength > MSGLENGTH) + { + ReplyToCommand(client, "[ConnectAnnounce] Maximum message length is %d characters!", MSGLENGTH); + return Plugin_Handled; + } + + + if (KvJumpToKey(g_hCustomMessageFile, sAuth, true)) + KvSetString(g_hCustomMessageFile, "message", sArg); + else + { + SetFailState("[ConnectAnnounce] Could not find/create Key Value!"); + return Plugin_Handled; + } + + KvRewind(g_hCustomMessageFile); + KeyValuesToFile(g_hCustomMessageFile, g_sCustomMessageFile); + CPrintToChat(client, "[ConnectAnnounce] Your Join Message is: %s", sArg); + + } + KvRewind(g_hCustomMessageFile); + return Plugin_Handled; +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public Action Command_ResetJoinMsg(int client, int args) +{ + if (!client) + { + ReplyToCommand(client, "[ConnectAnnounce] Cannot use command from server console"); + return Plugin_Handled; + } + + char sAuth[32]; + GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth)); + + if (g_hCustomMessageFile != null) + CloseHandle(g_hCustomMessageFile); + + g_hCustomMessageFile = CreateKeyValues("custom_messages"); + + if (!FileToKeyValues(g_hCustomMessageFile, g_sCustomMessageFile)) + { + SetFailState("[ConnectAnnounce] Config file missing!"); + return Plugin_Handled; + } + + KvRewind(g_hCustomMessageFile); + + if (KvJumpToKey(g_hCustomMessageFile, sAuth, true)) + KvSetString(g_hCustomMessageFile, "message", "reset"); + + KvRewind(g_hCustomMessageFile); + + KeyValuesToFile(g_hCustomMessageFile, g_sCustomMessageFile); + + CPrintToChat(client, "[ConnectAnnounce] Your Join Message got reset."); + return Plugin_Handled; + +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void TQueryCB(Handle owner, Handle rs, const char[] error, any data) +{ + int client = 0; + + if ((client = GetClientOfUserId(data)) == 0) + { + return; + } + + int iRank = -1; + if (SQL_GetRowCount(rs) > 0) + { + int iField; + + SQL_FetchRow(rs); + SQL_FieldNameToNum(rs, "rank", iField); + iRank = SQL_FetchInt(rs, iField); + iRank += 1; + } + Handle hFile = OpenFile(g_sDataFile, "r"); + static char sRawMsg[301]; + + if(hFile != INVALID_HANDLE) + { + ReadFileLine(hFile, sRawMsg, sizeof(sRawMsg)); + TrimString(sRawMsg); + CloseHandle(hFile); + } + else + { + LogError("[SM] File not found! (configs/ConnectAnnounce/settings.txt)"); + return; + } + + static char sIP[16]; + static char sAuth[32]; + static char sCountry[32]; + static char sName[128]; + + GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth)); + GetClientName(client, sName, sizeof(sName)); + AdminId aid; + + if(StrContains(sRawMsg, "{PLAYERTYPE}")) + { + + aid = GetUserAdmin(client); + + if(GetAdminFlag(aid, Admin_Generic)) + { + ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Admin"); + } + else if(GetAdminFlag(aid, Admin_Custom1)) + { + ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "VIP"); + } + else if(GetAdminFlag(aid, Admin_Custom6)) + { + ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Member"); + } + else + { + ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Player"); + } + } + + if(StrContains(sRawMsg, "{RANK}")) + { + if (iRank != -1) + { + char sBuffer[16]; + Format(sBuffer, sizeof(sBuffer), "[#%d] ", iRank); + ReplaceString(sRawMsg, sizeof(sRawMsg), "{RANK}", sBuffer); + } + } + + if(StrContains(sRawMsg, "{NOSTEAM}")) + { + if(!SteamClientAuthenticated(sAuth)) + ReplaceString(sRawMsg, sizeof(sRawMsg), "{NOSTEAM}", " "); + else + ReplaceString(sRawMsg, sizeof(sRawMsg), "{NOSTEAM}", ""); + } + + if(StrContains(sRawMsg, "{STEAMID}")) + { + ReplaceString(sRawMsg, sizeof(sRawMsg), "{STEAMID}", sAuth); + } + + if(StrContains(sRawMsg, "{NAME}")) + { + ReplaceString(sRawMsg, sizeof(sRawMsg), "{NAME}", sName); + } + + if(StrContains(sRawMsg, "{COUNTRY}")) + { + if(GetClientIP(client, sIP, sizeof(sIP)) && GeoipCountry(sIP, sCountry, sizeof(sCountry))) + { + char sBuffer[128]; + Format(sBuffer, sizeof(sBuffer), " from %s", sCountry); + ReplaceString(sRawMsg, sizeof(sRawMsg), "{COUNTRY}", sBuffer); + } + else + ReplaceString(sRawMsg, sizeof(sRawMsg), "{COUNTRY}", ""); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////// + + if (g_hCustomMessageFile2 != null) + CloseHandle(g_hCustomMessageFile2); + + g_hCustomMessageFile2 = CreateKeyValues("custom_messages"); + + if (!FileToKeyValues(g_hCustomMessageFile2, g_sCustomMessageFile)) + { + SetFailState("[ConnectAnnounce] Config file missing!"); + return; + } + + KvRewind(g_hCustomMessageFile2); + + char sFinalMessage[512]; + char sCustomMessage[256]; + + + + if (KvJumpToKey(g_hCustomMessageFile2, sAuth)) + { + KvGetString(g_hCustomMessageFile2, "message", sCustomMessage, sizeof(sCustomMessage), ""); + if (StrEqual(sCustomMessage, "reset")) + CPrintToChatAll(sRawMsg); + else + { + Format(sFinalMessage, sizeof(sFinalMessage), "%s %s", sRawMsg, sCustomMessage); + CPrintToChatAll(sFinalMessage); + } + } + else + CPrintToChatAll(sRawMsg); + + +} +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- public void OnClientPostAdminCheck(int client) { if(IsFakeClient(client)) return; - static char sIP[16]; static char sAuth[32]; - static char sCountry[32]; GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth)); - - char sNoSteam[16]; - if(!SteamClientAuthenticated(sAuth)) - strcopy(sNoSteam, sizeof(sNoSteam), " [\x03NoSteam\x04]"); - - if(GetClientIP(client, sIP, sizeof(sIP)) && GeoipCountry(sIP, sCountry, sizeof(sCountry))) - PrintToChatAll("\x04%N [\x03%s\x04] connected from %s%s", client, sAuth, sCountry, sNoSteam); - else - PrintToChatAll("\x04%N [\x03%s\x04] connected%s", client, sAuth, sNoSteam); + strcopy(sAuth, sizeof(sAuth), sAuth[8]); + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = 'css-ze' AND hideranking = 0 AND skill > (SELECT skill from hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE uniqueId = '%s' AND hlstats_PlayerUniqueIds.game = 'css-ze')", sAuth); + SQL_TQuery(g_hDatabase, TQueryCB, sQuery, GetClientUserId(client)); }