本文整理汇总了C#中Packet.ReadUInt16方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.ReadUInt16方法的具体用法?C# Packet.ReadUInt16怎么用?C# Packet.ReadUInt16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.ReadUInt16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsciiSpeech
public static void AsciiSpeech( Packet p, PacketHandlerEventArgs args )
{
// 0, 1, 2
Serial serial = p.ReadUInt32(); // 3, 4, 5, 6
ushort body = p.ReadUInt16(); // 7, 8
MessageType type = (MessageType)p.ReadByte(); // 9
ushort hue = p.ReadUInt16(); // 10, 11
ushort font = p.ReadUInt16();
string name = p.ReadStringSafe( 30 );
string text = p.ReadStringSafe();
if ( World.Player != null && serial == Serial.Zero && body == 0 && type == MessageType.Regular && hue == 0xFFFF && font == 0xFFFF && name == "SYSTEM" )
{
args.Block = true;
p.Seek( 3, SeekOrigin.Begin );
p.WriteAsciiFixed( "", (int)p.Length-3 );
ClientCommunication.DoFeatures( World.Player.Features ) ;
}
else
{
HandleSpeech( p, args, serial, body, type, hue, font, "A", name, text );
if ( !serial.IsValid )
BandageTimer.OnAsciiMessage( text );
}
}
示例2: 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();
}
示例3: ContainerContent
private static void ContainerContent(Packet p, PacketHandlerEventArgs args)
{
int count = p.ReadUInt16();
for (int i = 0; i < count; i++)
{
Item item = World.FindItem(p.ReadUInt32());
Item container = item.Container as Item;
if (container != null && container.ItemID == 0x2006)
foreach (LootItem loot in items)
if (item.ItemID == loot.Graphic && (item.Hue == loot.Color || loot.Color == 0xFFFF))
{
if (Fixes.LootBag.Bag != 0)
DragDrop.Move(item, Fixes.LootBag.Bag);
WorldEx.OverHeadMessage(loot.Name, container);
}
p.Seek(15, System.IO.SeekOrigin.Current);
}
}
示例4: ContainerContent
private static void ContainerContent(Packet p, PacketHandlerEventArgs args)
{
List<Serial> toRemove = new List<Serial>();
for (ushort count = p.ReadUInt16(); count > 0; count--)
{
Item item = World.FindItem(p.ReadUInt32());
if (item != null && item.Container == World.Player.Backpack)
foreach (FakeItem fake in items.Values)
if (item.ItemID == fake.OrigID && item.Hue == fake.OrigHue)
{
if (!fake.List.Contains(item.Serial))
fake.List.Add(item.Serial);
toRemove.Add(item.Serial);
}
p.Seek(15, SeekOrigin.Current);
}
if (toRemove.Count > 0)
Resend();
toRemove.ForEach(s => WorldEx.SendToClient(new RemoveObject(s)));
}
示例5: OnLocalizedMessage
private static void OnLocalizedMessage( Packet p, PacketHandlerEventArgs args )
{
// 0, 1, 2
Serial serial = p.ReadUInt32(); // 3, 4, 5, 6
ushort body = p.ReadUInt16(); // 7, 8
MessageType type = (MessageType)p.ReadByte(); // 9
ushort hue = p.ReadUInt16(); // 10, 11
ushort font = p.ReadUInt16();
int num = p.ReadInt32();
string name = p.ReadStringSafe( 30 );
string ext_str = p.ReadUnicodeStringLESafe();
if ( ( num >= 3002011 && num < 3002011+64 ) || // reg spells
( num >= 1060509 && num < 1060509+16 ) || // necro
( num >= 1060585 && num < 1060585+10 ) || // chiv
( num >= 1060493 && num < 1060493+10 ) || // chiv
( num >= 1060595 && num < 1060595+6 ) || // bush
( num >= 1060610 && num < 1060610+8 ) ) // ninj
{
type = MessageType.Spell;
}
BandageTimer.OnLocalizedMessage( num );
try
{
string text = Language.ClilocFormat( num, ext_str );
HandleSpeech( p, args, serial, body, type, hue, font, Language.CliLocName.ToUpper(), name, text );
}
catch ( Exception e )
{
Engine.LogCrash( new Exception( String.Format( "Exception in Ultima.dll cliloc: {0}, {1}", num, ext_str ), e ) );
}
}
示例6: MobileUpdate
private static void MobileUpdate( Packet p, PacketHandlerEventArgs args )
{
if ( World.Player == null )
return;
Serial serial = p.ReadUInt32();
Mobile m = World.FindMobile( serial );
if ( m == null )
World.AddMobile( m = new Mobile( serial ) );
bool wasHidden = !m.Visible;
m.Body = (ushort)(p.ReadUInt16() + p.ReadSByte());
m.Hue = p.ReadUInt16();
int ltHue = Config.GetInt( "LTHilight" );
if ( ltHue != 0 && Targeting.IsLastTarget( m ) )
{
p.Seek( -2, SeekOrigin.Current );
p.Write( (ushort)(ltHue|0x8000) );
}
bool wasPoisoned = m.Poisoned;
m.ProcessPacketFlags( p.ReadByte() );
if ( m == World.Player )
{
ClientCommunication.BeginCalibratePosition();
World.Player.Resync();
if ( !wasHidden && !m.Visible )
{
if ( Config.GetBool( "AlwaysStealth" ) )
StealthSteps.Hide();
}
else if ( wasHidden && m.Visible )
{
StealthSteps.Unhide();
}
if ( wasPoisoned != m.Poisoned )
ClientCommunication.RequestTitlebarUpdate();
}
ushort x = p.ReadUInt16();
ushort y = p.ReadUInt16();
p.ReadUInt16(); //always 0?
m.Direction = (Direction)p.ReadByte();
m.Position = new Point3D( x, y, p.ReadSByte() );
Item.UpdateContainers();
}
示例7: OnSpeech
public static void OnSpeech( Packet pvSrc, PacketHandlerEventArgs args )
{
MessageType type = (MessageType)pvSrc.ReadByte();
ushort hue = pvSrc.ReadUInt16();
ushort font = pvSrc.ReadUInt16();
string lang = pvSrc.ReadString( 4 );
string text = "";
ArrayList keys = null;
long txtOffset = 0;
World.Player.SpeechHue = hue;
if ( (type & MessageType.Encoded) != 0 )
{
int value = pvSrc.ReadInt16();
int count = (value & 0xFFF0) >> 4;
keys = new ArrayList();
keys.Add( (ushort)value );
for ( int i = 0; i < count; ++i )
{
if ( (i & 1) == 0 )
{
keys.Add( pvSrc.ReadByte() );
}
else
{
keys.Add( pvSrc.ReadByte() );
keys.Add( pvSrc.ReadByte() );
}
}
txtOffset = pvSrc.Position;
text = pvSrc.ReadUTF8StringSafe();
type &= ~MessageType.Encoded;
}
else
{
txtOffset = pvSrc.Position;
text = pvSrc.ReadUnicodeStringSafe();
}
text = text.Trim();
if ( text.Length > 0 )
{
if ( text[0] != '-' )
{
if ( ClientCommunication.TranslateEnabled && text[0] != '[' && text[0] != ']' )
{
StringBuilder sb = new StringBuilder( 512 );
uint outLen = 512;
ClientCommunication.TranslateDo( text, sb, ref outLen );
text = sb.ToString();
pvSrc.Seek( txtOffset, System.IO.SeekOrigin.Begin );
if ( keys != null && keys.Count > 0 )
pvSrc.WriteUTF8Null( text );
else
pvSrc.WriteBigUniNull( text );
pvSrc.UnderlyingStream.SetLength( pvSrc.Position );
}
Macros.MacroManager.Action( new Macros.SpeechAction( type, hue, font, lang, keys, text ) );
}
else
{
text = text.Substring( 1 );
string[] split = text.Split( ' ', '\t' );
CommandCallback call = (CommandCallback)m_List[split[0]];
if ( call != null )
{
string[] param = new String[split.Length-1];
for(int i=0;i<param.Length;i++)
param[i] = split[i+1];
call( param );
args.Block = true;
}
}
}
}
示例8: EquipmentUpdate
private static void EquipmentUpdate( Packet p, PacketHandlerEventArgs args )
{
Serial serial = p.ReadUInt32();
Item i = World.FindItem( serial );
bool isNew = false;
if ( i == null )
{
World.AddItem( i=new Item( serial ) );
isNew = true;
Item.UpdateContainers();
}
else
{
i.CancelRemove();
}
if ( !DragDropManager.EndHolding( serial ) )
return;
ushort iid = p.ReadUInt16();
i.ItemID = (ushort)(iid + p.ReadSByte()); // signed, itemID offset
i.Layer = (Layer)p.ReadByte();
Serial ser = p.ReadUInt32();// cont must be set after hue (for counters)
i.Hue = p.ReadUInt16();
i.Container = ser;
int ltHue = Config.GetInt( "LTHilight" );
if ( ltHue != 0 && Targeting.IsLastTarget( i.Container as Mobile ) )
{
p.Seek( -2, SeekOrigin.Current );
p.Write( (ushort)(ltHue&0x3FFF) );
}
if ( i.Layer == Layer.Backpack && isNew && Config.GetBool( "AutoSearch" ) && ser == World.Player.Serial )
{
m_IgnoreGumps.Add( i );
PlayerData.DoubleClick( i );
}
}
示例9: ContainerContentUpdate
private static void ContainerContentUpdate( Packet p, PacketHandlerEventArgs args )
{
// This function will ignore the item if the container item has not been sent to the client yet.
// We can do this because we can't really count on getting all of the container info anyway.
// (So we'd need to request the container be updated, so why bother with the extra stuff required to find the container once its been sent?)
Serial serial = p.ReadUInt32();
ushort itemid = p.ReadUInt16();
itemid = (ushort)(itemid + p.ReadSByte()); // signed, itemID offset
ushort amount = p.ReadUInt16();
if ( amount == 0 )
amount = 1;
Point3D pos = new Point3D( p.ReadUInt16(), p.ReadUInt16(), 0 );
byte gridPos = 0;
if ( Engine.UsePostKRPackets )
gridPos = p.ReadByte();
Serial cser = p.ReadUInt32();
ushort hue = p.ReadUInt16();
Item i = World.FindItem( serial );
if ( i == null )
{
if ( !serial.IsItem )
return;
World.AddItem( i = new Item( serial ) );
i.IsNew = i.AutoStack = true;
}
else
{
i.CancelRemove();
}
if ( serial != DragDropManager.Pending )
{
if ( !DragDropManager.EndHolding( serial ) )
return;
}
i.ItemID = itemid;
i.Amount = amount;
i.Position = pos;
i.GridNum = gridPos;
i.Hue = hue;
if ( SearchExemptionAgent.Contains( i ) )
{
p.Seek( -2, System.IO.SeekOrigin.Current );
p.Write( (short)Config.GetInt( "ExemptColor" ) );
}
i.Container = cser;
if ( i.IsNew )
Item.UpdateContainers();
if ( !SearchExemptionAgent.IsExempt( i ) && ( i.IsChildOf( World.Player.Backpack ) || i.IsChildOf( World.Player.Quiver ) ) )
Counter.Count( i );
}
示例10: 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);
}
示例11: 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);
}
}
示例12: 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);
}
示例13: HandleNATInfo
private void HandleNATInfo(TcpSession session, Packet p)
{
var ip = (IPEndPoint) session.Client.Client.RemoteEndPoint;
Player plr;
if (!Players.TryGetValue(session.Guid, out plr))
{
session.StopListening();
return;
}
plr.PrivateIP = p.ReadUInt32();
plr.PrivatePort = p.ReadUInt16();
plr.PublicIP = p.ReadUInt32();
plr.PublicPort = p.ReadUInt16();
// ignore public stuff from client
plr.PublicIP = (uint)ip.Address.Address;
plr.PublicPort = plr.PrivatePort;
plr.NATUnk = p.ReadUInt16();
plr.ConnectionType = p.ReadByte();
if (ip.Address.ToString() == "127.0.0.1")
plr.ConnectionType = 1;
if (plr.ConnectionType == 6)
plr.ConnectionType = 4;
Logger.Info("-CNATInfoReq- NATUnk: {0} Type: {1}", plr.NATUnk, plr.ConnectionType);
}
示例14: HandleEventMessage
private void HandleEventMessage(TcpSession session, Packet p)
{
var eventID = p.ReadByte();
var accID = p.ReadUInt64();
var unk1 = p.ReadUInt32();
var unk2 = p.ReadUInt16();
var strLen = p.ReadUInt32();
var str = (strLen > 0) ? p.ReadCString() : string.Empty;
//_logger.Debug("-C_EVENTMESSAGE_REQ- EventID: {0} AccID: {1} Unk1: {2} Unk2: {3} String: {4}", eventID, accID, unk1, unk2, str);
var player = Players.GetPlayerByID(accID);
Player sender;
if (!Players.TryGetValue(session.Guid, out sender))
{
session.StopListening();
return;
}
if (sender.Room == null)
return;
var room = sender.Room;
if (player != null && player.State == EPlayerState.Lobby && eventID == (byte)EPlayerEventMessage.StartGame && room.State != EGameRuleState.Waiting)
{
player.State = player.GameMode == EPlayerGameMode.Normal ? EPlayerState.Alive : EPlayerState.Spectating;
player.GameScore.JoinTime = DateTime.Now;
room.BroadcastBriefing();
}
var ack = new Packet(EGamePacket.SEventMessageAck);
ack.Write(eventID);
ack.Write(accID);
ack.Write(unk1);
ack.Write(unk2);
ack.Write(strLen);
if (strLen > 0)
ack.Write(str);
room.Broadcast(ack);
}
示例15: OnLocalizedMessageAffix
private static void OnLocalizedMessageAffix( Packet p, PacketHandlerEventArgs phea )
{
// 0, 1, 2
Serial serial = p.ReadUInt32(); // 3, 4, 5, 6
ushort body = p.ReadUInt16(); // 7, 8
MessageType type = (MessageType)p.ReadByte(); // 9
ushort hue = p.ReadUInt16(); // 10, 11
ushort font = p.ReadUInt16();
int num = p.ReadInt32();
byte affixType = p.ReadByte();
string name = p.ReadStringSafe( 30 );
string affix = p.ReadStringSafe();
string args = p.ReadUnicodeStringSafe();
if (( num >= 3002011 && num < 3002011+64 ) || // reg spells
( num >= 1060509 && num < 1060509+16 ) || // necro
( num >= 1060585 && num < 1060585+10 ) || // chiv
( num >= 1060493 && num < 1060493+10 ) || // chiv
( num >= 1060595 && num < 1060595+6 ) || // bush
( num >= 1060610 && num < 1060610+8 ) // ninj
)
{
type = MessageType.Spell;
}
string text;
if ( (affixType&1)!=0 ) // prepend
text = String.Format( "{0}{1}", affix, Language.ClilocFormat( num, args ) );
else // 0 == append, 2 = system
text = String.Format( "{0}{1}", Language.ClilocFormat( num, args ), affix );
HandleSpeech( p, phea, serial, body, type, hue, font, Language.CliLocName.ToUpper(), name, text );
}