Esempio n. 1
0
 private void ProcessPacket(StringBuilder dataPart, StringBuilder bufferedDataPart)
 {
     if (bufferedDataPart.Length >  0)
     {
         dataPart.Insert(0, bufferedDataPart);
     }
     Match match;
     string data = dataPart.ToString();
     while ((match = _regexPacketData.Match(data)).Success)
     {
         Packet packet = new Packet(match.Value);
         _inputQueue.Push(packet);
         data = data.Remove(0, match.Length);
     }
     bufferedDataPart.Length = 0;
     if (data.Length > 0)
     {
         bufferedDataPart.Append(data);
     }
     dataPart.Length = 0;
 }
        private void ProcessSubGroupsList(NetworkClient networkClient, GameClient client,
            string groupId, int groupPage, bool isAuction, Packet groups, 
            List<string> subGroupsOrderList)
        {
            //Get all subgroups nodes
            XmlNodeList itemsAndSubGroups = groups.GetNodes("O");
            if (itemsAndSubGroups != null)
            {
                //For each subgroup node
                foreach (XmlNode itemOrSubGroup in itemsAndSubGroups)
                {
                    //If it`s valid node
                    if (itemOrSubGroup.Attributes != null)
                    {
                        XmlAttribute name;
                        switch (groupId)
                        {
                            case GameItemsGroupID.PLANT_PACKS:
                                name = itemOrSubGroup.Attributes["namef"];
                                break;
                            case GameItemsGroupID.DOCUMENTS:
                                name = itemOrSubGroup.Attributes["namef"] ??
                                       itemOrSubGroup.Attributes["name"];
                                break;
                            default:
                                name = itemOrSubGroup.Attributes["name"];
                                break;
                        }

                        XmlAttribute type = itemOrSubGroup.Attributes["type"];

                        //If the node doesn`t have own name, ignore this node
                        if (name == null || type == null)
                        {
                            continue;
                        }

                        string subGroupId = name.InnerText;
                        string subGroupType = type.InnerText.Replace(".", "");

                        //Store subgroup->group relation
                        _gameItemsGroups.StoreSubGroupIDToGroupRelation(groupId, subGroupId, subGroupType);

                        //If we in the full processing mode (subGroupsOrderList != null),
                        //groupId should be stored in the appropriate list
                        if (subGroupsOrderList != null)
                        {
                            string ident = GameItemsSubGroup.GetSubGroupIdent(subGroupId, subGroupType);
                            subGroupsOrderList.Add(ident);
                        }

                        //Is this a subgroup of items?
                        XmlAttribute auc = itemOrSubGroup.Attributes["auc"];
                        if (auc != null)
                        {
                            //Check IgnoreForShopping flag
                            GameItemsSubGroup subGroup = _gameItemsGroups[groupId].GetSubGroup(subGroupId, subGroupType);
                            if (subGroup != null && (subGroup.IgnoreForShopping || subGroup.ItemsCount == 0))
                            {
                                continue;
                            }

                            //okay, now go inside the subgroup
                            XmlAttribute lvl = itemOrSubGroup.Attributes["lvl"];
                            XmlAttribute txt = itemOrSubGroup.Attributes["txt"];

                            //Verify parameters
                            if (txt != null)
                            {
                                string subGroupName = GameItem.GetPureItemText(txt.InnerText);
                                string subGroupLevel = lvl != null ? lvl.InnerText : "";

                                //There is one page available at least
                                int pagesCount = 1;

                                //For each page of items
                                for (int subGroupPage = 0; subGroupPage < pagesCount; subGroupPage++)
                                {
                                    //Make the filter string
                                    string filter = string.Format(@"name:{0},type:{1},lvl:{2}",
                                        subGroupId, subGroupType, subGroupLevel);

                                    //Get items list
                                    //Query params: 1: item group ID, 2: filter, 3: page number, 4: is auction?
                                    string getGroupsItemsListQuery = Packet.BuildPacket(FromClient.SHOP,
                                        Shop.ITEMS_GET_LIST, groupId, filter, subGroupPage,
                                        isAuction);
                                    networkClient.SendData(getGroupsItemsListQuery);

                                    //Get items list
                                    Packet groupItemsList = networkClient.InputQueue.Pop(FromServer.SHOP_DATA);

                                    if (groupItemsList != null)
                                    {
                                        //Calculate pages count or set according to ShopPagesLimit value
                                        if (subGroupPage == 0)
                                        {
                                            if (subGroup == null || subGroup.ShopPagesLimit == 0)
                                            {
                                                int itemsCount = int.Parse(groupItemsList["@m"]);
                                                pagesCount = itemsCount / 8 + (itemsCount % 8 > 0 ? 1 : 0);
                                            }
                                            else
                                            {
                                                pagesCount = subGroup.ShopPagesLimit;
                                            }
                                        }

                                        //Process items list
                                        ProcessItemsList(networkClient, client, groupId, groupPage, subGroupId,
                                            subGroupName, subGroupType, subGroupLevel, groupItemsList);
                                    }
                                }
                            }
                        }

                        //otherwise let`s process standalone item
                        else
                        {
                            //Check IgnoreForShopping flag
                            GameItemsSubGroup subGroup = _gameItemsGroups[groupId].GetSubGroup(subGroupId, subGroupType);
                            if (subGroup != null && (subGroup.IgnoreForShopping || subGroup.ItemsCount == 0))
                            {
                                continue;
                            }

                            XmlAttribute txt = itemOrSubGroup.Attributes["txt"];
                            XmlAttribute lvl = itemOrSubGroup.Attributes["lvl"];

                            //Verify parameters
                            if (txt != null)
                            {
                                string subGroupName = GameItem.GetPureItemText(txt.InnerText);
                                string subGroupLevel = lvl != null ? lvl.InnerText : "";

                                //Process item
                                ProcessItem(networkClient, client, groupId, 0, subGroupId, subGroupName,
                                            subGroupType, subGroupLevel, itemOrSubGroup);
                            }
                        }
                    }
                }
            }
        }
        private void ProcessMyAucItemsList(NetworkClient networkClient, GameClient client, 
                                           Packet itemsList)
        {
            //Get all nodes of items
            XmlNodeList items = itemsList.GetNodes("O");
            if (items != null)
            {
                //For each node of items
                foreach (XmlNode item in items)
                {
                    //Create new my shop item
                    ShopItem myItem = Helper.ParseShopItem(item, _gameItemsGroups);

                    //Validate the item
                    if (myItem != null && !string.IsNullOrEmpty(myItem.SubGroupID))
                    {
                        string groupId = _gameItemsGroups.SubGroupToGroupId(myItem.SubGroupID,
                                                                            myItem.SubGroupType);
                        if (!string.IsNullOrEmpty(groupId))
                        {
                            //Get subgroup
                            GameItemsSubGroup sg = _gameItemsGroups[groupId].GetSubGroup(
                                myItem.SubGroupID, myItem.SubGroupType);

                            //Cache items list from auction
                            CacheAuctionItems(networkClient, groupId, myItem.SubGroupID,
                                              sg.Type, sg.Level);

                            //Do dumping
                            DoDumping(networkClient, client, myItem, true);
                        }
                    }
                }
            }
        }
 private void ProcessItemsList(NetworkClient networkClient, GameClient client,
     string groupId, int groupPage, string subGroupId, string subGroupName, 
     string subGroupType, string subGroupLevel, Packet itemsList)
 {
     //Get all nodes of items
     XmlNodeList items = itemsList.GetNodes("O");
     if (items != null)
     {
         //For each node of items
         foreach (XmlNode item in items)
         {
             if (!ProcessItem(networkClient, client, groupId, groupPage, subGroupId,
                              subGroupName, subGroupType, subGroupLevel, item))
             {
                 return;
             }
         }
     }
 }
Esempio n. 5
0
 //Push packet to queue
 public void Push(Packet packet)
 {
     if (packet != null)
     {
         lock (_pushSync)
         {
             _list.Insert(0, packet);
             _queueSemaphore.Release();
             if (_typedPacketEvents.ContainsKey(packet.Type))
             {
                 _typedPacketEvents[packet.Type].Set();
             }
         }
     }
 }