本文整理汇总了C#中Packet.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.ReadBytes方法的具体用法?C# Packet.ReadBytes怎么用?C# Packet.ReadBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.ReadBytes方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteReadByteDataTest
public void WriteReadByteDataTest()
{
Packet writePacket = new Packet(packetOpcode);
writePacket.Write(uint32Value);
writePacket.Write(uint16Value);
writePacket.Write(byteValue);
writePacket.Write(int32Value);
writePacket.Write(int16Value);
writePacket.Write(sbyteValue);
writePacket.Write(stringValue);
writePacket.Write(byteArrayValue);
Packet readPacket = new Packet(writePacket.Data);
Assert.AreEqual(writePacket.OpcodeNumber, readPacket.OpcodeNumber);
Assert.AreEqual(uint32Value, readPacket.ReadUInt32());
Assert.AreEqual(uint16Value, readPacket.ReadUInt16());
Assert.AreEqual(byteValue, readPacket.ReadByte());
Assert.AreEqual(int32Value, readPacket.ReadInt32());
Assert.AreEqual(int16Value, readPacket.ReadInt16());
Assert.AreEqual(sbyteValue, readPacket.ReadSByte());
Assert.AreEqual(stringValue, readPacket.ReadString());
var packetBytes = readPacket.ReadBytes();
for (int i = 0; i < byteArrayValue.Length; i++)
Assert.AreEqual(byteArrayValue[i], packetBytes[i]);
readPacket.Dispose();
writePacket.Dispose();
}
示例2: HandleReqUpdateAccountData
public static void HandleReqUpdateAccountData(Packet packet)
{
packet.ReadEnum<AccountDataType>("Type");
packet.ReadTime("Time");
int inflatedSize = packet.ReadInt32("Size");
byte[] compressedData = packet.ReadBytes((int)packet.GetLength() - (int)packet.GetPosition());
byte[] data = new byte[inflatedSize];
var inflater = new Inflater();
inflater.SetInput(compressedData, 0, compressedData.Length);
inflater.Inflate(data, 0, inflatedSize);
Console.WriteLine("Data: {0}", encoder.GetString(data));
}
示例3: ReadMovementUpdateBlock
//.........这里部分代码省略.........
for (var i = 0; i < 9; i++)
{
var j = (SpeedType)i;
var speed = packet.ReadSingle();
Console.WriteLine(j + " Speed: " + speed);
switch (j)
{
case SpeedType.Walk:
{
moveInfo.WalkSpeed = speed / 2.5f;
break;
}
case SpeedType.Run:
{
moveInfo.RunSpeed = speed / 7.0f;
break;
}
}
}
if (moveFlags.HasFlag(MoveFlag.SplineEnabled))
{
var splineFlags = packet.ReadEnum<SplineFlag>("Spline Flags");
if (splineFlags.HasFlag(SplineFlag.FinalPoint))
packet.ReadVector3("Final Spline Coords");
if (splineFlags.HasFlag(SplineFlag.FinalTarget))
packet.ReadGuid("Final Spline Target GUID");
if (splineFlags.HasFlag(SplineFlag.FinalOrientation))
packet.ReadSingle("Final Spline Orientation");
packet.ReadInt32("Spline Time");
packet.ReadInt32("Spline Full Time");
packet.ReadInt32("Spline Unk Int32 1");
packet.ReadSingle("Spline Duration Multiplier");
packet.ReadSingle("Spline Unit Interval");
packet.ReadSingle("Spline Unk Float 2");
packet.ReadInt32("Spline Height Time");
var splineCount = packet.ReadInt32("Spline Count");
for (var i = 0; i < splineCount; i++)
packet.ReadVector3("Spline Waypoint " + i);
packet.ReadEnum<SplineMode>("Spline Mode");
packet.ReadVector3("Spline Endpoint");
}
}
else
{
if (flags.HasFlag(UpdateFlag.GOPosition))
{
packet.ReadPackedGuid("GO Position GUID");
var gopos = packet.ReadVector3("GO Position");
packet.ReadVector3("GO Transport Position");
var goFacing = packet.ReadSingle("GO Orientation");
moveInfo.Position = gopos;
moveInfo.Orientation = goFacing;
packet.ReadSingle("GO Transport Orientation");
}
else if (flags.HasFlag(UpdateFlag.StationaryObject))
packet.ReadVector4("Stationary Position");
}
if (flags.HasFlag(UpdateFlag.LowGuid))
packet.ReadInt32("Low GUID");
if (flags.HasFlag(UpdateFlag.AttackingTarget))
packet.ReadPackedGuid("Target GUID");
if (flags.HasFlag(UpdateFlag.Transport))
packet.ReadInt32("Transport Creation Time");
if (flags.HasFlag(UpdateFlag.Vehicle))
{
packet.ReadInt32("Vehicle ID");
packet.ReadSingle("Vehicle Orientation");
}
if (flags.HasFlag(UpdateFlag.GORotation))
packet.ReadPackedQuaternion("GO Rotation");
if (flags.HasFlag(UpdateFlag.Unknown2))
{
packet.ReadInt16("Unk Int16 1");
packet.ReadInt16("Unk Int16 2");
packet.ReadInt16("Unk Int16 3");
}
if (flags.HasFlag(UpdateFlag.Unknown3))
{
var count = packet.ReadByte("Unk count");
packet.ReadBytes(count * 4); // count ints
}
return moveInfo;
}
示例4: HandleWhisper
private void HandleWhisper(TcpSession session, Packet p)
{
var accID = p.ReadUInt64();
var unk1 = p.ReadUInt32();
var unk2 = p.ReadByte();
var msgSize = p.ReadUInt16();
var msg = Encoding.ASCII.GetString(p.ReadBytes(msgSize));
_logger.Debug("-C_WHISPER_REQ- accID: {0} unk1: {1} unk2: {2} Size: {3} Msg: {4}", accID, unk1, unk2, msgSize, msg);
var target = _players.GetPlayerByID(accID);
Player plr;
if (!_players.TryGetValue(session.Guid, out plr))
{
session.StopListening();
return;
}
if (target == null)
return;
var ack = new Packet(EChatPacket.SWhisperAck);
ack.Write(plr.AccountID);
ack.Write(unk1);
ack.Write(unk2);
ack.Write(msgSize);
ack.Write(msg);
target.Session.Send(ack);
}
示例5: HandleSetDataRequest
private void HandleSetDataRequest(TcpSession session, Packet p)
{
//_logger.Debug("-C_SETDATA_REQ-");
Player plr;
if (!_players.TryGetValue(session.Guid, out plr))
{
session.StopListening();
return;
}
p.ReadUInt16(); // unk
p.ReadUInt64(); // accID
plr.ServerID = p.ReadUInt16();
var channelID = p.ReadInt16();
var roomID = p.ReadInt32();
if(roomID == -1)
roomID = 0;
if (channelID == -1)
channelID = 0;
plr.Room = new Room(null, EServerType.Chat) { ID = (uint)roomID };
plr.CommunityByte = p.ReadByte();
p.ReadUInt32(); // total exp
p.ReadBytes(32); // td/dm info
plr.AllowCombiRequest = (EAllowCommunityRequest)p.ReadByte();
plr.AllowFriendRequest = (EAllowCommunityRequest)p.ReadByte();
plr.AllowInvite = (EAllowCommunityRequest)p.ReadByte();
plr.AllowInfoRequest = (EAllowCommunityRequest)p.ReadByte();
plr.CommunityData = p.ReadBytes(41);
Channel channel;
if (!_channels.TryGetValue((ushort)channelID, out channel))
return;
if (plr.Channel == null && channelID > 0) // join
{
var ack = new Packet(EChatPacket.SChannelPlayerListInfoAck);
ack.Write((uint)channel.ID);
ack.Write(channel.Players.Count);
foreach (var player in channel.Players.Values)
ack.WriteChatUserData(player);
session.Send(ack);
channel.Join(plr);
}
else if(channelID == 0) // leave
{
if(plr.Channel != null)
plr.Channel.Leave(plr);
}
else // update
{
var ack = new Packet(EChatPacket.SChannelPlayerListInfoAck);
ack.Write((uint)channel.ID);
ack.Write(channel.Players.Count);
foreach (var player in channel.Players.Values)
ack.WriteChatUserData(player);
channel.Broadcast(ack);
}
}
示例6: HandleChatMessage
private void HandleChatMessage(TcpSession session, Packet p)
{
var channelID = p.ReadUInt32();
var msgSize = p.ReadUInt16();
var msg = Encoding.ASCII.GetString(p.ReadBytes(msgSize));
//_logger.Debug("-C_MESSAGE_REQ- ChannelID: {0} Msg: {1}", channelID, msg);
Player plr;
if (!_players.TryGetValue(session.Guid, out plr))
{
session.StopListening();
return;
}
if (plr.Channel == null)
return;
var ack = new Packet(EChatPacket.SMessageAck);
ack.Write(plr.AccountID);
ack.Write((uint)plr.Channel.ID);
ack.Write((ushort)msg.Length);
ack.Write(msg);
plr.Channel.Broadcast(ack);
}
示例7: HandleBuyItem
private void HandleBuyItem(TcpSession session, Packet p)
{
int count = p.ReadByte();
Player player;
if (!Players.TryGetValue(session.Guid, out player))
{
session.StopListening();
return;
}
var buyTime = DateTime.Now;
var itemsToBuy = new List<Tuple<Item, ShopItem>>();
uint penCost = 0;
uint apCost = 0;
for (var i = 0; i < count; i++)
{
var item = new Item();
var mixedID = p.ReadBytes(4);
item.Category = mixedID[0];
item.SubCategory = mixedID[1];
item.ItemID = BitConverter.ToUInt16(mixedID, 2);
item.ProductID = p.ReadByte();
item.EffectID = p.ReadUInt32();
item.PurchaseTime = HelperUtils.GetUnixTimestamp(buyTime);
var shopItem = GameDatabase.Instance.GetShopItem(item.Category, item.SubCategory, item.ItemID, item.ProductID);
if (shopItem == null) // hacker
{
Logger.Error("-CBuyItemReq FAILED(HAX)- ItemID: {0} Category: {1} SubCategory: {2} Type: {3} EffectID: {4}", item.ItemID, item.Category, item.SubCategory, item.ProductID, item.EffectID);
session.StopListening();
return;
}
item.Energy = shopItem.Energy;
item.ExpireTime = (shopItem.Time == -1) ? -1 : HelperUtils.GetUnixTimestamp(buyTime.AddSeconds(shopItem.Time));
penCost += shopItem.Price;
apCost += shopItem.Cash;
itemsToBuy.Add(new Tuple<Item, ShopItem>(item, shopItem));
}
Packet ack;
if (player.PEN < penCost || player.AP < apCost)
{
ack = new Packet(EGamePacket.SBuyItemAck);
ack.Write((byte)EBuyItemResult.NotEnoughMoney);
session.Send(ack);
return;
}
_pluginManager.OnBuyItem(player, itemsToBuy.Select(e => e.Item1).ToList());
foreach (var tuple in itemsToBuy)
{
var item = tuple.Item1;
var shopItem = tuple.Item2;
//_logger.Debug("-C_BUY_ITEM_REQ- ItemID: {0} Category: {1} SubCategory: {2} Type: {3} EffectID: {4}", item.ItemID, item.Category, item.SubCategory, item.ProductID, item.EffectID);
player.PEN -= shopItem.Price;
player.AP -= shopItem.Cash;
var id = GameDatabase.Instance.CreateItem(item, player.AccountID);
if (id == 0)
{
ack = new Packet(EGamePacket.SBuyItemAck);
ack.Write((byte)EBuyItemResult.DBError);
session.Send(ack);
continue;
}
item.ID = id;
item.SetupAPWeapon();
player.AddItem(item);
ack = new Packet(EGamePacket.SBuyItemAck);
ack.Write((byte)EBuyItemResult.OK);
ack.Write(item.Category);
ack.Write(item.SubCategory);
ack.Write(item.ItemID);
ack.Write(item.ProductID);
ack.Write(item.EffectID);
ack.Write(item.ID);
session.Send(ack);
}
player.UpdateMoney();
}
示例8: HandleRoomChangeItems
private void HandleRoomChangeItems(TcpSession session, Packet p)
{
var accID = p.ReadUInt64();
var skill = p.ReadUInt32();
var skill2 = p.ReadUInt32(); // alpha thing -> removed in beta
var weapon1 = p.ReadUInt32();
var weapon2 = p.ReadUInt32();
var weapon3 = p.ReadUInt32();
var unk = p.ReadBytes(27);
//_logger.Debug("-C_ROOM_CHANGE_ITEMS_REQ-");
Player plr;
if (!Players.TryGetValue(session.Guid, out plr))
{
session.StopListening();
return;
}
var room = plr.Room;
if (room == null)
return;
// Slot freeze bug fix
if (skill2 != 0)
skill = skill2;
var ack = new Packet(EGamePacket.SRoomChangeItemsAck);
ack.Write(accID);
ack.Write(skill);
ack.Write(0);
ack.Write(weapon1);
ack.Write(weapon2);
ack.Write(weapon3);
ack.Write(unk);
room.Broadcast(ack, plr.AccountID);
}
示例9: HandleCreateRoom
private void HandleCreateRoom(TcpSession session, Packet p)
{
Player player;
if (!Players.TryGetValue(session.Guid, out player))
{
session.StopListening();
return;
}
if (player.Channel == null || player.PublicIP == 0)
return;
var room = new Room(Rooms);
var roomID = Rooms.CreateRoomID(player.Channel.ID);
var tunnelID = Rooms.CreateTunnelID();
room.MasterID = player.AccountID;
room.ID = roomID;
room.TunnelID = tunnelID;
room.Channel = player.Channel;
room.Name = p.ReadCStringBuffer(31);
room.MatchKey = p.ReadBytes(4);
room.TimeLimit = p.ReadByte();
room.TimeLimit *= 60 * 1000;
room.ScoreLimit = p.ReadByte();
room.Unk = p.ReadInt32();
room.Password = p.ReadUInt32();
room.IsFriendly = p.ReadBoolean();
room.IsBalanced = p.ReadBoolean();
room.MinLevel = p.ReadByte();
room.MaxLevel = p.ReadByte();
room.EquipLimit = p.ReadByte();
room.IsNoIntrusion = p.ReadBoolean();
room.State = EGameRuleState.Waiting;
var cont = _pluginManager.OnCreateRoom(player, room);
Packet ack;
//_logger.Debug("-CCreateRoom- MapID: {0} Mode: {1}", room.MapID, (int)room.GameRule);
if (!GameDatabase.Instance.IsValidMapID(room.MapID))
{
Logger.Error("-CCreateRoom HAX- NOT ALLOWED MapID: {0} Mode: {1}", room.MapID, (int)room.GameRule);
ack = new Packet(EGamePacket.SResultAck);
ack.Write((uint)EServerResult.FailedToRequestTask);
session.Send(ack);
return;
}
if (room.GameRule != EGameRule.Touchdown && room.GameRule != EGameRule.Deathmatch && room.GameRule != EGameRule.Survival && cont)
{
ack = new Packet(EGamePacket.SResultAck);
ack.Write((uint)EServerResult.FailedToRequestTask);
session.Send(ack);
return;
}
Rooms.TryAdd(tunnelID, room);
ack = new Packet(EGamePacket.SDeployRoomAck);
ack.Write(room.ID);
ack.Write(room.MatchKey);
ack.Write((byte)room.State);
ack.Write(room.GetPing());
ack.WriteStringBuffer(room.Name, 31);
ack.Write(room.PublicType);
ack.Write(room.TimeLimit);
ack.Write(room.ScoreLimit);
ack.Write(room.IsFriendly);
ack.Write(room.IsBalanced);
ack.Write(room.MinLevel);
ack.Write(room.MaxLevel);
ack.Write(room.EquipLimit);
ack.Write(room.IsNoIntrusion);
player.Channel.Broadcast(ack);
room.Join(player);
}
示例10: OnAuthSession
public static void OnAuthSession(Packet packet, RealmSession session)
{
// Part of the header
packet.Read<ushort>();
var loginServerId = packet.Read<uint>();
var build = packet.Read<short>();
var localChallenge = packet.Read<uint>();
var siteId = packet.Read<uint>();
var realmId = packet.Read<uint>();
var loginServerType = packet.Read<LoginServerTypes>();
var buildType = packet.Read<sbyte>();
var regionId = packet.Read<uint>();
var dosResponse = packet.Read<ulong>();
var digest = packet.ReadBytes(20);
var accountName = packet.ReadString(11);
var useIPv6 = packet.GetBit();
// AddonInfo stuff
var compressedAddonInfoSize = packet.Read<int>();
var uncompressedAddonInfoSize = packet.Read<int>();
var compressedAddonData = packet.ReadBytes(compressedAddonInfoSize - 4);
var accountParts = accountName.Split(new[] { '#' });
var authResult = AuthResults.Ok;
if (loginServerType != LoginServerTypes.Battlenet)
authResult = AuthResults.Reject;
if (authResult == AuthResults.Ok)
{
if (accountParts.Length == 2)
{
var accountId = int.Parse(accountParts[0]);
var gameIndex = byte.Parse(accountParts[1]);
var gameAccount = DB.Auth.GameAccounts.SingleOrDefault(ga => ga.AccountId == accountId && ga.Index == gameIndex);
if (gameAccount != null)
{
var sha1 = new Sha1();
sha1.Process(accountName);
sha1.Process(0u);
sha1.Process(localChallenge);
sha1.Process(session.Challenge);
sha1.Finish(gameAccount.SessionKey.ToByteArray(), 40);
// Check the password digest.
if (sha1.Digest.Compare(digest))
{
session.GameAccount = gameAccount;
AddonHandler.LoadAddonInfoData(session, compressedAddonData, compressedAddonInfoSize, uncompressedAddonInfoSize);
}
else
authResult = AuthResults.IncorrectPassword;
}
else
authResult = AuthResults.UnknownAccount;
}
else
authResult = AuthResults.UnknownAccount;
}
HandleAuthResponse(authResult, session);
//TODO [partially done] Implement security checks & field handling.
//TODO Implement AuthResponse.
}
示例11: Main
static void Main(string[] args)
{
// Client will send us the key and iVec
AesEncryptor aes = null;
// Rsa inicialization
RsaEncryptor rsa = new RsaEncryptor(RSAKey.RsaParams);
// Creates new server instance on port 10751
Server server = new Server(10751);
// Awaits client connection
var tcpClient = server.AcceptClientBlockWait();
// Creates client instance
var client = new Client(tcpClient);
byte[] data = null;
do
{
// Gets received data (everything that is in network pipe)
data = client.ReceiveData();
if (data == null)
continue;
do
{
var length = BitConverter.ToUInt16(data, 0);
data = data.Skip(sizeof(UInt16)).ToArray();
var packetData = data.Take(length).ToArray();
// init packet, decrypt stream after inicialization
Packet packet = new Packet(aes != null ? aes.Decrypt(packetData) : packetData);
Packet response = null;
switch ((ClientPacketTypes)packet.OpcodeNumber)
{
case ClientPacketTypes.CMSG_INIT_ENCRYPTED_RSA:
var keys = rsa.Decrypt(packet.ReadBytes());
aes = new AesEncryptor(keys.Take(16).ToArray(), keys.Skip(16).ToArray());
client.AesEncryptor = aes;
response = new Packet(ServerPacketTypes.SMSG_INIT_RESPONSE_ENCRYPTED_RSA);
response.Write("Hello Client!");
break;
case ClientPacketTypes.CMSG_INIT_ENCRYPTED_AES:
Console.WriteLine(packet.ReadString());
response = new Packet(ServerPacketTypes.SMSG_INIT_RESPONSE_ENCRYPTED_AES);
response.Write("Hello Client, We are now fully encrypted!");
break;
}
if (response != null)
{
client.SendPacket(response);
response.Dispose();
}
data = data.Skip(length).ToArray();
} while (data.Any());
break;
} while (true);
aes.Dispose();
client.Dispose();
server.Dispose();
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
示例12: EndReading
/// <summary>
/// Used as IAsyncResult parser for ContinueReading().
/// </summary>
/// <param name="pIAR">The result AsyncCallback makes</param>
private void EndReading(IAsyncResult pIAR)
{
int amountReceived = 0;
try
{
amountReceived = _socket.EndReceive(pIAR);
}
catch (Exception ex)
{
Debug.WriteLine(TypeName + " : " + ex.ToString());
amountReceived = 0;
}
if (amountReceived == 0)
{
// We got a disWvsBeta.Common.Sessions here!
OnDisconnectINTERNAL();
return;
}
// Add amount of bytes received to _bufferpos so we know if we got everything.
_bufferpos += amountReceived;
try
{
// Check if we got all data. There is _no_ way we would have received more bytes than needed. Period.
if (_bufferpos == _bufferlen)
{
// It seems we have all data we need
// Now check if we got a header
if (_header)
{
if (!_encryption && _receivingFromServer)
{
// Unencrypted packets have a short header with plain length.
ushort length = (ushort)(_buffer[0] | _buffer[1] << 8);
StartReading(length);
}
else
{
int length = GetHeaderLength(_buffer);
StartReading(length);
}
}
else
{
Packet packet;
if (_encryption)
{
_buffer = Decrypt(_buffer);
packet = new Packet(_buffer);
DoAction((date) =>
{
try
{
OnPacketInbound(this, packet);
}
catch (Exception ex)
{
Debug.WriteLine("Handling Packet Error: {0}", ex.ToString());
}
});
}
else
{
_encryption = true; // First packet received or sent is unencrypted. All others are.
packet = new Packet(_buffer);
_mapleVersion = packet.ReadUShort();
_maplePatchLocation = _maplePatchLocation = packet.ReadString();
_encryptIV = packet.ReadBytes(4);
_decryptIV = packet.ReadBytes(4);
_mapleLocale = packet.ReadByte();
Debug.WriteLine(TypeName + " MapleVersion: {0}; Patch Location: {1}; Locale: {2}", _mapleVersion, _maplePatchLocation, _mapleLocale);
if (_mapleLocale == 8 && _mapleVersion >= 118)
{
SwitchAESByVersion(_mapleVersion);
}
packet.Reset();
DoAction((date) =>
{
try
{
OnHandshakeInbound(packet);
}
catch (Exception ex)
{
Debug.WriteLine("Handling Packet Error: {0}", ex.ToString());
}
});
}
StartReading(4, true);
//.........这里部分代码省略.........