本文整理汇总了C#中Estrella.FiestaLib.Networking.Packet.TryReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.TryReadByte方法的具体用法?C# Packet.TryReadByte怎么用?C# Packet.TryReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Estrella.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, 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;
}
}
示例2: ChangeDropMode
public static void ChangeDropMode(WorldClient client, Packet packet)
{
byte dropState;
if (packet.TryReadByte(out dropState)) {
client.Character.Group.ChangeDropType(client.Character, dropState);
}
}
示例3: 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);
}
}
}
示例4: 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);
}
}
示例5: 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);
}
示例6: 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);
}
}
示例7: 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);
}
示例8: 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
}
示例9: 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);
}
}
}
}
示例10: 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;
}
示例11: 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);
}
}
}
示例12: 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);
}
}
示例13: 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);
}
}
}
示例14: SellItem
public static void SellItem(ZoneClient client, Packet packet)
{
byte slot;
int sellcount;
ZoneCharacter character = client.Character;
if (packet.TryReadByte(out slot) && packet.TryReadInt(out sellcount))
{
Item item;
character.Inventory.InventoryItems.TryGetValue(slot, out item);
if (item != null)
{
long fullSellPrice = sellcount * item.ItemInfo.SellPrice;
if (item.Ammount > 1)
{
item.Ammount -= (ushort)sellcount;
byte Slot = (byte)item.Slot;
Handler12.ModifyInventorySlot(character, 0x24, Slot, Slot, item);
character.Inventory.Money += fullSellPrice;
character.ChangeMoney(character.Inventory.Money);
}
else
{
character.Inventory.Money += fullSellPrice;
character.ChangeMoney(character.Inventory.Money);
character.Inventory.InventoryItems.Remove(slot);
ResetInventorySlot(character, slot);
}
System.Console.WriteLine(item.ItemInfo.Type);
}
}
}
示例15: MoveItemHandler
public static void MoveItemHandler(ZoneClient pClient, Packet pPacket)
{
byte oldslot, oldstate, newslot, newstate;
if (!pPacket.TryReadByte(out oldslot) ||
!pPacket.TryReadByte(out oldstate) ||
!pPacket.TryReadByte(out newslot) ||
!pPacket.TryReadByte(out newstate))
{
Log.WriteLine(LogLevel.Warn, "Could not read item move.");
return;
}
if (oldslot == newslot)
{
Log.WriteLine(LogLevel.Warn, "Client tried to dupe an item.");
return;
}
Item source;
if (!pClient.Character.Inventory.InventoryItems.TryGetValue(oldslot, out source) && newstate != 0x00 && oldstate != 0x00 || newstate == 0x00)
{
if (pClient.Character.Guild != null)
{
if(newstate == 0x00 && oldstate == 0x24)
{
source.Flags = Data.ItemFlags.GuildItem;
}
else if(newstate == 0x24 && oldstate == 0x00)
{
source.Flags = Data.ItemFlags.Normal;
}
else if (source == null || newstate != 0x24)
{
if (!pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(oldslot, out source))
{
return;
}
}
}
if (source == null)
{
Log.WriteLine(LogLevel.Warn, "Client tried to move empty slot.");
return;
}
}
if (newslot == 0xff || newstate == 0xff)
{
pClient.Character.Inventory.InventoryItems.Remove(oldslot);
source.Delete(); //TODO: make a drop
Handler12.ModifyInventorySlot(pClient.Character, oldslot, oldstate, (byte)source.Slot, null);
}
else if(newstate == 0x00 && oldstate == 0x24 && pClient.Character.Guild != null)
{
if (!pClient.Character.Guild.GuildStore.GetHasFreeGuildStoreSlot())
//todo GuildStorefuell
return;
pClient.Character.Inventory.RemoveInventory(source);
pClient.Character.Guild.GuildStore.GuildStorageItems.Add(newslot, source);
pClient.Character.Guild.GuildStore.SendAddGuildStore(Data.GuildStoreAddFlags.Item, pClient.Character.Character.Name, source.Ammount, 0, source.ItemInfo.ItemID);
pClient.Character.Guild.GuildStore.SaveStoreItem(pClient.Character.Guild.ID, source.ItemInfo.ItemID, newslot);
Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, oldslot, null);
Handler12.ModifyInventorySlot(pClient.Character, oldstate, newstate, oldslot, newslot, source);
return;
}
else if(oldstate == 0x00 && newstate == 0x24 && pClient.Character.Guild != null)
{
if (!pClient.Character.Guild.GuildStore.GuildStorageItems.TryGetValue(oldslot, out source))
return;
source.Slot = (sbyte)newslot;
pClient.Character.Guild.GuildStore.GuildStorageItems.Remove(oldslot);
pClient.Character.Inventory.AddToInventory(source);
pClient.Character.Guild.GuildStore.SendRemoveFromGuildStore (Data.GuildStoreAddFlags.Item, pClient.Character.Character.Name, source.Ammount, 0, source.ItemInfo.ItemID);
pClient.Character.Guild.GuildStore.RemoveStoreItem(pClient.Character.Guild.ID, source.ItemInfo.ItemID);
Handler12.ModifyInventorySlot(pClient.Character, newstate,oldstate, newslot, oldslot, null);
Handler12.ModifyInventorySlot(pClient.Character, newstate, newstate, newstate, newslot, source);
return;
}
if (source.Flags == Data.ItemFlags.Normal)
{
Item destination;
if (pClient.Character.Inventory.InventoryItems.TryGetValue(newslot, out destination))
{
//item swap
pClient.Character.Inventory.InventoryItems.Remove(oldslot);
pClient.Character.Inventory.InventoryItems.Remove(newslot);
source.Slot = (sbyte)newslot;
destination.Slot = (sbyte)oldslot;
pClient.Character.Inventory.InventoryItems.Add(newslot, source);
pClient.Character.Inventory.InventoryItems.Add(oldslot, destination);
source.Save();
destination.Save();
Handler12.ModifyInventorySlot(pClient.Character, newslot, 0x24, oldslot, destination);
Handler12.ModifyInventorySlot(pClient.Character, oldslot, 0x24, newslot, source);
}
else
{
//item moved to empty slot
pClient.Character.Inventory.InventoryItems.Remove(oldslot);
pClient.Character.Inventory.InventoryItems.Add(newslot, source);
//.........这里部分代码省略.........