new plugin HostnameManager

This commit is contained in:
neon
2019-06-04 17:39:39 +02:00
parent fd0db97ccd
commit 6a57a998f6
4 changed files with 220 additions and 38 deletions
+31 -19
View File
@@ -7,9 +7,7 @@
KeyValues g_Config;
ConVar g_cvHostName;
char g_sHostName[128];
char g_sStageName[32];
//----------------------------------------------------------------------------------------------------
// Purpose:
@@ -28,16 +26,27 @@ public Plugin myinfo =
//----------------------------------------------------------------------------------------------------
public void OnPluginStart()
{
g_cvHostName = FindConVar("hostname");
HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] sError, int errorSize)
{
CreateNative("SD_GetStage", Native_GetStage);
RegPluginLibrary("StageDisplay");
return APLRes_Success;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnMapStart()
{
g_sStageName = "unknown";
if(g_Config)
delete g_Config;
@@ -65,14 +74,6 @@ public void OnMapStart()
g_Config.Rewind();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnConfigsExecuted()
{
g_cvHostName.GetString(g_sHostName, sizeof(g_sHostName));
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@@ -202,15 +203,26 @@ public void CheckStage()
}
}
char sBuffer[sizeof(g_sHostName)];
if(bHasDiffCounter)
Format(sBuffer, sizeof(sBuffer), "%s | Stage: [%s - %s]", g_sHostName, sStageName, sDiffName);
Format(g_sStageName, sizeof(g_sStageName), "%s - %s", sStageName, sDiffName);
else
Format(sBuffer, sizeof(sBuffer), "%s | Stage: [%s]", g_sHostName, sStageName);
Format(g_sStageName, sizeof(g_sStageName), "%s", sStageName);
}
g_cvHostName.SetString(sBuffer, false, false);
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int Native_GetStage(Handle hPlugin, int numParams)
{
int length = GetNativeCell(2);
char[] sStage = new char[length + 1];
Format(sStage, length + 1, "%s", g_sStageName);
if (strcmp(sStage, "unknown", true) == 0)
return 0;
return !(SetNativeString(1, sStage, length + 1));
}
//----------------------------------------------------------------------------------------------------