예제 #1
0
        internal void RunDBUpdate()
        {
            //DateTime Start = DateTime.Now;
            try
            {
                if (mRemovedItems.Count > 0 || mAddedItems.Count > 0 || InventoryPets.Count > 0)
                {

                    QueryChunk queries = new QueryChunk();

                    if (mAddedItems.Count > 0) //This should be checked more carefully
                    {
                        foreach (UserItem Item in mAddedItems.Values)
                        {
                            queries.AddQuery("UPDATE items_users SET user_id = " + UserId + " WHERE item_id = " + Item.Id);
                            //parameters.Add("extra_data" + Item.Id, Item.ExtraData);
                            //QueryBuilder.Append("UPDATE user_items SET user_id = " + UserId + " , base_item =" + Item.BaseItem + ", extra_data = @extra_data" + Item.Id + " WHERE id = " + Item.Id + "; ");
                        }

                        mAddedItems.Clear();
                    }
                    if (mRemovedItems.Count > 0)
                    {
                        foreach (UInt32 ItemID in mRemovedItems.ToArray())
                        {
                            queries.AddQuery("DELETE FROM items_users WHERE item_id=" + ItemID + " AND user_id=" + UserId);
                        }

                        mRemovedItems.Clear();
                    }

                    foreach (Pet pet in InventoryPets.Values)
                    {
                        if (pet.DBState == DatabaseUpdateState.NeedsUpdate)
                        {

                            queries.AddParameter(pet.PetId + "name", pet.Name);
                            queries.AddParameter(pet.PetId + "race", pet.Race);
                            queries.AddParameter(pet.PetId + "color", pet.Color);
                            queries.AddQuery("UPDATE user_pets SET room_id = " + pet.RoomId + ", name = @" + pet.PetId + "name, race = @" + pet.PetId + "race, color = @" + pet.PetId + "color, type = " + pet.Type + ", expirience = " + pet.Expirience + ", " +
                                "energy = " + pet.Energy + ", nutrition = " + pet.Nutrition + ", respect = " + pet.Respect + ", createstamp = '" + pet.CreationStamp + "', x = " + pet.X + ", Y = " + pet.Y + ", Z = " + pet.Z + " WHERE id = " + pet.PetId);
                        }
                        pet.DBState = DatabaseUpdateState.Updated;
                    }

                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        queries.Execute(dbClient);
                    }
                }
            }
            catch (Exception e)
            {
                Logging.LogCacheError("FATAL ERROR DURING USER INVENTORY DB UPDATE: " + e.ToString());
            }
        }
예제 #2
0
        internal void RunDBUpdate()
        {
            //DateTime Start = DateTime.Now;
            try
            {
                if (mRemovedItems.Count > 0 || mAddedItems.Count > 0 || InventoryPets.Count > 0)
                {

                    QueryChunk queries = new QueryChunk();

                    if (mAddedItems.Count > 0)
                    {
                        foreach (UserItem Item in mAddedItems.Values)
                        {
                            queries.AddQuery("UPDATE items_users SET user_id = " + UserId + " WHERE item_id = " + Item.itemID);
                        }

                        mAddedItems.Clear();
                    }
                    if (mRemovedItems.Count > 0)
                    {
                        foreach (UInt32 ItemID in mRemovedItems.ToArray())
                        {
                            queries.AddQuery("DELETE FROM items_users WHERE item_id=" + ItemID + " AND user_id=" + UserId);
                        }

                        mRemovedItems.Clear();
                    }
                    lock (InventoryPets)
                    {
                        foreach (Pet pet in InventoryPets.Values)
                        {
                            if (pet.databaseState == DatabaseUpdateState.PendingUpdate)
                            {

                                queries.AddParameter(pet.petID + "name", pet.name);
                                queries.AddParameter(pet.petID + "race", pet.race);
                                queries.AddParameter(pet.petID + "color", pet.color);
                                queries.AddQuery("UPDATE user_pets SET room_id = " + pet.roomID + ", name = @" + pet.petID + "name, race = @" + pet.petID + "race, color = @" + pet.petID + "color, type = " + pet.petType + ", expirience = " + pet.experience + ", " +
                                    "energy = " + pet.energy + ", nutrition = " + pet.nutrition + ", respect = " + pet.respect + ", createstamp = '" + pet.creationStamp + "', x = " + pet.X + ", Y = " + pet.Y + ", Z = " + pet.Z + " WHERE id = " + pet.petID);
                            }
                            pet.databaseState = DatabaseUpdateState.Syncronized;
                        }
                    }

                    using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        queries.Execute(dbClient);
                    }
                }
            }
            catch (Exception e)
            {
                Logging.LogCacheError("FATAL ERROR DURING USER INVENTORY DB UPDATE: " + e.ToString());
            }
        }
예제 #3
0
파일: Navigator.cs 프로젝트: BjkGkh/R106
        internal ServerMessage SerializeNavigator(GameClient session, int mode)
        {
            if (mode > -1)
                return SerializeActiveRooms(mode);

            ServerMessage reply = PacketHandelingManager.GetRecycledItem(OutputCode.GuestRoomSearchResultEvent);

            switch (mode)
            {
                case -5:
                    {
                        reply.AddInt32(mode);

                        List<RoomData> activeFriends = session.GetHabboDataContainer().GetChatMessenger().GetActiveFriendsRooms().OrderByDescending(p => p.UsersNow).ToList();
                        SerializeNavigatorRooms(ref reply, activeFriends);

                        return reply;
                    }
                case -4:
                    {
                        reply.AddInt32(mode);

                        List<string> FriendsNames = session.GetHabboDataContainer().GetChatMessenger().GetFriendUsernames().ToList();

                        if (FriendsNames.Count == 0)
                        {
                            SerializeNavigatorRooms(ref reply, new List<RoomData>());

                            return reply;
                        }

                        QueryChunk Query = new QueryChunk("SELECT rooms.*, room_active.active_users FROM rooms LEFT JOIN room_active ON (room_active.roomid = rooms.id) WHERE");

                        int i = 0;
                        foreach (string Name in FriendsNames)
                        {
                            if (i > 0)
                                Query.AddSpecialRawQuery(" OR");

                            Query.AddSpecialRawQuery(" owner = '" + ButterflyEnvironment.FilterInjectionChars(Name, true) + "'");

                            i++;
                        }

                        Query.AddQuery(" ORDER BY room_active.active_users DESC LIMIT 40;");

                        using (IQueryAdapter dbClient = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            Query.Execute(dbClient);
                            DataTable dTable = dbClient.getTable();

                            List<RoomData> parsedRoomData = new List<RoomData>();

                            foreach (DataRow dRow in dTable.Rows)
                            {
                                RoomData data = new RoomData();
                                data.Fill(dRow);

                                bool any = false;

                                foreach (RoomData p in parsedRoomData)
                                {
                                    if (p.Id == data.Id)
                                    {
                                        any = true;
                                        break;
                                    }

                                    if (p.Name == data.Name)
                                    {
                                        any = true;
                                        break;
                                    }
                                }

                                if (any)
                                    continue;

                                parsedRoomData.Add(data);
                            }

                            SerializeNavigatorRooms(ref reply, parsedRoomData);

                            Query.Dispose();
                        }

                        FriendsNames = null;

                        return reply;
                    }

                case -3:
                    {
                        reply.AddInt32(mode);

                        SerializeNavigatorRooms(ref reply, session.GetHabbo().UsersRooms);

                        return reply;
                    }

                case -2:
                    {
                        reply.AddInt32(mode);

                        int count = 0;
                        ISortable<RoomData>[] rooms = ButterflyEnvironment.GetGame().GetRoomManager().GetActiveRooms(out count);

                        SerializeNavigatorRooms(reply, rooms, count);

                        rooms = null;

                        return reply;
                    }

                case -1:
                    {
                        reply.AddInt32(mode);

                        int count = 0;
                        ISortable<RoomData>[] rooms = ButterflyEnvironment.GetGame().GetRoomManager().GetActiveRooms(out count);

                        SerializeNavigatorRooms(reply, rooms, count);

                        rooms = null;

                        return reply;
                    }
            }

            return reply;
        }
예제 #4
0
        internal void SaveFurniture(IQueryAdapter dbClient)
        {
			//if (dbClient.dbType == Database_Manager.Database.DatabaseType.MSSQL)
			//{
			//	SaveFurnitureToMSSQL(dbClient);
			//	return;
			//}

            try
            {
                if (mAddedItems.Count > 0 || mRemovedItems.Count > 0 || mMovedItems.Count > 0 || room.GetRoomUserManager().PetCount > 0)
                {
                    QueryChunk standardQueries = new QueryChunk();
                    QueryChunk itemInserts = new QueryChunk("REPLACE INTO items_rooms (item_id,room_id,x,y,n) VALUES ");
                    QueryChunk extradataInserts = new QueryChunk("REPLACE INTO items_extradata (item_id,data) VALUES ");

                    foreach (RoomItem Item in mRemovedItems.Values)
                    {
                        standardQueries.AddQuery("DELETE FROM items_rooms WHERE item_id = " + Item.Id + " AND room_id = " + room.RoomId); //Do join + function
                    }

                    if (mAddedItems.Count > 0)
                    {
                        foreach (RoomItem Item in mAddedItems.Values)
                        {
                            if (!string.IsNullOrEmpty(Item.ExtraData))
                            {
                                extradataInserts.AddQuery("(" + Item.Id + ",@data_id" + Item.Id + ")");
                                extradataInserts.AddParameter("@data_id" + Item.Id, Item.ExtraData);
                            }

                            if (Item.IsFloorItem)
                            {
								double combinedCoords = TextHandling.CombineDBVal(Item.GetX, Item.GetY);
                                itemInserts.AddQuery("(" + Item.Id + "," + Item.RoomId + "," + TextHandling.GetString(combinedCoords) + "," + TextHandling.GetString(Item.GetZ) + "," + Item.Rot + ")");
                            }
                            else
                            {
                                itemInserts.AddQuery("(" + Item.Id + "," + Item.RoomId + "," + TextHandling.GetString(Item.wallCoord.GetXValue()) + "," + TextHandling.GetString(Item.wallCoord.GetYValue()) + "," + Item.wallCoord.n() + ")");
                            }
                        }
                    }


                    foreach (RoomItem Item in mMovedItems.Values)
                    {
                        if (!string.IsNullOrEmpty(Item.ExtraData))
                        {
                            standardQueries.AddQuery("UPDATE items_extradata SET data = @data" + Item.Id + " WHERE item_id = " + Item.Id);
                            standardQueries.AddParameter("data" + Item.Id, Item.ExtraData);
                        }

                        if (Item.IsWallItem)
                        {
                            standardQueries.AddQuery("UPDATE items_rooms SET x=" + TextHandling.GetString(Item.wallCoord.GetXValue()) + ", y=" + TextHandling.GetString(Item.wallCoord.GetYValue()) + ", n=" + Item.wallCoord.n() + " WHERE item_id = " + Item.Id);
                        }
                        else
                        {
							double combinedCoords = TextHandling.CombineDBVal(Item.GetX, Item.GetY);

                            standardQueries.AddQuery("UPDATE items_rooms SET x=" + TextHandling.GetString(combinedCoords) + ", y=" + TextHandling.GetString(Item.GetZ) + ", n=" + Item.Rot + " WHERE item_id = " + Item.Id);
                        }
                    }

                    room.GetRoomUserManager().AppendPetsUpdateString(dbClient);

                    mAddedItems.Clear();
                    mRemovedItems.Clear();
                    mMovedItems.Clear();

                    standardQueries.Execute(dbClient);
                    itemInserts.Execute(dbClient);
                    extradataInserts.Execute(dbClient);

                    standardQueries.Dispose();
                    itemInserts.Dispose();
                    extradataInserts.Dispose();

                    standardQueries = null;
                    itemInserts = null;
                    extradataInserts = null;
                }
            }
            catch (Exception e)
            {
                Logging.LogCriticalException("Error during saving furniture for room " + room.RoomId + ". Stack: " + e.ToString());
            }
        }
예제 #5
0
        internal void AppendPetsUpdateString(IQueryAdapter dbClient)
        {
            QueryChunk inserts = new QueryChunk("INSERT INTO user_pets (id,user_id,room_id,name,type,race,color,expirience,energy,createstamp,nutrition,respect,z,y,z) VALUES ");
            QueryChunk updates = new QueryChunk();

            List<uint> petsSaved = new List<uint>();
            foreach (Pet pet in GetPets())
            {
                if (petsSaved.Contains(pet.PetId))
                    continue;

                petsSaved.Add(pet.PetId);
                if (pet.DBState == DatabaseUpdateState.NeedsInsert)
                {
                    inserts.AddParameter(pet.PetId + "name", pet.Name);
                    inserts.AddParameter(pet.PetId + "race", pet.Race);
                    inserts.AddParameter(pet.PetId + "color", pet.Color);
                    inserts.AddQuery("(" + pet.PetId + "," + pet.OwnerId + "," + pet.RoomId + ",@" + pet.PetId + "name," + pet.Type + ",@" + pet.PetId + "race,@" + pet.PetId + "color,0,100,'" + pet.CreationStamp + "',0,0,0,0,0)");
                }
                else if (pet.DBState == DatabaseUpdateState.NeedsUpdate)
                {
                    updates.AddParameter(pet.PetId + "name", pet.Name);
                    updates.AddParameter(pet.PetId + "race", pet.Race);
                    updates.AddParameter(pet.PetId + "color", pet.Color);
                    updates.AddQuery("UPDATE user_pets SET room_id = " + pet.RoomId + ", name = @" + pet.PetId + "name, race = @" + pet.PetId + "race, color = @" + pet.PetId + "color, type = " + pet.Type + ", expirience = " + pet.Expirience + ", " +
                        "energy = " + pet.Energy + ", nutrition = " + pet.Nutrition + ", respect = " + pet.Respect + ", createstamp = '" + pet.CreationStamp + "', x = " + pet.X + ", Y = " + pet.Y + ", Z = " + pet.Z + " WHERE id = " + pet.PetId);
                }

                pet.DBState = DatabaseUpdateState.Updated;
            }

            inserts.Execute(dbClient);
            updates.Execute(dbClient);

            inserts.Dispose();
            updates.Dispose();

            inserts = null;
            updates = null;
        }