Added Shavit_LogMessage native.

This commit is contained in:
shavit 2018-03-15 00:06:12 +02:00
parent f726b6b05a
commit b46c7eadd7
2 changed files with 39 additions and 7 deletions

View File

@ -1108,6 +1108,16 @@ native StringMap Shavit_GetMapTiers();
*/
native int Shavit_PrintToChat(int client, const char[] format, any ...);
/**
* Logs an entry to bhoptimer's log file.
* (addons/sourcemod/logs/shavit.log)
*
* @param format Formatting rules.
* @param any Variable number of format parameters.
* @noreturn
*/
native void Shavit_LogMessage(const char[] format, any ...);
// same as Shavit_PrintToChat() but loops through the whole server
// code stolen from the base halflife.inc file
stock void Shavit_PrintToChatAll(const char[] format, any ...)

View File

@ -129,6 +129,7 @@ char gS_ChatStrings[CHATSETTINGS_SIZE][128];
// misc cache
bool gB_StopChatSound = false;
bool gB_HookedJump = false;
char gS_LogPath[PLATFORM_MAX_PATH];
// kz support
bool gB_KZMap = false;
@ -163,6 +164,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Shavit_IsKZMap", Native_IsKZMap);
CreateNative("Shavit_IsPracticeMode", Native_IsPracticeMode);
CreateNative("Shavit_LoadSnapshot", Native_LoadSnapshot);
CreateNative("Shavit_LogMessage", Native_LogMessage);
CreateNative("Shavit_MarkKZMap", Native_MarkKZMap);
CreateNative("Shavit_PauseTimer", Native_PauseTimer);
CreateNative("Shavit_PrintToChat", Native_PrintToChat);
@ -276,11 +278,14 @@ public void OnPluginStart()
// style commands
gSM_StyleCommands = new StringMap();
// commands END
#if defined DEBUG
RegConsoleCmd("sm_finishtest", Command_FinishTest);
#endif
// commands END
// logs
BuildPath(Path_SM, gS_LogPath, PLATFORM_MAX_PATH, "logs/shavit.log");
CreateConVar("shavit_version", SHAVIT_VERSION, "Plugin version.", (FCVAR_NOTIFY | FCVAR_DONTRECORD));
@ -1025,11 +1030,11 @@ public int Native_StopChatSound(Handle handler, int numParams)
public int Native_PrintToChat(Handle handler, int numParams)
{
int client = GetNativeCell(1);
static int written = 0; // useless?
static int iWritten = 0; // useless?
char[] buffer = new char[300];
FormatNativeString(0, 2, 3, 300, written, buffer);
Format(buffer, 300, "%s %s%s", gS_ChatStrings[sMessagePrefix], gS_ChatStrings[sMessageText], buffer);
char[] sBuffer = new char[300];
FormatNativeString(0, 2, 3, 300, iWritten, sBuffer);
Format(sBuffer, 300, "%s %s%s", gS_ChatStrings[sMessagePrefix], gS_ChatStrings[sMessageText], sBuffer);
if(IsSource2013(gEV_Type))
{
@ -1039,7 +1044,7 @@ public int Native_PrintToChat(Handle handler, int numParams)
{
BfWriteByte(hSayText2, 0);
BfWriteByte(hSayText2, !gB_StopChatSound);
BfWriteString(hSayText2, buffer);
BfWriteString(hSayText2, sBuffer);
}
EndMessage();
@ -1047,7 +1052,7 @@ public int Native_PrintToChat(Handle handler, int numParams)
else
{
PrintToChat(client, " %s", buffer);
PrintToChat(client, " %s", sBuffer);
}
gB_StopChatSound = false;
@ -1162,6 +1167,23 @@ public int Native_LoadSnapshot(Handle handler, int numParams)
gI_SHSW_FirstCombination[client] = view_as<int>(snapshot[iSHSWCombination]);
}
public int Native_LogMessage(Handle plugin, int numParams)
{
char[] sPlugin = new char[32];
if(!GetPluginInfo(plugin, PlInfo_Name, sPlugin, 32))
{
GetPluginFilename(plugin, sPlugin, 32);
}
static int iWritten = 0;
char[] sBuffer = new char[300];
FormatNativeString(0, 1, 2, 300, iWritten, sBuffer);
LogToFileEx(gS_LogPath, "%s", sBuffer);
}
public int Native_MarkKZMap(Handle handler, int numParams)
{
gB_KZMap = true;