Last active
May 14, 2016 18:41
-
-
Save shavitush/65e6abfb23837ef63023cc8469392135 to your computer and use it in GitHub Desktop.
SM Connection message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sourcemod> | |
#pragma semicolon 1 | |
#pragma newdecls required | |
bool gB_MessagePrinted[MAXPLAYERS+1]; | |
char gS_NameColor[16]; | |
Database gH_DB = null; | |
public Plugin myinfo = | |
{ | |
name = "[SB] Connect Message", | |
author = "shavit", | |
description = "Prints a dis/connection message for every player individually. Respects SourceBans(++) 1.5.x.", | |
version = "1.0", | |
url = "http://forums.alliedmods.net/member.php?u=163134" | |
} | |
public void OnPluginStart() | |
{ | |
strcopy(gS_NameColor, 16, GetEngineVersion() == Engine_CSGO? " \x03":"\x0773F1FA"); | |
HookEvent("player_connect", Player_ConnectMessageHook, EventHookMode_Pre); | |
HookEvent("player_connect_client", Player_ConnectMessageHook, EventHookMode_Pre); // orangebox | |
HookEvent("player_disconnect", Player_ConnectMessageHook, EventHookMode_Pre); | |
Database.Connect(OnDatabaseConnected, "sourcebans"); | |
} | |
public Action Player_ConnectMessageHook(Event event, const char[] sName, bool dB) | |
{ | |
dB = true; | |
return Plugin_Changed; | |
} | |
public void OnDatabaseConnected(Database db, const char[] error, any data) | |
{ | |
if(db == INVALID_HANDLE) | |
{ | |
SetFailState("Failed to connect to SourceBans DB. Error: %s", error); | |
} | |
gH_DB = db; | |
} | |
public void OnClientPutInServer(int client) | |
{ | |
if(IsFakeClient(client)) | |
{ | |
return; | |
} | |
gB_MessagePrinted[client] = false; | |
CreateTimer(1.0, PrintMessage, GetClientSerial(client)); | |
} | |
public Action PrintMessage(Handle Timer, any data) | |
{ | |
int client = GetClientFromSerial(client); | |
if(client == 0) | |
{ | |
return Plugin_Stop; | |
} | |
char[] auth = new char[32]; | |
GetClientAuthId(client, AuthId_Engine, auth, 32); | |
auth[6] = '0'; | |
char[] auth2 = new char[32]; | |
strcopy(auth2, 32, auth); | |
auth2[6] = '1'; | |
// auth2 is being used for bans that are placed using the STEAM_0 format | |
// that's good for communities that run both CS:GO and other source engine game servers | |
char[] sQuery = new char[256]; | |
FormatEx(sQuery, 256, "SELECT * FROM `sb_bans` WHERE (authid = '%s' OR authid = '%s') AND RemoveType IS NULL", auth, auth2); | |
gH_DB.Query(SelectCallback, sQuery, GetClientSerial(client), DBPrio_High); | |
return Plugin_Stop; | |
} | |
public void SelectCallback(Database db, DBResultSet results, const char[] error, any data) | |
{ | |
if(results == null || results.RowCount > 0) | |
{ | |
return; | |
} | |
int client = GetClientFromSerial(data); | |
if(!client) | |
{ | |
return; | |
} | |
gB_MessagePrinted[client] = true; | |
char[] auth = new char[32]; | |
GetClientAuthId(client, AuthId_Engine, auth, 32); | |
PrintToChatAll("%s%N\x01 [\x04%s\x01] has \x05connected\x01.", gS_NameColor, client, auth); | |
} | |
public void OnClientDisconnect(int client) | |
{ | |
if(!IsFakeClient(client) && gB_MessagePrinted[client] && IsClientInGame(client) && GetClientTeam(client) >= 1) | |
{ | |
char[] sAuth = new char[32]; | |
GetClientAuthId(client, AuthId_Engine, sAuth, 32); | |
PrintToChatAll("%s%N\x01 [\x04%s\x01] has \x02disconnected\x01.", gS_NameColor, client, sAuth); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment