Added amb<536> requested for using sm_kick without putting quotes around reason.
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "PluginSys.h"
16 #include "Translator.h"
17 #include "LibrarySys.h"
18 #include "sm_stringutil.h"
19 #include "PlayerManager.h"
21 static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
25 CPlugin *pl = (CPlugin *)g_PluginSys.FindPluginByContext(pCtx->GetContext());
27 pCtx->LocalToString(params[1], &filename);
29 /* Check if there is no extension */
30 const char *ext = g_LibSys.GetFileExtension(filename);
31 if (!ext || (strcmp(ext, "cfg") && strcmp(ext, "txt")))
34 static char new_file[PLATFORM_MAX_PATH];
35 UTIL_Format(new_file, sizeof(new_file), "%s.txt", filename);
39 index = g_Translator.FindOrAddPhraseFile(filename);
40 pl->AddLangFile(index);
45 static cell_t sm_SetGlobalTransTarget(IPluginContext *pContext, const cell_t *params)
47 g_SourceMod.SetGlobalTarget(params[1]);
52 static cell_t sm_GetClientLanguage(IPluginContext *pContext, const cell_t *params)
54 CPlayer *player = g_Players.GetPlayerByIndex(params[1]);
55 if (!player || !player->IsConnected())
57 return pContext->ThrowNativeError("Invalid client index %d", params[1]);
60 return g_Translator.GetClientLanguage(params[1]);
63 static cell_t sm_GetServerLanguage(IPluginContext *pContext, const cell_t *params)
65 return g_Translator.GetServerLanguage();
68 static cell_t sm_GetLanguageCount(IPluginContext *pContext, const cell_t *params)
70 return g_Translator.GetLanguageCount();
73 static cell_t sm_GetLanguageInfo(IPluginContext *pContext, const cell_t *params)
78 if (!g_Translator.GetLanguageInfo(params[1], &code, &name))
80 return pContext->ThrowNativeError("Invalid language number %d", params[1]);
83 pContext->StringToLocalUTF8(params[2], params[3], code, NULL);
84 pContext->StringToLocalUTF8(params[4], params[5], name, NULL);
89 REGISTER_NATIVES(langNatives)
91 {"LoadTranslations", sm_LoadTranslations},
92 {"SetGlobalTransTarget", sm_SetGlobalTransTarget},
93 {"GetClientLanguage", sm_GetClientLanguage},
94 {"GetServerLanguage", sm_GetServerLanguage},
95 {"GetLanguageCount", sm_GetLanguageCount},
96 {"GetLanguageInfo", sm_GetLanguageInfo},