| 1 | /* |
| 2 | * Copyright (C) 2014 HarpyWar ([email protected]) |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | */ |
| 18 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 19 | |
| 20 | #include <algorithm> |
| 21 | #include <cctype> |
| 22 | #include <cstdio> |
| 23 | #include <cerrno> |
| 24 | #include <cstring> |
| 25 | #include <ctime> |
| 26 | #include <cstdlib> |
| 27 | #include <sstream> |
| 28 | #include <iostream> |
| 29 | #include <fstream> |
| 30 | #include <vector> |
| 31 | #include <utility> |
| 32 | #include <map> |
| 33 | #include <string.h> |
| 34 | |
| 35 | #ifdef HAVE_SYS_STAT_Hcxx . . $ `build/config.h:21:9`! |
| 36 | # include <sys/stat.h> |
| 37 | #endif |
| 38 | |
| 39 | #include "compat/strcasecmp.h"cxx . . $ `<file>/src/compat/strcasecmp.h`/ |
| 40 | #include "compat/pdir.h"cxx . . $ `<file>/src/compat/pdir.h`/ |
| 41 | |
| 42 | #include "common/token.h"cxx . . $ `<file>/src/common/token.h`/ |
| 43 | |
| 44 | #include "common/list.h"cxx . . $ `<file>/src/common/list.h`/ |
| 45 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 46 | #include "common/xalloc.h"cxx . . $ `<file>/src/common/xalloc.h`/ |
| 47 | #include "common/xstring.h"cxx . . $ `<file>/src/common/xstring.h`/ |
| 48 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 49 | #include "common/tag.h"cxx . . $ `<file>/src/common/tag.h`/ |
| 50 | #include "common/pugixml.h"cxx . . $ `<file>/src/common/pugixml.h`/ |
| 51 | #include "common/format.h"cxx . . $ `<file>/src/common/format.h`/ |
| 52 | |
| 53 | #include "account.h"cxx . . $ `<file>/src/bnetd/account.h`/ |
| 54 | #include "connection.h"cxx . . $ `<file>/src/bnetd/connection.h`/ |
| 55 | #include "message.h"cxx . . $ `<file>/src/bnetd/message.h`/ |
| 56 | #include "helpfile.h"cxx . . $ `<file>/src/bnetd/helpfile.h`/ |
| 57 | #include "channel.h"cxx . . $ `<file>/src/bnetd/channel.h`/ |
| 58 | #include "prefs.h"cxx . . $ `<file>/src/bnetd/prefs.h`/ |
| 59 | #include "account_wrap.h"cxx . . $ `<file>/src/bnetd/account_wrap.h`/ |
| 60 | #include "command.h"cxx . . $ `<file>/src/bnetd/command.h`/ |
| 61 | #include "i18n.h"cxx . . $ `<file>/src/bnetd/i18n.h`/ |
| 62 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 63 | |
| 64 | namespace pvpgncxx . . $ pvpgn/ |
| 65 | { |
| 66 | |
| 67 | namespace bnetdcxx . . $ pvpgn/bnetd/ |
| 68 | { |
| 69 | const char * commonfilecxx . . $ pvpgn/bnetd/commonfile. = "common.xml"; // filename template, actually file name is "common-{lang}.xml" |
| 70 | |
| 71 | /* Array with string translations, each string has array with pair language=translation |
| 72 | { |
| 73 | original = { |
| 74 | { language = translate }, |
| 75 | ... |
| 76 | }, |
| 77 | ... |
| 78 | } |
| 79 | */ |
| 80 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::mapcxx . . $ std/map#<t_gamelangcxx . . $ pvpgn/t_gamelang#, stdcxx . . $ std/::stringcxx . . $ std/string#> > translationscxx . . $ pvpgn/bnetd/translations. = stdcxx . . $ std/map#map(49f6e7a06ebc5aa8).::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::mapcxx . . $ std/map#<t_gamelangcxx . . $ pvpgn/t_gamelang#, stdcxx . . $ std/::stringcxx . . $ std/string#> >(); |
| 81 | |
| 82 | const char * _find_stringcxx . . $ pvpgn/bnetd/_find_string(40ba6f3a182722ca).(char const * text, t_gamelangcxx . . $ pvpgn/t_gamelang# gamelang); |
| 83 | |
| 84 | // http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx |
| 85 | // https://www.microsoft.com/resources/msdn/goglobal/default.mspx |
| 86 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<t_languagecxx . . $ pvpgn/bnetd/t_language#> languagescxx . . $ pvpgn/bnetd/languages. = {cxx . . $ std/vector#vector(9619226211e5a241). |
| 87 | { GAMELANG_ENGLISH_UINTcxx . . $ `src/common/tag.h:164:9`!, "English", { "USA" } } /* enUS */ |
| 88 | |
| 89 | /* other countries should be loaded from common.xml of other languages */ |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | int convert_utf8_to_windows1251cxx . . $ pvpgn/bnetd/convert_utf8_to_windows1251(8cded89eb41cb9be).(const char* utf8, char* windows1251, size_t n); |
| 94 | int convert_windows1252_to_utf8cxx . . $ pvpgn/bnetd/convert_windows1252_to_utf8(1ef8e6ec083aabb9).(char * windows1252); |
| 95 | |
| 96 | |
| 97 | extern int i18n_reloadcxx . . $ pvpgn/bnetd/i18n_reload(b126dc7c1de90089).(void) |
| 98 | { |
| 99 | translationscxx . . $ pvpgn/bnetd/translations..clearcxx . . $ std/map#clear(ced63f7c635d850d).(); |
| 100 | i18n_loadcxx . . $ pvpgn/bnetd/i18n_load(b126dc7c1de90089).(); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | extern int i18n_loadcxx . . $ pvpgn/bnetd/i18n_load(b126dc7c1de90089).(void) |
| 106 | { |
| 107 | stdcxx . . $ std/::stringcxx . . $ std/string# lang_filenamecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 108 | pugicxx . . $ pugi/::xml_documentcxx . . $ pugi/xml_document# doccxx . . $ pugi/xml_document#xml_document(49f6e7a06ebc5aa8).; |
| 109 | stdcxx . . $ std/::stringcxx . . $ std/string# originalcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., translatecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 110 | |
| 111 | |
| 112 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> files = dir_getfilescxx . . $ pvpgn/dir_getfiles(aac66aa6092d8307).(prefs_get_i18ndircxx . . $ pvpgn/bnetd/prefs_get_i18ndir(33a1f659e94feb42).(), ".xml", true); |
| 113 | |
| 114 | // load common.xml from each directory |
| 115 | for (int i = 0; i < files.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++i) |
| 116 | { |
| 117 | lang_filename =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). files[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; //i18n_filename(prefs_get_localizefile(), languages[i]); |
| 118 | if (FILE *f = fopen(lang_filename.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), "r")) |
| 119 | { |
| 120 | fclose(f); |
| 121 | |
| 122 | if (!doc.load_filecxx . . $ pugi/xml_document#load_file(f7f2c4c0d31325b1).(lang_filename.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).())) |
| 123 | { |
| 124 | ERROR1cxx . . $ `src/common/eventlog.h:74:9`!("could not parse localization file \"{}\"", lang_filename); |
| 125 | continue; |
| 126 | } |
| 127 | } |
| 128 | else |
| 129 | { |
| 130 | // file not exists, ignore it |
| 131 | continue; |
| 132 | } |
| 133 | |
| 134 | // root node |
| 135 | pugicxx . . $ pugi/::xml_nodecxx . . $ pugi/xml_node# root_node = doc.childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("root"); |
| 136 | pugicxx . . $ pugi/::xml_nodecxx . . $ pugi/xml_node# meta_node = root_node.childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("meta"); |
| 137 | |
| 138 | // read language tag |
| 139 | stdcxx . . $ std/::stringcxx . . $ std/string# lang_name = meta_nodecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("language").child_valuecxx . . $ pugi/xml_node#child_value(a9f41ea0e82d88cf).(); |
| 140 | stdcxx . . $ std/::stringcxx . . $ std/string# lang_tag = meta_nodecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("language").attributecxx . . $ pugi/xml_node#attribute(760b1819de0561d9).("tag").as_stringcxx . . $ pugi/xml_attribute#as_string(865ea18671f48fc1).(); |
| 141 | t_gamelangcxx . . $ pvpgn/t_gamelang# lang_tag_uint = tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(lang_tag.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 142 | |
| 143 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> countriescxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 144 | // read all country codes for the current language |
| 145 | pugicxx . . $ pugi/::xml_nodecxx . . $ pugi/xml_node# country_nodes = root_node.childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("meta").childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("countries"); |
| 146 | for (pugicxx . . $ pugi/::xml_nodecxx . . $ pugi/xml_node# node = country_nodes.childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("country"); node; node =cxx . . $ pugi/xml_node#`operator=`(60f758adcaa60a9c). node.next_siblingcxx . . $ pugi/xml_node#next_sibling(19545ac55d8e08f4).("country")) |
| 147 | { |
| 148 | countries.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).( nodecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..child_valuecxx . . $ pugi/xml_node#child_value(a9f41ea0e82d88cf).() ); |
| 149 | } |
| 150 | |
| 151 | // if the tag not found in languages then add it |
| 152 | bool found; |
| 153 | language_find_by_tagcxx . . $ pvpgn/bnetd/language_find_by_tag(4ad94360b135822).(lang_tag_uint, found); |
| 154 | if (!found) |
| 155 | { |
| 156 | languagescxx . . $ pvpgn/bnetd/languages..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).({ lang_tag_uint, xstrdupcxx . . $ `/build/tmp.prHwK0hYwT/package/src/common/xalloc.h:49:9`!(lang_name.c_str()), countries }); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | // read xml strings to map |
| 161 | pugicxx . . $ pugi/::xml_nodecxx . . $ pugi/xml_node# item_nodes = root_node.childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("items"); |
| 162 | for (pugicxx . . $ pugi/::xml_nodecxx . . $ pugi/xml_node# node = item_nodes.childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("item"); node; node =cxx . . $ pugi/xml_node#`operator=`(60f758adcaa60a9c). node.next_siblingcxx . . $ pugi/xml_node#next_sibling(19545ac55d8e08f4).("item")) |
| 163 | { |
| 164 | original =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). node.child_valuecxx . . $ pugi/xml_node#child_value(865ea18671f48fc1).("original"); |
| 165 | if (original[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '\0') |
| 166 | continue; |
| 167 | |
| 168 | //std::map<const char *, std::map<t_gamelang, const char *> >::iterator it = translations.find(original); |
| 169 | // if not found then init |
| 170 | //if (it == translations.end()) |
| 171 | // translations[original] = std::map<t_gamelang, const char *>(); |
| 172 | |
| 173 | |
| 174 | // check if translate string has a reference to another translation |
| 175 | if (pugicxx . . $ pugi/::xml_attributecxx . . $ pugi/xml_attribute# attr = node.childcxx . . $ pugi/xml_node#child(19545ac55d8e08f4).("translate").attributecxx . . $ pugi/xml_node#attribute(760b1819de0561d9).("refid")) |
| 176 | { |
| 177 | if (pugicxx . . $ pugi/::xml_nodecxx . . $ pugi/xml_node# n = item_nodes.find_child_by_attributecxx . . $ pugi/xml_node#find_child_by_attribute(4fba0d41e7f1949c).("id", attr.valuecxx . . $ pugi/xml_attribute#value(a9f41ea0e82d88cf).())) |
| 178 | translate =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). n.child_valuecxx . . $ pugi/xml_node#child_value(865ea18671f48fc1).("translate"); |
| 179 | else |
| 180 | { |
| 181 | translate =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). original; |
| 182 | //WARN2("could not find translate reference refid=\"{}\", use original string ({})", attr.value(), lang_filename.c_str()); |
| 183 | } |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | translate =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). node.child_valuecxx . . $ pugi/xml_node#child_value(865ea18671f48fc1).("translate"); |
| 188 | if (translate[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).0] == '\0') |
| 189 | { |
| 190 | translate =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). original; |
| 191 | //WARN2("empty translate for \"{}\", use original string ({})", original.c_str(), lang_filename.c_str()); |
| 192 | } |
| 193 | } |
| 194 | translationscxx . . $ pvpgn/bnetd/translations.[cxx . . $ std/map#`operator[]`(bbd415b616967878).original][cxx . . $ std/map#`operator[]`(bbd415b616967878).lang_tag_uint] =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). translate; |
| 195 | } |
| 196 | |
| 197 | INFO1cxx . . $ `src/common/eventlog.h:84:9`!("localization file loaded \"{}\"", lang_filename); |
| 198 | } |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | extern stdcxx . . $ std/::stringcxx . . $ std/string# _localizecxx . . $ pvpgn/bnetd/_localize(50ad54f02f25b5d8).(t_connection * c, const char * func, const char * fmt, const fmtcxx . . $ fmt/::ArgListcxx . . $ fmt/ArgList# &args) |
| 204 | { |
| 205 | const char *format = fmt; |
| 206 | stdcxx . . $ std/::stringcxx . . $ std/string# outputcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).(fmt); |
| 207 | t_gamelangcxx . . $ pvpgn/t_gamelang# lang; |
| 208 | |
| 209 | if (!c) { |
| 210 | eventlogcxx . . $ pvpgn/eventlog(f1d8dd72586f1e25).(eventlog_level_errorcxx . . $ pvpgn/eventlog_level_error., __FUNCTION__, "got bad connection"); |
| 211 | return formatcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 212 | } |
| 213 | try |
| 214 | { |
| 215 | if (lang = conn_get_gamelang_localizedcxx . . $ pvpgn/bnetd/conn_get_gamelang_localized(c9be5e844f0af884).(c)) |
| 216 | if (!(format = _find_stringcxx . . $ pvpgn/bnetd/_find_string(40ba6f3a182722ca).(fmt, lang))) |
| 217 | format = fmt; // if not found use original |
| 218 | |
| 219 | output =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). fmtcxx . . $ fmt/::formatcxx . . $ fmt/format(d879789e7f34a190).(formatcxx . . $ fmt/BasicCStringRef#BasicCStringRef(88376428bb603c08)., args); |
| 220 | |
| 221 | char tmp[MAX_MESSAGE_LENcxx . . $ MAX_MESSAGE_LEN.]; |
| 222 | stdcxx . . $ std/::snprintfcxx . . $ std/snprintf(416d90c494a2998e).(tmp, sizeof tmp, "%s", output.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 223 | |
| 224 | i18n_convertcxx . . $ pvpgn/bnetd/i18n_convert(c30c6622e93e4e71).(c, tmp); |
| 225 | output =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). tmp; |
| 226 | } |
| 227 | catch (const stdcxx . . $ std/::exception& e) |
| 228 | { |
| 229 | WARN2cxx . . $ `src/common/eventlog.h:80:9`!("Can't format translation string \"{}\" ({})", fmt, e.what()); |
| 230 | } |
| 231 | |
| 232 | return outputcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | /* Find localized text for the given language */ |
| 237 | const char * _find_stringcxx . . $ pvpgn/bnetd/_find_string(40ba6f3a182722ca).(char const * text, t_gamelangcxx . . $ pvpgn/t_gamelang# gamelang) |
| 238 | { |
| 239 | stdcxx . . $ std/::mapcxx . . $ std/map#<std::string, std::map<t_gamelang, std::string> >::iteratorcxx . . $ std/map#iterator# it = translationscxx . . $ pvpgn/bnetd/translations..findcxx . . $ std/map#find(36f8d56706583706).(textcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 240 | if (it !=cxx . . $ std/`operator!=`(be6a71a859368080). translationscxx . . $ pvpgn/bnetd/translations..endcxx . . $ std/map#end(7e4de33083b6e738).()) |
| 241 | { |
| 242 | if (!it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.[cxx . . $ std/map#`operator[]`(bbd415b616967878).gamelang].emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 243 | return it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.[cxx . . $ std/map#`operator[]`(bbd415b616967878).gamelang].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(); |
| 244 | } |
| 245 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 246 | } |
| 247 | |
| 248 | /* Add a locale tag into filename |
| 249 | example: motd.txt -> motd-ruRU.txt */ |
| 250 | extern stdcxx . . $ std/::stringcxx . . $ std/string# i18n_filenamecxx . . $ pvpgn/bnetd/i18n_filename(caf975da75400ef4).(const char * filename, t_tagcxx . . $ pvpgn/t_tag# gamelang) |
| 251 | { |
| 252 | stdcxx . . $ std/::stringcxx . . $ std/string# path = fmtcxx . . $ fmt/::formatcxx . . $ fmt/format(9dfaebe7421e19ae).("{}/{}/{}"cxx . . $ fmt/BasicCStringRef#BasicCStringRef(88376428bb603c08)., prefs_get_i18ndircxx . . $ pvpgn/bnetd/prefs_get_i18ndir(33a1f659e94feb42).(), tag_uint_to_str2cxx . . $ pvpgn/tag_uint_to_str2(8297fed3afd4179b).(gamelang), filename); |
| 253 | |
| 254 | // if localized file not found |
| 255 | struct stat sfile = {}; |
| 256 | if (stat(path.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), &sfile) < 0) |
| 257 | { |
| 258 | // use default file |
| 259 | path =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). fmtcxx . . $ fmt/::formatcxx . . $ fmt/format(9dfaebe7421e19ae).("{}/{}"cxx . . $ fmt/BasicCStringRef#BasicCStringRef(88376428bb603c08)., prefs_get_i18ndircxx . . $ pvpgn/bnetd/prefs_get_i18ndir(33a1f659e94feb42).(), filename); |
| 260 | } |
| 261 | |
| 262 | return pathcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 263 | } |
| 264 | |
| 265 | |
| 266 | extern t_gamelangcxx . . $ pvpgn/t_gamelang# conn_get_gamelang_localizedcxx . . $ pvpgn/bnetd/conn_get_gamelang_localized(c9be5e844f0af884).(t_connection * c) |
| 267 | { |
| 268 | t_gamelangcxx . . $ pvpgn/t_gamelang# gamelang = conn_get_gamelangcxx . . $ pvpgn/bnetd/conn_get_gamelang(8bd2285a65940781).(c); |
| 269 | |
| 270 | // force localize by user country |
| 271 | if (prefs_get_localize_by_countrycxx . . $ pvpgn/bnetd/prefs_get_localize_by_country(db52760e79bf9054).()) |
| 272 | if (const char * country = conn_get_countrycxx . . $ pvpgn/bnetd/conn_get_country(c99dbccf638f5c6).(c)) |
| 273 | gamelang = gamelang_get_by_countrycxx . . $ pvpgn/bnetd/gamelang_get_by_country(c61c63047ce273de).(country); |
| 274 | |
| 275 | // if user set own language |
| 276 | if (t_accountcxx . . $ pvpgn/bnetd/t_account# * a = conn_get_accountcxx . . $ pvpgn/bnetd/conn_get_account(8df8b24b7c17a7f3).(c)) |
| 277 | if (const char * l = account_get_userlangcxx . . $ pvpgn/bnetd/account_get_userlang(4b37305d4a4563d0).(a)) |
| 278 | gamelang = tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(l); |
| 279 | |
| 280 | // FIXME: Russian text displays not correctly directly in game in non-russian Starcraft |
| 281 | // but most Russians use English Starcraft. |
| 282 | // Instead of next hack we can add "if (conn_get_game(c) {}" in i18n_convert() and return transliterated text |
| 283 | // |
| 284 | // Return English text in game for Russian |
| 285 | if (t_clienttagcxx . . $ pvpgn/t_clienttag# clienttag = conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(c)) |
| 286 | if (gamelang == GAMELANG_RUSSIAN_UINTcxx . . $ `src/common/tag.h:173:9`! && conn_get_gamecxx . . $ pvpgn/bnetd/conn_get_game(692151a8f99bc3ef).(c) && |
| 287 | (clienttag == CLIENTTAG_STARCRAFT_UINTcxx . . $ `src/common/tag.h:87:9`! || clienttag == CLIENTTAG_BROODWARS_UINTcxx . . $ `src/common/tag.h:89:9`! || clienttag == CLIENTTAG_STARJAPAN_UINTcxx . . $ `src/common/tag.h:101:9`! || clienttag == CLIENTTAG_SHAREWARE_UINTcxx . . $ `src/common/tag.h:91:9`! || |
| 288 | clienttag == CLIENTTAG_DIABLORTL_UINTcxx . . $ `src/common/tag.h:93:9`! || clienttag == CLIENTTAG_DIABLOSHR_UINTcxx . . $ `src/common/tag.h:95:9`! || clienttag == CLIENTTAG_WARCIIBNE_UINTcxx . . $ `src/common/tag.h:97:9`!)) |
| 289 | { |
| 290 | gamelang = GAMELANG_ENGLISH_UINTcxx . . $ `src/common/tag.h:164:9`!; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | return gamelang; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /* Set custom user language (command) */ |
| 299 | extern int handle_language_commandcxx . . $ pvpgn/bnetd/handle_language_command(2e9022cda97b266d).(t_connection * c, char const *text) |
| 300 | { |
| 301 | // split command args |
| 302 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> args = split_commandcxx . . $ pvpgn/bnetd/split_command(36641c1b5e9c088b).(text, 3); |
| 303 | if (args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 304 | { |
| 305 | // display command help |
| 306 | describe_commandcxx . . $ pvpgn/bnetd/describe_command(2e9022cda97b266d).(c, args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 307 | |
| 308 | |
| 309 | stdcxx . . $ std/::stringcxx . . $ std/string# out = " "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 310 | stdcxx . . $ std/::stringcxx . . $ std/string# lang_strcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 311 | // display available language list |
| 312 | for (int i = 0; i < languagescxx . . $ pvpgn/bnetd/languages..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) |
| 313 | { |
| 314 | lang_str =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). tag_uint_to_str2cxx . . $ pvpgn/tag_uint_to_str2(8297fed3afd4179b).(languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i].gamelangcxx . . $ pvpgn/bnetd/$anonymous_type_e9cf31f8eef22f11_0#gamelang.); |
| 315 | |
| 316 | // select with brackets current user language |
| 317 | if (languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i].gamelangcxx . . $ pvpgn/bnetd/$anonymous_type_e9cf31f8eef22f11_0#gamelang. == conn_get_gamelang_localizedcxx . . $ pvpgn/bnetd/conn_get_gamelang_localized(c9be5e844f0af884).(c)) |
| 318 | out +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). "[" +cxx . . $ std/operator+(42c652dfebe55ad7). lang_str +cxx . . $ std/operator+(900ec9581c410ad9). "]"; |
| 319 | else |
| 320 | out +=cxx . . $ std/__cxx11/basic_string#`operator+=`(c0b47be1fddc0e75). lang_str; |
| 321 | if (i < languagescxx . . $ pvpgn/bnetd/languages..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() - 1) |
| 322 | out +=cxx . . $ std/__cxx11/basic_string#`operator+=`(978ca1133b5f6e74). ", "; |
| 323 | } |
| 324 | message_send_textcxx . . $ pvpgn/bnetd/message_send_text(61daf7e3ba1862c4).(c, message_type_info, c, out.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 325 | |
| 326 | return -1; |
| 327 | } |
| 328 | |
| 329 | const char * userlang = args[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(); |
| 330 | |
| 331 | // validate given language |
| 332 | bool found; |
| 333 | t_languagecxx . . $ pvpgn/bnetd/t_language# lang = language_find_by_tagcxx . . $ pvpgn/bnetd/language_find_by_tag(4ad94360b135822).(tag_str_to_uintcxx . . $ pvpgn/tag_str_to_uint(c61c63047ce273de).(userlang), found); |
| 334 | if (!found) |
| 335 | { |
| 336 | message_send_textcxx . . $ pvpgn/bnetd/message_send_text(6288036871507e5c).(c, message_type_error, c, localizecxx . . $ `src/bnetd/i18n.h:73:11`!(c, "Bad language code.")); |
| 337 | return -1; |
| 338 | } |
| 339 | |
| 340 | if (t_accountcxx . . $ pvpgn/bnetd/t_account# * account = conn_get_accountcxx . . $ pvpgn/bnetd/conn_get_account(8df8b24b7c17a7f3).(c)) |
| 341 | { |
| 342 | account_set_userlangcxx . . $ pvpgn/bnetd/account_set_userlang(6a8854b990ebab09).(account, tag_uint_to_str2cxx . . $ pvpgn/tag_uint_to_str2(8297fed3afd4179b).(lang.gamelangcxx . . $ pvpgn/bnetd/$anonymous_type_e9cf31f8eef22f11_0#gamelang.)); |
| 343 | message_send_textcxx . . $ pvpgn/bnetd/message_send_text(6288036871507e5c).(c, message_type_error, c, localizecxx . . $ `src/bnetd/i18n.h:73:11`!(c, "Set your language to {} ({})", tag_uint_to_str2(lang.gamelang), lang.name)); |
| 344 | } |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | /* |
| 351 | Return language tag by country code (for example: "USA") |
| 352 | If not found then return default language (enUS) |
| 353 | */ |
| 354 | extern t_languagecxx . . $ pvpgn/bnetd/t_language# language_find_by_countrycxx . . $ pvpgn/bnetd/language_find_by_country(720127fdcbf74daa).(const char * code, bool &found) |
| 355 | { |
| 356 | found = false; |
| 357 | if (!code || code[0] == '\0') |
| 358 | return languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]; |
| 359 | |
| 360 | for (int i = 0; i < languagescxx . . $ pvpgn/bnetd/languages..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) |
| 361 | { |
| 362 | for (int j = 0; j < languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i].countriescxx . . $ pvpgn/bnetd/$anonymous_type_e9cf31f8eef22f11_0#countries..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); j++) |
| 363 | if (strcasecmp(code, languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i].countriescxx . . $ pvpgn/bnetd/$anonymous_type_e9cf31f8eef22f11_0#countries.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).j].c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()) == 0) |
| 364 | { |
| 365 | found = true; |
| 366 | return languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; |
| 367 | } |
| 368 | } |
| 369 | return languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]; // default |
| 370 | } |
| 371 | /* |
| 372 | Return language tag by gamelang |
| 373 | If not found then return default language (enUS) |
| 374 | */ |
| 375 | extern t_languagecxx . . $ pvpgn/bnetd/t_language# language_find_by_tagcxx . . $ pvpgn/bnetd/language_find_by_tag(4ad94360b135822).(t_tagcxx . . $ pvpgn/t_tag# gamelang, bool &found) |
| 376 | { |
| 377 | found = false; |
| 378 | t_languagecxx . . $ pvpgn/bnetd/t_language# lang; |
| 379 | |
| 380 | for (int i = 0; i < languagescxx . . $ pvpgn/bnetd/languages..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) |
| 381 | { |
| 382 | if (strcasecmp(tag_uint_to_str2cxx . . $ pvpgn/tag_uint_to_str2(8297fed3afd4179b).(languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i].gamelangcxx . . $ pvpgn/bnetd/$anonymous_type_e9cf31f8eef22f11_0#gamelang.).c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), tag_uint_to_str2cxx . . $ pvpgn/tag_uint_to_str2(8297fed3afd4179b).(gamelang).c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()) == 0) |
| 383 | { |
| 384 | found = true; |
| 385 | return languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; |
| 386 | } |
| 387 | } |
| 388 | return languagescxx . . $ pvpgn/bnetd/languages.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0]; |
| 389 | } |
| 390 | |
| 391 | |
| 392 | extern t_languagecxx . . $ pvpgn/bnetd/t_language# language_get_by_countrycxx . . $ pvpgn/bnetd/language_get_by_country(c0fa690ee7ce572b).(const char * code) |
| 393 | { |
| 394 | bool found; |
| 395 | return language_find_by_countrycxx . . $ pvpgn/bnetd/language_find_by_country(720127fdcbf74daa).(code, found); |
| 396 | } |
| 397 | extern t_gamelangcxx . . $ pvpgn/t_gamelang# gamelang_get_by_countrycxx . . $ pvpgn/bnetd/gamelang_get_by_country(c61c63047ce273de).(const char * code) |
| 398 | { |
| 399 | bool found; |
| 400 | return language_find_by_countrycxx . . $ pvpgn/bnetd/language_find_by_country(720127fdcbf74daa).(code, found).gamelangcxx . . $ pvpgn/bnetd/$anonymous_type_e9cf31f8eef22f11_0#gamelang.; |
| 401 | } |
| 402 | |
| 403 | extern t_languagecxx . . $ pvpgn/bnetd/t_language# language_get_by_tagcxx . . $ pvpgn/bnetd/language_get_by_tag(d4f431141f94e5b6).(t_gamelangcxx . . $ pvpgn/t_gamelang# gamelang) |
| 404 | { |
| 405 | bool found; |
| 406 | return language_find_by_tagcxx . . $ pvpgn/bnetd/language_find_by_tag(4ad94360b135822).(gamelang, found); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | /* Convert text with user native encoding */ |
| 413 | extern char * i18n_convertcxx . . $ pvpgn/bnetd/i18n_convert(c30c6622e93e4e71).(t_connection * c, char * buf) |
| 414 | { |
| 415 | t_gamelangcxx . . $ pvpgn/t_gamelang# gamelang = conn_get_gamelang_localizedcxx . . $ pvpgn/bnetd/conn_get_gamelang_localized(c9be5e844f0af884).(c); |
| 416 | t_clienttagcxx . . $ pvpgn/t_clienttag# clienttag = conn_get_clienttagcxx . . $ pvpgn/bnetd/conn_get_clienttag(8bd2285a65940781).(c); |
| 417 | |
| 418 | switch (gamelang) |
| 419 | { |
| 420 | case GAMELANG_RUSSIAN_UINTcxx . . $ `src/common/tag.h:173:9`!: |
| 421 | // All Blizzard games except Warcraft 3 |
| 422 | if (clienttag == CLIENTTAG_STARCRAFT_UINTcxx . . $ `src/common/tag.h:87:9`! || clienttag == CLIENTTAG_BROODWARS_UINTcxx . . $ `src/common/tag.h:89:9`! || clienttag == CLIENTTAG_STARJAPAN_UINTcxx . . $ `src/common/tag.h:101:9`! || clienttag == CLIENTTAG_SHAREWARE_UINTcxx . . $ `src/common/tag.h:91:9`! || |
| 423 | clienttag == CLIENTTAG_DIABLORTL_UINTcxx . . $ `src/common/tag.h:93:9`! || clienttag == CLIENTTAG_DIABLOSHR_UINTcxx . . $ `src/common/tag.h:95:9`! || clienttag == CLIENTTAG_WARCIIBNE_UINTcxx . . $ `src/common/tag.h:97:9`! || |
| 424 | clienttag == CLIENTTAG_DIABLO2DV_UINTcxx . . $ `src/common/tag.h:99:9`! || clienttag == CLIENTTAG_DIABLO2XP_UINTcxx . . $ `src/common/tag.h:105:9`!) |
| 425 | { |
| 426 | convert_utf8_to_windows1251cxx . . $ pvpgn/bnetd/convert_utf8_to_windows1251(8cded89eb41cb9be).(buf, buf, MAX_MESSAGE_LENcxx . . $ MAX_MESSAGE_LEN.); |
| 427 | } |
| 428 | // There is an additional conversion in Starcraft and Diablo 2 |
| 429 | if (clienttag == CLIENTTAG_STARCRAFT_UINTcxx . . $ `src/common/tag.h:87:9`! || clienttag == CLIENTTAG_BROODWARS_UINTcxx . . $ `src/common/tag.h:89:9`! || clienttag == CLIENTTAG_STARJAPAN_UINTcxx . . $ `src/common/tag.h:101:9`! || clienttag == CLIENTTAG_SHAREWARE_UINTcxx . . $ `src/common/tag.h:91:9`! || |
| 430 | clienttag == CLIENTTAG_DIABLO2DV_UINTcxx . . $ `src/common/tag.h:99:9`! || clienttag == CLIENTTAG_DIABLO2XP_UINTcxx . . $ `src/common/tag.h:105:9`!) |
| 431 | { |
| 432 | convert_windows1252_to_utf8cxx . . $ pvpgn/bnetd/convert_windows1252_to_utf8(1ef8e6ec083aabb9).(buf); |
| 433 | } |
| 434 | break; |
| 435 | |
| 436 | default: |
| 437 | break; |
| 438 | } |
| 439 | return buf; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | /* |
| 444 | * Text conversion for Russian text |
| 445 | */ |
| 446 | #ifndef REGION_CONVERT_RUSSIAN |
| 447 | |
| 448 | typedef struct ConvLettercxx . . $ pvpgn/bnetd/ConvLetter# |
| 449 | { |
| 450 | unsigned char win1251cxx . . $ pvpgn/bnetd/ConvLetter#win1251.; |
| 451 | int unicodecxx . . $ pvpgn/bnetd/ConvLetter#unicode.; |
| 452 | } Lettercxx . . $ pvpgn/bnetd/Letter#; |
| 453 | |
| 454 | static Lettercxx . . $ pvpgn/bnetd/Letter# g_letterscxx . . $ pvpgn/bnetd/g_letters.[] = { |
| 455 | { 0x82, 0x201A }, { 0x83, 0x0453 }, { 0x84, 0x201E }, { 0x85, 0x2026 }, |
| 456 | { 0x86, 0x2020 }, { 0x87, 0x2021 }, { 0x88, 0x20AC }, { 0x89, 0x2030 }, |
| 457 | { 0x8A, 0x0409 }, { 0x8B, 0x2039 }, { 0x8C, 0x040A }, { 0x8D, 0x040C }, |
| 458 | { 0x8E, 0x040B }, { 0x8F, 0x040F }, { 0x90, 0x0452 }, { 0x91, 0x2018 }, |
| 459 | { 0x92, 0x2019 }, { 0x93, 0x201C }, { 0x94, 0x201D }, { 0x95, 0x2022 }, |
| 460 | { 0x96, 0x2013 }, { 0x97, 0x2014 }, { 0x99, 0x2122 }, { 0x9A, 0x0459 }, |
| 461 | { 0x9B, 0x203A }, { 0x9C, 0x045A }, { 0x9D, 0x045C }, { 0x9E, 0x045B }, |
| 462 | { 0x9F, 0x045F }, { 0xA0, 0x00A0 }, { 0xA1, 0x040E }, { 0xA2, 0x045E }, |
| 463 | { 0xA3, 0x0408 }, { 0xA4, 0x00A4 }, { 0xA5, 0x0490 }, { 0xA6, 0x00A6 }, |
| 464 | { 0xA7, 0x00A7 }, { 0xA8, 0x0401 }, { 0xA9, 0x00A9 }, { 0xAA, 0x0404 }, |
| 465 | { 0xAB, 0x00AB }, { 0xAC, 0x00AC }, { 0xAD, 0x00AD }, { 0xAE, 0x00AE }, |
| 466 | { 0xAF, 0x0407 }, { 0xB0, 0x00B0 }, { 0xB1, 0x00B1 }, { 0xB2, 0x0406 }, |
| 467 | { 0xB3, 0x0456 }, { 0xB4, 0x0491 }, { 0xB5, 0x00B5 }, { 0xB6, 0x00B6 }, |
| 468 | { 0xB7, 0x00B7 }, { 0xB8, 0x0451 }, { 0xB9, 0x2116 }, { 0xBA, 0x0454 }, |
| 469 | { 0xBB, 0x00BB }, { 0xBC, 0x0458 }, { 0xBD, 0x0405 }, { 0xBE, 0x0455 }, |
| 470 | { 0xBF, 0x0457 } |
| 471 | }; |
| 472 | |
| 473 | // https://code.google.com/p/convert-utf8-to-cp1251/ |
| 474 | int convert_utf8_to_windows1251cxx . . $ pvpgn/bnetd/convert_utf8_to_windows1251(8cded89eb41cb9be).(const char* utf8, char* windows1251, size_t n) |
| 475 | { |
| 476 | int i = 0; |
| 477 | int j = 0; |
| 478 | for (; i < (int)n && utf8[i] != 0; ++i) { |
| 479 | char prefix = utf8[i]; |
| 480 | char suffix = utf8[i + 1]; |
| 481 | if ((prefix & 0x80) == 0) { |
| 482 | windows1251[j] = (char)prefix; |
| 483 | ++j; |
| 484 | } |
| 485 | else if ((~prefix) & 0x20) { |
| 486 | int first5bit = prefix & 0x1F; |
| 487 | first5bit <<= 6; |
| 488 | int sec6bit = suffix & 0x3F; |
| 489 | int unicode_char = first5bit + sec6bit; |
| 490 | |
| 491 | if (unicode_char >= 0x410 && unicode_char <= 0x44F) { |
| 492 | windows1251[j] = (char)(unicode_char - 0x350); |
| 493 | } |
| 494 | else if (unicode_char >= 0x80 && unicode_char <= 0xFF) { |
| 495 | windows1251[j] = (char)(unicode_char); |
| 496 | } |
| 497 | else if (unicode_char >= 0x402 && unicode_char <= 0x403) { |
| 498 | windows1251[j] = (char)(unicode_char - 0x382); |
| 499 | } |
| 500 | else { |
| 501 | int count = sizeof(g_letterscxx . . $ pvpgn/bnetd/g_letters.) / sizeof(Lettercxx . . $ pvpgn/bnetd/Letter#); |
| 502 | for (int k = 0; k < count; ++k) { |
| 503 | if (unicode_char == g_letterscxx . . $ pvpgn/bnetd/g_letters.[k].unicodecxx . . $ pvpgn/bnetd/ConvLetter#unicode.) { |
| 504 | windows1251[j] = g_letterscxx . . $ pvpgn/bnetd/g_letters.[k].win1251cxx . . $ pvpgn/bnetd/ConvLetter#win1251.; |
| 505 | goto NEXT_LETTER; |
| 506 | } |
| 507 | } |
| 508 | // can't convert this char |
| 509 | return 0; |
| 510 | } |
| 511 | NEXT_LETTER: |
| 512 | ++i; |
| 513 | ++j; |
| 514 | } |
| 515 | else { |
| 516 | // can't convert this chars |
| 517 | return 0; |
| 518 | } |
| 519 | } |
| 520 | windows1251[j] = 0; |
| 521 | return 1; |
| 522 | } |
| 523 | |
| 524 | int convert_windows1252_to_utf8cxx . . $ pvpgn/bnetd/convert_windows1252_to_utf8(1ef8e6ec083aabb9).(char * windows1252) |
| 525 | { |
| 526 | int i = 0, j = 0; |
| 527 | unsigned char c, temp[512]; |
| 528 | |
| 529 | while (windows1252[i] != 0) |
| 530 | { |
| 531 | c = windows1252[i]; |
| 532 | |
| 533 | if (c < 128) |
| 534 | { |
| 535 | temp[j] = c; |
| 536 | j++; |
| 537 | } |
| 538 | else |
| 539 | { |
| 540 | temp[j] = (c >> 6) | 192; |
| 541 | temp[j + 1] = (c & 63) | 128; |
| 542 | j += 2; |
| 543 | } |
| 544 | i++; |
| 545 | } |
| 546 | temp[j] = 0; |
| 547 | memcpy(windows1252, temp, j + 1); |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | #endif |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | } |
| 559 | } |