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


C# Packet.TryReadByte方法代码示例

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


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

示例1: CreateCharHandler

        public static void CreateCharHandler(WorldClient client, Packet packet)
        {
            string name;
            byte slot, jobGender, hair, color, style;
            if (!packet.TryReadByte(out slot) || !packet.TryReadString(out name, 16) ||
                !packet.TryReadByte(out jobGender) || !packet.TryReadByte(out hair) ||
                !packet.TryReadByte(out color) || !packet.TryReadByte(out style))
            {
                Log.WriteLine(LogLevel.Warn, "Error reading create char for {0}", client.Username);
                return;
            }

            if (DatabaseChecks.IsCharNameUsed(name))
            {
                SendCharCreationError(client, CreateCharError.NameTaken);
                return;
            }
            else if (DataProvider.Instance.IsBadName(name))
            {
                SendCharCreationError(client, CreateCharError.NameInUse);
                return;
            }

            byte isMaleByte = (byte)((jobGender >> 7) & 0x01);
            byte classIDByte = (byte)((jobGender >> 2) & 0x1F);
            Job job = (Job)classIDByte;
            switch (job)
            {
                case Job.Archer:
                case Job.Cleric:
                case Job.Fighter:
                case Job.Mage:
                case Job.Trickster:
                case Job.Crusader:
                   //create character here
                    try
                    {
                        WorldCharacter wchar = client.CreateCharacter(name, slot, hair, color, style, job, Convert.ToBoolean(isMaleByte));
                        SendCharOKResponse(client, wchar);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine(LogLevel.Exception, "Error creating character for {0}: {1}", client.Username, ex.InnerException.ToString());
                        SendCharCreationError(client, CreateCharError.FailedToCreate);
                        return;
                    }
                    break;
                default:
                    SendCharCreationError(client, CreateCharError.WrongClass);
                    Log.WriteLine(LogLevel.Warn, "Invalid job ID at char creation from {0}", client.Username);
                    break;
            }
        }
开发者ID:Canic,项目名称:Zepheus_2k15,代码行数:53,代码来源:Handler5.cs

示例2: CharacterSelectHandler

        public static void CharacterSelectHandler(WorldClient client, Packet packet)
        {
            byte slot;
            if (!packet.TryReadByte(out slot) || slot > 10 || !client.Characters.ContainsKey(slot))
            {
                Log.WriteLine(LogLevel.Warn, "{0} selected an invalid character.", client.Username);
                return;
            }

            WorldCharacter character;
            if (client.Characters.TryGetValue(slot, out character))
            {
                //generate transfer

                ZoneConnection zone = Program.GetZoneByMap(character.Character.PositionInfo.Map);
                if (zone != null)
                {
                    client.Characters.Clear(); //we clear the other ones from memory
                    client.Character = character; //only keep the one selecte
                    //Database.Storage.Characters.AddChars(character.Character);
                    zone.SendTransferClientFromZone(client.AccountID, client.Username, client.Character.Character.Name,client.Character.ID, client.RandomID, client.Admin, client.Host);
                    ClientManager.Instance.AddClientByName(client); //so we can look them up fast using charname later.
                    SendZoneServerIP(client, zone);
                }
                else
                {
                    Log.WriteLine(LogLevel.Warn, "Character tried to join unloaded map: {0}", character.Character.PositionInfo.Map);
                    SendConnectError(client, ConnectErrors.MapUnderMaintenance);
                }
            }
        }
开发者ID:Dextan,项目名称:Estrella,代码行数:31,代码来源:Handler4.cs

示例3: HandleSetStatPoint

        public static void HandleSetStatPoint(ZoneClient client, Packet packet)
        {
            byte stat;
            if (!packet.TryReadByte(out stat))
            {
                Log.WriteLine(LogLevel.Warn, "Couldn't read HandleSetStatPoint packet. {0}", client);
                return;
            }

            if (client.Character.Character.UsablePoints == 0)
            {
                Log.WriteLine(LogLevel.Warn, "User tried to set stat point while not having any left. {0}", client);
            }
            else
            {
                // LETS DO ET
                switch (stat)
                {
                    case 0: client.Character.Str++; break;
                    case 1: client.Character.Dex++; break;
                    case 2: client.Character.End++; break;
                    case 3: client.Character.Int++; break;
                    case 4: client.Character.Spr++; break;
                    default:
                        {
                            Log.WriteLine(LogLevel.Warn, "User tried to set stat point on unknown stat {0} {1}", stat, client);
                            return;
                        }
                }
                client.Character.Character.UsablePoints--;
                //Program.Entity.SaveChanges();
                SendSetUsablePoint(client, stat);
            }
        }
开发者ID:Dextan,项目名称:Estrella,代码行数:34,代码来源:Handler4.cs

示例4: ChangeDropMode

 public static void ChangeDropMode(WorldClient client, Packet packet)
 {
     byte dropState;
     if (packet.TryReadByte(out dropState)) {
         client.Character.Group.ChangeDropType(client.Character, dropState);
     }
 }
开发者ID:Dextan,项目名称:Estrella,代码行数:7,代码来源:Handler14.cs

示例5: sendPartyMessage

        public static void sendPartyMessage(WorldClient client, Packet packet)
        {
            string mess;
            byte len;
            if (!packet.TryReadByte(out len) || !packet.TryReadString(out mess, len))
            {
                Log.WriteLine(LogLevel.Error, "PartyChat :: Can not parse party chat from {0}", client.Character.Character.Name);
                return;
            }

            if(Program.Entity.Parties.Where(c => c.CharNo == client.Character.Character.ID).Count() == 1)
            {
                Party getPartyInfo = Program.Entity.Parties.First(c => c.CharNo == client.Character.Character.ID);
                foreach (Party party in Program.Entity.Parties.Where(c => c.PartyNo == getPartyInfo.PartyNo))
                {
                    Character character = Program.Entity.Characters.First(c => c.ID == party.CharNo);
                    WorldClient wclient = ClientManager.Instance.GetClientByCharname(character.Name);
                    using (var ppacket = new Packet(SH8Type.PartyChat))
                    {
                        ppacket.WriteString(client.Character.Character.Name, 16);
                        ppacket.WriteByte(len);
                        ppacket.WriteString(mess, len);
                        wclient.SendPacket(ppacket);
                    }
                }
            }
            else
            {
                using (var ppacket = new Packet(SH8Type.PartyChatErr))
                {
                    ppacket.WriteUShort(1985);
                    client.SendPacket(ppacket);
                }
            }
        }
开发者ID:Canic,项目名称:Zepheus_2k15,代码行数:35,代码来源:Handler8.cs

示例6: TradeRemovitem

 public static void TradeRemovitem(ZoneClient pClient, Packet pPacket)
 {
     byte pSlot;
     if (!pPacket.TryReadByte(out pSlot))
         return;
     if (pClient.Character.Trade == null)
         return;
     pClient.Character.Trade.RemoveItemToHandel(pClient.Character, pSlot);
 }
开发者ID:Dextan,项目名称:Estrella,代码行数:9,代码来源:Handler19.cs

示例7: MasterRequestCoper

 public static void MasterRequestCoper(ZoneClient client, Packet pPacket)
 {
     byte unk;
     if (!pPacket.TryReadByte(out unk))
         return;
     using (var packet = new Packet(SH37Type.SendRecivveCopper))
     {
         packet.WriteUShort(7264);//unk
         packet.WriteLong(client.Character.Character.ReviveCoper);
         client.SendPacket(packet);
     }
 }
开发者ID:Dextan,项目名称:Estrella,代码行数:12,代码来源:Handler37.cs

示例8: PartyChat

        public static void PartyChat(WorldClient client, Packet packet)
        {
            if (client.Character.Group == null)
                return;

            byte msgLen;
            string msg = string.Empty;

            if (!packet.TryReadByte(out msgLen) || !packet.TryReadString(out msg, msgLen))
                return;

            client.Character.Group.Chat(client, msg);
        }
开发者ID:Dextan,项目名称:Estrella,代码行数:13,代码来源:Handler8.cs

示例9: ChangeCharNameHandler

 public static void ChangeCharNameHandler(WorldClient client, Packet packet)
 {
     byte Character_slot;
     string charname;
     if (!packet.TryReadByte(out Character_slot) || !packet.TryReadString(out charname, 16))
         return;
     using (var pack = new Packet(SH5Type.SendCharacterChangeNewName))
     {
         pack.WriteByte(Character_slot);
         pack.WriteString(charname,16);
         pack.WriteUShort(208);//Responsecode?
     }
     //Todo ChangeinDatabase
 }
开发者ID:Dextan,项目名称:Estrella,代码行数:14,代码来源:Handler5.cs

示例10: Wisper

 public static void Wisper(WorldClient client, Packet packet)
 {
     string toname;
     byte messagelenght;
     if (packet.TryReadString(out toname, 16) && packet.TryReadByte(out messagelenght))
     {
         string message;
         if (!packet.TryReadString(out message, messagelenght))
         {
             return;
         }
         WorldClient toChar = ClientManager.Instance.GetClientByCharname(toname);
         if (toChar != null)
         {
             using (var frompacket = new Packet(SH8Type.WisperFrom))
             {
                 frompacket.WriteString(client.Character.Character.Name, 16);
                 if (!toChar.Character.BlocketUser.Contains(client.Character.Character.Name))
                 {
                     frompacket.WriteByte(0);
                 }
                 else
                 {
                     frompacket.WriteByte(12);//blocket notdisplay message
                 }
                 frompacket.WriteByte(messagelenght);
                 frompacket.WriteString(message, messagelenght);
                 toChar.SendPacket(frompacket);
             }
             using (var pack = new Packet(SH8Type.WisperTo))
             {
                 pack.WriteString(toname, 16);
                 pack.WriteByte(messagelenght);
                 pack.WriteString(message, messagelenght);
                 client.SendPacket(pack);
             }
         }
         else
         {
             //target not found
             using (var pp = new Packet(SH8Type.WisperTargetNotfound))
             {
                 pp.WriteUShort(3945);//unk
                 pp.WriteString(toname, 16);
                 client.SendPacket(pp);
             }
         }
     }
 }
开发者ID:Dextan,项目名称:Estrella,代码行数:49,代码来源:Handler8.cs

示例11: questionHandler

        public static void questionHandler(ZoneClient client, Packet packet)
        {
            byte answer;
            if (!packet.TryReadByte(out answer))
            {
                Log.WriteLine(LogLevel.Warn, "Received invalid question response.");
                return;
            }

            ZoneCharacter character = client.Character;
            if (character.Question == null)
                return;
            else if (character.Question.Answers.Count <= answer)
                return;

            character.Question.Function(character, answer);
            character.Question = null;
        }
开发者ID:Canic,项目名称:Zepheus_2k15,代码行数:18,代码来源:Handler15.cs

示例12: ClientEquippedItem

        public static void ClientEquippedItem(ZoneClient pClient, Packet pPacket)
        {
            byte fromSlot;
            if (!pPacket.TryReadByte(out fromSlot))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read equip slot.");
                return;
            }

            Item fromItem;
            if (!pClient.Character.Inventory.InventoryItems.TryGetValue(fromSlot, out fromItem))
            {
                Log.WriteLine(LogLevel.Warn, "Equipping empty inventory slot.");
                return;
            }

            if (fromItem == null)
            {
                Log.WriteLine(LogLevel.Warn, "Client tries to equip an ITEM, not EQUIP!");
                return;
            }
            byte toSlot = (byte)fromItem.Slot;
            Item toEquip = pClient.Character.Inventory.EquippedItems.Find(e => e.ItemInfo.Slot == fromItem.ItemInfo.Slot);

            // TODO: Check, does user equip item to correct slot. Right now client only does it.

            ZoneClient client = pClient;
            if (fromItem.ItemInfo.Level > pClient.Character.Level)
            {
                FailedEquip(client.Character, 645); // 85 02
            }
            else
            {
                if (toEquip == null)
                {
                    pClient.Character.EquipItem(fromItem);
                }
                else
                {
                    pClient.Character.SwapEquips(toEquip, fromItem);
                }
            }
        }
开发者ID:Dextan,项目名称:Estrella,代码行数:43,代码来源:Handler12.cs

示例13: DeleteCharacterHandler

 public static void DeleteCharacterHandler(WorldClient client, Packet packet)
 {
     byte slot;
     if (!packet.TryReadByte(out slot) || slot > 10 || !client.Characters.ContainsKey(slot))
     {
         Log.WriteLine(LogLevel.Warn, "{0} tried to delete character out of range.", client.Username);
         return;
     }
     WorldCharacter todelete = client.Characters[slot];
     if (todelete.Delete())
     {
         client.Characters.Remove(slot);
         SendCharDeleteOKResponse(client, slot);
     }
     else
     {
         Handler3.SendError(client, ServerError.DATABASE_ERROR);
     }
 }
开发者ID:Zepheus,项目名称:Zepheus_Fiesta,代码行数:19,代码来源:Handler5.cs

示例14: getWhisperMessage

        public static void getWhisperMessage(WorldClient client, Packet packet)
        {
            string toChar;
            byte len;
            string mess;
            if (!packet.TryReadString(out toChar, 16) || !packet.TryReadByte(out len) || !packet.TryReadString(out mess, len))
            {
                Log.WriteLine(LogLevel.Error, "WhisperChat :: Can not parse Whisper request from {0}", client.Character.Character.Name);
                return;
            }

            WorldClient wclient = ClientManager.Instance.GetClientByCharname(toChar);

            if (wclient != null)
            {
                using (var ppacket = new Packet(SH8Type.WhisperTo))
                {
                    ppacket.WriteString(toChar, 16);
                    ppacket.WriteByte(len);
                    ppacket.WriteString(mess, len);
                    client.SendPacket(ppacket);
                }

                using (var ppacket = new Packet(SH8Type.WhisperFrom))
                {
                    ppacket.WriteString(client.Character.Character.Name, 16);
                    ppacket.WriteByte(0); // unk
                    ppacket.WriteByte(len);
                    ppacket.WriteString(mess, len);
                    wclient.SendPacket(ppacket);
                }
            }
            else
            {
                using (var ppacket = new Packet(SH8Type.WhisperErrAnswer))
                {
                    ppacket.WriteUShort(3945);
                    ppacket.WriteString(toChar, 16);
                    client.SendPacket(ppacket);
                }
            }
        }
开发者ID:Canic,项目名称:Zepheus_2k15,代码行数:42,代码来源:Handler8.cs

示例15: MasterRequestResponse

        public static void MasterRequestResponse(WorldClient client, Packet packet)
        {
            string requester = string.Empty;
            string target = string.Empty;
            byte response;
            if (!packet.TryReadString(out requester, 16))
                return;
            if (!packet.TryReadString(out target, 16))
                return;

            if (!packet.TryReadByte(out response))
                return;
            if (response == 0)
            {
                MasterManager.Instance.RemoveMasterRequest(client);
            }
            else if(response == 1)
            {
                MasterManager.Instance.MasterRequestAccept(requester, target);
            }
        }
开发者ID:Dextan,项目名称:Estrella,代码行数:21,代码来源:Handler37.cs


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