Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 47 additions & 81 deletions addons/sourcemod/scripting/CustomChatColors.sp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public Plugin myinfo =
url = "http://www.doctormckay.com"
};

//Handle colorForward;
//Handle nameForward;
//Handle tagForward;
//Handle applicationForward;
//Handle messageForward;
Handle preLoadedForward;
Handle loadedForward;
Handle configReloadedForward;
Expand All @@ -59,6 +54,8 @@ ConVar g_cvHUDChannel;

ConVar g_Cvar_Chatmode;

ConVar g_cvar_DBConnectDelay;

char g_sSmCategoryColor[32];
char g_sSmNameColor[32];
char g_sSmChatColor[32];
Expand Down Expand Up @@ -147,6 +144,9 @@ int g_iClientPsayCooldown[MAXPLAYERS + 1] = { 0, ... };
int g_iClientFastReply[MAXPLAYERS + 1] = { 0, ... };
bool g_bDisablePsay[MAXPLAYERS + 1];

bool g_bDBConnectDelayActive = false;
bool g_bClientDataLoaded[MAXPLAYERS + 1] = {false, ...};

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
MarkNativeAsOptional("Updater_AddPlugin");
Expand Down Expand Up @@ -244,6 +244,7 @@ public void OnPluginStart()
g_cvar_GreenText = CreateConVar("sm_ccc_green_text", "1", "Enables greentexting (First chat character must be \">\")", FCVAR_REPLICATED);
g_cvar_ReplaceText = CreateConVar("sm_ccc_replace", "1", "Enables text replacing", FCVAR_REPLICATED);

g_cvar_DBConnectDelay = CreateConVar("sm_ccc_db_connect_delay", "0.0", "Delay in seconds before connecting to the database (0.0 = instant, max 60.0)", FCVAR_NONE, true, 0.0, true, 60.0);
g_cvar_SQLRetryTime = CreateConVar("sm_ccc_sql_retry_time", "10.0", "Number of seconds to wait before a new retry on a failed query", FCVAR_REPLICATED);
g_cvar_SQLMaxRetries = CreateConVar("sm_ccc_sql_max_retries", "1", "Number of sql retries on all queries if one fails", FCVAR_REPLICATED);

Expand All @@ -254,11 +255,6 @@ public void OnPluginStart()
g_cvPsayPrivacy = CreateConVar("sm_ccc_psay_privacy", "1", "Hide to admins all usage of sm_psay", FCVAR_PROTECTED);
g_cvHUDChannel = CreateConVar("sm_ccc_hud_channel", "0", "The channel for the hud if using DynamicChannels", _, true, 0.0, true, 5.0);

//colorForward = CreateGlobalForward("CCC_OnChatColor", ET_Event, Param_Cell);
//nameForward = CreateGlobalForward("CCC_OnNameColor", ET_Event, Param_Cell);
//tagForward = CreateGlobalForward("CCC_OnTagApplied", ET_Event, Param_Cell);
//applicationForward = CreateGlobalForward("CCC_OnColor", ET_Event, Param_Cell, Param_String, Param_Cell);
//messageForward = CreateGlobalForward("CCC_OnChatMessage", ET_Ignore, Param_Cell, Param_String, Param_Cell);
preLoadedForward = CreateGlobalForward("CCC_OnUserConfigPreLoaded", ET_Event, Param_Cell);
loadedForward = CreateGlobalForward("CCC_OnUserConfigLoaded", ET_Ignore, Param_Cell);
configReloadedForward = CreateGlobalForward("CCC_OnConfigReloaded", ET_Ignore);
Expand All @@ -267,7 +263,6 @@ public void OnPluginStart()

AutoExecConfig(true);

DB_Connect();
ResetReplace();
LoadColorArray();

Expand All @@ -285,6 +280,11 @@ public void OnPluginEnd()
}
if (g_sColorsArray != null)
delete g_sColorsArray;

g_DatabaseState = DatabaseState_Disconnected;
g_hDatabase = null;
g_hReconnectTimer = null;
g_bDBConnectDelayActive = false;
}

public void OnAllPluginsLoaded()
Expand Down Expand Up @@ -370,6 +370,18 @@ stock void VerifyNative_DynamicChannel()

public void OnConfigsExecuted()
{
float fDelay = g_cvar_DBConnectDelay.FloatValue;
if (fDelay > 0.0)
{
g_bDBConnectDelayActive = true;
CreateTimer(fDelay, Timer_DelayedDBConnectCCC, _, TIMER_FLAG_NO_MAPCHANGE);
}
else
{
g_bDBConnectDelayActive = false;
DB_Connect();
}

g_cSmCategoryColor.GetString(g_sSmCategoryColor, sizeof(g_sSmCategoryColor));
g_cSmNameColor.GetString(g_sSmNameColor, sizeof(g_sSmNameColor));
g_cSmChatColor.GetString(g_sSmChatColor, sizeof(g_sSmChatColor));
Expand All @@ -391,20 +403,27 @@ public void OnClientDisconnect(int client)
else
SQLInsert_TagClient(client);

g_bClientDataLoaded[client] = false;
g_iClientPsayCooldown[client] = 0;
g_iClientFastReply[client] = -1;
g_sSteamIDs[client][0] = '\0';
}

public void OnClientPostAdminCheck(int client)
{
if (g_bClientDataLoaded[client])
return;

if (g_DatabaseState != DatabaseState_Connected)
return;

ResetClient(client);

char auth[MAX_AUTHID_LENGTH];
GetClientAuthId(client, AuthId_Steam2, auth, sizeof(auth));
FormatEx(g_sSteamIDs[client], sizeof(g_sSteamIDs[]), "%s", auth);
// if (strncmp(auth[6], "ID_", 3) == 0)
// GetClientAuthId(client, AuthId_Steam2, g_sSteamIDs[client], sizeof(g_sSteamIDs[]), false);

ConfigForward(client);

if (HasFlag(client, Admin_Custom1))
{
Expand Down Expand Up @@ -519,6 +538,9 @@ stock void ResetReplace()

stock bool DB_Connect()
{
if (g_bDBConnectDelayActive)
return false;

//PrintToServer("DB_Connect(handle %d, state %d, lock %d)", g_hDatabase, g_DatabaseState, g_iConnectLock);

if (g_hDatabase != null && g_DatabaseState == DatabaseState_Connected)
Expand Down Expand Up @@ -1201,8 +1223,6 @@ stock void OnSQLSelect_TagGroup(Database db, DBResultSet results, const char[] e
}
else if (SQL_FetchRow(results))
{
// pack.ReadString(g_sClientSID[client], sizeof(g_sClientSID[]));

g_iClientEnable[client] = SQL_FetchInt(results, 1);
SQL_FetchString(results, 2, g_sClientTag[client], sizeof(g_sClientTag[]));
SQL_FetchString(results, 3, g_sClientTagColor[client], sizeof(g_sClientTagColor[]));
Expand All @@ -1214,6 +1234,8 @@ stock void OnSQLSelect_TagGroup(Database db, DBResultSet results, const char[] e
strcopy(g_sDefaultClientTagColor[client], sizeof(g_sDefaultClientTagColor[]), g_sClientTagColor[client]);
strcopy(g_sDefaultClientNameColor[client], sizeof(g_sDefaultClientNameColor[]), g_sClientNameColor[client]);
strcopy(g_sDefaultClientChatColor[client], sizeof(g_sDefaultClientChatColor[]), g_sClientChatColor[client]);

g_bClientDataLoaded[client] = true;
}

g_bSQLSelectTagGroupRetry[client] = 0;
Expand Down Expand Up @@ -1259,6 +1281,8 @@ public void OnSQLSelect_Tag(Database db, DBResultSet results, const char[] err,
Call_StartForward(loadedForward);
Call_PushCell(client);
Call_Finish();

g_bClientDataLoaded[client] = true;
}
else
{
Expand Down Expand Up @@ -4192,72 +4216,6 @@ public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info
// 888 Y8888 d8888888888 888 888 Y888P 888 Y88b d88P
// 888 Y888 d88P 888 888 8888888 Y8P 8888888888 "Y8888P"

// stock bool CheckForward(int author, const char[] message, CCC_ColorType type)
// {
// Action result = Plugin_Continue;

// Call_StartForward(applicationForward);
// Call_PushCell(author);
// Call_PushString(message);
// Call_PushCell(type);
// Call_Finish(result);

// if (result >= Plugin_Handled)
// return false;

// // Compatibility
// switch(type)
// {
// case CCC_TagColor: return TagForward(author);
// case CCC_NameColor: return NameForward(author);
// case CCC_ChatColor: return ColorForward(author);
// }

// return true;
// }

// stock bool ColorForward(int author)
// {
// Action result = Plugin_Continue;

// Call_StartForward(colorForward);
// Call_PushCell(author);
// Call_Finish(result);

// if (result >= Plugin_Handled)
// return false;

// return true;
// }

// stock bool NameForward(int author)
// {
// Action result = Plugin_Continue;

// Call_StartForward(nameForward);
// Call_PushCell(author);
// Call_Finish(result);

// if (result >= Plugin_Handled)
// return false;

// return true;
// }

// stock bool TagForward(int author)
// {
// Action result = Plugin_Continue;

// Call_StartForward(tagForward);
// Call_PushCell(author);
// Call_Finish(result);

// if (result >= Plugin_Handled)
// return false;

// return true;
// }

stock bool ConfigForward(int client)
{
Action myresult = Plugin_Continue;
Expand Down Expand Up @@ -4581,3 +4539,11 @@ public int Native_IsClientEnabled(Handle plugin, int numParams)
int client = GetNativeCell(1);
return (HasFlag(client, Admin_Generic) || HasFlag(client, Admin_Custom1)) && g_iClientEnable[client];
}

public Action Timer_DelayedDBConnectCCC(Handle timer, any data)
{
g_bDBConnectDelayActive = false;
DB_Connect();
LateLoad();
return Plugin_Stop;
}
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/include/ccc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define CCC_V_MAJOR "7"
#define CCC_V_MINOR "4"
#define CCC_V_PATCH "16"
#define CCC_V_PATCH "17"

#define CCC_VERSION CCC_V_MAJOR..."."...CCC_V_MINOR..."."...CCC_V_PATCH

Expand Down Expand Up @@ -249,4 +249,4 @@ public __pl_ccc_SetNTVOptional() {
MarkNativeAsOptional("CCC_UpdateIgnoredArray");
MarkNativeAsOptional("CCC_IsClientEnabled");
}
#endif
#endif