Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using MySql.Data.MySqlClient;
  9. using Yezz.Core;
  10.  
  11. using Yezz.HabboHotel;
  12. using Yezz.HabboHotel.GameClients;
  13. using Yezz.HabboHotel.Users;
  14. using Yezz.HabboHotel.Users.UserDataManagement;
  15.  
  16. using Yezz.Net;
  17. using Yezz.Utilities;
  18. using log4net;
  19.  
  20. using System.Collections.Concurrent;
  21. using Yezz.Communication.Packets.Outgoing.Moderation;
  22. using Yezz.Communication.Encryption.Keys;
  23. using Yezz.Communication.Encryption;
  24.  
  25. using Yezz.Database.Interfaces;
  26. using Yezz.HabboHotel.Cache;
  27. using Yezz.Database;
  28. using Yezz.Communication.Packets.Outgoing.Notifications;
  29. using System.Reflection;
  30. using System.Diagnostics;
  31.  
  32. namespace Yezz
  33. {
  34. public static class YezzEnvironment
  35. {
  36. private static readonly ILog log = LogManager.GetLogger("Yezz.YezzEnvironment");
  37.  
  38. public const string PrettyVersion = "Habbo Emulator";
  39. public const string PrettyBuild = "3.8";
  40. public static string HotelName;
  41. public const string pin = "Habbo.am";
  42.  
  43. private static ConfigurationData _configuration;
  44. private static Encoding _defaultEncoding;
  45. private static ConnectionHandling _connectionManager;
  46. private static Game _game;
  47. private static DatabaseManager _manager;
  48. public static ConfigData ConfigData;
  49. public static MusSocket MusSystem;
  50. public static CultureInfo CultureInfo;
  51.  
  52. public static int hour_lastlotto = DateTime.Now.Hour;
  53. public static double lotto_end = YezzEnvironment.GetUnixTimestamp();
  54. public static bool lotto = false;
  55. public static int lottozahl = 999;
  56. public static int lottowinner = 0;
  57. public static int lotto_einsatz = 5000;
  58. public static int mylottozahl = 999;
  59.  
  60.  
  61. public static bool Event = false;
  62. public static DateTime lastEvent;
  63. public static DateTime ServerStarted;
  64.  
  65. private static readonly List<char> Allowedchars = new List<char>(new[]
  66. {
  67. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  68. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
  69. 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '.'
  70. });
  71.  
  72. private static ConcurrentDictionary<int, Habbo> _usersCached = new ConcurrentDictionary<int, Habbo>();
  73.  
  74.  
  75. public static string SWFRevision = "";
  76. public static int Quartovip;
  77. public static int Prisao;
  78. public static string source;
  79. internal static object string_5;
  80.  
  81. public static void Initialize()
  82. {
  83. string CurrentTime = DateTime.Now.ToString("HH:mm:ss" + " | ");
  84. ServerStarted = DateTime.Now;
  85. Console.BackgroundColor = ConsoleColor.White;
  86. Console.ForegroundColor = ConsoleColor.DarkBlue;
  87. Console.Clear();
  88. Console.WriteLine(@" " + @" ");
  89. Console.WriteLine(@" _ _ ____ _____ _____ _____ ____ ___ __ ");
  90. Console.WriteLine(@" | | | | / | | _ \ | _ \ / _ \ / | | _ \/ _ | ");
  91. Console.WriteLine(@" | |_| | / /| | | |_| | | |_| | | | | | / /| | | | \_/ | | ");
  92. Console.WriteLine(@" | _ | / /_| | | _ { | _ { | | | | / /_| | | | | | ");
  93. Console.WriteLine(@" | | | | / / | | | |_| | | |_| | | |_| | _ / / | | | | | | ");
  94. Console.WriteLine(@" |_| |_| /_/ |_| |_____/ |_____/ \_____/ |_| /_/ |_| |_| |_| ");
  95. Console.WriteLine(@" ");
  96. Console.WriteLine(@" " + @" Copyright by HabboAM Server 3.2 [STABLE] ");
  97. Console.WriteLine(@" " + @" © All rights reserved to their respective owners. ");
  98. Console.WriteLine(@" " + @" Credits: » @Forbi @Sledmore @Bios @Antoniocrevi @Areware @Sealife");
  99. Console.Title = "Habbo.am Emulator wird geladen...";
  100. _defaultEncoding = Encoding.Default;
  101. Console.WriteLine("");
  102. Console.WriteLine("Lotto gestartet! Nächste Ziehung um " + (hour_lastlotto + 1) + ":00 Uhr");
  103.  
  104. CultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
  105.  
  106. Console.Write("Geben Sie das Passwort ein, um den Emulator zu starten: ");
  107. string pass = Console.ReadLine();
  108.  
  109. if (pass == pin)
  110. {
  111. Console.Clear();
  112. }
  113.  
  114. else
  115. {
  116. Console.ForegroundColor = ConsoleColor.Red;
  117. Console.Title = ("Habbo Emulator - Falsches Passwort!");
  118. Console.Clear();
  119. Console.WriteLine("Das Passwort ist falsch!");
  120. Console.WriteLine(" ");
  121. Console.WriteLine("Klicken Sie auf eine beliebige Taste, um Habbo Emulator auszuschalten");
  122. Console.ReadKey();
  123. Environment.Exit(1);
  124. }
  125.  
  126.  
  127. ServerStarted = DateTime.Now;
  128. Console.BackgroundColor = ConsoleColor.White;
  129. Console.ForegroundColor = ConsoleColor.DarkBlue;
  130. Console.Clear();
  131. Console.WriteLine(@" " + @" ");
  132. Console.WriteLine(@" _ _ ____ _____ _____ _____ ____ ___ __ ");
  133. Console.WriteLine(@" | | | | / | | _ \ | _ \ / _ \ / | | _ \/ _ | ");
  134. Console.WriteLine(@" | |_| | / /| | | |_| | | |_| | | | | | / /| | | | \_/ | | ");
  135. Console.WriteLine(@" | _ | / /_| | | _ { | _ { | | | | / /_| | | | | | ");
  136. Console.WriteLine(@" | | | | / / | | | |_| | | |_| | | |_| | _ / / | | | | | | ");
  137. Console.WriteLine(@" |_| |_| /_/ |_| |_____/ |_____/ \_____/ |_| /_/ |_| |_| |_| ");
  138. Console.WriteLine(@" ");
  139. Console.WriteLine(@" " + @" Copyright by HabboAM Server 3.2 [STABLE] ");
  140. Console.WriteLine(@" " + @" © All rights reserved to their respective owners. ");
  141. Console.WriteLine(@" " + @" Credits: » @Forbi @Sledmore @Bios @Antoniocrevi @Areware @Sealife");
  142. Console.Title = "Habbo.am Emulator wird geladen...";
  143. _defaultEncoding = Encoding.Default;
  144. Console.WriteLine("");
  145. Console.WriteLine("Lotto gestartet! Nächste Ziehung um " + (hour_lastlotto + 1) + ":00 Uhr");
  146.  
  147. CultureInfo = CultureInfo.CreateSpecificCulture("en-GB");
  148.  
  149.  
  150. try
  151. {
  152.  
  153. _configuration = new ConfigurationData(Path.Combine(Application.StartupPath, @"config.ini"));
  154.  
  155. var connectionString = new MySqlConnectionStringBuilder
  156. {
  157. ConnectionTimeout = 10,
  158. Database = GetConfig().data["db.name"],
  159. DefaultCommandTimeout = 30,
  160. Logging = false,
  161. MaximumPoolSize = uint.Parse(GetConfig().data["db.pool.maxsize"]),
  162. MinimumPoolSize = uint.Parse(GetConfig().data["db.pool.minsize"]),
  163. Password = GetConfig().data["db.password"],
  164. Pooling = true,
  165. Port = uint.Parse(GetConfig().data["db.port"]),
  166. Server = GetConfig().data["db.hostname"],
  167. UserID = GetConfig().data["db.username"],
  168. AllowZeroDateTime = true,
  169. ConvertZeroDateTime = true,
  170. };
  171.  
  172. _manager = new DatabaseManager(connectionString.ToString());
  173.  
  174. if (!_manager.IsConnected())
  175. {
  176. Console.WriteLine(CurrentTime + "» Eine Verbindung zur Datenbank existiert bereits.");
  177. Console.ReadKey(true);
  178. Environment.Exit(1);
  179. return;
  180. }
  181. Console.ForegroundColor = ConsoleColor.DarkGray;
  182. Console.WriteLine(CurrentTime + "» Verbindung zur Datenbank");
  183.  
  184. HotelName = Convert.ToString(GetConfig().data["hotel.name"]);
  185.  
  186. //Reset our statistics first.
  187. using (IQueryAdapter dbClient = GetDatabaseManager().GetQueryReactor())
  188. {
  189. dbClient.RunQuery("TRUNCATE `catalog_marketplace_data`");
  190. dbClient.RunQuery("UPDATE `rooms` SET `users_now` = '0' WHERE `users_now` > '0';");
  191. dbClient.RunQuery("UPDATE `users` SET `online` = '0' WHERE `online` = '1'");
  192. dbClient.RunQuery("UPDATE `server_status` SET `users_online` = '0', `loaded_rooms` = '0'");
  193. }
  194.  
  195. //Get the configuration & Game set.
  196. ConfigData = new ConfigData();
  197. _game = new Game();
  198.  
  199. //Have our encryption ready.
  200. HabboEncryptionV2.Initialize(new RSAKeys());
  201.  
  202. //Make sure MUS is working.
  203. MusSystem = new MusSocket(GetConfig().data["mus.tcp.bindip"], int.Parse(GetConfig().data["mus.tcp.port"]), GetConfig().data["mus.tcp.allowedaddr"].Split(Convert.ToChar(";")), 0);
  204.  
  205. //Accept connections.
  206. _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");
  207. _connectionManager.init();
  208.  
  209. _game.StartGameLoop();
  210.  
  211. TimeSpan TimeUsed = DateTime.Now - ServerStarted;
  212.  
  213. Console.WriteLine();
  214.  
  215. Logging.WriteLine(">> Habbo SERVER -> Alles wurde vorbereitet, um zu spielen! (" + TimeUsed.Seconds + " s, " + TimeUsed.Milliseconds + " ms)", ConsoleColor.DarkGray);
  216. }
  217. catch (KeyNotFoundException e)
  218. {
  219. Logging.WriteLine("Please check your configuration file - some values appear to be missing.", ConsoleColor.Red);
  220. Logging.WriteLine("Press any key to shut down ...");
  221. Logging.WriteLine(e.ToString());
  222. Console.ReadKey(true);
  223. Environment.Exit(1);
  224. return;
  225. }
  226. catch (InvalidOperationException e)
  227. {
  228. Logging.WriteLine("Failed to initialize KeyEmulator: " + e.Message, ConsoleColor.Red);
  229. Logging.WriteLine("Press any key to shut down ...");
  230. Console.ReadKey(true);
  231. Environment.Exit(1);
  232. return;
  233. }
  234. catch (Exception e)
  235. {
  236. Logging.WriteLine("Fatal error during startup: " + e, ConsoleColor.Red);
  237. Logging.WriteLine("Press a key to exit");
  238.  
  239. Console.ReadKey();
  240. Environment.Exit(1);
  241. }
  242. }
  243.  
  244. public static bool EnumToBool(string Enum)
  245. {
  246. return (Enum == "1");
  247. }
  248.  
  249. public static string BoolToEnum(bool Bool)
  250. {
  251. return (Bool == true ? "1" : "0");
  252. }
  253.  
  254. public static int GetRandomNumber(int Min, int Max)
  255. {
  256. return RandomNumber.GenerateNewRandom(Min, Max);
  257. }
  258.  
  259. public static double GetUnixTimestamplotto()
  260. {
  261. return (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
  262. }
  263.  
  264.  
  265. public static double GetUnixTimestamp()
  266. {
  267. TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
  268. return ts.TotalSeconds;
  269. }
  270.  
  271. internal static int GetIUnixTimestamp()
  272. {
  273. var ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
  274. var unixTime = ts.TotalSeconds;
  275. return Convert.ToInt32(unixTime);
  276. }
  277.  
  278. private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  279.  
  280. public static long CurrentTimeMillis()
  281. {
  282. return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
  283. }
  284.  
  285. public static long Now()
  286. {
  287. TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
  288. double unixTime = ts.TotalMilliseconds;
  289. return (long)unixTime;
  290. }
  291.  
  292. public static string FilterFigure(string figure)
  293. {
  294. foreach (char character in figure)
  295. {
  296. if (!isValid(character))
  297. 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";
  298. }
  299.  
  300. return figure;
  301. }
  302.  
  303. internal static bool IsNum(string Int)
  304. {
  305. double Num;
  306. bool isNum = double.TryParse(Int, out Num);
  307. if (isNum)
  308. return true;
  309. else
  310. return false;
  311. }
  312.  
  313. private static bool isValid(char character)
  314. {
  315. return Allowedchars.Contains(character);
  316. }
  317.  
  318. public static bool IsValidAlphaNumeric(string inputStr)
  319. {
  320. inputStr = inputStr.ToLower();
  321. if (string.IsNullOrEmpty(inputStr))
  322. {
  323. return false;
  324. }
  325.  
  326. for (int i = 0; i < inputStr.Length; i++)
  327. {
  328. if (!isValid(inputStr[i]))
  329. {
  330. return false;
  331. }
  332. }
  333.  
  334. return true;
  335. }
  336.  
  337. public static string GetUsernameById(int UserId)
  338. {
  339. string Name = "Unknown User";
  340.  
  341. GameClient Client = GetGame().GetClientManager().GetClientByUserID(UserId);
  342. if (Client != null && Client.GetHabbo() != null)
  343. return Client.GetHabbo().Username;
  344.  
  345. UserCache User = YezzEnvironment.GetGame().GetCacheManager().GenerateUser(UserId);
  346. if (User != null)
  347. return User.Username;
  348.  
  349. using (IQueryAdapter dbClient = YezzEnvironment.GetDatabaseManager().GetQueryReactor())
  350. {
  351. dbClient.SetQuery("SELECT `username` FROM `users` WHERE id = @id LIMIT 1");
  352. dbClient.AddParameter("id", UserId);
  353. Name = dbClient.getString();
  354. }
  355.  
  356. if (string.IsNullOrEmpty(Name))
  357. Name = "Unknown User";
  358.  
  359. return Name;
  360. }
  361.  
  362. public static string RainbowT()
  363. {
  364. int numColorst = 1000;
  365. var colorst = new List<string>();
  366. var randomt = new Random();
  367. for (int i = 0; i < numColorst; i++)
  368. {
  369. colorst.Add(String.Format("#{0:X6}", randomt.Next(0x1000000)));
  370. }
  371.  
  372. int indext = 0;
  373. string rainbowt = colorst[indext];
  374.  
  375. if (indext > numColorst)
  376. indext = 0;
  377. else
  378. indext++;
  379.  
  380. return rainbowt;
  381. }
  382.  
  383. public static Habbo GetHabboById(int UserId)
  384. {
  385. try
  386. {
  387. GameClient Client = GetGame().GetClientManager().GetClientByUserID(UserId);
  388. if (Client != null)
  389. {
  390. Habbo User = Client.GetHabbo();
  391. if (User != null && User.Id > 0)
  392. {
  393. if (_usersCached.ContainsKey(UserId))
  394. _usersCached.TryRemove(UserId, out User);
  395. return User;
  396. }
  397. }
  398. else
  399. {
  400. try
  401. {
  402. if (_usersCached.ContainsKey(UserId))
  403. return _usersCached[UserId];
  404. else
  405. {
  406. UserData data = UserDataFactory.GetUserData(UserId);
  407. if (data != null)
  408. {
  409. Habbo Generated = data.user;
  410. if (Generated != null)
  411. {
  412. Generated.InitInformation(data);
  413. _usersCached.TryAdd(UserId, Generated);
  414. return Generated;
  415. }
  416. }
  417. }
  418. }
  419. catch { return null; }
  420. }
  421. return null;
  422. }
  423. catch
  424. {
  425. return null;
  426. }
  427. }
  428.  
  429. public static Habbo GetHabboByUsername(String UserName)
  430. {
  431. try
  432. {
  433. using (IQueryAdapter dbClient = GetDatabaseManager().GetQueryReactor())
  434. {
  435. dbClient.SetQuery("SELECT `id` FROM `users` WHERE `username` = @user LIMIT 1");
  436. dbClient.AddParameter("user", UserName);
  437. int id = dbClient.getInteger();
  438. if (id > 0)
  439. return GetHabboById(Convert.ToInt32(id));
  440. }
  441. return null;
  442. }
  443. catch { return null; }
  444. }
  445.  
  446.  
  447.  
  448. internal static void PerformShutDown()
  449. {
  450. PerformShutDown(false);
  451. }
  452.  
  453.  
  454. internal static void PerformRestart()
  455. {
  456. PerformShutDown(true);
  457. }
  458.  
  459. public static void PerformShutDown(bool restart)
  460. {
  461. Console.Clear();
  462. log.Info("Habbo EMULATOR --> Herunterfahren");
  463. Console.Title = "Habbo EMULATOR: Fährt Herunter!";
  464.  
  465. GetGame().StopGameLoop();
  466. Thread.Sleep(2500);
  467. GetConnectionManager().Destroy();//Stop listening.
  468. GetGame().GetPacketManager().UnregisterAll();//Unregister the packets.
  469. GetGame().GetPacketManager().WaitForAllToComplete();
  470. GetGame().GetClientManager().CloseAll();//Close all connections
  471. GetGame().GetRoomManager().Dispose();//Stop the game loop.
  472.  
  473. using (IQueryAdapter dbClient = _manager.GetQueryReactor())
  474. {
  475. dbClient.RunQuery("TRUNCATE `catalog_marketplace_data`");
  476. dbClient.RunQuery("UPDATE `users` SET online = '0'");
  477. dbClient.RunQuery("TRUNCATE `user_auth_ticket`");
  478. dbClient.RunQuery("UPDATE `rooms` SET `users_now` = '0' WHERE `users_now` > '0'");
  479. dbClient.RunQuery("UPDATE `server_status` SET `users_online` = '0', `loaded_rooms` = '0'");
  480. }
  481.  
  482. log.Info("Habbo session shutted down.");
  483.  
  484. if (restart) Process.Start(Assembly.GetEntryAssembly().Location);
  485. Thread.Sleep(1000);
  486. Environment.Exit(0);
  487. }
  488.  
  489. public static ConfigurationData GetConfig()
  490. {
  491. return _configuration;
  492. }
  493.  
  494. public static ConfigData GetDBConfig()
  495. {
  496. return ConfigData;
  497. }
  498.  
  499. public static Encoding GetDefaultEncoding()
  500. {
  501. return _defaultEncoding;
  502. }
  503.  
  504. public static ConnectionHandling GetConnectionManager()
  505. {
  506. return _connectionManager;
  507. }
  508.  
  509. public static Game GetGame()
  510. {
  511. return _game;
  512. }
  513.  
  514. public static DatabaseManager GetDatabaseManager()
  515. {
  516. return _manager;
  517. }
  518.  
  519. public static ICollection<Habbo> GetUsersCached()
  520. {
  521. return _usersCached.Values;
  522. }
  523.  
  524. public static bool RemoveFromCache(int Id, out Habbo Data)
  525. {
  526. return _usersCached.TryRemove(Id, out Data);
  527. }
  528. }
  529. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement