/// <summary> /// Mies the handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="UnhandledExceptionEventArgs" /> instance containing the event data.</param> private static void ExceptionHandler(object sender, UnhandledExceptionEventArgs args) { ServerLogManager.DisablePrimaryWriting(true); Exception ex = (Exception)args.ExceptionObject; ServerLogManager.LogCriticalException($"SYSTEM CRITICAL EXCEPTION: {ex}"); }
/// <summary> /// Closes all. /// </summary> internal void CloseAll() { StringBuilder stringBuilder = new StringBuilder(); bool flag = false; Writer.WriteLine("Saving Inventary Content....", "Yupi.Boot", ConsoleColor.DarkCyan); foreach (GameClient current2 in Clients.Values.Where(current2 => current2.GetHabbo() != null)) { current2.GetHabbo().GetInventoryComponent().RunDbUpdate(); current2.GetHabbo().RunDbUpdate(Yupi.GetDatabaseManager().GetQueryReactor()); stringBuilder.Append(current2.GetHabbo().GetQueryString); flag = true; Console.ForegroundColor = ConsoleColor.DarkMagenta; } Writer.WriteLine("Inventary Content Saved!", "Yupi.Boot", ConsoleColor.DarkCyan); if (flag) { if (stringBuilder.Length > 0) { using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) queryReactor.RunFastQuery(stringBuilder.ToString()); } } try { Writer.WriteLine("Closing Connection Manager...", "Yupi.Boot", ConsoleColor.DarkMagenta); foreach (GameClient current3 in Clients.Values.Where(current3 => current3.GetConnection() != null)) { current3.GetConnection().Dispose(); Console.ForegroundColor = ConsoleColor.DarkMagenta; Writer.WriteLine("Connection Manager Closed!", "Yupi.Boot", ConsoleColor.DarkMagenta); } } catch (Exception ex) { ServerLogManager.LogCriticalException(ex.ToString()); } Clients.Clear(); Writer.WriteLine("Connections closed", "Yupi.Conn", ConsoleColor.DarkYellow); }
private static string GetRsaStringEncrypted(string message) { try { byte[] m = Encoding.Default.GetBytes(message); byte[] c = Rsa.Sign(m); return(Converter.BytesToHexString(c)); } catch { ServerLogManager.LogCriticalException( "Sorry, the Encryption Handler stopped Inesperatelly. Please Restart Emulator."); return(null); } }
public static BigInteger CalculateDiffieHellmanSharedKey(string publicKey) { try { byte[] bytes = BigInteger.Parse('0' + publicKey, NumberStyles.HexNumber).ToByteArray(); byte[] keyBytes = Rsa.Verify(bytes); string keyString = Encoding.Default.GetString(keyBytes); return(DiffieHellman.CalculateSharedKey(BigInteger.Parse(keyString))); } catch { ServerLogManager.LogCriticalException( "Sorry, the Encryption Handler stopped Inesperatelly. Please Restart Emulator."); return(0); } }
/// <summary> /// Mains the game loop. /// </summary> private void MainGameLoop() { while (GameLoopActiveExt) { ServerCpuLowPriorityWorker.Process(); try { RoomManagerCycleEnded = false; ClientManagerCycleEnded = false; _roomManager.OnCycle(); _clientManager.OnCycle(); } catch (Exception ex) { ServerLogManager.LogCriticalException($"Exception in Game Loop!: {ex}"); } Thread.Sleep(GameLoopSleepTimeExt); } }
/// <summary> /// Initializes a new instance of the <see cref="RoomModel" /> class. /// </summary> /// <param name="doorX">The door x.</param> /// <param name="doorY">The door y.</param> /// <param name="doorZ">The door z.</param> /// <param name="doorOrientation">The door orientation.</param> /// <param name="heightmap">The heightmap.</param> /// <param name="staticFurniMap">The static furni map.</param> /// <param name="clubOnly">if set to <c>true</c> [club only].</param> /// <param name="poolmap">The poolmap.</param> internal RoomModel(int doorX, int doorY, double doorZ, int doorOrientation, string heightmap, string staticFurniMap, bool clubOnly, string poolmap) { try { DoorX = doorX; DoorY = doorY; DoorZ = doorZ; DoorOrientation = doorOrientation; Heightmap = heightmap.ToLower(); StaticFurniMap = staticFurniMap; GotPublicPool = !string.IsNullOrEmpty(poolmap); heightmap = heightmap.Replace($"{Convert.ToChar(10)}", string.Empty); string[] array = heightmap.Split(Convert.ToChar(13)); MapSizeX = array[0].Length; MapSizeY = array.Length; ClubOnly = clubOnly; SqState = new SquareState[MapSizeX][]; for (int i = 0; i < MapSizeX; i++) { SqState[i] = new SquareState[MapSizeY]; } SqFloorHeight = new short[MapSizeX][]; for (int i = 0; i < MapSizeX; i++) { SqFloorHeight[i] = new short[MapSizeY]; } SqSeatRot = new byte[MapSizeX][]; for (int i = 0; i < MapSizeX; i++) { SqSeatRot[i] = new byte[MapSizeY]; } SqChar = new char[MapSizeX][]; for (int i = 0; i < MapSizeX; i++) { SqChar[i] = new char[MapSizeY]; } if (GotPublicPool) { MRoomModelfx = new byte[MapSizeX][]; for (int i = 0; i < MapSizeX; i++) { MRoomModelfx[i] = new byte[MapSizeY]; } } for (int y = 0; y < MapSizeY; y++) { string text2 = array[y].Replace($"{Convert.ToChar(13)}", string.Empty) .Replace($"{Convert.ToChar(10)}", string.Empty); for (int x = 0; x < MapSizeX; x++) { char c = 'x'; if (x < text2.Length) { c = text2[x]; } if (x == doorX && y == doorY) { SqFloorHeight[x][y] = (short)DoorZ; SqState[x][y] = SquareState.Open; if (SqFloorHeight[x][y] > 9) { SqChar[x][y] = Letters[SqFloorHeight[x][y] - 10]; } else { SqChar[x][y] = char.Parse(DoorZ.ToString(CultureInfo.InvariantCulture)); } } else { if (c.Equals('x')) { SqFloorHeight[x][y] = -1; SqState[x][y] = SquareState.Blocked; SqChar[x][y] = c; } else if (char.IsLetterOrDigit(c)) { SqFloorHeight[x][y] = char.IsDigit(c) ? short.Parse(c.ToString()) : Convert.ToInt16(Letters.IndexOf(char.ToLower(c)) + 10); SqState[x][y] = SquareState.Open; SqChar[x][y] = c; } } } } } catch (Exception e) { ServerLogManager.LogCriticalException(e.ToString()); } }
/// <summary> /// Tries the login. /// </summary> /// <param name="authTicket">The authentication ticket.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> internal bool TryLogin(string authTicket) { try { string ip = GetConnection().GetIp(); uint errorCode; UserData userData = UserDataFactory.GetUserData(authTicket, out errorCode); if (errorCode == 1 || errorCode == 2) { return(false); } Yupi.GetGame().GetClientManager().RegisterClient(this, userData.UserId, userData.User.UserName); _habbo = userData.User; userData.User.LoadData(userData); string banReason = Yupi.GetGame().GetBanManager().GetBanReason(userData.User.UserName, ip, MachineId); if (!string.IsNullOrEmpty(banReason) || userData.User.UserName == null) { SendNotifWithScroll(banReason); using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) { queryReactor.SetQuery($"SELECT ip_last FROM users WHERE id={GetHabbo().Id} LIMIT 1"); string supaString = queryReactor.GetString(); queryReactor.SetQuery($"SELECT COUNT(0) FROM users_bans_access WHERE user_id={_habbo.Id} LIMIT 1"); int integer = queryReactor.GetInteger(); if (integer > 0) { queryReactor.RunFastQuery("UPDATE users_bans_access SET attempts = attempts + 1, ip='" + supaString + "' WHERE user_id=" + GetHabbo().Id + " LIMIT 1"); } else { queryReactor.RunFastQuery("INSERT INTO users_bans_access (user_id, ip) VALUES (" + GetHabbo().Id + ", '" + supaString + "')"); } } return(false); } using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor()) queryReactor.RunFastQuery($"UPDATE users SET ip_last='{ip}' WHERE id={GetHabbo().Id}"); userData.User.Init(this, userData); QueuedServerMessage queuedServerMessage = new QueuedServerMessage(_connection); ServerMessage serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("UniqueMachineIDMessageComposer")); serverMessage.AppendString(MachineId); queuedServerMessage.AppendResponse(serverMessage); queuedServerMessage.AppendResponse(new ServerMessage(LibraryParser.OutgoingRequest("AuthenticationOKMessageComposer"))); ServerMessage serverMessage2 = new ServerMessage(LibraryParser.OutgoingRequest("HomeRoomMessageComposer")); serverMessage2.AppendInteger(_habbo.HomeRoom); serverMessage2.AppendInteger(_habbo.HomeRoom); queuedServerMessage.AppendResponse(serverMessage2); serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("MinimailCountMessageComposer")); serverMessage.AppendInteger(_habbo.MinimailUnreadMessages); queuedServerMessage.AppendResponse(serverMessage); serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("FavouriteRoomsMessageComposer")); serverMessage.AppendInteger(30); if (userData.User.FavoriteRooms == null || !userData.User.FavoriteRooms.Any()) { serverMessage.AppendInteger(0); } else { serverMessage.AppendInteger(userData.User.FavoriteRooms.Count); foreach (uint i in userData.User.FavoriteRooms) { serverMessage.AppendInteger(i); } } queuedServerMessage.AppendResponse(serverMessage); ServerMessage rightsMessage = new ServerMessage(LibraryParser.OutgoingRequest("UserClubRightsMessageComposer")); rightsMessage.AppendInteger(userData.User.GetSubscriptionManager().HasSubscription ? 2 : 0); rightsMessage.AppendInteger(userData.User.Rank); rightsMessage.AppendInteger(0); queuedServerMessage.AppendResponse(rightsMessage); serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("EnableNotificationsMessageComposer")); serverMessage.AppendBool(true); //isOpen serverMessage.AppendBool(false); queuedServerMessage.AppendResponse(serverMessage); serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("EnableTradingMessageComposer")); serverMessage.AppendBool(true); queuedServerMessage.AppendResponse(serverMessage); userData.User.UpdateCreditsBalance(); serverMessage = new ServerMessage(LibraryParser.OutgoingRequest("ActivityPointsMessageComposer")); serverMessage.AppendInteger(2); serverMessage.AppendInteger(0); serverMessage.AppendInteger(userData.User.ActivityPoints); serverMessage.AppendInteger(5); serverMessage.AppendInteger(userData.User.Diamonds); queuedServerMessage.AppendResponse(serverMessage); if (userData.User.HasFuse("fuse_mod")) { queuedServerMessage.AppendResponse(Yupi.GetGame().GetModerationTool().SerializeTool(this)); } queuedServerMessage.AppendResponse(Yupi.GetGame().GetAchievementManager().AchievementDataCached); if (!GetHabbo().NuxPassed&& ServerExtraSettings.NewUsersGiftsEnabled) { queuedServerMessage.AppendResponse(new ServerMessage(LibraryParser.OutgoingRequest("NuxSuggestFreeGiftsMessageComposer"))); } queuedServerMessage.AppendResponse(GetHabbo().GetAvatarEffectsInventoryComponent().GetPacket()); queuedServerMessage.SendResponse(); Yupi.GetGame().GetAchievementManager().TryProgressHabboClubAchievements(this); Yupi.GetGame().GetAchievementManager().TryProgressRegistrationAchievements(this); Yupi.GetGame().GetAchievementManager().TryProgressLoginAchievements(this); return(true); } catch (Exception ex) { ServerLogManager.LogCriticalException($"Bug during user login: {ex}"); } return(false); }