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


C# Packet.TryReadByte方法代码示例

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


在下文中一共展示了Packet.TryReadByte方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, 20) ||
                !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:
                   //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:iFeddy,项目名称:SolarFiesta,代码行数:52,代码来源: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.Map);
                if (zone != null)
                {
                    client.Characters.Clear(); //we clear the other ones from memory
                    client.Character = character; //only keep the one selected
                    zone.SendTransferClientFromZone(client.AccountID, client.Username, client.Character.Character.Name, 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.Map);
                    SendConnectError(client, ConnectErrors.MapUnderMaintenance);
                }
            }
        }
开发者ID:iFeddy,项目名称:SolarFiesta,代码行数: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:iFeddy,项目名称:SolarFiesta,代码行数:34,代码来源:Handler4.cs

示例4: 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:iFeddy,项目名称:SolarFiesta,代码行数:18,代码来源:Handler15.cs

示例5: 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:iFeddy,项目名称:SolarFiesta,代码行数:19,代码来源:Handler5.cs

示例6: WorldSelectHandler

        public static void WorldSelectHandler(LoginClient pClient, Packet pPacket)
        {
            if (!pClient.IsAuthenticated || pClient.IsTransferring)
            {
                Log.WriteLine(LogLevel.Warn, "Invalid world select request.");
                SendFailedLogin(pClient, ServerError.EXCEPTION);
                return;
            }

            byte id;
            if (!pPacket.TryReadByte(out id))
            {
                Log.WriteLine(LogLevel.Warn, "Invalid world select.");
                return;
            }
            WorldConnection world;
            if (WorldManager.Instance.Worlds.TryGetValue(id, out world))
            {
                switch (world.Status)
                {
                    case WorldStatus.MAINTENANCE:
                        Log.WriteLine(LogLevel.Warn, "{0} tried to join world in maintentance.", pClient.Username);
                        SendFailedLogin(pClient, ServerError.SERVER_MAINTENANCE);
                        return;
                    case WorldStatus.OFFLINE:
                        Log.WriteLine(LogLevel.Warn, "{0} tried to join offline world.", pClient.Username);
                        SendFailedLogin(pClient, ServerError.SERVER_MAINTENANCE);
                        return;
                    default: Log.WriteLine(LogLevel.Debug, "{0} joins world {1}", pClient.Username, world.Name); break;
                }
                string hash = System.Guid.NewGuid().ToString().Replace("-", "");
                world.SendTransferClientFromWorld(pClient.AccountID, pClient.Username, pClient.Admin, pClient.Host, hash);
                Log.WriteLine(LogLevel.Debug, "Transferring login client {0}.", pClient.Username);
                pClient.IsTransferring = true;
                SendWorldServerIP(pClient, world, hash);
            }
            else
            {
                Log.WriteLine(LogLevel.Warn, "{0} selected invalid world.", pClient.Username);
                return;
            }
        }
开发者ID:iFeddy,项目名称:SolarFiesta,代码行数:42,代码来源:LoginHandler.cs

示例7: UnequipHandler

        public static void UnequipHandler(ZoneClient client, Packet packet)
        {
            ZoneCharacter character = client.Character;

            byte sourceSlot;
            sbyte destinationSlot; //not so sure about this one anymore
            if (!packet.TryReadByte(out sourceSlot) ||
                !packet.TryReadSByte(out destinationSlot))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read unequip values from {0}.", character.Name);
                return;
            }
            character.UnequipItem((ItemSlot)sourceSlot, destinationSlot);
        }
开发者ID:iFeddy,项目名称:SolarFiesta,代码行数:14,代码来源:Handler12.cs

示例8: MoveItemHandler

 public static void MoveItemHandler(ZoneClient client, Packet packet)
 {
     byte from, oldstate, to, newstate;
     if(!packet.TryReadByte(out from) ||
         !packet.TryReadByte(out oldstate) ||
         !packet.TryReadByte(out to) ||
         !packet.TryReadByte(out newstate))
     {
             Log.WriteLine(LogLevel.Warn, "Invalid item move received.");
             return;
     }
     client.Character.MoveItem((sbyte)from, (sbyte)to);
 }
开发者ID:iFeddy,项目名称:SolarFiesta,代码行数:13,代码来源:Handler12.cs

示例9: EmoteHandler

        public static void EmoteHandler(ZoneClient client, Packet packet)
        {
            ZoneCharacter character = client.Character;
            byte action;
            if (!packet.TryReadByte(out action))
            {
                Log.WriteLine(LogLevel.Warn, "{0} did empty emote.", character.Name);
                return;
            }

            if (action > 74)
            {
                character.CheatTracker.AddCheat(CheatTypes.EMOTE, 500);
                return;
            }

            using (var broad = Animation(character, action))
            {
                character.Broadcast(broad, true);
            }
        }
开发者ID:iFeddy,项目名称:SolarFiesta,代码行数:21,代码来源:Handler8.cs

示例10: ShoutHandler

        public static void ShoutHandler(ZoneClient client, Packet packet)
        {
            ZoneCharacter character = client.Character;
            byte len;
            string message;
            if (!packet.TryReadByte(out len) ||
                !packet.TryReadString(out message, len))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read shout from {0}.", character.Name);
                return;
            }

            int shoutcheck = character.ShoutCheck();
            if (shoutcheck > 0)
            {
                Handler2.SendChatBlock(character, shoutcheck);
            }
            else
            {
                ChatLog.Instance.LogChat(client.Character.Name, message, true);
                using (var broad = Shout(character.Name, message))
                {
                    character.Map.Broadcast(broad);
                }
            }
        }
开发者ID:iFeddy,项目名称:SolarFiesta,代码行数:26,代码来源:Handler8.cs

示例11: NormalChatHandler

 public static void NormalChatHandler(ZoneClient client, Packet packet)
 {
     byte len;
     string text;
     if (!packet.TryReadByte(out len) || !packet.TryReadString(out text, len))
     {
         Log.WriteLine(LogLevel.Warn, "Could not parse normal chat from {0}.", client.Character.Name);
         return;
     }
     if (client.Admin > 0 && (text.StartsWith("&") || text.StartsWith("/")))
     {
         CommandLog.Instance.LogCommand(client.Character.Name, text);
         CommandStatus status = CommandHandler.Instance.ExecuteCommand(client.Character, text.Split(' '));
         switch (status)
         {
             case CommandStatus.ERROR:
                 client.Character.DropMessage("Error executing command.");
                 break;
             case CommandStatus.GM_LEVEL_TOO_LOW:
                 client.Character.DropMessage("You do not have the privileges for this command.");
                 break;
             case CommandStatus.NOT_FOUND:
                 client.Character.DropMessage("Command not found.");
                 break;
         }
     }
     else
     {
         int chatblock = client.Character.ChatCheck();
         if (chatblock == -1)
         {
             ChatLog.Instance.LogChat(client.Character.Name, text, false);
             SendNormalChat(client.Character, text, client.Admin > 0 ? (byte)0x03 : (byte)0x2a);
         }
         else
         {
             Handler2.SendChatBlock(client.Character, chatblock);
         }
     }
 }
开发者ID:iFeddy,项目名称:SolarFiesta,代码行数:40,代码来源:Handler8.cs


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