Esempio n. 1
0
        private HashSet <string> mRights      = new HashSet <string>(); // A collection of fuse rights in this group.
        #endregion

        #region Constructor
        /// <summary>
        /// Creates a new instance of FuseGroup and loads the group infomation from the database.
        /// </summary>
        /// <param name="ID">The numerical ID of the group.</param>
        /// <param name="Name">The name of the group.</param>
        /// <param name="dbClient">The database connection to use to.</param>
        public FuseGroup(ushort ID, string Name, DatabaseClient dbClient)
        {
            this.mName        = Name;
            this.mChildGroups = new HashSet <ushort>();;


            dbClient.ClearParams();               // Remove any previous parameters from the database connection.
            dbClient.AddParamWithValue("id", ID); // Add ID as a parameter


            DataColumn dCol = dbClient.ReadDataColumn("SELECT valueid FROM fuse_item WHERE type = 'group' AND groupid = @id"); // Get all child groups of this group.

            if (dCol != null)                                                                                                  // If any exist...
            {
                for (int i = 0; i < dCol.Table.Rows.Count; i++)                                                                // Loop through them all...
                {
                    this.mChildGroups.Add((ushort)(uint)dCol.Table.Rows[i]["valueid"]);                                        // And add each one to the collection of child groups.
                }
            }
            dCol = dbClient.ReadDataColumn("SELECT `fuse_right`.`right` AS `right` FROM `fuse_right`,`fuse_item` WHERE `fuse_item`.`type` = 'right' AND `fuse_item`.`groupid` = @id AND `fuse_item`.`valueid` = `fuse_right`.`id`"); // Get all fuse rights in this group from the database.

            if (dCol != null)                                                                                                                                                                                                        // If there is fuse rights in this group...
            {
                for (int i = 0; i < dCol.Table.Rows.Count; i++)                                                                                                                                                                      // Loop through them all...
                {
                    mRights.Add((string)dCol.Table.Rows[i]["right"]);                                                                                                                                                                // And add each one to the collection of fuse rights
                }
            }
        }
Esempio n. 2
0
        public void SaveAll()
        {
            if (this.AddedAndMovedRoomItems.Count > 0 || this.RoomItemStateUpdated.Count > 0 || this.ItemDataChanged.Count > 0)
            {
                using (DatabaseClient dbClient = Skylight.GetDatabaseManager().GetClient())
                {
                    if (this.AddedAndMovedRoomItems.Count > 0 || this.RoomItemStateUpdated.Count > 0)
                    {
                        StringBuilder  stringBuilder = new StringBuilder();
                        HashSet <uint> dublicates    = new HashSet <uint>();

                        while (this.AddedAndMovedRoomItems.TryDequeueValue(out RoomItem item))
                        {
                            if (dublicates.Add(item.ID))
                            {
                                if (item.IsWallItem) //wall items
                                {
                                    dbClient.AddParamWithValue("room_id" + item.ID, this.Room.ID);
                                    dbClient.AddParamWithValue("base_item" + item.ID, item.BaseItem.ID);
                                    dbClient.AddParamWithValue("extra_data" + item.ID, item.ExtraData);
                                    dbClient.AddParamWithValue("wall_pos" + item.ID, item.WallCoordinate.ToString());
                                    dbClient.AddParamWithValue("item_id" + item.ID, item.ID);

                                    stringBuilder.Append("UPDATE items SET room_id = @room_id" + item.ID + ", base_item = @base_item" + item.ID + ", extra_data = @extra_data" + item.ID + ", wall_pos = @wall_pos" + item.ID + " WHERE id = @item_id" + item.ID + " LIMIT 1; ");
                                }
                                else //others
                                {
                                    dbClient.AddParamWithValue("room_id" + item.ID, this.Room.ID);
                                    dbClient.AddParamWithValue("base_item" + item.ID, item.BaseItem.ID);
                                    dbClient.AddParamWithValue("extra_data" + item.ID, item.ExtraData);
                                    dbClient.AddParamWithValue("x" + item.ID, item.X);
                                    dbClient.AddParamWithValue("y" + item.ID, item.Y);
                                    dbClient.AddParamWithValue("z" + item.ID, item.Z);
                                    dbClient.AddParamWithValue("rot" + item.ID, item.Rot);
                                    dbClient.AddParamWithValue("item_id" + item.ID, item.ID);

                                    stringBuilder.Append("UPDATE items SET room_id = @room_id" + item.ID + ", base_item = @base_item" + item.ID + ", extra_data = @extra_data" + item.ID + ", x = @x" + item.ID + ", y = @y" + item.ID + ", z = @z" + item.ID + ", rot = @rot" + item.ID + ", wall_pos = '' WHERE id = @item_id" + item.ID + " LIMIT 1; ");
                                }
                            }
                        }

                        while (this.RoomItemStateUpdated.TryDequeueValue(out RoomItem item))
                        {
                            if (dublicates.Add(item.ID))
                            {
                                dbClient.AddParamWithValue("room_id" + item.ID, this.Room.ID);
                                dbClient.AddParamWithValue("base_item" + item.ID, item.BaseItem.ID);
                                dbClient.AddParamWithValue("extra_data" + item.ID, item.ExtraData);
                                dbClient.AddParamWithValue("item_id" + item.ID, item.ID);

                                stringBuilder.Append("UPDATE items SET room_id = @room_id" + item.ID + ", base_item = @base_item" + item.ID + ", extra_data = @extra_data" + item.ID + " WHERE id = @item_id" + item.ID + " LIMIT 1; ");
                            }
                        }

                        if (stringBuilder.Length > 0)
                        {
                            dbClient.ExecuteQuery(stringBuilder.ToString());
                            dbClient.ClearParams();
                        }
                    }

                    //WIRED ETC
                    if (this.ItemDataChanged.Count > 0)
                    {
                        StringBuilder  stringBuilder = new StringBuilder();
                        HashSet <uint> dublicates    = new HashSet <uint>();

                        while (this.ItemDataChanged.TryDequeueValue(out RoomItem item))
                        {
                            if (dublicates.Add(item.ID))
                            {
                                dbClient.AddParamWithValue("item_id" + item.ID, item.ID);
                                dbClient.AddParamWithValue("data" + item.ID, item.GetItemData());

                                stringBuilder.Append("INSERT INTO items_data(item_id, data) VALUES(@item_id" + item.ID + ", @data" + item.ID + ") ON DUPLICATE KEY UPDATE data = VALUES(data); ");
                            }
                        }

                        if (stringBuilder.Length > 0)
                        {
                            dbClient.ExecuteQuery(stringBuilder.ToString());
                        }
                    }
                }
            }
        }