core/smn_filesystem.cpp
changeset 347 aa2dfce8bff6
parent 345 df0b05b4f50d
child 351 7c219cde57e7
     1.1 --- a/core/smn_filesystem.cpp	Thu Jan 25 06:18:22 2007 +0000
     1.2 +++ b/core/smn_filesystem.cpp	Thu Jan 25 06:19:17 2007 +0000
     1.3 @@ -3,6 +3,9 @@
     1.4  #include "HandleSys.h"
     1.5  #include "LibrarySys.h"
     1.6  #include "sm_stringutil.h"
     1.7 +#include "CLogger.h"
     1.8 +#include "PluginSys.h"
     1.9 +#include "sourcemm_api.h"
    1.10  
    1.11  HandleType_t g_FileType;
    1.12  HandleType_t g_DirType;
    1.13 @@ -440,6 +443,47 @@
    1.14  	return g_SourceMod.BuildPath(Path_SM_Rel, buffer, params[3], "%s", path);
    1.15  }
    1.16  
    1.17 +static cell_t sm_LogToGame(IPluginContext *pContext, const cell_t *params)
    1.18 +{
    1.19 +	char buffer[1024];
    1.20 +	size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 1);
    1.21 +
    1.22 +	if (len >= sizeof(buffer)-2)
    1.23 +	{
    1.24 +		buffer[1022] = '\n';
    1.25 +		buffer[1023] = '\0';
    1.26 +	} else {
    1.27 +		buffer[len++] = '\n';
    1.28 +		buffer[len] = '\0';
    1.29 +	}
    1.30 +
    1.31 +	engine->LogPrint(buffer);
    1.32 +
    1.33 +	return 1;
    1.34 +}
    1.35 +
    1.36 +static cell_t sm_LogMessage(IPluginContext *pContext, const cell_t *params)
    1.37 +{
    1.38 +	char buffer[1024];
    1.39 +	size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 1);
    1.40 +
    1.41 +	IPlugin *pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext());
    1.42 +	g_Logger.LogMessage("[%s] %s", pPlugin->GetFilename(), buffer);
    1.43 +
    1.44 +	return 1;
    1.45 +}
    1.46 +
    1.47 +static cell_t sm_LogError(IPluginContext *pContext, const cell_t *params)
    1.48 +{
    1.49 +	char buffer[1024];
    1.50 +	size_t len = g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 1);
    1.51 +
    1.52 +	IPlugin *pPlugin = g_PluginSys.FindPluginByContext(pContext->GetContext());
    1.53 +	g_Logger.LogError("[%s] %s", pPlugin->GetFilename(), buffer);
    1.54 +
    1.55 +	return 1;
    1.56 +}
    1.57 +
    1.58  static FileNatives s_FileNatives;
    1.59  
    1.60  REGISTER_NATIVES(filesystem)
    1.61 @@ -459,5 +503,8 @@
    1.62  	{"RemoveDir",				sm_RemoveDir},
    1.63  	{"WriteFileLine",			sm_WriteFileLine},
    1.64  	{"BuildPath",				sm_BuildPath},
    1.65 +	{"LogToGame",			sm_LogToGame},
    1.66 +	{"LogMessage",			sm_LogMessage},
    1.67 +	{"LogError",				sm_LogError},
    1.68  	{NULL,						NULL},
    1.69  };