Ejemplo n.º 1
0
        /// <summary>
        /// 从buffer中解析房区信息
        /// </summary>
        /// <param name="message"></param>
        public HousingSlotSnapshot(byte[] message)
        {
            Time = DateTime.Now;

            var dataList   = message.SubArray(32, message.Length - 32);
            var dataHeader = dataList.SubArray(0, 8);

            switch (dataHeader[4])
            {
            case 0x53:
                Area = HouseArea.海雾村;
                break;

            case 0x54:
                Area = HouseArea.薰衣草苗圃;
                break;

            case 0x55:
                Area = HouseArea.高脚孤丘;
                break;

            case 0x81:
                Area = HouseArea.白银乡;
                break;
            }
            Slot = dataHeader[2];

            for (int i = 8; i < dataList.Length; i += 40)
            {
                int         houseId = (i - 8) / 40;
                HousingItem house   = new HousingItem(this, houseId, dataList.SubArray(i, 40));
                HouseList.Add(houseId, house);
            }
        }
Ejemplo n.º 2
0
 public HousingOnSaleItem(HousingItem item)
 {
     Area          = item.Area;
     Slot          = item.Slot;
     Id            = item.Id;
     Size          = item.Size;
     Price         = item.Price;
     AddTime       = DateTime.Now;
     ExistenceTime = DateTime.Now;
     CurrentStatus = true;
 }
Ejemplo n.º 3
0
 public void Update(HousingItem item)
 {
     if (item.Area == Area &&
         item.Slot == Slot &&
         item.Id == Id)
     {
         Price         = item.Price;
         ExistenceTime = DateTime.Now;
         CurrentStatus = item.IsEmpty;
     }
 }
Ejemplo n.º 4
0
        public HousingSlotSnapshotJSONObject ToJsonObject()
        {
            HousingSlotSnapshotJSONObject ret = new HousingSlotSnapshotJSONObject();

            ret.area   = HousingItem.GetHouseAreaStr(Area);
            ret.server = ServerId;
            ret.slot   = Slot;
            ret.time   = new DateTimeOffset(Time).ToUnixTimeSeconds();

            List <HousingItemJSONObject> houseListJson = new List <HousingItemJSONObject>();

            foreach (var house in HouseList.Values)
            {
                houseListJson.Add(house.ToJsonObject());
            }

            ret.houses = houseListJson.ToArray();

            return(ret);
        }
Ejemplo n.º 5
0
        void NetworkReceived(string connection, long epoch, byte[] message)
        {
            var opcode = BitConverter.ToUInt16(message, 18);

            if (opcode != 0x164 && message.Length != 2440)
            {
                return;
            }
            HousingSlotSnapshot snapshot;

            try
            {
                //解析数据包
                snapshot          = new HousingSlotSnapshot(message);
                snapshot.ServerId = GetServerId();

                /*foreach(var house in snapshot.HouseList.Values)
                 * {
                 *  Log("Debug", house.Id + ": " + house.Flags.ToString());
                 * }*/
                //存入存储
                SnapshotStorage.Insert(snapshot);
                AutoUploadSnapshot[new Tuple <HouseArea, int>(snapshot.Area, snapshot.Slot)] = snapshot;

                foreach (HousingOnSaleItem item in HousingList)
                {
                    if (item.Area == snapshot.Area && item.Slot == snapshot.Slot)
                    {
                        item.CurrentStatus = false;
                    }
                }

                HousingItem[] onSaleList = snapshot.GetOnSale();

                Monitor.Enter(this);
                foreach (var item in HousingList)
                {
                    if (item.Area == snapshot.Area && item.Slot == snapshot.Slot)
                    {
                        if (onSaleList.Where(x => x.Slot == item.Slot && x.IsEmpty)
                            .ToArray().Length == 0)
                        {
                            //空房已消失
                            item.CurrentStatus = false;
                            HousingListUpdated = true;
                            try
                            {
                                bindingSource1.ResetItem(HousingList.IndexOf(item));
                            }
                            catch (Exception ex)
                            {
                                Log("Error", ex, "刷新列表出错:");
                            }
                        }
                    }
                }

                int listIndex;
                //更新空房列表
                foreach (HousingItem house in onSaleList)
                {
                    HousingOnSaleItem onSaleItem = new HousingOnSaleItem(house);
                    Log("Info", string.Format("{0} 第{1}区 {2}号 {3}房在售 当前价格: {4}",
                                              onSaleItem.AreaStr, onSaleItem.DisplaySlot, onSaleItem.DisplayId,
                                              onSaleItem.SizeStr, onSaleItem.Price));

                    if (onSaleItem.Size == HouseSize.M || onSaleItem.Size == HouseSize.L)
                    {
                        Console.Beep(3000, 1000);
                    }

                    if ((listIndex = HousingList.IndexOf(onSaleItem)) != -1)
                    {
                        HousingList[listIndex].Update(house);
                        Log("Info", "重复土地,已更新。");
                    }
                    else
                    {
                        bindingSource1.Add(onSaleItem);
                    }
                    HousingListUpdated = true;
                }
                LastOperateTime = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds(); //更新上次操作的时间

                Log("Info", string.Format("{0} 第{1}区查询完成",
                                          HousingItem.GetHouseAreaStr(snapshot.Area),
                                          snapshot.Slot + 1)); //输出翻页日志
                Monitor.Exit(this);
            }
            catch (Exception ex)
            {
                Log("Error", ex, "查询房屋列表出错:");
                return;
            }
        }
Ejemplo n.º 6
0
        void NetworkReceived(string connection, long epoch, byte[] message)
        {
            var opcode = BitConverter.ToUInt16(message, 18);

            if (opcode != 183 /*&& message.Length != 2440*/)
            {
                return;
            }
            //Log("Debug", $"OPCODE:{opcode}");
            var    data_list   = message.SubArray(32, message.Length - 32);
            var    data_header = data_list.SubArray(0, 8);
            string area        = "";

            if (data_header[4] == 0x53)
            {
                area = "海雾村";
            }
            else if (data_header[4] == 0x54)
            {
                area = "薰衣草苗圃";
            }
            else if (data_header[4] == 0x55)
            {
                area = "高脚孤丘";
            }
            else if (data_header[4] == 0x81)
            {
                area = "白银乡";
            }
            int slot = data_header[2];

            for (int i = 8; i < data_list.Length; i += 40)
            {
                var    house_id    = (i - 8) / 40;
                var    name_header = data_list.SubArray(i, 8);
                int    price       = BitConverter.ToInt32(name_header, 0);
                string size        = (price > 30000000) ? "L" : ((price > 10000000) ? "M" : "S");
                var    name_array  = data_list.SubArray(i + 8, 32);
                if (name_array[0] == 0)
                {
                    string text = $"{area} 第{slot + 1}区 {house_id + 1}号 {size}房在售 当前价格:{price} {Environment.NewLine}";
                    Log("Info", text);
                    var housignItem = new HousingItem(
                        area,
                        slot + 1,
                        house_id + 1,
                        size,
                        price
                        );
                    if (HousingList.IndexOf(housignItem) == -1)
                    {
                        bindingSource1.Add(housignItem);
                    }
                    else
                    {
                        HousingList[HousingList.IndexOf(housignItem)].ExistenceTime = DateTime.Now;     //更新时间
                        HousingList[HousingList.IndexOf(housignItem)].Price         = price;            //更新价格
                        Log("Info", "重复土地,已更新。");
                        control.dataGridView1.Refresh();                                                //刷新控件
                    }
                    if (size == "M" || size == "L")
                    {
                        Console.Beep(3000, 1000);
                    }
                    if (control.upload)
                    {
                        if (!control.checkBoxML.Checked || (size == "M" || size == "L"))
                        {
                            OtterText      += text;
                            OtterUploadFlag = true;
                        }
                    }
                }
            }
            Log("Info", $"查询第{slot + 1}区");     //输出翻页日志
        }