From 1d17835e9a949c7d269c5441b648d2af8c3776fb Mon Sep 17 00:00:00 2001 From: xPaw Date: Sun, 27 Jul 2014 10:54:46 +0300 Subject: [PATCH 1/5] Update multilingual plugin - User pcvars - Remove vault usage - Remove amx_setlang (not very useful, it's covered by the cvar now) - Remove server language from the menu (covered by the cvar now) - Add a cvar for previously hardcoded DISPLAY_MSG --- plugins/multilingual.sma | 154 +++++++++++---------------------------- 1 file changed, 41 insertions(+), 113 deletions(-) diff --git a/plugins/multilingual.sma b/plugins/multilingual.sma index ddb91a1c..496a9adc 100755 --- a/plugins/multilingual.sma +++ b/plugins/multilingual.sma @@ -34,13 +34,13 @@ #include #include -#define DISPLAY_MSG // Comment to disable message on join - -new g_menuLang[MAX_PLAYERS][2] -new g_serverLang +new g_menuLang[33] new g_langNum new g_coloredMenus +new g_cvarDisplayClientMessage; +new g_cvarClientLanguages; + public plugin_init() { register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team") @@ -48,34 +48,18 @@ public plugin_init() register_dictionary("common.txt") register_dictionary("languages.txt") - register_cvar("amx_language", "en", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY) - //Set to zero to disable client effects - register_cvar("amx_client_languages", "1") - register_concmd("amx_setlang", "cmdLang", ADMIN_CFG, "") + g_cvarClientLanguages = register_cvar("amx_client_languages", "1") + g_cvarDisplayClientMessage = register_cvar("amx_language_display_msg", "1") register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL) register_menu("Language Menu", 1023, "actionMenu") - - new lang[3] - if (vaultdata_exists("server_language")) - { - get_vaultdata("server_language", lang, 2) - } else { - copy(lang, 2, "en") - set_vaultdata("server_language", lang) - } - - set_cvar_string("amx_language", lang) - g_langNum = get_langsnum() - g_serverLang = get_lang_id(lang) g_coloredMenus = colored_menus() } -#if defined DISPLAY_MSG public client_putinserver(id) { - if (get_cvar_num("amx_client_languages") && !is_user_bot(id)) + if (get_pcvar_num(g_cvarDisplayClientMessage) && get_pcvar_num(g_cvarClientLanguages) && !is_user_bot(id)) set_task(10.0, "dispInfo", id) } @@ -86,132 +70,76 @@ public client_disconnect(id) public dispInfo(id) { - if (get_cvar_num("amx_client_languages")) - client_print(id, print_chat, "%L", id, "TYPE_LANGMENU") -} -#endif - -public cmdLang(id, level, cid) -{ - if (!cmd_access(id, level, cid, 2)) - return PLUGIN_HANDLED - - new arg[3] - read_argv(1, arg, 2) - - if (!lang_exists(arg)) - { - console_print(id, "[AMXX] %L", id, "LANG_NOT_EXISTS") - return PLUGIN_HANDLED - } - - set_vaultdata("server_language", arg) - set_cvar_string("amx_language", arg) - g_serverLang = get_lang_id(arg) - - return PLUGIN_HANDLED + client_print(id, print_chat, "%L", id, "TYPE_LANGMENU") } public cmdLangMenu(id, level, cid) { - new buffer[3] - - if (!get_cvar_num("amx_client_languages")) + if (!get_pcvar_num(g_cvarClientLanguages)) { client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED") return PLUGIN_HANDLED } - + + new buffer[3] get_user_info(id, "lang", buffer, 2) - g_menuLang[id][0] = get_lang_id(buffer) - g_menuLang[id][1] = g_serverLang - + g_menuLang[id] = get_lang_id(buffer) + showMenu(id) - + return PLUGIN_HANDLED } showMenu(id) { - if (!get_cvar_num("amx_client_languages")) - return PLUGIN_HANDLED + if (!get_pcvar_num(g_cvarClientLanguages)) + return new menuBody[512], pLang[3] - - get_lang(g_menuLang[id][0], pLang) - + + get_lang(g_menuLang[id], pLang) + new len = format(menuBody, 511, (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU") len += format(menuBody[len], 511-len, (g_coloredMenus ? "1. %L\R\r%L\w^n" : "1. %L %L^n"), id, "PERSO_LANG", pLang, "LANG_NAME") - - if (access(id, ADMIN_CFG)) - { - new sLang[3] - - get_lang(g_menuLang[id][1], sLang) - len += format(menuBody[len], 511-len, (g_coloredMenus ? "2. %L\R\r%L\w^n^n" : "2. %L %L^n^n"), id, "SERVER_LANG", sLang, "LANG_NAME") - len += format(menuBody[len], 511-len, "3. %L", id, "SAVE_LANG") - } else { - len += format(menuBody[len], 511-len, "^n2. %L", id, "SAVE_LANG") - } - + len += format(menuBody[len], 511-len, "^n2. %L", id, "SAVE_LANG") format(menuBody[len], 511-len, "^n^n0. %L", id, "EXIT") - - show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3, menuBody, -1, "Language Menu") - - return 1 + + show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2, menuBody, -1, "Language Menu") } public actionMenu(id, key) { - if (!get_cvar_num("amx_client_languages")) + if (!get_pcvar_num(g_cvarClientLanguages)) return 0 - new isAdmin = access(id, ADMIN_CFG) - if (key == 0) { - if (g_menuLang[id][0] < (g_langNum-1)) - g_menuLang[id][0]++ + if (g_menuLang[id] < (g_langNum-1)) + g_menuLang[id]++ else - g_menuLang[id][0] = 0 + g_menuLang[id] = 0 showMenu(id) } - - if (isAdmin && (key == 1)) + else if(key == 1) { - if (g_menuLang[id][1] < (g_langNum - 1)) - g_menuLang[id][1]++ - else - g_menuLang[id][1] = 0 + new pLang[3], pLang_old[3] - showMenu(id) + get_lang(g_menuLang[id], pLang) + get_user_info(id, "lang", pLang_old, 2) + + if (!equali(pLang, pLang_old)) + { + client_cmd(id, "setinfo ^"lang^" ^"%s^"", pLang) + set_user_info(id, "lang", pLang); // In case setinfo breaks (slowhacking and all), this will at least be a fallback while the user is connect + + new lName[64] + format(lName, 63, "%L", pLang, "LANG_NAME") + client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName) + } } - - new pLang[3], pLang_old[3], sLang[3], sLang_old[3], lName[64] - get_lang(g_menuLang[id][0], pLang) - get_lang(g_menuLang[id][1], sLang) - get_user_info(id, "lang", pLang_old, 2) - get_lang(g_serverLang, sLang_old) - - if (isAdmin && (key == 2) && !equali(sLang, sLang_old)) - { - set_vaultdata("server_language", sLang) - set_cvar_string("amx_language", sLang) - g_serverLang = g_menuLang[id][1] - format(lName, 63, "%L", sLang, "LANG_NAME") - client_print(id, print_chat, "%L", pLang, "SET_LANG_SERVER", lName) - } - - if (!equali(pLang, pLang_old) && ((isAdmin && (key == 2)) || (!isAdmin && (key == 1)))) - { - client_cmd(id, "setinfo ^"lang^" ^"%s^"", pLang) - format(lName, 63, "%L", pLang, "LANG_NAME") - client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName) - } - return 0 } @@ -227,4 +155,4 @@ get_lang_id(lang[]) } return 0 -} +} \ No newline at end of file From b4d006438c8fefb519b5ec6e6e76128984ad09a6 Mon Sep 17 00:00:00 2001 From: xPaw Date: Sun, 27 Jul 2014 11:42:34 +0300 Subject: [PATCH 2/5] Update core to use amx_language cvar instead of vault --- amxmodx/format.cpp | 10 +++++----- amxmodx/meta_api.cpp | 10 ++++------ configs/amxx.cfg | 11 +++++++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/amxmodx/format.cpp b/amxmodx/format.cpp index 1ec60e2a..023e568c 100644 --- a/amxmodx/format.cpp +++ b/amxmodx/format.cpp @@ -52,18 +52,18 @@ const char *translate(AMX *amx, cell amxaddr, const char *key) amx_cl_langs = CVAR_GET_POINTER("amx_client_languages"); if ( (int)amx_cl_langs->value == 0 ) { - pLangName = g_vault.get("server_language"); + pLangName = amxmodx_language->string; } else { pLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(g_langMngr.GetDefLang())->pEdict, "lang"); } } else if (addr[0] == LANG_SERVER) { - pLangName = g_vault.get("server_language"); + pLangName = amxmodx_language->string; } else if (addr[0] >= 1 && addr[0] <= gpGlobals->maxClients) { if (!amx_cl_langs) amx_cl_langs = CVAR_GET_POINTER("amx_client_languages"); if ( (int)amx_cl_langs->value == 0 ) { - pLangName = g_vault.get("server_language"); + pLangName = amxmodx_language->string; } else { pLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(addr[0])->pEdict, "lang"); } @@ -110,9 +110,9 @@ const char *translate(AMX *amx, cell amxaddr, const char *key) } if (addr[0] != LANG_SERVER) - def = g_langMngr.GetDef(g_vault.get("server_language"), key, status); + def = g_langMngr.GetDef(amxmodx_language->string, key, status); - if (!def && (strcmp(pLangName, "en") != 0 && strcmp(g_vault.get("server_language"), "en") != 0)) + if (!def && (strcmp(pLangName, "en") != 0 && strcmp(amxmodx_language->string, "en") != 0)) def = g_langMngr.GetDef("en", key, status); } diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 67172920..43ea5030 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -142,9 +142,11 @@ cvar_t init_amxmodx_version = {"amxmodx_version", "", FCVAR_SERVER | FCVAR_SPONL cvar_t init_amxmodx_modules = {"amxmodx_modules", "", FCVAR_SPONLY}; cvar_t init_amxmodx_debug = {"amx_debug", "1", FCVAR_SPONLY}; cvar_t init_amxmodx_mldebug = {"amx_mldebug", "", FCVAR_SPONLY}; +cvar_t init_amxmodx_language = {"amx_language", "en", FCVAR_SERVER}; cvar_t init_amxmodx_cl_langs = {"amx_client_languages", "", FCVAR_SERVER}; cvar_t* amxmodx_version = NULL; cvar_t* amxmodx_modules = NULL; +cvar_t* amxmodx_language = NULL; cvar_t* hostname = NULL; cvar_t* mp_timelimit = NULL; @@ -464,12 +466,6 @@ int C_Spawn(edict_t *pent) char file[255]; g_vault.setSource(build_pathname_r(file, sizeof(file) - 1, "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini"))); g_vault.loadVault(); - - if (strlen(g_vault.get("server_language")) < 1) - { - g_vault.put("server_language", "en"); - g_vault.saveVault(); - } // ###### Init time and freeze tasks g_game_timeleft = g_bmod_dod ? 1.0f : 0.0f; @@ -1446,9 +1442,11 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m CVAR_REGISTER(&init_amxmodx_modules); CVAR_REGISTER(&init_amxmodx_debug); CVAR_REGISTER(&init_amxmodx_mldebug); + CVAR_REGISTER(&init_amxmodx_language); CVAR_REGISTER(&init_amxmodx_cl_langs); amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name); + amxmodx_language = CVAR_GET_POINTER(init_amxmodx_language.name); REG_SVR_COMMAND("amxx", amx_command); diff --git a/configs/amxx.cfg b/configs/amxx.cfg index b7dbe597..dd4f920c 100755 --- a/configs/amxx.cfg +++ b/configs/amxx.cfg @@ -134,12 +134,23 @@ amx_extendmap_max 90 // Default value: 15 amx_extendmap_step 15 +// Server language in ISO 639-1 format +// Please see data/lang/languages.txt file for a list of supported languages +// +// Default value: en +amx_language "en" + // If you set this to 0, clients cannot chose their language, instead they use // whatever language the server is configured to use. // // Default value: 1 amx_client_languages 1 +// If you set this to 0, clients will not see a message about amx_langmenu when they join the server +// +// Default value: 1 +amx_language_display_msg 1 + // Plugin Debug mode // 0 - No debugging (garbage line numbers) // 1 - Plugins with "debug" option in plugins.ini are put into debug mode From 60b1ec222e8d5844026f372a6ea545d8540c3048 Mon Sep 17 00:00:00 2001 From: xPaw Date: Sun, 27 Jul 2014 11:52:30 +0300 Subject: [PATCH 3/5] Add extern amxmodx_language --- amxmodx/amxmodx.h | 1 + 1 file changed, 1 insertion(+) diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 331e433c..46e72069 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -204,6 +204,7 @@ extern bool g_bmod_dod; extern bool g_dontprecache; extern int g_srvindex; extern cvar_t* amxmodx_version; +extern cvar_t* amxmodx_language; extern cvar_t* hostname; extern cvar_t* mp_timelimit; extern fakecmd_t g_fakecmd; From 499b5a1ac8e99f056b8b18bc0cf9bdac93d3c845 Mon Sep 17 00:00:00 2001 From: xPaw Date: Sun, 27 Jul 2014 12:37:58 +0300 Subject: [PATCH 4/5] Use MAX_PLAYERS --- plugins/multilingual.sma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/multilingual.sma b/plugins/multilingual.sma index 496a9adc..17a9c283 100755 --- a/plugins/multilingual.sma +++ b/plugins/multilingual.sma @@ -34,7 +34,7 @@ #include #include -new g_menuLang[33] +new g_menuLang[MAX_PLAYERS] new g_langNum new g_coloredMenus From dff6dc53f466b76670bcaad83beeb80f5fd8064e Mon Sep 17 00:00:00 2001 From: xPaw Date: Sun, 27 Jul 2014 12:51:36 +0300 Subject: [PATCH 5/5] Use formatex and charsmax --- plugins/multilingual.sma | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/plugins/multilingual.sma b/plugins/multilingual.sma index 17a9c283..ff0101a4 100755 --- a/plugins/multilingual.sma +++ b/plugins/multilingual.sma @@ -60,7 +60,9 @@ public plugin_init() public client_putinserver(id) { if (get_pcvar_num(g_cvarDisplayClientMessage) && get_pcvar_num(g_cvarClientLanguages) && !is_user_bot(id)) + { set_task(10.0, "dispInfo", id) + } } public client_disconnect(id) @@ -93,17 +95,19 @@ public cmdLangMenu(id, level, cid) showMenu(id) { if (!get_pcvar_num(g_cvarClientLanguages)) + { return + } new menuBody[512], pLang[3] get_lang(g_menuLang[id], pLang) - new len = format(menuBody, 511, (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU") + new len = formatex(menuBody, charsmax(menuBody), (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU") - len += format(menuBody[len], 511-len, (g_coloredMenus ? "1. %L\R\r%L\w^n" : "1. %L %L^n"), id, "PERSO_LANG", pLang, "LANG_NAME") - len += format(menuBody[len], 511-len, "^n2. %L", id, "SAVE_LANG") - format(menuBody[len], 511-len, "^n^n0. %L", id, "EXIT") + len += formatex(menuBody[len], charsmax(menuBody) - len, (g_coloredMenus ? "1. %L\R\r%L\w^n" : "1. %L %L^n"), id, "PERSO_LANG", pLang, "LANG_NAME") + len += formatex(menuBody[len], charsmax(menuBody) - len, "^n2. %L", id, "SAVE_LANG") + formatex(menuBody[len], charsmax(menuBody) - len, "^n^n0. %L", id, "EXIT") show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2, menuBody, -1, "Language Menu") } @@ -111,14 +115,20 @@ showMenu(id) public actionMenu(id, key) { if (!get_pcvar_num(g_cvarClientLanguages)) + { return 0 + } if (key == 0) { - if (g_menuLang[id] < (g_langNum-1)) + if (g_menuLang[id] < (g_langNum - 1)) + { g_menuLang[id]++ + } else + { g_menuLang[id] = 0 + } showMenu(id) } @@ -135,7 +145,7 @@ public actionMenu(id, key) set_user_info(id, "lang", pLang); // In case setinfo breaks (slowhacking and all), this will at least be a fallback while the user is connect new lName[64] - format(lName, 63, "%L", pLang, "LANG_NAME") + formatex(lName, charsmax(lName), "%L", pLang, "LANG_NAME") client_print(id, print_chat, "%L", pLang, "SET_LANG_USER", lName) } } @@ -150,9 +160,12 @@ get_lang_id(lang[]) for (new i = 0; i < g_langNum; i++) { get_lang(i, tLang) + if (equali(tLang, lang)) + { return i + } } return 0 -} \ No newline at end of file +}