Merge pull request #82 from xPaw/ml-plugin-update

Multilingual plugin update
This commit is contained in:
Vincent Herbet 2014-07-27 11:57:51 +02:00
commit 88042ce5a9
5 changed files with 77 additions and 126 deletions

View File

@ -204,6 +204,7 @@ extern bool g_bmod_dod;
extern bool g_dontprecache; extern bool g_dontprecache;
extern int g_srvindex; extern int g_srvindex;
extern cvar_t* amxmodx_version; extern cvar_t* amxmodx_version;
extern cvar_t* amxmodx_language;
extern cvar_t* hostname; extern cvar_t* hostname;
extern cvar_t* mp_timelimit; extern cvar_t* mp_timelimit;
extern fakecmd_t g_fakecmd; extern fakecmd_t g_fakecmd;

View File

@ -52,18 +52,18 @@ const char *translate(AMX *amx, cell amxaddr, const char *key)
amx_cl_langs = CVAR_GET_POINTER("amx_client_languages"); amx_cl_langs = CVAR_GET_POINTER("amx_client_languages");
if ( (int)amx_cl_langs->value == 0 ) if ( (int)amx_cl_langs->value == 0 )
{ {
pLangName = g_vault.get("server_language"); pLangName = amxmodx_language->string;
} else { } else {
pLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(g_langMngr.GetDefLang())->pEdict, "lang"); pLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(g_langMngr.GetDefLang())->pEdict, "lang");
} }
} else if (addr[0] == LANG_SERVER) { } 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) { } else if (addr[0] >= 1 && addr[0] <= gpGlobals->maxClients) {
if (!amx_cl_langs) if (!amx_cl_langs)
amx_cl_langs = CVAR_GET_POINTER("amx_client_languages"); amx_cl_langs = CVAR_GET_POINTER("amx_client_languages");
if ( (int)amx_cl_langs->value == 0 ) if ( (int)amx_cl_langs->value == 0 )
{ {
pLangName = g_vault.get("server_language"); pLangName = amxmodx_language->string;
} else { } else {
pLangName = ENTITY_KEYVALUE(GET_PLAYER_POINTER_I(addr[0])->pEdict, "lang"); 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) 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); def = g_langMngr.GetDef("en", key, status);
} }

View File

@ -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_modules = {"amxmodx_modules", "", FCVAR_SPONLY};
cvar_t init_amxmodx_debug = {"amx_debug", "1", 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_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 init_amxmodx_cl_langs = {"amx_client_languages", "", FCVAR_SERVER};
cvar_t* amxmodx_version = NULL; cvar_t* amxmodx_version = NULL;
cvar_t* amxmodx_modules = NULL; cvar_t* amxmodx_modules = NULL;
cvar_t* amxmodx_language = NULL;
cvar_t* hostname = NULL; cvar_t* hostname = NULL;
cvar_t* mp_timelimit = NULL; cvar_t* mp_timelimit = NULL;
@ -464,12 +466,6 @@ int C_Spawn(edict_t *pent)
char file[255]; 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.setSource(build_pathname_r(file, sizeof(file) - 1, "%s", get_localinfo("amxx_vault", "addons/amxmodx/configs/vault.ini")));
g_vault.loadVault(); 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 // ###### Init time and freeze tasks
g_game_timeleft = g_bmod_dod ? 1.0f : 0.0f; 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_modules);
CVAR_REGISTER(&init_amxmodx_debug); CVAR_REGISTER(&init_amxmodx_debug);
CVAR_REGISTER(&init_amxmodx_mldebug); CVAR_REGISTER(&init_amxmodx_mldebug);
CVAR_REGISTER(&init_amxmodx_language);
CVAR_REGISTER(&init_amxmodx_cl_langs); CVAR_REGISTER(&init_amxmodx_cl_langs);
amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name); amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name);
amxmodx_language = CVAR_GET_POINTER(init_amxmodx_language.name);
REG_SVR_COMMAND("amxx", amx_command); REG_SVR_COMMAND("amxx", amx_command);

View File

@ -134,12 +134,23 @@ amx_extendmap_max 90
// Default value: 15 // Default value: 15
amx_extendmap_step 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 // If you set this to 0, clients cannot chose their language, instead they use
// whatever language the server is configured to use. // whatever language the server is configured to use.
// //
// Default value: 1 // Default value: 1
amx_client_languages 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 // Plugin Debug mode
// 0 - No debugging (garbage line numbers) // 0 - No debugging (garbage line numbers)
// 1 - Plugins with "debug" option in plugins.ini are put into debug mode // 1 - Plugins with "debug" option in plugins.ini are put into debug mode

View File

@ -34,13 +34,13 @@
#include <amxmodx> #include <amxmodx>
#include <amxmisc> #include <amxmisc>
#define DISPLAY_MSG // Comment to disable message on join new g_menuLang[MAX_PLAYERS]
new g_menuLang[MAX_PLAYERS][2]
new g_serverLang
new g_langNum new g_langNum
new g_coloredMenus new g_coloredMenus
new g_cvarDisplayClientMessage;
new g_cvarClientLanguages;
public plugin_init() public plugin_init()
{ {
register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team") register_plugin("Multi-Lingual System", AMXX_VERSION_STR, "AMXX Dev Team")
@ -48,35 +48,21 @@ public plugin_init()
register_dictionary("common.txt") register_dictionary("common.txt")
register_dictionary("languages.txt") register_dictionary("languages.txt")
register_cvar("amx_language", "en", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY) g_cvarClientLanguages = register_cvar("amx_client_languages", "1")
//Set to zero to disable client effects g_cvarDisplayClientMessage = register_cvar("amx_language_display_msg", "1")
register_cvar("amx_client_languages", "1")
register_concmd("amx_setlang", "cmdLang", ADMIN_CFG, "<language>")
register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL) register_clcmd("amx_langmenu", "cmdLangMenu", ADMIN_ALL)
register_menu("Language Menu", 1023, "actionMenu") 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_langNum = get_langsnum()
g_serverLang = get_lang_id(lang)
g_coloredMenus = colored_menus() g_coloredMenus = colored_menus()
} }
#if defined DISPLAY_MSG
public client_putinserver(id) 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) set_task(10.0, "dispInfo", id)
}
} }
public client_disconnect(id) public client_disconnect(id)
@ -86,132 +72,84 @@ public client_disconnect(id)
public dispInfo(id) public dispInfo(id)
{ {
if (get_cvar_num("amx_client_languages")) client_print(id, print_chat, "%L", id, "TYPE_LANGMENU")
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
} }
public cmdLangMenu(id, level, cid) public cmdLangMenu(id, level, cid)
{ {
new buffer[3] if (!get_pcvar_num(g_cvarClientLanguages))
if (!get_cvar_num("amx_client_languages"))
{ {
client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED") client_print(id, print_console, "[AMXX] %L", LANG_SERVER, "LANG_MENU_DISABLED")
return PLUGIN_HANDLED return PLUGIN_HANDLED
} }
new buffer[3]
get_user_info(id, "lang", buffer, 2) get_user_info(id, "lang", buffer, 2)
g_menuLang[id][0] = get_lang_id(buffer) g_menuLang[id] = get_lang_id(buffer)
g_menuLang[id][1] = g_serverLang
showMenu(id) showMenu(id)
return PLUGIN_HANDLED return PLUGIN_HANDLED
} }
showMenu(id) showMenu(id)
{ {
if (!get_cvar_num("amx_client_languages")) if (!get_pcvar_num(g_cvarClientLanguages))
return PLUGIN_HANDLED
new menuBody[512], pLang[3]
get_lang(g_menuLang[id][0], 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] return
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")
} }
format(menuBody[len], 511-len, "^n^n0. %L", id, "EXIT") new menuBody[512], pLang[3]
show_menu(id, MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3, menuBody, -1, "Language Menu") get_lang(g_menuLang[id], pLang)
return 1 new len = formatex(menuBody, charsmax(menuBody), (g_coloredMenus ? "\y%L\w^n^n" : "%L^n^n"), id, "LANG_MENU")
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")
} }
public actionMenu(id, key) public actionMenu(id, key)
{ {
if (!get_cvar_num("amx_client_languages")) if (!get_pcvar_num(g_cvarClientLanguages))
{
return 0 return 0
}
new isAdmin = access(id, ADMIN_CFG)
if (key == 0) if (key == 0)
{ {
if (g_menuLang[id][0] < (g_langNum-1)) if (g_menuLang[id] < (g_langNum - 1))
g_menuLang[id][0]++ {
g_menuLang[id]++
}
else else
g_menuLang[id][0] = 0 {
g_menuLang[id] = 0
}
showMenu(id) showMenu(id)
} }
else if(key == 1)
if (isAdmin && (key == 1))
{ {
if (g_menuLang[id][1] < (g_langNum - 1)) new pLang[3], pLang_old[3]
g_menuLang[id][1]++
else
g_menuLang[id][1] = 0
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]
formatex(lName, charsmax(lName), "%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 return 0
} }
@ -222,8 +160,11 @@ get_lang_id(lang[])
for (new i = 0; i < g_langNum; i++) for (new i = 0; i < g_langNum; i++)
{ {
get_lang(i, tLang) get_lang(i, tLang)
if (equali(tLang, lang)) if (equali(tLang, lang))
{
return i return i
}
} }
return 0 return 0