core/smn_lang.cpp
author Phong Dang <teame06@gmail.com>
Sun Jul 29 19:20:42 2007 +0000 (2007-07-29)
changeset 1211 990912ee1e1e
parent 1105 ce907ba50921
child 1231 17badaf66ce4
permissions -rw-r--r--
Added amb<536> requested for using sm_kick without putting quotes around reason.
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     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
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #include "PluginSys.h"
    16 #include "Translator.h"
    17 #include "LibrarySys.h"
    18 #include "sm_stringutil.h"
    19 #include "PlayerManager.h"
    20 
    21 static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params)
    22 {
    23 	char *filename;
    24 	unsigned int index;
    25 	CPlugin *pl = (CPlugin *)g_PluginSys.FindPluginByContext(pCtx->GetContext());
    26 
    27 	pCtx->LocalToString(params[1], &filename);
    28 
    29 	/* Check if there is no extension */
    30 	const char *ext = g_LibSys.GetFileExtension(filename);
    31 	if (!ext || (strcmp(ext, "cfg") && strcmp(ext, "txt")))
    32 	{
    33 		/* Append one */
    34 		static char new_file[PLATFORM_MAX_PATH];
    35 		UTIL_Format(new_file, sizeof(new_file), "%s.txt", filename);
    36 		filename = new_file;
    37 	}
    38 
    39 	index = g_Translator.FindOrAddPhraseFile(filename);
    40 	pl->AddLangFile(index);
    41 
    42 	return 1;
    43 }
    44 
    45 static cell_t sm_SetGlobalTransTarget(IPluginContext *pContext, const cell_t *params)
    46 {
    47 	g_SourceMod.SetGlobalTarget(params[1]);
    48 
    49 	return 1;
    50 }
    51 
    52 static cell_t sm_GetClientLanguage(IPluginContext *pContext, const cell_t *params)
    53 {
    54 	CPlayer *player = g_Players.GetPlayerByIndex(params[1]);
    55 	if (!player || !player->IsConnected())
    56 	{
    57 		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
    58 	}
    59 
    60 	return g_Translator.GetClientLanguage(params[1]);
    61 }
    62 
    63 static cell_t sm_GetServerLanguage(IPluginContext *pContext, const cell_t *params)
    64 {
    65 	return g_Translator.GetServerLanguage();
    66 }
    67 
    68 static cell_t sm_GetLanguageCount(IPluginContext *pContext, const cell_t *params)
    69 {
    70 	return g_Translator.GetLanguageCount();
    71 }
    72 
    73 static cell_t sm_GetLanguageInfo(IPluginContext *pContext, const cell_t *params)
    74 {
    75 	const char *code;
    76 	const char *name;
    77 
    78 	if (!g_Translator.GetLanguageInfo(params[1], &code, &name))
    79 	{
    80 		return pContext->ThrowNativeError("Invalid language number %d", params[1]);
    81 	}
    82 
    83 	pContext->StringToLocalUTF8(params[2], params[3], code, NULL);
    84 	pContext->StringToLocalUTF8(params[4], params[5], name, NULL);
    85 
    86 	return 1;
    87 }
    88 
    89 REGISTER_NATIVES(langNatives)
    90 {
    91 	{"LoadTranslations",			sm_LoadTranslations},
    92 	{"SetGlobalTransTarget",		sm_SetGlobalTransTarget},
    93 	{"GetClientLanguage",			sm_GetClientLanguage},
    94 	{"GetServerLanguage",			sm_GetServerLanguage},
    95 	{"GetLanguageCount",			sm_GetLanguageCount},
    96 	{"GetLanguageInfo",				sm_GetLanguageInfo},
    97 	{NULL,							NULL},
    98 };