diff --git a/core/CLogger.h b/core/CLogger.h index 9eed457d..c28136f1 100644 --- a/core/CLogger.h +++ b/core/CLogger.h @@ -35,8 +35,8 @@ public: void LogMessage(const char *msg, ...); void LogError(const char *msg, ...); void MapChange(const char *mapname); - const char *GetLogFileName(LogType type); - LoggingMode GetLoggingMode(); + const char *GetLogFileName(LogType type) const; + LoggingMode GetLoggingMode() const; private: void _CloseFile(); void _NewMapFile(); @@ -55,7 +55,7 @@ private: extern CLogger g_Logger; -inline const char *CLogger::GetLogFileName(LogType type) +inline const char *CLogger::GetLogFileName(LogType type) const { switch (type) { @@ -74,7 +74,7 @@ inline const char *CLogger::GetLogFileName(LogType type) } } -inline LoggingMode CLogger::GetLoggingMode() +inline LoggingMode CLogger::GetLoggingMode() const { return m_mode; } diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index 79ada0a9..e66833ad 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -203,6 +203,10 @@ RelativePath="..\sm_autonatives.cpp" > + + diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 441d0ec4..62f22cae 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -1,4 +1,5 @@ #include "CPlayerManager.h" +#include "sm_stringutil.h" static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) { @@ -58,7 +59,15 @@ static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) return pCtx->ThrowNativeError("Client %d is not connected.", index); } - pCtx->StringToLocal(params[2], static_cast(params[3]), pPlayer->PlayerIP()); + char buf[64], *ptr; + strcpy(buf, pPlayer->PlayerIP()); + + if (params[4] && (ptr = strchr(buf, ':'))) + { + *ptr = '\0'; + } + + pCtx->StringToLocal(params[2], static_cast(params[3]), buf); return 1; } @@ -130,6 +139,52 @@ static cell_t sm_IsPlayerFakeClient(IPluginContext *pCtx, const cell_t *params) return (pPlayer->IsPlayerFakeClient()) ? 1 : 0; } +static cell_t sm_PrintToServer(IPluginContext *pCtx, const cell_t *params) +{ + char buffer[1024]; + char *fmt; + int arg = 2; + + pCtx->LocalToString(params[1], &fmt); + size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg); + + buffer[res++] = '\n'; + buffer[res] = '\0'; + + META_CONPRINT(buffer); + + return 1; +} + +static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > g_PlayerManager.GetMaxClients())) + { + return pCtx->ThrowNativeError("Invalid client index %d.", index); + } + + CPlayer *pPlayer = g_PlayerManager.GetPlayerByIndex(index); + if (!pPlayer->IsPlayerInGame()) + { + return pCtx->ThrowNativeError("Client %d is not in game.", index); + } + + char buffer[1024]; + char *fmt; + int arg = 3; + + pCtx->LocalToString(params[2], &fmt); + size_t res = atcprintf(buffer, sizeof(buffer)-2, fmt, pCtx, params, &arg); + + buffer[res++] = '\n'; + buffer[res] = '\0'; + + engine->ClientPrintf(pPlayer->GetPlayerEdict(), buffer); + + return 1; +} + REGISTER_NATIVES(playernatives) { {"GetMaxClients", sm_GetMaxClients}, @@ -141,5 +196,7 @@ REGISTER_NATIVES(playernatives) {"IsPlayerInGame", sm_IsPlayerIngame}, {"IsPlayerAuthorized", sm_IsPlayerAuthorized}, {"IsPlayerFakeClient", sm_IsPlayerFakeClient}, + {"PrintToServer", sm_PrintToServer}, + {"PrintToConsole", sm_PrintToConsole}, {NULL, NULL} }; \ No newline at end of file diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index deef6f13..efd9686b 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -155,10 +155,11 @@ native bool:GetClientName(client, String:name[], maxlen); * @param client Player index. * @param name Buffer to store the client's ip address. * @param maxlen Maximum length of string buffer (includes NULL terminator). + * @param remport Remove client's port from the ip string (true by default). * @return True on success, false otherwise. * @error If the client is not connected an error will be thrown. */ -native bool:GetClientIP(client, String:ip[], maxlen); +native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true); /** * Retrieves a client's authentication string (SteamID). @@ -202,3 +203,23 @@ native bool:IsPlayerAuthorized(client); * @return True if player is a fake client, false otherwise. */ native bool:IsPlayerFakeClient(client); + +/** + * Sends a message to the server console. + * + * @param format Formatting rules. + * @param ... Variable number of format parameters. + * @noreturn + */ +native PrintToServer(const String:format[], {Handle,Float,String,_}:...); + +/** + * Sends a message to a client's console. + * + * @param client Player index. + * @param format Formatting rules. + * @param ... Variable number of format parameters. + * @noreturn + * @error If the client is not connected an error will be thrown. + */ +native PrintToConsole(client, const String:format[], {Handle,Float,String,_}:...);