changed to use the new language system

This commit is contained in:
Pavol Marko 2004-07-28 18:33:20 +00:00
parent 286a0d0d02
commit 8811b56756
4 changed files with 145 additions and 57 deletions

View File

@ -97,6 +97,7 @@ static cell AMX_NATIVE_CALL emit_sound(AMX *amx, cell *params) /* 7 param */
static cell AMX_NATIVE_CALL server_print(AMX *amx, cell *params) /* 1 param */ static cell AMX_NATIVE_CALL server_print(AMX *amx, cell *params) /* 1 param */
{ {
int len; int len;
g_langMngr.SetDefLang(LANG_SERVER); // Default language = server
char* message = format_amxstring(amx,params,1,len); char* message = format_amxstring(amx,params,1,len);
if ( len > 254 ) len = 254; if ( len > 254 ) len = 254;
message[len++]='\n'; message[len++]='\n';
@ -107,38 +108,52 @@ static cell AMX_NATIVE_CALL server_print(AMX *amx, cell *params) /* 1 param */
static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param */ static cell AMX_NATIVE_CALL engclient_print(AMX *amx, cell *params) /* 3 param */
{ {
int len; int len;
char* message = format_amxstring(amx,params,3,len); char *msg;
message[len++]='\n'; if (params[1] == 0)
message[len]=0; {
if (params[1] == 0) { for(int i = 1; i <= gpGlobals->maxClients; ++i)
for(int i = 1; i <= gpGlobals->maxClients ; ++i){ {
CPlayer* pPlayer = GET_PLAYER_POINTER_I(i); CPlayer* pPlayer = GET_PLAYER_POINTER_I(i);
if (pPlayer->ingame) if (pPlayer->ingame)
CLIENT_PRINT(pPlayer->pEdict, (PRINT_TYPE)(int)params[2] , message ); {
} g_langMngr.SetDefLang(i);
} msg = format_amxstring(amx, params, 3, len);
else { msg[len++] = '\n';
int index = params[1]; msg[len] = 0;
if (index < 1 || index > gpGlobals->maxClients){ CLIENT_PRINT(pPlayer->pEdict, (PRINT_TYPE)(int)params[2], msg);
amx_RaiseError(amx,AMX_ERR_NATIVE); }
return 0; }
} }
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); else
if (pPlayer->ingame) {
CLIENT_PRINT(pPlayer->pEdict, (PRINT_TYPE)(int)params[2] , message ); int index = params[1];
} if (index < 1 || index > gpGlobals->maxClients){
return len; amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0;
}
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame)
{
g_langMngr.SetDefLang(index);
msg = format_amxstring(amx, params, 3, len);
msg[len++] = '\n';
msg[len] = 0;
CLIENT_PRINT(pPlayer->pEdict, (PRINT_TYPE)(int)params[2], msg);
}
}
return len;
} }
static cell AMX_NATIVE_CALL console_cmd(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL console_cmd(AMX *amx, cell *params) /* 2 param */
{ {
int index = params[1];
g_langMngr.SetDefLang(index);
int len; int len;
char* cmd = format_amxstring(amx,params,2,len); char* cmd = format_amxstring(amx,params,2,len);
cmd[len++]='\n'; cmd[len++]='\n';
cmd[len]=0; cmd[len]=0;
int index = params[1];
if (index < 1 || index > gpGlobals->maxClients){ if (index < 1 || index > gpGlobals->maxClients){
SERVER_COMMAND( cmd ); SERVER_COMMAND( cmd );
} }
@ -152,44 +167,66 @@ static cell AMX_NATIVE_CALL console_cmd(AMX *amx, cell *params) /* 2 param */
static cell AMX_NATIVE_CALL console_print(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL console_print(AMX *amx, cell *params) /* 2 param */
{ {
int len; int index = params[1];
char* message = format_amxstring(amx,params,2,len); if (index < 1 || index > gpGlobals->maxClients)
if ( len > 254 ) len = 254; g_langMngr.SetDefLang(LANG_SERVER);
message[len++]='\n'; else
message[len]=0; g_langMngr.SetDefLang(index);
int index = params[1];
if (index < 1 || index > gpGlobals->maxClients){ int len;
SERVER_PRINT( message ); char* message = format_amxstring(amx,params,2,len);
} if (len > 254 )
else { len = 254;
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); message[len++] = '\n';
if (pPlayer->ingame) message[len] = 0;
UTIL_ClientPrint(pPlayer->pEdict, 2 , message ); if (index < 1 || index > gpGlobals->maxClients)
} SERVER_PRINT( message );
return len; else
{
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
if (pPlayer->ingame)
UTIL_ClientPrint(pPlayer->pEdict, 2 , message );
}
return len;
} }
static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */ static cell AMX_NATIVE_CALL client_print(AMX *amx, cell *params) /* 3 param */
{ {
int len; int len;
char* message = format_amxstring(amx,params,3,len); char *msg;
message[len++]='\n'; if (params[1] == 0)
message[len]=0; {
if (params[1] == 0) { for (int i = 1; i <= gpGlobals->maxClients; ++i)
UTIL_ClientPrint(NULL, params[2] , message ); {
} CPlayer *pPlayer = GET_PLAYER_POINTER_I(i);
else { if (pPlayer->ingame)
int index = params[1]; {
if (index < 1 || index > gpGlobals->maxClients){ g_langMngr.SetDefLang(i);
amx_RaiseError(amx,AMX_ERR_NATIVE); msg = format_amxstring(amx, params, 3, len);
return 0; msg[len++] = '\n';
} msg[len] = 0;
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index); UTIL_ClientPrint(NULL, params[2], msg);
if (pPlayer->ingame) }
UTIL_ClientPrint(pPlayer->pEdict, params[2] , message ); }
} }
return len; else
{
int index = params[1];
if (index < 1 || index > gpGlobals->maxClients)
{
amx_RaiseError(amx,AMX_ERR_NATIVE);
return 0;
}
CPlayer* pPlayer = GET_PLAYER_POINTER_I(index);
g_langMngr.SetDefLang(index);
msg = format_amxstring(amx, params, 3, len);
msg[len++] = '\n';
msg[len] = 0;
if (pPlayer->ingame)
UTIL_ClientPrint(pPlayer->pEdict, params[2], format_amxstring(amx, params, 3, len));
}
return len;
} }
static cell AMX_NATIVE_CALL show_motd(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL show_motd(AMX *amx, cell *params) /* 2 param */
@ -251,6 +288,7 @@ static cell AMX_NATIVE_CALL set_hudmessage(AMX *amx, cell *params) /* 11 param
static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param */ static cell AMX_NATIVE_CALL show_hudmessage(AMX *amx, cell *params) /* 2 param */
{ {
int len; int len;
g_langMngr.SetDefLang(params[1]);
char* message = UTIL_SplitHudMessage( format_amxstring(amx,params,2,len) ); char* message = UTIL_SplitHudMessage( format_amxstring(amx,params,2,len) );
if (params[1] == 0) { if (params[1] == 0) {
UTIL_HudMessage(NULL, g_hudset, message ); UTIL_HudMessage(NULL, g_hudset, message );
@ -1003,6 +1041,7 @@ static cell AMX_NATIVE_CALL user_slap(AMX *amx, cell *params) /* 2 param */
static cell AMX_NATIVE_CALL server_cmd(AMX *amx, cell *params) /* 1 param */ static cell AMX_NATIVE_CALL server_cmd(AMX *amx, cell *params) /* 1 param */
{ {
int len; int len;
g_langMngr.SetDefLang(LANG_SERVER);
char* cmd = format_amxstring(amx,params,1,len); char* cmd = format_amxstring(amx,params,1,len);
cmd[len++]='\n'; cmd[len++]='\n';
cmd[len]=0; cmd[len]=0;
@ -1172,6 +1211,7 @@ static cell AMX_NATIVE_CALL write_string(AMX *amx, cell *params) /* 1 param */
static cell AMX_NATIVE_CALL log_message(AMX *amx, cell *params) /* 1 param */ static cell AMX_NATIVE_CALL log_message(AMX *amx, cell *params) /* 1 param */
{ {
int len; int len;
g_langMngr.SetDefLang(LANG_SERVER);
char* message = format_amxstring(amx,params,1,len); char* message = format_amxstring(amx,params,1,len);
message[len++]='\n'; message[len++]='\n';
message[len]=0; message[len]=0;
@ -1199,6 +1239,7 @@ static cell AMX_NATIVE_CALL log_to_file(AMX *amx, cell *params) /* 1 param */
time_t td; time(&td); time_t td; time(&td);
strftime(date,31,"%m/%d/%Y - %H:%M:%S",localtime(&td)); strftime(date,31,"%m/%d/%Y - %H:%M:%S",localtime(&td));
int len; int len;
g_langMngr.SetDefLang(LANG_SERVER);
char* message = format_amxstring(amx,params,2,len); char* message = format_amxstring(amx,params,2,len);
message[len++]='\n'; message[len++]='\n';
message[len]=0; message[len]=0;
@ -2228,6 +2269,7 @@ static cell AMX_NATIVE_CALL log_amx(AMX *amx, cell *params)
CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx); CPluginMngr::CPlugin *plugin = g_plugins.findPluginFast(amx);
int len; int len;
g_langMngr.SetDefLang(LANG_SERVER);
AMXXLOG_Log("[%s] %s", plugin->getName(), format_amxstring(amx, params, 1, len)); AMXXLOG_Log("[%s] %s", plugin->getName(), format_amxstring(amx, params, 1, len));
return 0; return 0;
} }
@ -2499,6 +2541,35 @@ static cell callfunc_push_str(AMX *amx, cell *params)
return 0; return 0;
} }
// get_langsnum();
static cell get_langsnum(AMX *amx, cell *params)
{
return g_langMngr.GetLangsNum();
}
// get_lang(id, name[(at least 3)]);
static cell get_lang(AMX *amx, cell *params)
{
set_amxstring(amx, params[2], g_langMngr.GetLangName(params[1]), 2);
return 0;
}
// register_dictionary(const filename[]);
static cell register_dictionary(AMX *amx, cell *params)
{
int len;
g_langMngr.MergeDefinitionFile(build_pathname("%s/lang/%s",
get_localinfo("amxx_datadir", "addons/amxx/data"), get_amxstring(amx, params[1], 1, len)));
return 0;
}
// lang_exists(const name[]);
static cell lang_exists(AMX *amx, cell *params)
{
int len;
return g_langMngr.LangExists(get_amxstring(amx, params[1], 1, len)) ? 1 : 0;
}
AMX_NATIVE_INFO amxmod_Natives[] = { AMX_NATIVE_INFO amxmod_Natives[] = {
{ "client_cmd", client_cmd }, { "client_cmd", client_cmd },
{ "client_print", client_print }, { "client_print", client_print },
@ -2649,5 +2720,9 @@ AMX_NATIVE_INFO amxmod_Natives[] = {
{ "write_long", write_long }, { "write_long", write_long },
{ "write_short", write_short }, { "write_short", write_short },
{ "write_string", write_string }, { "write_string", write_string },
{ "get_langsnum", get_langsnum },
{ "get_lang", get_lang },
{ "register_dictionary", register_dictionary },
{ "lang_exists", lang_exists },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -55,6 +55,7 @@
#include "CCmd.h" #include "CCmd.h"
#include "CMenu.h" #include "CMenu.h"
#include "CEvent.h" #include "CEvent.h"
#include "CLang.h"
#include "fakemeta.h" #include "fakemeta.h"
#include "amxxlog.h" #include "amxxlog.h"
@ -143,6 +144,7 @@ extern EventsMngr g_events;
extern Grenades g_grenades; extern Grenades g_grenades;
extern LogEventsMngr g_logevents; extern LogEventsMngr g_logevents;
extern MenuMngr g_menucmds; extern MenuMngr g_menucmds;
extern CLangMngr g_langMngr;
extern String g_log_dir; extern String g_log_dir;
extern String g_mod_name; extern String g_mod_name;
extern TeamIds g_teamsIds; extern TeamIds g_teamsIds;

View File

@ -72,6 +72,7 @@ EventsMngr g_events;
Grenades g_grenades; Grenades g_grenades;
LogEventsMngr g_logevents; LogEventsMngr g_logevents;
MenuMngr g_menucmds; MenuMngr g_menucmds;
CLangMngr g_langMngr;
String g_log_dir; String g_log_dir;
String g_mod_name; String g_mod_name;
XVars g_xvars; XVars g_xvars;
@ -216,6 +217,9 @@ int C_Spawn( edict_t *pent ) {
// ###### Initialize task manager // ###### Initialize task manager
g_tasksMngr.registerTimers( &gpGlobals->time, &mp_timelimit->value, &g_game_timeleft ); g_tasksMngr.registerTimers( &gpGlobals->time, &mp_timelimit->value, &g_game_timeleft );
// ###### Load lang
g_langMngr.Load(build_pathname("%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxx/data")));
g_langMngr.MergeDefinitionFile(build_pathname("%s/langnames.lng", get_localinfo("amxx_datadir", "addons/amxx/data")));
// ###### Initialize commands prefixes // ###### Initialize commands prefixes
g_commands.registerPrefix( "amx" ); g_commands.registerPrefix( "amx" );
g_commands.registerPrefix( "amxx" ); g_commands.registerPrefix( "amxx" );
@ -393,6 +397,9 @@ void C_ServerActivate_Post( edict_t *pEdictList, int edictCount, int clientMax )
executeForwards(FF_PluginInit); executeForwards(FF_PluginInit);
executeForwards(FF_PluginCfg); executeForwards(FF_PluginCfg);
// ###### Save lang
g_langMngr.Save(build_pathname("%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxx/data")));
// Correct time in Counter-Strike and other mods (except DOD) // Correct time in Counter-Strike and other mods (except DOD)
if ( !g_bmod_dod) g_game_timeleft = 0; if ( !g_bmod_dod) g_game_timeleft = 0;
@ -450,7 +457,8 @@ void C_ServerDeactivate_Post() {
g_vault.clear(); g_vault.clear();
g_xvars.clear(); g_xvars.clear();
g_plugins.clear(); g_plugins.clear();
g_langMngr.Save(build_pathname("%s/languages.dat", get_localinfo("amxx_datadir", "addons/amxx/data")));
g_langMngr.Clear();
// last memreport // last memreport
#ifdef MEMORY_TEST #ifdef MEMORY_TEST
if (g_memreport_enabled) if (g_memreport_enabled)

View File

@ -55,6 +55,7 @@ const char* stristr(const char* str,const char* substr)
char* format_amxstring(AMX *amx, cell *params, int parm,int& len) char* format_amxstring(AMX *amx, cell *params, int parm,int& len)
{ {
/*
static char buffer[2][3072]; static char buffer[2][3072];
static char format[16]; static char format[16];
char *ptr,*arg; char *ptr,*arg;
@ -88,6 +89,8 @@ char* format_amxstring(AMX *amx, cell *params, int parm,int& len)
*dest=0; *dest=0;
len = dest - *buffer; len = dest - *buffer;
return *buffer; return *buffer;
*/
return g_langMngr.FormatAmxString(amx, params, parm, len);
} }
int amxstring_len(cell* a) int amxstring_len(cell* a)