Merge remote-tracking branch 'unloze/master'

and fix like everything
This commit is contained in:
BotoX
2019-07-25 00:14:52 +02:00
1024 changed files with 52953 additions and 9868 deletions
+190 -85
View File
@@ -1,9 +1,10 @@
#pragma semicolon 1
#include <sourcemod>
#include <connect>
#include <geoip>
#include <multicolors>
#include <clientprefs>
#include <PlayerManager>
#pragma newdecls required
@@ -15,6 +16,10 @@ Database g_hDatabase;
Handle g_hCustomMessageFile;
Handle g_hCustomMessageFile2;
bool g_bHideCsays[MAXPLAYERS + 1] = { false, ... };
Handle g_hCookieHideCsays = null;
ConVar g_cvHlstatsServerName;
#define MSGLENGTH 100
@@ -22,11 +27,11 @@ Handle g_hCustomMessageFile2;
// Purpose:
//----------------------------------------------------------------------------------------------------
public Plugin myinfo = {
name = "Connect Announce",
author = "Neon + Botox",
description = "Connect Announcer",
version = "2.0",
url = ""
name = "Connect Announce",
author = "Neon + Botox + Dogan",
description = "Connect Announcer with special features for VIPS",
version = "3.0",
url = ""
}
//----------------------------------------------------------------------------------------------------
@@ -34,23 +39,147 @@ public Plugin myinfo = {
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
g_cvHlstatsServerName = CreateConVar("sm_connectannounce_hlstats_server_name", "css-ze", "Hlstats server name to check the rank for");
AutoExecConfig(true);
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);
}
Database.Connect(OnDatabaseConnect, "hlstatsx");
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");
RegConsoleCmd("sm_hide_connect_csays", OnToggleHideCsays, "Toggle blocking connect csay messages");
g_hCookieHideCsays = RegClientCookie("csays_blocked", "are csays blocked", CookieAccess_Protected);
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Hide Connect Csays");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnDatabaseConnect(Database db, const char[] error, any data)
{
if(db == INVALID_HANDLE || strlen(error) > 0)
{
LogError("Error connecting to database: %s", error);
return;
}
g_hDatabase = db;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ToggleHideCsays(int client)
{
g_bHideCsays[client] = !g_bHideCsays[client];
SetClientCookie(client, g_hCookieHideCsays, g_bHideCsays[client] ? "1" : "");
CPrintToChat(client, "{cyan}[ConnectAnnounce] {white}%s", g_bHideCsays[client] ? "You hid Connect Csay Messages." : "You unhid Connect Csay Messages.");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientCookiesCached(int client)
{
char sBuffer[2];
GetClientCookie(client, g_hCookieHideCsays, sBuffer, sizeof(sBuffer));
if(sBuffer[0] != '\0')
{
g_bHideCsays[client] = true;
}
else
{
g_bHideCsays[client] = false;
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client)
{
g_bHideCsays[client] = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action OnToggleHideCsays(int client, int args)
{
ToggleHideCsays(client);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void ShowSettingsMenu(int client)
{
Menu menu = new Menu(MenuHandler_MainMenu);
menu.SetTitle("ConnectCsay Settings", client);
char sBuffer[128];
Format(sBuffer, sizeof(sBuffer), "Hiding Connect Csays: %s", g_bHideCsays[client] ? "Enabled" : "Disabled");
menu.AddItem("0", sBuffer);
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
{
switch(action)
{
case(CookieMenuAction_DisplayOption):
{
Format(buffer, maxlen, "ConnectAnnounce", client);
}
case(CookieMenuAction_SelectOption):
{
ShowSettingsMenu(client);
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection)
{
switch(action)
{
case(MenuAction_Select):
{
switch(selection)
{
case(0): ToggleHideCsays(client);
}
ShowSettingsMenu(client);
}
case(MenuAction_Cancel):
{
ShowCookieMenu(client);
}
case(MenuAction_End):
{
delete menu;
}
}
}
//----------------------------------------------------------------------------------------------------
@@ -67,8 +196,7 @@ public Action Command_JoinMsg(int client, int args)
char sAuth[32];
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
if (g_hCustomMessageFile != null)
CloseHandle(g_hCustomMessageFile);
delete g_hCustomMessageFile;
g_hCustomMessageFile = CreateKeyValues("custom_messages");
@@ -108,6 +236,7 @@ public Action Command_JoinMsg(int client, int args)
return Plugin_Handled;
}
StripQuotes(sArg);
if (KvJumpToKey(g_hCustomMessageFile, sAuth, true))
KvSetString(g_hCustomMessageFile, "message", sArg);
@@ -140,8 +269,7 @@ public Action Command_ResetJoinMsg(int client, int args)
char sAuth[32];
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
if (g_hCustomMessageFile != null)
CloseHandle(g_hCustomMessageFile);
delete g_hCustomMessageFile;
g_hCustomMessageFile = CreateKeyValues("custom_messages");
@@ -167,7 +295,7 @@ public Action Command_ResetJoinMsg(int client, int args)
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
public void TQueryCB(Handle owner, Handle rs, const char[] error, any data)
{
int client = 0;
@@ -184,8 +312,8 @@ public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
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];
@@ -193,7 +321,7 @@ public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
{
ReadFileLine(hFile, sRawMsg, sizeof(sRawMsg));
TrimString(sRawMsg);
CloseHandle(hFile);
delete hFile;
}
else
{
@@ -219,22 +347,10 @@ public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
{
ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Admin");
}
else if(GetAdminFlag(aid, Admin_Custom4))
{
ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Top25");
}
else if(GetAdminFlag(aid, Admin_Custom1))
{
ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "VIP");
}
else if(GetAdminFlag(aid, Admin_Custom3))
{
ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Top50");
}
else if(GetAdminFlag(aid, Admin_Custom5))
{
ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Supporter");
}
else if(GetAdminFlag(aid, Admin_Custom6))
{
ReplaceString(sRawMsg, sizeof(sRawMsg), "{PLAYERTYPE}", "Member");
@@ -257,7 +373,7 @@ public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
if(StrContains(sRawMsg, "{NOSTEAM}"))
{
if(!SteamClientAuthenticated(sAuth))
if(!PM_IsPlayerSteam(client))
ReplaceString(sRawMsg, sizeof(sRawMsg), "{NOSTEAM}", " <NoSteam>");
else
ReplaceString(sRawMsg, sizeof(sRawMsg), "{NOSTEAM}", "");
@@ -293,8 +409,7 @@ public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
return;
}
if (g_hCustomMessageFile2 != null)
CloseHandle(g_hCustomMessageFile2);
delete g_hCustomMessageFile2;
g_hCustomMessageFile2 = CreateKeyValues("custom_messages");
@@ -310,60 +425,47 @@ public void TQueryCB2(Handle owner, Handle rs, const char[] error, any data)
char sFinalMessage[512];
char sCustomMessage[256];
if (KvJumpToKey(g_hCustomMessageFile2, sAuth))
{
KvGetString(g_hCustomMessageFile2, "banned", sBanned, sizeof(sBanned), "");
KvGetString(g_hCustomMessageFile2, "message", sCustomMessage, sizeof(sCustomMessage), "");
if (StrEqual(sCustomMessage, "reset") || StrEqual(sBanned, "true"))
if(StrEqual(sCustomMessage, "reset") || StrEqual(sBanned, "true"))
{
CPrintToChatAll(sRawMsg);
for(int i = 1; i <= MaxClients; i++)
{
if(!g_bHideCsays[i] && IsClientInGame(i))
{
PrintCenterText(i, "%s %s %s", "[VIP]", sName, "connected");
}
}
}
else
{
Format(sFinalMessage, sizeof(sFinalMessage), "%s %s", sRawMsg, sCustomMessage);
CPrintToChatAll(sFinalMessage);
for(int i = 1; i <= MaxClients; i++)
{
if(!g_bHideCsays[i] && IsClientInGame(i))
{
CRemoveTags(sCustomMessage, 256);
PrintCenterText(i, "%s %s %s %s", "[VIP]", sName, "connected", sCustomMessage);
}
}
}
}
else
{
CPrintToChatAll(sRawMsg);
for(int i = 1; i <= MaxClients; i++)
{
if(!g_bHideCsays[i] && IsClientInGame(i))
{
PrintCenterText(i, "%s %s %s", "[VIP]", sName, "connected");
}
}
}
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void TQueryCB(Handle owner, Handle rs, const char[] error, any data)
{
int client = 0;
if ((client = GetClientOfUserId(data)) == 0)
{
return;
}
if (rs == null)
{
LogError("Database Error: null result");
return;
}
int iPlayerId = -1;
if (SQL_GetRowCount(rs) > 0)
{
int iField;
SQL_FetchRow(rs);
SQL_FieldNameToNum(rs, "playerId", iField);
iPlayerId = SQL_FetchInt(rs, iField);
}
char sQuery[1024];
Format(sQuery, sizeof(sQuery), "SELECT T1.playerid, T1.skill, T2.rank FROM hlstats_Players T1 LEFT JOIN (SELECT skill, (@v_id := @v_Id + 1) AS rank FROM (SELECT DISTINCT skill FROM hlstats_Players WHERE game = 'css-ze' ORDER BY skill DESC) t, (SELECT @v_id := 0) r) T2 ON T1.skill = T2.skill WHERE game = 'css-ze' AND playerId = %d ORDER BY skill DESC" ,iPlayerId);
SQL_TQuery(g_hDatabase, TQueryCB2, sQuery, GetClientUserId(client));
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@@ -372,15 +474,18 @@ public void OnClientPostAdminCheck(int client)
if(IsFakeClient(client))
return;
char error[255];
if(g_hDatabase == INVALID_HANDLE)
return;
static char sAuth[32];
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
strcopy(sAuth, sizeof(sAuth), sAuth[8]);
char sServer[16];
g_cvHlstatsServerName.GetString(sServer, sizeof(sServer));
char sQuery[255];
Format(sQuery, sizeof(sQuery), "SELECT * FROM hlstats_PlayerUniqueIds WHERE uniqueId = '%s' AND game = 'css-ze'", sAuth);
//PrintToChatAll(sQuery);
SQL_TQuery(g_hDatabase, TQueryCB, sQuery, GetClientUserId(client));
}
char sQuery[512];
Format(sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = '%s' 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 = '%s')", sServer, sAuth, sServer);
g_hDatabase.Query(TQueryCB, sQuery, GetClientUserId(client));
}
@@ -0,0 +1,217 @@
#pragma semicolon 1
#include <sourcemod>
#include <multicolors>
#include <ccc>
bool g_bNewPlayer[MAXPLAYERS + 1] = { false, ... };
bool g_bNewPlayerChatBlock[MAXPLAYERS + 1] = { false, ...};
ConVar g_cvServerType;
char g_cServerMessage[128];
Database g_hDatabase;
public Plugin myinfo =
{
name = "ConnectAnnounceNewPlayers",
author = "Dogan",
description = "Connect Announcer for new Players",
version = "1.3.0",
url = ""
}
public void OnPluginStart()
{
Database.Connect(SQL_OnDatabaseConnect, "unloze_newplayers");
g_cvServerType = CreateConVar("sm_server_type", "1", "Server related private message for new players: 1 = ze; 2 = mg; 3 = zr; any other value = neutral");
AddMultiTargetFilter("@newplayer", Filter_NewPlayers, "New Players", false);
RegConsoleCmd("sm_newplayer", Command_DisplayNewPlayers, "Shows the number of new players");
AutoExecConfig(true, "plugin.ConnectAnnounceNewPlayers");
GetConVars();
}
public void OnPluginEnd()
{
RemoveMultiTargetFilter("@newplayer", Filter_NewPlayers);
}
public void GetConVars()
{
if(g_cvServerType.IntValue == 1)
{
g_cServerMessage = "Zombie Escape";
}
else if(g_cvServerType.IntValue == 2)
{
g_cServerMessage = "Minigames";
}
else if(g_cvServerType.IntValue == 3)
{
g_cServerMessage = "Zombie Riot";
}
else
{
g_cServerMessage = "";
}
}
public void ConVarChange(ConVar convar, char[] oldValue, char[] newValue)
{
GetConVars();
}
public bool Filter_NewPlayers(const char[] sPattern, Handle hClients)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
if(g_bNewPlayer[i])
PushArrayCell(hClients, i);
}
}
return true;
}
public Action Command_DisplayNewPlayers(int client, int args)
{
char aBuf[1024];
char aBuf2[MAX_NAME_LENGTH];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
if(g_bNewPlayer[i])
{
GetClientName(i, aBuf2, sizeof(aBuf2));
StrCat(aBuf, sizeof(aBuf), aBuf2);
StrCat(aBuf, sizeof(aBuf), ", ");
}
}
}
if(strlen(aBuf))
{
aBuf[strlen(aBuf) - 2] = 0;
ReplyToCommand(client, "[SM] New Players online: %s", aBuf);
}
else
ReplyToCommand(client, "[SM] New Players online: none");
return Plugin_Handled;
}
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;
}
g_bNewPlayer[client] = true;
g_bNewPlayerChatBlock[client] = true;
NewPlayerMessage(client);
CreateTimer(10.0, BlockChat, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
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)
{
CPrintToChatAll("{cyan}Player {lightgreen}%N {cyan}has just connected to an UNLOZE Server for the first time! Welcome!", client);
if(g_cvServerType.IntValue >= 1 && g_cvServerType.IntValue <= 3)
{
CPrintToChat(client, "{purple}****************************************************");
CPrintToChat(client, "{purple}****************************************************");
CPrintToChat(client, "{cyan}Hi {lightgreen}%N{cyan}. Welcome to the {blueviolet}Unloze %s Server{cyan}! We hope you enjoy your stay here and add our server to your favorites. Make sure to check out our website at {blueviolet}www.unloze.com{cyan}.", client, g_cServerMessage);
CPrintToChat(client, "{purple}****************************************************");
CPrintToChat(client, "{purple}****************************************************");
}
else
{
CPrintToChat(client, "{purple}****************************************************");
CPrintToChat(client, "{purple}****************************************************");
CPrintToChat(client, "{cyan}Hi {lightgreen}%N. Welcome to this {blueviolet}Unloze Server{cyan}! We hope you enjoy your stay here and add our server to your favorites. Make sure to check out our website at {blueviolet}www.unloze.com{cyan}.", client);
CPrintToChat(client, "{purple}****************************************************");
CPrintToChat(client, "{purple}****************************************************");
}
}
public void OnClientDisconnect(int client)
{
g_bNewPlayer[client] = false;
g_bNewPlayerChatBlock[client] = false;
}
public Action BlockChat(Handle timer, int serialid)
{
int client;
if ((client = GetClientFromSerial(serialid)) == 0)
return;
g_bNewPlayerChatBlock[client] = false;
}
public Action CCC_OnChatMessage(int client, int author, const char[] message)
{
if(g_bNewPlayerChatBlock[client])
return Plugin_Handled;
return Plugin_Continue;
}