示例#1
0
        /// <summary>
        ///     Gives the coins.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="e">The <see cref="ElapsedEventArgs" /> instance containing the event data.</param>
        internal void GiveCoins(object source, ElapsedEventArgs e)
        {
            try
            {
                ICollection <GameClient> clients = Yupi.GetGame().GetClientManager().Clients.Values;

                foreach (GameClient client in clients.Where(client => client?.GetHabbo() != null))
                {
                    client.GetHabbo().Credits += (uint)ServerExtraSettings.CreditsToGive;
                    client.GetHabbo().UpdateCreditsBalance();
                    client.GetHabbo().Duckets += (uint)ServerExtraSettings.PixelsToGive;

                    if (ServerExtraSettings.DiamondsLoopEnabled && ServerExtraSettings.DiamondsVipOnly)
                    {
                        client.GetHabbo().Diamonds += client.GetHabbo().Vip || client.GetHabbo().Rank >= 6
                            ? (uint)ServerExtraSettings.DiamondsToGive
                            : (uint)ServerExtraSettings.DiamondsToGive;
                    }

                    client.GetHabbo().UpdateSeasonalCurrencyBalance();
                }
            }
            catch (Exception ex)
            {
                ServerLogManager.LogException(ex.ToString());
            }
        }
示例#2
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");
            }
        }
示例#3
0
        public override bool Execute(GameClient session, string[] pms)
        {
            GameClient user = Yupi.GetGame().GetClientManager().GetClientByUserName(pms[0]);

            if (user == null)
            {
                session.SendWhisper(Yupi.GetLanguage().GetVar("user_not_found"));
                return(true);
            }
            if (user.GetHabbo().Rank >= session.GetHabbo().Rank)
            {
                session.SendWhisper(Yupi.GetLanguage().GetVar("user_is_higher_rank"));
                return(true);
            }
            try
            {
                Yupi.GetGame()
                .GetBanManager()
                .BanUser(user, session.GetHabbo().UserName, 788922000.0, string.Join(" ", pms.Skip(2)),
                         true, false);
            }
            catch
            {
                ServerLogManager.LogException($"An error occurred when {session.GetHabbo().UserName} tried to ban {user.GetHabbo().UserName}");
            }

            return(true);
        }
示例#4
0
        public bool ExecuteWired(Interaction type, params object[] stuff)
        {
            try
            {
                if (!IsTrigger(type) || stuff == null)
                {
                    return(false);
                }

                if (type == Interaction.TriggerCollision)
                {
                    foreach (IWiredItem wiredItem in _wiredItems.Where(wiredItem => wiredItem != null && wiredItem.Type == type))
                    {
                        wiredItem.Execute(stuff);
                    }
                }
                else if (_wiredItems.Any(current => current != null && current.Type == type && current.Execute(stuff)))
                {
                    return(true);
                }
            }
            catch
            {
                ServerLogManager.LogException($"Error trying Execute Wired Furniture.");
            }

            return(false);
        }
示例#5
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.LogException(ex, "Yupi.Net.Connection.ConnectionHandler.ConnectionHandling");
     }
 }
示例#6
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.LogException(ex, "Yupi.Net.Connection.ConnectionHandler.ConnectionHandling");
     }
 }
示例#7
0
        public void OnCycle()
        {
            try
            {
                Queue queue = new Queue();
                lock (_cycleItems.SyncRoot)
                {
                    while (_cycleItems.Count > 0)
                    {
                        IWiredItem   wiredItem = (IWiredItem)_cycleItems.Dequeue();
                        IWiredCycler item      = wiredItem as IWiredCycler;

                        if (item == null)
                        {
                            continue;
                        }

                        IWiredCycler wiredCycler = item;

                        if (!wiredCycler.OnCycle())
                        {
                            if (!queue.Contains(item))
                            {
                                queue.Enqueue(item);
                            }
                        }
                    }
                }

                _cycleItems = queue;
            }
            catch (Exception e)
            {
                ServerLogManager.LogException(e, MethodBase.GetCurrentMethod());
            }
        }
示例#8
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");
            }
        }
示例#9
0
        /// <summary>
        ///     Unloads the room.
        /// </summary>
        /// <param name="room">The room.</param>
        /// <param name="reason">The reason.</param>
        internal void UnloadRoom(Room room, string reason)
        {
            if (room?.RoomData == null || room.Disposed)
            {
                return;
            }

            room.Disposed = true;

            if (Yupi.GetGame().GetNavigator().PrivateCategories.Contains(room.RoomData.Category))
            {
                ((PublicCategory)Yupi.GetGame().GetNavigator().PrivateCategories[room.RoomData.Category]).UsersNow -= room.UserCount;
            }

            room.RoomData.UsersNow = 0;
            string state = "open";

            if (room.RoomData.State == 1)
            {
                state = "locked";
            }
            else if (room.RoomData.State > 1)
            {
                state = "password";
            }

            uint roomId = room.RoomId;

            try
            {
                using (IQueryAdapter commitableQueryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                {
                    commitableQueryReactor.SetQuery(
                        "UPDATE rooms_data SET caption = @caption, description = @description, password = @password, category = " +
                        room.RoomData.Category + ", state = '" + state +
                        "', tags = @tags, users_now = '0', users_max = " +
                        room.RoomData.UsersMax + ", allow_pets = '" + Yupi.BoolToEnum(room.RoomData.AllowPets) +
                        "', allow_pets_eat = '" +
                        Yupi.BoolToEnum(room.RoomData.AllowPetsEating) + "', allow_walkthrough = '" +
                        Yupi.BoolToEnum(room.RoomData.AllowWalkThrough) +
                        "', hidewall = '" + Yupi.BoolToEnum(room.RoomData.HideWall) + "', floorthick = " +
                        room.RoomData.FloorThickness +
                        ", wallthick = " + room.RoomData.WallThickness + ", mute_settings='" + room.RoomData.WhoCanMute +
                        "', kick_settings='" + room.RoomData.WhoCanKick + "',ban_settings='" + room.RoomData.WhoCanBan +
                        "', walls_height = '" + room.RoomData.WallHeight +
                        "', chat_type = @chat_t,chat_balloon = @chat_b,chat_speed = @chat_s,chat_max_distance = @chat_m,chat_flood_protection = @chat_f, trade_state = '" +
                        room.RoomData.TradeState + "' WHERE id = " + roomId);
                    commitableQueryReactor.AddParameter("caption", room.RoomData.Name);
                    commitableQueryReactor.AddParameter("description", room.RoomData.Description);
                    commitableQueryReactor.AddParameter("password", room.RoomData.PassWord);
                    commitableQueryReactor.AddParameter("tags", string.Join(",", room.RoomData.Tags));
                    commitableQueryReactor.AddParameter("chat_t", room.RoomData.ChatType);
                    commitableQueryReactor.AddParameter("chat_b", room.RoomData.ChatBalloon);
                    commitableQueryReactor.AddParameter("chat_s", room.RoomData.ChatSpeed);
                    commitableQueryReactor.AddParameter("chat_m", room.RoomData.ChatMaxDistance);
                    commitableQueryReactor.AddParameter("chat_f", room.RoomData.ChatFloodProtection);
                    commitableQueryReactor.RunQuery();
                }
            }
            catch (Exception e)
            {
                ServerLogManager.LogException(e.ToString());
            }

            if (room.GetRoomUserManager() != null && room.GetRoomUserManager().UserList != null)
            {
                using (IQueryAdapter commitableQueryReactor = Yupi.GetDatabaseManager().GetQueryReactor())
                {
                    foreach (RoomUser current in room.GetRoomUserManager().UserList.Values.Where(current => current != null))
                    {
                        if (current.IsPet)
                        {
                            if (current.PetData == null)
                            {
                                continue;
                            }

                            commitableQueryReactor.SetQuery("UPDATE pets_data SET x=@x, y=@y, z=@z WHERE id=@id LIMIT 1");
                            commitableQueryReactor.AddParameter("x", current.X);
                            commitableQueryReactor.AddParameter("y", current.Y);
                            commitableQueryReactor.AddParameter("z", current.Z);
                            commitableQueryReactor.AddParameter("id", current.PetData.PetId);
                            commitableQueryReactor.RunQuery();

                            if (current.BotAi == null)
                            {
                                continue;
                            }

                            current.BotAi.Dispose();
                        }
                        else if (current.IsBot)
                        {
                            if (current.BotData == null)
                            {
                                continue;
                            }

                            commitableQueryReactor.SetQuery("UPDATE bots_data SET x=@x, y=@y, z=@z, name=@name, motto=@motto, look=@look, rotation=@rotation, dance=@dance WHERE id=@id LIMIT 1");
                            commitableQueryReactor.AddParameter("name", current.BotData.Name);
                            commitableQueryReactor.AddParameter("motto", current.BotData.Motto);
                            commitableQueryReactor.AddParameter("look", current.BotData.Look);
                            commitableQueryReactor.AddParameter("rotation", current.BotData.Rot);
                            commitableQueryReactor.AddParameter("dance", current.BotData.DanceId);
                            commitableQueryReactor.AddParameter("x", current.X);
                            commitableQueryReactor.AddParameter("y", current.Y);
                            commitableQueryReactor.AddParameter("z", current.Z);
                            commitableQueryReactor.AddParameter("id", current.BotData.BotId);
                            commitableQueryReactor.RunQuery();

                            current.BotAi?.Dispose();
                        }
                        else
                        {
                            if (current.GetClient() != null)
                            {
                                room.GetRoomUserManager().RemoveUserFromRoom(current.GetClient(), true, false);
                                current.GetClient().CurrentRoomUserId = -1;
                            }
                        }
                    }
                }
            }

            room.SaveRoomChatlog();

            Room junkRoom;

            LoadedRooms.TryRemove(room.RoomId, out junkRoom);

            Writer.WriteLine(string.Format("Room #{0} was unloaded, reason: " + reason, room.RoomId),
                             "Yupi.Rooms", ConsoleColor.DarkGray);

            room.Destroy();
        }
示例#10
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)
            {
                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;
                        }

                        short messageId = 0;

                        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.LogException(exception, "Yupi.Net.Packets.ServerPacketParser.HandlePacketData");
                }
            }
        }
示例#11
0
        public bool Execute(params object[] stuff)
        {
            if (!Items.Any())
            {
                return(true);
            }

            bool useExtradata, useRot, usePos;

            Dictionary <uint, string[]> itemsOriginalData;

            try
            {
                if (string.IsNullOrWhiteSpace(OtherString) || !OtherString.Contains(",") ||
                    !OtherExtraString.Contains("|"))
                {
                    return(false);
                }

                string[] booleans = OtherString.ToLower().Split(',');

                useExtradata = booleans[0] == "true";
                useRot       = booleans[1] == "true";
                usePos       = booleans[2] == "true";

                itemsOriginalData =
                    OtherExtraString.Split('/')
                    .Select(data => data.Split('|'))
                    .ToDictionary(array => uint.Parse(array[0]), array => array.Skip(1).ToArray());
            }
            catch (Exception e)
            {
                ServerLogManager.LogException(e.ToString());

                return(false);
            }

            foreach (RoomItem current in Items)
            {
                if (current == null || !itemsOriginalData.ContainsKey(current.Id))
                {
                    return(false);
                }

                string[] originalData = itemsOriginalData[current.Id];

                if (useRot)
                {
                    if (current.Rot != int.Parse(originalData[1]))
                    {
                        return(true);
                    }
                }

                if (useExtradata)
                {
                    if (current.ExtraData == string.Empty)
                    {
                        current.ExtraData = "0";
                    }

                    if (current.ExtraData != (originalData[0] == string.Empty ? "0" : originalData[0]))
                    {
                        return(true);
                    }
                }

                if (!usePos)
                {
                    continue;
                }

                string[] originalPos = originalData[2].Split(',');

                if ((current.X != int.Parse(originalPos[0])) && (current.Y != int.Parse(originalPos[1])))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#12
0
        internal override void OnChatTick()
        {
            if (GetBotData() == null || GetRoomUser() == null || GetBotData().WasPicked ||
                GetBotData().RandomSpeech == null || !GetBotData().RandomSpeech.Any())
            {
                StopTimerTick();
                return;
            }

            if (GetRoom() != null && GetRoom().MutedBots)
            {
                return;
            }

            string randomSpeech = GetBotData().GetRandomSpeech(GetBotData().MixPhrases);

            try
            {
                switch (randomSpeech)
                {
                case ":sit":
                {
                    RoomUser user = GetRoomUser();

                    if (user.RotBody % 2 != 0)
                    {
                        user.RotBody--;
                    }

                    user.Z = GetRoom().GetGameMap().SqAbsoluteHeight(user.X, user.Y);

                    if (!user.Statusses.ContainsKey("sit"))
                    {
                        user.UpdateNeeded = true;
                        user.Statusses.Add("sit", "0.55");
                    }

                    user.IsSitting = true;

                    return;
                }

                case ":stand":
                {
                    RoomUser user = GetRoomUser();

                    if (user.IsSitting)
                    {
                        user.Statusses.Remove("sit");
                        user.IsSitting    = false;
                        user.UpdateNeeded = true;
                    }
                    else if (user.IsLyingDown)
                    {
                        user.Statusses.Remove("lay");
                        user.IsLyingDown  = false;
                        user.UpdateNeeded = true;
                    }

                    return;
                }
                }

                if (GetRoom() != null)
                {
                    randomSpeech = randomSpeech.Replace("%user_count%",
                                                        GetRoom().GetRoomUserManager().GetRoomUserCount().ToString());
                    randomSpeech = randomSpeech.Replace("%item_count%",
                                                        GetRoom().GetRoomItemHandler().TotalItems.ToString());
                    randomSpeech = randomSpeech.Replace("%floor_item_count%",
                                                        GetRoom().GetRoomItemHandler().FloorItems.Keys.Count.ToString());
                    randomSpeech = randomSpeech.Replace("%wall_item_count%",
                                                        GetRoom().GetRoomItemHandler().WallItems.Keys.Count.ToString());

                    if (GetRoom().RoomData != null)
                    {
                        randomSpeech = randomSpeech.Replace("%roomname%", GetRoom().RoomData.Name);
                        randomSpeech = randomSpeech.Replace("%owner%", GetRoom().RoomData.Owner);
                    }
                }

                if (GetBotData() != null)
                {
                    randomSpeech = randomSpeech.Replace("%name%", GetBotData().Name);
                }

                GetRoomUser().Chat(null, randomSpeech, false, 0);
            }
            catch (Exception e)
            {
                ServerLogManager.LogException(e.ToString());
            }
        }