Esempio n. 1
0
        /// <summary>
        /// Handles the disconnect.
        /// </summary>
        /// <param name="socketError">The socket error.</param>
        /// <param name="exception">The exception.</param>
        private void HandleDisconnect(SocketError socketError, Exception exception)
        {
            try
            {
                if (_socket != null && _socket.Connected)
                {
                    try
                    {
                        _socket.Shutdown(SocketShutdown.Both);
                        _socket.Close();
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }

                _connected = false;
                Parser.Dispose();

                SocketConnectionCheck.FreeConnection(GetIp());

                DisconnectAction(this, exception);
            }
            catch (Exception ex)
            {
                ServerLogManager.LogException(ex.ToString());
                ServerLogManager.HandleException(ex, "Yupi.Connection.Connection.ConnectionInformation");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Closes the connection.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="exception"></param>
 private static void OnClientDisconnected(ConnectionData connection, Exception exception)
 {
     try
     {
         Yupi.GetGame().GetClientManager().DisposeConnection(connection.GetConnectionId());
     }
     catch (Exception ex)
     {
         ServerLogManager.HandleException(ex, "Yupi.Configuration.ConnectionHandling");
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Managers the connection event.
 /// </summary>
 /// <param name="connection">The connection.</param>
 private static void OnClientConnected(ConnectionData connection)
 {
     try
     {
         Yupi.GetGame().GetClientManager().CreateAndStartClient(connection.GetConnectionId(), connection);
     }
     catch (Exception ex)
     {
         ServerLogManager.HandleException(ex, "Yupi.Configuration.ConnectionHandling");
     }
 }
Esempio n. 4
0
        /// <summary>
        ///     Fills the specified row.
        /// </summary>
        /// <param name="row">The row.</param>
        internal void Fill(DataRow row)
        {
            try
            {
                Id          = (uint)row["id"];
                Name        = (string)row["caption"];
                PassWord    = (string)row["password"];
                Description = (string)row["description"];
                Type        = (string)row["roomtype"];
                Owner       = string.Empty;
                OwnerId     = (uint)row["owner"];
                RoomChat    = new ConcurrentStack <Chatlog>();
                WordFilter  = new List <string>();

                using (IQueryAdapter queryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                {
                    queryReactor.SetQuery("SELECT username FROM users WHERE id = @userId");
                    queryReactor.AddParameter("userId", OwnerId);

                    Owner = queryReactor.GetString();

                    queryReactor.SetQuery($"SELECT user_id, message, timestamp FROM users_chatlogs WHERE room_id = '{Id}' ORDER BY timestamp ASC LIMIT 150");
                    DataTable table = queryReactor.GetTable();

                    foreach (DataRow dataRow in table.Rows)
                    {
                        RoomChat.Push(new Chatlog((uint)dataRow[0], (string)dataRow[1], Yupi.UnixToDateTime(int.Parse(dataRow[2].ToString())), false));
                    }

                    queryReactor.SetQuery($"SELECT word FROM rooms_wordfilter WHERE room_id = '{Id}'");
                    DataTable tableFilter = queryReactor.GetTable();

                    foreach (DataRow dataRow in tableFilter.Rows)
                    {
                        WordFilter.Add(dataRow["word"].ToString());
                    }
                }

                string roomState = row["state"].ToString().ToLower();

                switch (roomState)
                {
                case "locked":
                    State = 1;
                    break;

                case "password":
                    State = 2;
                    break;

                default:
                    State = 0;
                    break;
                }

                ModelName = (string)row["model_name"];
                WallPaper = (string)row["wallpaper"];
                Floor     = (string)row["floor"];
                LandScape = (string)row["landscape"];
                CcTs      = (string)row["public_ccts"];

                int.TryParse(row["trade_state"].ToString(), out TradeState);
                int.TryParse(row["category"].ToString(), out Category);
                int.TryParse(row["walls_height"].ToString(), out WallHeight);
                int.TryParse(row["score"].ToString(), out Score);
                int.TryParse(row["floorthick"].ToString(), out FloorThickness);
                int.TryParse(row["wallthick"].ToString(), out WallThickness);
                int.TryParse(row["chat_type"].ToString(), out ChatType);
                int.TryParse(row["game_id"].ToString(), out GameId);
                int.TryParse(row["mute_settings"].ToString(), out WhoCanMute);
                int.TryParse(row["kick_settings"].ToString(), out WhoCanKick);
                int.TryParse(row["ban_settings"].ToString(), out WhoCanBan);

                uint.TryParse(row["users_now"].ToString(), out UsersNow);
                uint.TryParse(row["users_max"].ToString(), out UsersMax);
                uint.TryParse(row["group_id"].ToString(), out GroupId);
                uint.TryParse(row["chat_balloon"].ToString(), out ChatBalloon);
                uint.TryParse(row["chat_speed"].ToString(), out ChatSpeed);
                uint.TryParse(row["chat_max_distance"].ToString(), out ChatMaxDistance);
                uint.TryParse(row["chat_flood_protection"].ToString(), out ChatFloodProtection);

                AllowPets        = Yupi.EnumToBool(row["allow_pets"].ToString());
                AllowPetsEating  = Yupi.EnumToBool(row["allow_pets_eat"].ToString());
                AllowWalkThrough = Yupi.EnumToBool(row["allow_walkthrough"].ToString());
                HideWall         = Yupi.EnumToBool(row["hidewall"].ToString());

                AllowRightsOverride = false;

                Group             = Yupi.GetGame().GetGroupManager().GetGroup(GroupId);
                Event             = Yupi.GetGame().GetRoomEvents().GetEvent(Id);
                _model            = Yupi.GetGame().GetRoomManager().GetModel(ModelName, Id);
                CompetitionStatus = 0;

                Tags = new List <string>();

                if (row.IsNull("tags") || string.IsNullOrEmpty(row["tags"].ToString()))
                {
                    return;
                }

                foreach (string item in row["tags"].ToString().Split(','))
                {
                    Tags.Add(item);
                }
            }
            catch (Exception ex)
            {
                ServerLogManager.LogException("Exception on RoomData Loading (Fill Void): " + ex);
                ServerLogManager.HandleException(ex, "Yupi.HabboHotel.Rooms.RoomData");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Handles the packet data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="length">The length.</param>
        public void HandlePacketData(byte[] data, int length)
        {
            if (length > 0 && _currentClient != null)
            {
                short messageId = 0;

                try
                {
                    int pos;

                    for (pos = 0; pos < length;)
                    {
                        if (_currentPacketLength == -1)
                        {
                            if (length < IntSize)
                            {
                                BufferCopy(data, length);
                                break;
                            }

                            _currentPacketLength = HabboEncoding.DecodeInt32(data, ref pos);
                        }

                        if (_currentPacketLength < 2 || _currentPacketLength > 4096)
                        {
                            _currentPacketLength = -1;

                            break;
                        }

                        if (_currentPacketLength == length - pos + _bufferPos)
                        {
                            if (_bufferPos != 0)
                            {
                                BufferCopy(data, length, pos);

                                pos = 0;

                                messageId = HabboEncoding.DecodeInt16(_bufferedData, ref pos);

                                HandleMessage(messageId, _bufferedData, 2, _currentPacketLength);
                            }
                            else
                            {
                                messageId = HabboEncoding.DecodeInt16(data, ref pos);
                                HandleMessage(messageId, data, pos, _currentPacketLength);
                            }

                            pos = length;
                            _currentPacketLength = -1;
                        }
                        else
                        {
                            int remainder = length - pos - (_currentPacketLength - _bufferPos);

                            if (_bufferPos != 0)
                            {
                                int toCopy = remainder - _bufferPos;

                                BufferCopy(data, toCopy, pos);

                                int zero = 0;

                                messageId = HabboEncoding.DecodeInt16(_bufferedData, ref zero);

                                HandleMessage(messageId, _bufferedData, 2, _currentPacketLength);
                            }
                            else
                            {
                                messageId = HabboEncoding.DecodeInt16(data, ref pos);

                                HandleMessage(messageId, data, pos, _currentPacketLength);

                                // ReSharper disable once RedundantAssignment
                                pos -= 2;
                            }

                            _currentPacketLength = -1;

                            pos = length - remainder;
                        }
                    }
                }
                catch (Exception exception)
                {
                    ServerLogManager.HandleException(exception, $"packet handling ----> {messageId}");
                }
            }
        }
Esempio n. 6
0
File: PetBot.cs Progetto: sgf/Yupi
        /// <summary>
        ///     Called when [timer tick].
        /// </summary>
        internal override void OnTimerTick()
        {
            if (_speechTimer <= 0)
            {
                RoomUser roomUser = GetRoomUser();

                if (roomUser != null)
                {
                    if (roomUser.PetData.DbState != DatabaseUpdateState.NeedsInsert)
                    {
                        roomUser.PetData.DbState = DatabaseUpdateState.NeedsUpdate;
                    }

                    Random random = new Random();

                    RemovePetStatus();

                    string[] value = PetLocale.GetValue($"speech.pet{roomUser.PetData.Type}");

                    string text = value[random.Next(0, value.Length - 1)];

                    if (GetRoom() != null && !GetRoom().MutedPets)
                    {
                        roomUser.Chat(null, text, false, 0);
                    }
                    else
                    {
                        roomUser.Statusses.Add(text, ServerUserChatTextHandler.GetString(roomUser.Z));
                    }
                }

                _speechTimer = Yupi.GetRandomNumber(20, 120);
            }
            else
            {
                _speechTimer--;
            }

            if (_actionTimer <= 0 && GetRoomUser() != null)
            {
                try
                {
                    _actionTimer = GetRoomUser().FollowingOwner != null ? 2 : Yupi.GetRandomNumber(15, 40 + GetRoomUser().PetData.VirtualId);

                    RemovePetStatus();

                    _actionTimer = Yupi.GetRandomNumber(15, 40 + GetRoomUser().PetData.VirtualId);

                    if (GetRoomUser().RidingHorse != true)
                    {
                        RemovePetStatus();

                        if (GetRoomUser().FollowingOwner != null)
                        {
                            GetRoomUser().MoveTo(GetRoomUser().FollowingOwner.SquareBehind);
                        }
                        else
                        {
                            if (GetRoomUser().PetData.Type == 16)
                            {
                                return;                                   //Monsterplants can't move
                            }
                            Point nextCoord = GetRoom().GetGameMap().GetRandomValidWalkableSquare();
                            GetRoomUser().MoveTo(nextCoord.X, nextCoord.Y);
                        }
                    }

                    if (new Random().Next(2, 15) % 2 == 0)
                    {
                        if (GetRoomUser().PetData.Type == 16)
                        {
                            MoplaBreed breed = GetRoomUser().PetData.MoplaBreed;
                            GetRoomUser().PetData.Energy--;
                            GetRoomUser().AddStatus("gst", breed.LiveState == MoplaState.Dead ? "sad" : "sml");
                            GetRoomUser()
                            .PetData.MoplaBreed.OnTimerTick(GetRoomUser().PetData.LastHealth,
                                                            GetRoomUser().PetData.UntilGrown);
                        }
                        else
                        {
                            if (GetRoomUser().PetData.Energy < 30)
                            {
                                GetRoomUser().AddStatus("lay", "");
                            }
                            else
                            {
                                GetRoomUser().AddStatus("gst", "joy");
                                if (new Random().Next(1, 7) == 3)
                                {
                                    GetRoomUser().AddStatus("snf", "");
                                }
                            }
                        }
                        GetRoomUser().UpdateNeeded = true;
                    }

                    goto IL_1B5;
                }
                catch (Exception pException)
                {
                    ServerLogManager.HandleException(pException, "PetBot.OnTimerTick");

                    goto IL_1B5;
                }
            }

            _actionTimer--;

IL_1B5:

            if (_energyTimer <= 0)
            {
                RemovePetStatus();

                RoomUser roomUser2 = GetRoomUser();

                roomUser2?.PetData.PetEnergy(true);

                _energyTimer = Yupi.GetRandomNumber(30, 120);

                return;
            }

            _energyTimer--;
        }