当前位置: 首页>>代码示例>>C#>>正文


C# NetworkClient.SendData方法代码示例

本文整理汇总了C#中NetworkClient.SendData方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkClient.SendData方法的具体用法?C# NetworkClient.SendData怎么用?C# NetworkClient.SendData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkClient的用法示例。


在下文中一共展示了NetworkClient.SendData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoStep

        public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            bool chatStarted = false;
            networkClient.OutLogMessage("Starting chat...");

            //Get chat info
            string getInfo = Packet.BuildPacket(FromClient.CHAT_CTRL, Chat.START);
            networkClient.SendData(getInfo);

            //Start chat
            Packet chat = networkClient.InputQueue.Pop(FromServer.CHAT_CTRL);
            if (chat != null)
            {
                string chatServer = chat["@server"];
                string sessionId = (string)client.AdditionalData[ObjectPropertyName.SESSION_ID][0];
                chatStarted = networkClient.StartChat(chatServer, sessionId);
                if (chatStarted)
                {
                    //1: Session ID, 2: Login
                    string chatAuth = Packet.BuildPacket(FromClient.CHAT_CTRL, Chat.AUTH,
                        sessionId, client.Login);
                    networkClient.SendChatData(chatAuth);
                }
            }

            networkClient.OutLogMessage(!chatStarted
                ? "WARNING: chat wasn`t started"
                : "Chat was successfully started");

            return true;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:31,代码来源:LoginStep5_StartChat.cs

示例2: DoStep

        public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            networkClient.OutLogMessage("Getting a servers list...");

            //Send greeting
            string greeting = Packet.BuildPacket(FromClient.GREETING);
            networkClient.SendData(greeting);

            //Get response
            Packet packet = networkClient.InputQueue.Pop();

            if (packet != null)
            {
                //Get available servers
                List<string> servers = packet.GetValues("S/@host");

                //Log message
                StringBuilder sServers = new StringBuilder();

                //Store available servers
                foreach (string server in servers)
                {
                    sServers.AppendFormat("{0}{1}", sServers.Length > 0 ? ", " : "", server);
                    client.AdditionalData.Add(ObjectPropertyName.GAME_SERVER, server);
                }

                networkClient.OutLogMessage(sServers.Insert(0, "Available servers: ").ToString());
                return true;
            }

            networkClient.ThrowError("Failed to getting a servers list or the connection was terminated");
            return false;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:33,代码来源:LoginStep1_Greeting.cs

示例3: DoStep

        public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            int curTickCount = Environment.TickCount;

            //Just started
            if (_prewPingTime == 0)
            {
                _prewPingTime = curTickCount;
                return false;
            }

            if (curTickCount - _prewPingTime >= PING_DELAY_MS)
            {
                //Query params: 0: is a first time ping?, [1]: I1, [2]: ID2, [3]: ID1
                string ping = Packet.BuildPacket(FromClient.PING,
                    _firstTime,
                    client.AdditionalData[ObjectPropertyName.I1][0],
                    client.AdditionalData[ObjectPropertyName.ID2][0],
                    client.AdditionalData[ObjectPropertyName.ID1][0]);
                networkClient.SendData(ping);
                networkClient.SendChatData(ping);

                _firstTime = false;
                _prewPingTime = Environment.TickCount;
                return true;
            }

            return false;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:29,代码来源:GameSystemStep_Ping.cs

示例4: DoStep

 public void DoStep(NetworkClient networkClient, Client client)
 {
     int curTickCount = Environment.TickCount;
     if (_prewPingTime == 0 || curTickCount - _prewPingTime >= PING_DELAY_MS)
     {
         _prewPingTime = curTickCount;
         const string ping = "<N />";
         networkClient.SendData(ping);
     }
 }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:10,代码来源:GameStep_Ping.cs

示例5: DoJoin

        public static bool DoJoin(NetworkClient networkClient, GameClient client)
        {
            Dictionary<string, InventoryItemList> items = new Dictionary<string, InventoryItemList>();

            foreach (InventoryItem inventoryItem in client.InventoryItems)
            {
                //Get the item ident
                string ident = inventoryItem.Ident;
                InventoryItemList inventoryItemsList;

                //Get items list for the item
                if (items.ContainsKey(ident))
                {
                    inventoryItemsList = items[ident];
                }
                else
                {
                    items.Add(ident, inventoryItemsList = new InventoryItemList());
                }

                //Add the item to items list
                inventoryItemsList.Add(inventoryItem);
            }

            //Do join items
            foreach (string ident in items.Keys)
            {
                InventoryItemList inventoryItemsList = items[ident];
                int itemsCount = inventoryItemsList.Count;
                if (itemsCount > 1)
                {
                    InventoryItem item2 = inventoryItemsList[0];
                    for (int i = 1; i < itemsCount; i++)
                    {
                        InventoryItem item1 = inventoryItemsList[i];
                        string joinInventory = Packet.BuildPacket(FromClient.JOIN_INVENTORY,
                            item1.ID, item2.ID);
                        networkClient.SendData(joinInventory);
                        item2.Count += item1.Count;
                        client.InventoryItems.Remove(item1);
                    }
                }
            }

            return true;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:46,代码来源:GameStep_JoinInventory.cs

示例6: DoStep

        public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            networkClient.OutLogMessage("Getting my information...");

            //Get my information
            string getInfo = Packet.BuildPacket(FromClient.GET_MY_INFO);
            networkClient.SendData(getInfo);

            //Read and store current location information
            Packet myInfo = networkClient.InputQueue.Pop(FromServer.MY_INFO);
            if (myInfo != null)
            {
                string data = myInfo.Data;

                //Store game client additional info
                Match locationInfo = _regexLocationInfo.Match(data);
                client.AdditionalData.Add(ObjectPropertyName.LOCATION_BUILDING,
                    locationInfo.Groups["B"].Value);
                client.AdditionalData.Add(ObjectPropertyName.LOCATION_X,
                    locationInfo.Groups["X"].Value);
                client.AdditionalData.Add(ObjectPropertyName.LOCATION_Y,
                    locationInfo.Groups["Y"].Value);
                client.AdditionalData.Add(ObjectPropertyName.ID1,
                    locationInfo.Groups["ID1"].Value);
                client.AdditionalData.Add(ObjectPropertyName.ID2,
                    locationInfo.Groups["ID2"].Value);
                client.AdditionalData.Add(ObjectPropertyName.I1,
                    locationInfo.Groups["I1"].Success
                        ? locationInfo.Groups["I1"].Value
                        : "0");

                //Update inventory
                client.InventoryItems = Helper.ParseInventoryItems(data);

                return true;
            }

            networkClient.ThrowError("Failed to getting my info or the connection was terminated");
            return false;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:40,代码来源:LoginStep4_GetMe.cs

示例7: DoStep

        public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            List<string> messages = new List<string>();

            Packet[] packets = networkClient.InputQueue.PopAll(FromServer.IMS);

            if (!networkClient.OutInstantMessages || packets.Length == 0)
            {
                return false;
            }

            foreach (Packet packet in packets)
            {
                string sMessages = packet["@m"];
                messages.AddRange(sMessages.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries));
            }

            if (messages.Count > 0)
            {
                networkClient.OutInstantMessage(string.Format("Instant message(s), {0} received:", messages.Count));
                foreach (string message in messages)
                {
                    string logMessage;

                    string[] messageParts = message.Split('\t');

                    //Switch IMS command type
                    switch (messageParts[1])
                    {
                        //Private IM
                        case "100":
                            {
                                logMessage = string.Format("\t• {0}. Private from [{1}]: {2}",
                                    messageParts[0], messageParts[2], messageParts[3]);
                                break;
                            }
                        //Shop message
                        case "217":
                            {
                                logMessage = string.Format("\t• {0}. Was received Coins[{1}] from [{2}]. Target: {3}",
                                    messageParts[0], messageParts[3], messageParts[4], messageParts[6]);
                                break;
                            }
                        default:
                            {
                                logMessage = message;
                                break;
                            }
                    }

                    //Play alert
                    _soundPlayer.Play();

                    networkClient.OutInstantMessage(logMessage);
                }

                //Clear all IMS on server
                string clearIMS = Packet.BuildPacket(FromClient.CLEAR_IMS);
                networkClient.SendData(clearIMS);

                return true;
            }

            return false;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:65,代码来源:GameSystemStep_IMS.cs

示例8: DoStep

        public bool DoStep(NetworkClient networkClient, GameClient client)
        {
            //Get password key
            Packet data = networkClient.InputQueue.Pop();
            if (data != null)
            {
                string key = data["@s"];

                //Store password key
                client.AdditionalData.Add(ObjectPropertyName.PASSWORD_KEY, key);

                //Get hashed password
                string passwordHash = client.GetPasswordHash(key);

                networkClient.OutLogMessage(
                    string.Format("Trying to login: U = {0}, P = {1}, K = {2}, H = {3}...",
                    client.Login, client.Password, key, passwordHash));

                //Do login
                string login = Packet.BuildPacket(FromClient.LOGIN_DATA,
                    networkClient.LocalIPAddress, client.Version2, client.Version, passwordHash, client.Login);
                networkClient.SendData(login);

                //Get login result
                data = networkClient.InputQueue.Pop();

                if (data != null)
                {
                    //Check on login error
                    string errorCode = data["@code"];
                    if (errorCode != null)
                    {
                        string errorMessage = Errors.GameError.GetErrorMessage(errorCode);
                        switch (errorCode)
                        {
                            //Should be login to another server
                            case Errors.GameError.E_PLAYER_ON_ANOTHER_SERVER:
                                {
                                    networkClient.ThrowError(errorMessage, false);
                                    break;
                                }
                            //General login error
                            default:
                                {
                                    networkClient.ThrowError(errorMessage);
                                    break;
                                }
                        }
                        return false;
                    }

                    //No errors? Continue...
                    string sessionId = data["@ses"];
                    client.AdditionalData.Add(ObjectPropertyName.SESSION_ID, sessionId);

                    networkClient.OutLogMessage(string.Format("User login successful"));

                    return true;
                }
            }

            networkClient.ThrowError("Failed to login or the connection was terminated");
            return false;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:64,代码来源:LoginStep3_Authorization.cs

示例9: ProcessSubGroupsList

        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"]);
//.........这里部分代码省略.........
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:101,代码来源:GameStep_Shopping.cs

示例10: ProcessGroupPagesFull

        private void ProcessGroupPagesFull(NetworkClient networkClient, GameClient client,
            string locationIdent, bool isAuction, IEnumerable<KeyValuePair<string, string>> fullList)
        {
            //For all items groups...
            foreach (KeyValuePair<string, string> item in fullList)
            {
                //Get group ID
                string groupId = item.Key;

                //Ignore for shopping?
                GameItemsGroup group = _gameItemsGroups[groupId];
                if (group == null || group.IgnoreForShopping)
                {
                    continue;
                }

                //If number of items is more than 0
                if (int.Parse(item.Value) > 0)
                {
                    DateTime startTime = DateTime.Now;
                    string groupName = group.Name;
                    int subGroupsCount = group.SubGroupsCount;

                    List<string> subGroupsOrderList = new List<string>();

                    //Get cached group page ident
                    string cachedGroupPageIdent = GetCachedGroupPageIdent(locationIdent, groupId);

                    //Get cached group pages
                    List<Packet> cachedGroupPages;
                    if (!_cachedGroupPages.ContainsKey(cachedGroupPageIdent))
                    {
                        cachedGroupPages = new List<Packet>();
                        _cachedGroupPages.Add(cachedGroupPageIdent, cachedGroupPages);
                    }
                    else
                    {
                        cachedGroupPages = _cachedGroupPages[cachedGroupPageIdent];
                    }

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

                    //For each page of group
                    for (int groupPage = 0; groupPage < pagesCount; groupPage++)
                    {
                        //Query page[i] of group
                        //Query params: 1: group ID, 2: filter, 3: page number, 4: is auction?
                        string getGroupPagesList = Packet.BuildPacket(FromClient.SHOP,
                            Shop.ITEMS_GET_LIST, groupId, string.Empty, groupPage,
                            isAuction);
                        networkClient.SendData(getGroupPagesList);

                        //Get group page
                        Packet groups = networkClient.InputQueue.Pop(FromServer.SHOP_DATA);

                        if (groups != null)
                        {
                            //Calculate pages count
                            if (groupPage == 0)
                            {
                                int cnt = int.Parse(groups["@m"]);
                                pagesCount = cnt / 8 + (cnt % 8 > 0 ? 1 : 0);
                            }

                            //Process items list
                            ProcessSubGroupsList(networkClient, client, groupId, groupPage, isAuction,
                                                 groups, subGroupsOrderList);

                            //Store cached group page
                            cachedGroupPages.Add(groups);
                        }
                    }

                    //Reorder subgroups
                    group.ReorderSubGroups(subGroupsOrderList);

                    //Out action message
                    string endTime = DateTime.Now.Subtract(startTime).ToString();
                    string message = string.Format("'{0}' processed. Subgroups count: {1}, duration: {2}",
                        groupName, subGroupsCount, Helper.RemoveMilliseconds(endTime));
                    networkClient.OutActionLogMessage(this, message);
                }
            }
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:85,代码来源:GameStep_Shopping.cs

示例11: InstantBuyItem

        private void InstantBuyItem(NetworkClient networkClient, GameClient client,
            string groupId, int groupPage, XmlNode item, GameItem gameItem, 
            string owner)
        {
            if (item != null && item.Attributes != null)
            {
                XmlAttribute cost = item.Attributes["cost"];
                if (cost != null)
                {
                    float qualityMdf = 1f;
                    float fCost = float.Parse(cost.InnerText);

                    //If InstantPurchaseCost isn`t very low, take into an item quality
                    if (gameItem.FactoryCost > 0 && gameItem.InstantPurchaseCost > 0 &&
                        gameItem.FactoryCost / gameItem.InstantPurchaseCost > 10f)
                    {
                        XmlAttribute quality = item.Attributes["quality"];
                        XmlAttribute maxQuality = item.Attributes["maxquality"];
                        if (quality != null && maxQuality != null)
                        {
                            float fQuality = float.Parse(quality.InnerText);
                            float fMaxQuality = float.Parse(maxQuality.InnerText);
                            qualityMdf = fQuality / fMaxQuality;
                        }
                    }

                    //If an item cost is lower than InstantPurchaseCost, let`s try to buy the item
                    if (fCost <= gameItem.InstantPurchaseCost * qualityMdf)
                    {
                        XmlAttribute id = item.Attributes["id"];
                        XmlAttribute count = item.Attributes["count"];
                        if (id != null && count != null)
                        {
                            string sId = id.InnerText;
                            int iCount = int.Parse(count.InnerText);

                            //Check on antibot maneuvers
                            if (!PassAntibotManeuvers(gameItem, iCount, owner))
                            {
                                return;
                            }

                            //Out log message
                            int totalCost = (int) Math.Ceiling(iCount * fCost);
                            string groupName = _gameItemsGroups[groupId].Name;
                            string message =
                                string.Format("Trying to buy: '{0}', owner: [{1}], group: {2}, page: {3}, count: {4}, cost: {5}, total cost: {6}...",
                                gameItem, owner, groupName, groupPage + 1, iCount, fCost, totalCost);
                            networkClient.OutLogMessage(message);

                            //Try to buy the item
                            //Query params: 1: item ID, 2: count, 3: cost
                            string getGroupsItemsList = Packet.BuildPacket(FromClient.SHOP,
                                Shop.ITEMS_BUY, sId, iCount, fCost);
                            networkClient.SendData(getGroupsItemsList);

                            //Get a purchase result
                            string[] packetTypes = new[] {FromServer.ITEM_ADD_ONE, FromServer.SHOP_ERROR};
                            Packet purchaseResult = networkClient.InputQueue.PopAny(packetTypes);

                            //Check the purchase result
                            if (purchaseResult != null)
                            {
                                switch (purchaseResult.Type)
                                {
                                    //Purchasing is failed
                                    case FromServer.SHOP_ERROR:
                                        {
                                            string errorCode = purchaseResult["@code"];
                                            string errorMessage = Errors.ShopError.GetErrorMessage(errorCode);
                                            networkClient.ThrowError(errorMessage, false);
                                            break;
                                        }
                                    //Successful
                                    default:
                                        {
                                            //Add the item to the inventory or, if it`s bad, out log message
                                            InventoryItem inventoryItem = Helper.ParseInventoryItem(purchaseResult.Data);
                                            if (inventoryItem != null)
                                            {
                                                //Add inventory item record
                                                client.InventoryItems.Add(inventoryItem);

                                                //Join inventory items
                                                GameStep_JoinInventory.DoJoin(networkClient, client);
                                            }
                                            else
                                            {
                                                string errorMessage = string.Format("BUY: BAD INVENTORY ITEM: {0}",
                                                    purchaseResult.Data);
                                                networkClient.ThrowError(errorMessage);
                                            }

                                            //Play alert
                                            _soundPlayer.Play();

                                            //Out log message
                                            networkClient.OutLogMessage("Successful");
                                            break;
                                        }
//.........这里部分代码省略.........
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:101,代码来源:GameStep_Shopping.cs

示例12: DoShopping

        private void DoShopping(NetworkClient networkClient, GameClient client, 
            string locationIdent, bool isAuction, bool fullUpdate)
        {
            //Full update
            if (fullUpdate)
            {
                //Clear all of cached group pages
                _cachedGroupPages.Clear();

                //Clear all SubGroupIDToGroup relations
                _gameItemsGroups.ClearSubGroupToGroupIDList();

                //Send: get full groups list
                string getFullGroupsList = Packet.BuildPacket(FromClient.SHOP,
                    Shop.ITEMS_GET_FULL);
                networkClient.SendData(getFullGroupsList);

                //Get response
                Packet fullGroupsList = networkClient.InputQueue.Pop(FromServer.SHOP_DATA);

                if (fullGroupsList != null)
                {
                    //Populate items list, full1: [groupId, itemsNum]
                    string full = fullGroupsList.GetValue("@full");
                    IEnumerable<KeyValuePair<string, string>> fullList = Helper.SplitStringItems(full, ":", ",");

                    //Process all items
                    ProcessGroupPagesFull(networkClient, client, locationIdent, isAuction, fullList);
                }
            }

            //or lets use cached group pages
            else
            {
                //Process every cached group
                foreach (GameItemsGroup group in _gameItemsGroups.Groups)
                {
                    if (!group.IgnoreForShopping)
                    {
                        ProcessGroupPagesFromCache(networkClient, client, locationIdent, isAuction, group);
                    }
                }
            }
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:44,代码来源:GameStep_Shopping.cs

示例13: SellItem

        private void SellItem(NetworkClient networkClient, GameClient client,
                              string itemID, string itemName, int itemCount, 
                              float cost, bool isSingleItem)
        {
            string sellItem = isSingleItem
                ? Packet.BuildPacket(FromClient.SHOP, Shop.ITEM_SELL,
                                    itemID, cost)
                : Packet.BuildPacket(FromClient.SHOP, Shop.ITEM_SELL,
                                    itemID, cost, itemCount);
            networkClient.SendData(sellItem);

            string message = string.Format("Trying to sell: '{0}', cost: {1}, count: {2}...",
                                           itemName, cost, itemCount);
            networkClient.OutLogMessage(message);

            //Get a result
            string[] packetTypes = new[] { FromServer.SHOP_OK, FromServer.SHOP_ERROR };
            Packet getResult = networkClient.InputQueue.PopAny(packetTypes);

            //Check the result
            if (getResult != null)
            {
                switch (getResult.Type)
                {
                    //Selling is failed
                    case FromServer.SHOP_ERROR:
                        {
                            string errorCode = getResult["@code"];
                            string errorMessage = Errors.ShopError.GetErrorMessage(errorCode);
                            networkClient.ThrowError(errorMessage, false);
                            break;
                        }
                    //Done
                    default:
                        {
                            //Remove the item from inventory
                            InventoryItem inventoryItem = client.InventoryItems.Find(ii => ii.ID == itemID);
                            if (inventoryItem != null)
                            {
                                client.InventoryItems.Remove(inventoryItem);
                            }

                            //Play alert
                            _soundPlayer.Play();

                            //Out log message
                            networkClient.OutLogMessage("Successful");
                            break;
                        }
                }
            }
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:52,代码来源:GameStep_Selling.cs

示例14: GetOwnItem

        private bool GetOwnItem(NetworkClient networkClient, GameClient client,
                                ShopItem shopItem)
        {
            string message = string.Format("Trying to get: '{0}'...", shopItem.Parent);
            networkClient.OutLogMessage(message);

            //Try to get the item
            //Query params: 1: item ID
            string getGroupsItemsList = Packet.BuildPacket(FromClient.SHOP,
                Shop.ITEM_GET_OWN, shopItem.ID);
            networkClient.SendData(getGroupsItemsList);

            //Get a result
            string[] packetTypes = new[] { FromServer.ITEM_ADD_ONE, FromServer.SHOP_ERROR };
            Packet getResult = networkClient.InputQueue.PopAny(packetTypes);

            //Check the result
            if (getResult != null)
            {
                switch (getResult.Type)
                {
                    //Getting is failed
                    case FromServer.SHOP_ERROR:
                        {
                            string errorCode = getResult["@code"];
                            string errorMessage = Errors.ShopError.GetErrorMessage(errorCode);
                            networkClient.ThrowError(errorMessage, false);
                            break;
                        }
                    //Successful
                    default:
                        {
                            //Add the item to the inventory or, if it`s bad, out log message
                            InventoryItem inventoryItem = Helper.ParseInventoryItem(getResult.Data);
                            if (inventoryItem != null)
                            {
                                //Add the item to inventory
                                client.InventoryItems.Add(inventoryItem);

                                //Join inventory items
                                GameStep_JoinInventory.DoJoin(networkClient, client);

                                //Out log message
                                networkClient.OutLogMessage("Successful");

                                //Done
                                return true;
                            }
                            string errorMessage = string.Format("GET OWN ITEM: BAD INVENTORY ITEM: {0}", getResult.Data);
                            networkClient.ThrowError(errorMessage);
                            break;
                        }
                }
            }

            return false;
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:57,代码来源:GameStep_Selling.cs

示例15: DoSellingItemsFromAuc

        private void DoSellingItemsFromAuc(NetworkClient networkClient, GameClient client)
        {
            //There is one page available at least
            int pagesCount = 1;

            //For each page of group
            for (int itemsPage = 0; itemsPage < pagesCount; itemsPage++)
            {
                //Query page[i] of group
                //Query params: 1: group ID, 2: filter, 3: page number, 4: is auction?
                string getGroupPagesList = Packet.BuildPacket(FromClient.SHOP,
                    Shop.ITEMS_GET_LIST, GameItemsGroupID.MY_THINGS, "",
                    itemsPage, true);
                networkClient.SendData(getGroupPagesList);

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

                if (itemsList != null)
                {
                    //Calculate items pages count
                    if (itemsPage == 0)
                    {
                        int cnt = int.Parse(itemsList["@m"]);
                        pagesCount = cnt / 8 + (cnt % 8 > 0 ? 1 : 0);
                    }

                    //Process items list
                    ProcessMyAucItemsList(networkClient, client, itemsList);
                }
            }
        }
开发者ID:TimeZeroForever,项目名称:TZToolz,代码行数:32,代码来源:GameStep_Selling.cs


注:本文中的NetworkClient.SendData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。