Исправить вывод сообщений на русском в игре - C#

Узнай цену своей работы

Формулировка задачи:

Здравствуйте.. Мне нужна помощь, для того чтобы перевести на UTF8, чтоб показывало на русском..
Листинг программы
  1. using System;
  2. private static Encoding _defaultEncoding;
  3. public static CultureInfo CultureInfo;
  4. private static Game _game;
  5. private static ConfigurationData _configuration;
  6. private static ConnectionHandling _connectionManager;
  7. private static LanguageManager _languageManager;
  8. private static SettingsManager _settingsManager;
  9. private static DatabaseManager _manager;
  10. private static RCONSocket _rcon;
  11. private static FigureDataManager _figureManager;
  12. // TODO: Get rid?
  13. public static bool Event = false;
  14. public static DateTime lastEvent;
  15. public static DateTime ServerStarted;
  16. private static readonly List<char> Allowedchars = new List<char>(new[]
  17. {
  18. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  19. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
  20. 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '.'
  21. });
  22. private static ConcurrentDictionary<int, Habbo> _usersCached = new ConcurrentDictionary<int, Habbo>();
  23. public static string SWFRevision = "";
  24. public static void Initialize()
  25. {
  26. ServerStarted = DateTime.Now;
  27. Console.ForegroundColor = ConsoleColor.DarkGreen;
  28. Console.WriteLine();
  29. Console.WriteLine(" ____ __ ________ _____ __");
  30. Console.WriteLine(@" / __ \/ /_ _______/ ____/ |/ / / / /");
  31. Console.WriteLine(" / /_/ / / / / / ___/ __/ / /|_/ / / / / ");
  32. Console.WriteLine(" / ____/ / /_/ (__ ) /___/ / / / /_/ / ");
  33. Console.WriteLine(@" /_/ /_/\__,_/____/_____/_/ /_/\____/ ");
  34. Console.ForegroundColor = ConsoleColor.Green;
  35. Console.WriteLine(" " + PrettyVersion + " <Build " + PrettyBuild + ">");
  36. Console.WriteLine(" http://PlusIndustry.com");
  37. Console.WriteLine("");
  38. Console.Title = "Loading Plus Emulator";
  39. _defaultEncoding = Encoding.UTF8;
  40. Console.WriteLine("");
  41. Console.WriteLine("");
  42. CultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
  43. try
  44. {
  45. _configuration = new ConfigurationData(Path.Combine(Application.StartupPath, @"config.ini"));
  46. var connectionString = new MySqlConnectionStringBuilder
  47. {
  48. ConnectionTimeout = 10,
  49. Database = GetConfig().data["db.name"],
  50. DefaultCommandTimeout = 30,
  51. Logging = false,
  52. MaximumPoolSize = uint.Parse(GetConfig().data["db.pool.maxsize"]),
  53. MinimumPoolSize = uint.Parse(GetConfig().data["db.pool.minsize"]),
  54. Password = GetConfig().data["db.password"],
  55. Pooling = true,
  56. Port = uint.Parse(GetConfig().data["db.port"]),
  57. Server = GetConfig().data["db.hostname"],
  58. UserID = GetConfig().data["db.username"],
  59. AllowZeroDateTime = true,
  60. ConvertZeroDateTime = true,
  61. };
  62. _manager = new DatabaseManager(connectionString.ToString());
  63. if (!_manager.IsConnected())
  64. {
  65. log.Error("Failed to connect to the specified MySQL server.");
  66. Console.ReadKey(true);
  67. Environment.Exit(1);
  68. return;
  69. }
  70. log.Info("Connected to Database!");
  71. //Reset our statistics first.
  72. using (IQueryAdapter dbClient = GetDatabaseManager().GetQueryReactor())
  73. {
  74. dbClient.RunQuery("TRUNCATE `catalog_marketplace_data`");
  75. dbClient.RunQuery("UPDATE `rooms` SET `users_now` = '0' WHERE `users_now` > '0';");
  76. dbClient.RunQuery("UPDATE `users` SET `online` = '0' WHERE `online` = '1'");
  77. dbClient.RunQuery("UPDATE `server_status` SET `users_online` = '0', `loaded_rooms` = '0'");
  78. }
  79. //Get the configuration & Game set.
  80. _languageManager = new LanguageManager();
  81. _languageManager.Init();
  82. _settingsManager = new SettingsManager();
  83. _settingsManager.Init();
  84. _figureManager = new FigureDataManager();
  85. _figureManager.Init();
  86. //Have our encryption ready.
  87. HabboEncryptionV2.Initialize(new RSAKeys());
  88. //Make sure RCON is connected before we allow clients to connect.
  89. _rcon = new RCONSocket(GetConfig().data["rcon.tcp.bindip"], int.Parse(GetConfig().data["rcon.tcp.port"]), GetConfig().data["rcon.tcp.allowedaddr"].Split(Convert.ToChar(";")));
  90. //Accept connections.
  91. _connectionManager = new ConnectionHandling(int.Parse(GetConfig().data["game.tcp.port"]), int.Parse(GetConfig().data["game.tcp.conlimit"]), int.Parse(GetConfig().data["game.tcp.conperip"]), GetConfig().data["game.tcp.enablenagles"].ToLower() == "true");
  92. _connectionManager.init();
  93. _game = new Game();
  94. _game.StartGameLoop();
  95. TimeSpan TimeUsed = DateTime.Now - ServerStarted;
  96. Console.WriteLine();
  97. log.Info("EMULATOR -> READY! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)");
  98. }
  99. catch (KeyNotFoundException e)
  100. {
  101. log.Error("Please check your configuration file - some values appear to be missing.");
  102. log.Error("Press any key to shut down ...");
  103. Console.ReadKey(true);
  104. Environment.Exit(1);
  105. return;
  106. }
  107. catch (InvalidOperationException e)
  108. {
  109. log.Error("Failed to initialize PlusEmulator: " + e.Message);
  110. log.Error("Press any key to shut down ...");
  111. Console.ReadKey(true);
  112. Environment.Exit(1);
  113. return;
  114. }
  115. catch (Exception e)
  116. {
  117. log.Error("Fatal error during startup: " + e);
  118. log.Error("Press a key to exit");
  119. Console.ReadKey();
  120. Environment.Exit(1);
  121. }
  122. }
  123. public static bool EnumToBool(string Enum)
  124. {
  125. return (Enum == "1");
  126. }
  127. public static string BoolToEnum(bool Bool)
  128. {
  129. return (Bool == true ? "1" : "0");
  130. }
  131. public static int GetRandomNumber(int Min, int Max)
  132. {
  133. return RandomNumber.GenerateNewRandom(Min, Max);
  134. }
  135. public static double GetUnixTimestamp()
  136. {
  137. TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
  138. return ts.TotalSeconds;
  139. }
  140. public static long Now()
  141. {
  142. TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
  143. double unixTime = ts.TotalMilliseconds;
  144. return (long)unixTime;
  145. }
  146. public static string FilterFigure(string figure)
  147. {
  148. foreach (char character in figure)
  149. {
  150. if (!isValid(character))
  151. return "sh-3338-93.ea-1406-62.hr-831-49.ha-3331-92.hd-180-7.ch-3334-93-1408.lg-3337-92.ca-1813-62";
  152. }
  153. return figure;
  154. }
  155. private static bool isValid(char character)
  156. {
  157. return Allowedchars.Contains(character);
  158. }
  159. public static bool IsValidAlphaNumeric(string inputStr)
  160. {
  161. inputStr = inputStr.ToLower();
  162. if (string.IsNullOrEmpty(inputStr))
  163. {
  164. return false;
  165. }
  166. for (int i = 0; i < inputStr.Length; i++)
  167. {
  168. if (!isValid(inputStr[i]))
  169. {
  170. return false;
  171. }
  172. }
  173. return true;
  174. }
  175. public static string GetUsernameById(int UserId)
  176. {
  177. string Name = "Unknown User";
  178. GameClient Client = GetGame().GetClientManager().GetClientByUserID(UserId);
  179. if (Client != null && Client.GetHabbo() != null)
  180. return Client.GetHabbo().Username;
  181. UserCache User = PlusEnvironment.GetGame().GetCacheManager().GenerateUser(UserId);
  182. if (User != null)
  183. return User.Username;
  184. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  185. {
  186. dbClient.SetQuery("SELECT `username` FROM `users` WHERE `id` = @id LIMIT 1");
  187. dbClient.AddParameter("id", UserId);
  188. Name = dbClient.GetString();
  189. }
  190. if (string.IsNullOrEmpty(Name))
  191. Name = "Unknown User";
  192. return Name;
  193. }
  194. public static Habbo GetHabboById(int UserId)
  195. {
  196. try
  197. {
  198. GameClient Client = GetGame().GetClientManager().GetClientByUserID(UserId);
  199. if (Client != null)
  200. {
  201. Habbo User = Client.GetHabbo();
  202. if (User != null && User.Id > 0)
  203. {
  204. if (_usersCached.ContainsKey(UserId))
  205. _usersCached.TryRemove(UserId, out User);
  206. return User;
  207. }
  208. }
  209. else
  210. {
  211. try
  212. {
  213. if (_usersCached.ContainsKey(UserId))
  214. return _usersCached[UserId];
  215. else
  216. {
  217. UserData data = UserDataFactory.GetUserData(UserId);
  218. if (data != null)
  219. {
  220. Habbo Generated = data.user;
  221. if (Generated != null)
  222. {
  223. Generated.InitInformation(data);
  224. _usersCached.TryAdd(UserId, Generated);
  225. return Generated;
  226. }
  227. }
  228. }
  229. }
  230. catch { return null; }
  231. }
  232. return null;
  233. }
  234. catch
  235. {
  236. return null;
  237. }
  238. }
  239. public static Habbo GetHabboByUsername(String UserName)
  240. {
  241. try
  242. {
  243. using (IQueryAdapter dbClient = GetDatabaseManager().GetQueryReactor())
  244. {
  245. dbClient.SetQuery("SELECT `id` FROM `users` WHERE `username` = @user LIMIT 1");
  246. dbClient.AddParameter("user", UserName);
  247. int id = dbClient.GetInteger();
  248. if (id > 0)
  249. return GetHabboById(Convert.ToInt32(id));
  250. }
  251. return null;
  252. }
  253. catch { return null; }
  254. }
  255.  
  256. public static void PerformShutDown()
  257. {
  258. Console.Clear();
  259. log.Info("Server shutting down...");
  260. Console.Title = "PLUS EMULATOR: SHUTTING DOWN!";
  261. PlusEnvironment.GetGame().GetClientManager().SendPacket(new BroadcastMessageAlertComposer(GetLanguageManager().TryGetValue("server.shutdown.message")));
  262. GetGame().StopGameLoop();
  263. Thread.Sleep(2500);
  264. GetConnectionManager().Destroy();//Stop listening.
  265. GetGame().GetPacketManager().UnregisterAll();//Unregister the packets.
  266. GetGame().GetPacketManager().WaitForAllToComplete();
  267. GetGame().GetClientManager().CloseAll();//Close all connections
  268. GetGame().GetRoomManager().Dispose();//Stop the game loop.
  269. using (IQueryAdapter dbClient = _manager.GetQueryReactor())
  270. {
  271. dbClient.RunQuery("TRUNCATE `catalog_marketplace_data`");
  272. dbClient.RunQuery("UPDATE `users` SET `online` = '0', `auth_ticket` = NULL");
  273. dbClient.RunQuery("UPDATE `rooms` SET `users_now` = '0' WHERE `users_now` > '0'");
  274. dbClient.RunQuery("UPDATE `server_status` SET `users_online` = '0', `loaded_rooms` = '0'");
  275. }
  276. log.Info("Plus Emulator has successfully shutdown.");
  277. Thread.Sleep(1000);
  278. Environment.Exit(0);
  279. }
  280. public static ConfigurationData GetConfig()
  281. {
  282. return _configuration;
  283. }
  284. public static Encoding GetDefaultEncoding()
  285. {
  286. return _defaultEncoding;
  287. }
  288. public static ConnectionHandling GetConnectionManager()
  289. {
  290. return _connectionManager;
  291. }
  292. public static Game GetGame()
  293. {
  294. return _game;
  295. }
  296. public static RCONSocket GetRCONSocket()
  297. {
  298. return _rcon;
  299. }
  300. public static FigureDataManager GetFigureManager()
  301. {
  302. return _figureManager;
  303. }
  304. public static DatabaseManager GetDatabaseManager()
  305. {
  306. return _manager;
  307. }
  308. public static LanguageManager GetLanguageManager()
  309. {
  310. return _languageManager;
  311. }
  312. public static SettingsManager GetSettingsManager()
  313. {
  314. return _settingsManager;
  315. }
  316. public static ICollection<Habbo> GetUsersCached()
  317. {
  318. return _usersCached.Values;
  319. }
  320. public static bool RemoveFromCache(int Id, out Habbo Data)
  321. {
  322. return _usersCached.TryRemove(Id, out Data);
  323. }
  324. }
  325. }
Я поставил на UTF-8, в игре показывается вот так: Изображение:

Решение задачи: «Исправить вывод сообщений на русском в игре»

textual
Листинг программы
  1. Encoding.Default;
  2. Encoding.GetEncoding("windows-1251");

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

9   голосов , оценка 3.778 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы