From 39e55a630d5b2d8726a7664e2aad3d2112040914 Mon Sep 17 00:00:00 2001 From: Dogan Date: Mon, 27 May 2019 02:11:27 +0200 Subject: [PATCH] New Plugin: ConnectAnnounceNewPlayers --- .../scripting/ConnectAnnounceNewPlayers.sp | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 ConnectAnnounce/scripting/ConnectAnnounceNewPlayers.sp diff --git a/ConnectAnnounce/scripting/ConnectAnnounceNewPlayers.sp b/ConnectAnnounce/scripting/ConnectAnnounceNewPlayers.sp new file mode 100644 index 00000000..e6b58eb9 --- /dev/null +++ b/ConnectAnnounce/scripting/ConnectAnnounceNewPlayers.sp @@ -0,0 +1,95 @@ +#pragma semicolon 1 + +#include +#include + +bool NewPlayer[MAXPLAYERS + 1] = { false, ... }; + +Database g_hDatabase; + +public Plugin myinfo = +{ + name = "ConnectAnnounceNewPlayers", + author = "'Dogan", + description = "Connect Announcer for new Players", + version = "1.0.0", + url = "" +} + +public void OnPluginStart() +{ + Database.Connect(SQL_OnDatabaseConnect, "unloze_newplayers"); +} + +public void OnClientPostAdminCheck(int client) +{ + if(IsFakeClient(client) || IsClientSourceTV(client)) + return; + + char sAuthID[32]; + GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID)); + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "SELECT * FROM connections WHERE auth='%s'", sAuthID); + + g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, GetClientSerial(client), DBPrio_Low); +} + +public void SQL_OnDatabaseConnect(Database db, const char[] error, any data) +{ + if(!db || strlen(error)) + { + LogError("Database error: %s", error); + return; + } + + g_hDatabase = db; + + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS connections (`auth` varchar(32))"); + + g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_Low); +} + +public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, any data) +{ + if(!db || strlen(error)) + { + LogError("Query error: %s", error); + return; + } + + int client; + if ((client = GetClientFromSerial(data)) == 0) + return; + + char sAuthID[32]; + GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID)); + + if(results.RowCount && results.FetchRow()) + { + int iFieldNum; + char sResultAddress[32]; + results.FieldNameToNum("auth", iFieldNum); + results.FetchString(iFieldNum, sResultAddress, sizeof(sResultAddress)); + + if(StrEqual(sAuthID, sResultAddress, true)) + return; + } + + NewPlayer[client] = true; + NewPlayerMessage(client); + char sQuery[512]; + Format(sQuery, sizeof(sQuery), "INSERT INTO connections (auth) VALUES ('%s')" , sAuthID); + + g_hDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_Low); +} + +public Action NewPlayerMessage(int client) +{ + char sName[128]; + GetClientName(client, sName, sizeof(sName)); + + CPrintToChatAll("{cyan}Player {midnightblue}%s {cyan}has just connected an Unloze Server for the first time! Welcome!", sName); + CPrintToChat(client, "{cyan}Hi %s. Welcome to the {midnightblue}Unloze Zombie Escape Server{cyan}! We hope you enjoy your stay here and add our server to your favorites. Make sure to check out our website at {midnightblue}www.unloze.com{cyan}.", sName); +} \ No newline at end of file