本文整理汇总了C#中Package.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Package.GetType方法的具体用法?C# Package.GetType怎么用?C# Package.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandlePackage
internal void HandlePackage(Package message, PlayerNetworkSession playerSession)
{
if (message == null) return;
TraceReceive(message);
if (typeof (UnknownPackage) == message.GetType())
{
return;
}
if (typeof (McpeBatch) == message.GetType())
{
McpeBatch batch = (McpeBatch) message;
var messages = new List<Package>();
// Get bytes
byte[] payload = batch.payload;
// Decompress bytes
MemoryStream stream = new MemoryStream(payload);
if (stream.ReadByte() != 0x78)
{
throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
}
stream.ReadByte();
using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
{
// Get actual package out of bytes
MemoryStream destination = new MemoryStream();
defStream2.CopyTo(destination);
destination.Position = 0;
NbtBinaryReader reader = new NbtBinaryReader(destination, true);
int len = reader.ReadInt32();
byte[] internalBuffer = reader.ReadBytes(len);
//byte[] internalBuffer = destination.ToArray();
messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
if (destination.Length > destination.Position) throw new Exception("Have more data");
}
foreach (var msg in messages)
{
msg.DatagramSequenceNumber = batch.DatagramSequenceNumber;
msg.OrderingChannel = batch.OrderingChannel;
msg.OrderingIndex = batch.OrderingIndex;
HandlePackage(msg, playerSession);
msg.PutPool();
}
return;
}
Player player = playerSession.Player;
if (player != null) player.HandlePackage(message);
}
示例2: TraceReceive
private static void TraceReceive(Package message, int refNumber = 0)
{
if (!Log.IsDebugEnabled) return;
if (!Debugger.IsAttached) return;
if (!(message is InternalPing) /*&& message.Id != (int) DefaultMessageIdTypes.ID_CONNECTED_PING && message.Id != (int) DefaultMessageIdTypes.ID_UNCONNECTED_PING*/)
{
Log.DebugFormat("> Receive: {0}: {1} (0x{0:x2}) #{2}", message.Id, message.GetType().Name, refNumber);
}
}
示例3: TraceSend
private static void TraceSend(Package message)
{
if (!Log.IsDebugEnabled) return;
if (!Debugger.IsAttached) return;
if (!(message is InternalPing) /*&& message.Id != (int) DefaultMessageIdTypes.ID_CONNECTED_PONG && message.Id != (int) DefaultMessageIdTypes.ID_UNCONNECTED_PONG*/)
{
Log.DebugFormat("< Send: {0}: {1} (0x{0:x2})", message.Id, message.GetType().Name);
}
}
示例4: HandlePackage
public void HandlePackage(Package message)
{
//if (!IsConnected) return;
LastNetworkActivity = DateTime.UtcNow;
var result = Server.PluginManager.PluginPacketHandler(message, true, this);
//if (result != message) message.PutPool();
message = result;
if (message == null)
{
return;
}
else if (typeof (McpeUpdateBlock) == message.GetType())
{
// DO NOT USE. Will dissapear from MCPE any release.
// It is a bug that it leaks these messages.
}
else if (typeof (McpeRemoveBlock) == message.GetType())
{
HandleRemoveBlock((McpeRemoveBlock) message);
}
else if (typeof (McpeAnimate) == message.GetType())
{
HandleAnimate((McpeAnimate) message);
}
else if (typeof (McpeUseItem) == message.GetType())
{
HandleUseItem((McpeUseItem) message);
}
else if (typeof (McpeEntityEvent) == message.GetType())
{
HandleEntityEvent((McpeEntityEvent) message);
}
else if (typeof (ConnectedPing) == message.GetType())
{
HandleConnectedPing((ConnectedPing) message);
}
else if (typeof (ConnectedPong) == message.GetType())
{
HandleConnectedPong((ConnectedPong) message);
}
else if (typeof (ConnectionRequest) == message.GetType())
{
HandleConnectionRequest((ConnectionRequest) message);
}
else if (typeof (NewIncomingConnection) == message.GetType())
{
HandleNewIncomingConnection((NewIncomingConnection) message);
}
else if (typeof (DisconnectionNotification) == message.GetType())
{
HandleDisconnectionNotification();
}
else if (typeof (McpeText) == message.GetType())
{
HandleMessage((McpeText) message);
}
else if (typeof (McpeRemovePlayer) == message.GetType())
{
// Do nothing right now, but should clear out the entities and stuff
// from this players internal structure.
}
else if (typeof (McpeLogin) == message.GetType())
{
HandleLogin((McpeLogin) message);
}
else if (typeof (McpeMovePlayer) == message.GetType())
{
HandleMovePlayer((McpeMovePlayer) message);
}
else if (typeof (McpeInteract) == message.GetType())
{
HandleInteract((McpeInteract) message);
}
else if (typeof (McpeRespawn) == message.GetType())
{
HandleRespawn((McpeRespawn) message);
}
else if (typeof (McpeTileEntityData) == message.GetType())
{
HandleEntityData((McpeTileEntityData) message);
//.........这里部分代码省略.........
示例5: HandlePackage
/// <summary>
/// Handles the specified package.
/// </summary>
/// <param name="message">The package.</param>
/// <param name="senderEndpoint">The sender's endpoint.</param>
private void HandlePackage(Package message, PlayerNetworkSession playerSession)
{
TraceReceive(message);
if (typeof (UnknownPackage) == message.GetType())
{
return;
}
if (typeof (McpeBatch) == message.GetType())
{
McpeBatch batch = (McpeBatch) message;
var messages = new List<Package>();
// Get bytes
byte[] payload = batch.payload;
// Decompress bytes
MemoryStream stream = new MemoryStream(payload);
if (stream.ReadByte() != 0x78)
{
throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
}
stream.ReadByte();
using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
{
// Get actual package out of bytes
MemoryStream destination = new MemoryStream();
defStream2.CopyTo(destination);
byte[] internalBuffer = destination.ToArray();
messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
}
foreach (var msg in messages)
{
HandlePackage(msg, playerSession);
}
}
playerSession.Player.HandlePackage(message);
playerSession.LastUpdatedTime = DateTime.UtcNow;
if (typeof (DisconnectionNotification) == message.GetType())
{
PlayerNetworkSession value;
_playerSessions.TryRemove(playerSession.EndPoint, out value);
}
}
示例6: TraceSend
private void TraceSend(Package message)
{
Log.DebugFormat("< Send: {0}: {1} (0x{0:x2})", message.Id, message.GetType().Name);
}
示例7: HandlePackage
private void HandlePackage(Package message)
{
if (typeof (McpeBatch) == message.GetType())
{
OnBatch(message);
return;
}
else if (typeof (McpeDisconnect) == message.GetType())
{
McpeDisconnect msg = (McpeDisconnect) message;
Log.InfoFormat("Disconnect {1}: {0}", msg.message, Username);
//SendDisconnectionNotification();
StopClient();
return;
}
else if (typeof (ConnectedPing) == message.GetType())
{
ConnectedPing msg = (ConnectedPing) message;
SendConnectedPong(msg.sendpingtime);
return;
}
else if (typeof (McpeFullChunkData) == message.GetType())
{
OnFullChunkData(message);
return;
}
else if (typeof (ConnectionRequestAccepted) == message.GetType())
{
OnConnectionRequestAccepted();
return;
}
else if (typeof (McpeSetSpawnPosition) == message.GetType())
{
OnMcpeSetSpawnPosition(message);
return;
}
else if (typeof (McpeStartGame) == message.GetType())
{
OnMcpeStartGame(message);
return;
}
else if (typeof (McpeTileEvent) == message.GetType())
{
OnMcpeTileEvent(message);
return;
}
else if (typeof (McpeAddEntity) == message.GetType())
{
OnMcpeAddEntity(message);
return;
}
else if (typeof (McpeAddPlayer) == message.GetType())
{
OnMcpeAddPlayer(message);
return;
}
else if (typeof (McpeSetEntityData) == message.GetType())
{
OnMcpeSetEntityData(message);
return;
}
else if (typeof (McpeMovePlayer) == message.GetType())
{
//OnMcpeMovePlayer(message);
return;
}
else if (typeof (McpeUpdateBlock) == message.GetType())
{
OnMcpeUpdateBlock(message);
return;
}
else if (typeof (McpeLevelEvent) == message.GetType())
{
OnMcpeLevelEvent(message);
return;
}
else if (typeof (McpeMobEffect) == message.GetType())
{
OnMcpeMobEffect(message);
return;
}
else if (typeof (McpeSpawnExperienceOrb) == message.GetType())
{
//.........这里部分代码省略.........
示例8: HandlePackage
/// <summary>
/// Handles the specified package.
/// </summary>
/// <param name="message">The package.</param>
/// <param name="senderEndpoint">The sender's endpoint.</param>
private void HandlePackage(Package message, IPEndPoint senderEndpoint)
{
if (typeof (McpeBatch) == message.GetType())
{
McpeBatch batch = (McpeBatch) message;
var messages = new List<Package>();
// Get bytes
byte[] payload = batch.payload;
// Decompress bytes
MemoryStream stream = new MemoryStream(payload);
if (stream.ReadByte() != 0x78)
{
throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
}
stream.ReadByte();
using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
{
// Get actual package out of bytes
MemoryStream destination = new MemoryStream();
defStream2.CopyTo(destination);
byte[] internalBuffer = destination.ToArray();
messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
}
foreach (var msg in messages)
{
HandlePackage(msg, senderEndpoint);
}
return;
}
TraceReceive(message);
if (typeof (UnknownPackage) == message.GetType())
{
return;
}
if (typeof (McpeDisconnect) == message.GetType())
{
McpeDisconnect msg = (McpeDisconnect) message;
Log.Debug(msg.message);
StopServer();
return;
}
if (typeof (ConnectedPing) == message.GetType())
{
ConnectedPing msg = (ConnectedPing) message;
SendConnectedPong(msg.sendpingtime);
return;
}
if (typeof (McpeFullChunkData) == message.GetType())
{
McpeFullChunkData msg = (McpeFullChunkData) message;
ChunkColumn chunk = ClientUtils.DecocedChunkColumn(msg.chunkData);
if (chunk != null)
{
Log.DebugFormat("Chunk X={0}", chunk.x);
Log.DebugFormat("Chunk Z={0}", chunk.z);
ClientUtils.SaveChunkToAnvil(chunk);
}
return;
}
if (typeof (ConnectionRequestAccepted) == message.GetType())
{
Thread.Sleep(50);
SendNewIncomingConnection();
var t1 = new Timer(state => SendConnectedPing(), null, 2000, 5000);
Thread.Sleep(50);
SendLogin("Client12");
return;
}
if (typeof (McpeSetSpawnPosition) == message.GetType())
{
McpeSetSpawnPosition msg = (McpeSetSpawnPosition) message;
_spawn = new Vector3(msg.x, msg.y, msg.z);
_level.SpawnX = (int) _spawn.X;
_level.SpawnY = (int) _spawn.Y;
_level.SpawnZ = (int) _spawn.Z;
return;
}
if (typeof (McpeStartGame) == message.GetType())
{
McpeStartGame msg = (McpeStartGame) message;
_entityId = msg.entityId;
_spawn = new Vector3(msg.x, msg.y, msg.z);
//.........这里部分代码省略.........
示例9: TraceReceive
private void TraceReceive(Package message)
{
if (message is McpeMoveEntity
|| message is McpeMovePlayer
|| message is McpeSetEntityMotion
|| message is McpeBatch
|| message is McpeFullChunkData
|| message is ConnectedPing) return;
var stringWriter = new StringWriter();
ObjectDumper.Write(message, 1, stringWriter);
//Log.DebugFormat("> Receive: {0}: {1} (0x{0:x2})", message.Id, message.GetType().Name);
Log.DebugFormat("> Receive: {0} (0x{0:x2}) {1}:\n{2} ", message.Id, message.GetType().Name, stringWriter.ToString());
}
示例10: TraceReceive
private static void TraceReceive(Package message)
{
Log.DebugFormat("> Receive: {0}: {1} (0x{0:x2})", message.Id, message.GetType().Name);
}
示例11: HandlePackage
internal void HandlePackage(Package message, PlayerNetworkSession playerSession)
{
Player player = playerSession.Player;
if (message == null)
{
return;
}
if (typeof (McpeWrapper) == message.GetType())
{
McpeWrapper batch = (McpeWrapper) message;
// Get bytes
byte[] payload = batch.payload;
if (playerSession.CryptoContext != null && Config.GetProperty("UseEncryption", true))
{
payload = CryptoUtils.Decrypt(payload, playerSession.CryptoContext);
}
//if (Log.IsDebugEnabled)
// Log.Debug($"0x{payload[0]:x2}\n{Package.HexDump(payload)}");
var msg = PackageFactory.CreatePackage(payload[0], payload, "mcpe") ?? new UnknownPackage(payload[0], payload);
HandlePackage(msg, playerSession);
msg.PutPool();
return;
}
if (typeof (UnknownPackage) == message.GetType())
{
UnknownPackage packet = (UnknownPackage) message;
Log.Warn($"Received unknown package 0x{message.Id:X2}\n{Package.HexDump(packet.Message)}");
return;
}
if (typeof (McpeBatch) == message.GetType())
{
Log.Debug("Handle MCPE batch message");
McpeBatch batch = (McpeBatch) message;
var messages = new List<Package>();
// Get bytes
byte[] payload = batch.payload;
// Decompress bytes
MemoryStream stream = new MemoryStream(payload);
if (stream.ReadByte() != 0x78)
{
throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
}
stream.ReadByte();
using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
{
// Get actual package out of bytes
MemoryStream destination = MiNetServer.MemoryStreamManager.GetStream();
defStream2.CopyTo(destination);
destination.Position = 0;
NbtBinaryReader reader = new NbtBinaryReader(destination, true);
while (destination.Position < destination.Length)
{
int len = reader.ReadInt32();
byte[] internalBuffer = reader.ReadBytes(len);
//if (Log.IsDebugEnabled)
// Log.Debug($"0x{internalBuffer[0]:x2}\n{Package.HexDump(internalBuffer)}");
messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer, "mcpe") ?? new UnknownPackage(internalBuffer[0], internalBuffer));
}
if (destination.Length > destination.Position) throw new Exception("Have more data");
}
foreach (var msg in messages)
{
msg.DatagramSequenceNumber = batch.DatagramSequenceNumber;
msg.OrderingChannel = batch.OrderingChannel;
msg.OrderingIndex = batch.OrderingIndex;
HandlePackage(msg, playerSession);
msg.PutPool();
}
return;
}
if (player != null) player.HandlePackage(message);
}
示例12: HandlePackage
/// <summary>
/// Handles the specified package.
/// </summary>
/// <param name="message">The package.</param>
/// <param name="senderEndpoint">The sender's endpoint.</param>
private void HandlePackage(Package message, IPEndPoint senderEndpoint)
{
if (typeof (McpeBatch) == message.GetType())
{
Log.Debug("Processing Batch package");
McpeBatch batch = (McpeBatch) message;
var messages = new List<Package>();
// Get bytes
byte[] payload = batch.payload;
// Decompress bytes
MemoryStream stream = new MemoryStream(payload);
if (stream.ReadByte() != 0x78)
{
throw new InvalidDataException("Incorrect ZLib header. Expected 0x78");
}
stream.ReadByte();
using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
{
// Get actual package out of bytes
MemoryStream destination = new MemoryStream();
defStream2.CopyTo(destination);
destination.Position = 0;
NbtBinaryReader reader = new NbtBinaryReader(destination, true);
do
{
int len = reader.ReadInt32();
byte[] internalBuffer = reader.ReadBytes(len);
messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
} while (destination.Position < destination.Length); // throw new Exception("Have more data");
}
foreach (var msg in messages)
{
HandlePackage(msg, senderEndpoint);
msg.PutPool();
}
return;
}
TraceReceive(message);
if (typeof (UnknownPackage) == message.GetType())
{
return;
}
if (typeof (McpeDisconnect) == message.GetType())
{
McpeDisconnect msg = (McpeDisconnect) message;
Log.InfoFormat("Disconnect {1}: {0}", msg.message, Username);
SendDisconnectionNotification();
StopClient();
return;
}
if (typeof (ConnectedPing) == message.GetType())
{
ConnectedPing msg = (ConnectedPing) message;
SendConnectedPong(msg.sendpingtime);
return;
}
if (typeof (McpeFullChunkData) == message.GetType())
{
//McpeFullChunkData msg = (McpeFullChunkData) message;
//ChunkColumn chunk = ClientUtils.DecocedChunkColumn(msg.chunkData);
//if (chunk != null)
//{
// Log.DebugFormat("Chunk X={0}", chunk.x);
// Log.DebugFormat("Chunk Z={0}", chunk.z);
// //ClientUtils.SaveChunkToAnvil(chunk);
//}
return;
}
if (typeof (ConnectionRequestAccepted) == message.GetType())
{
Thread.Sleep(50);
SendNewIncomingConnection();
//_connectedPingTimer = new Timer(state => SendConnectedPing(), null, 1000, 1000);
Thread.Sleep(50);
SendLogin(Username);
return;
}
if (typeof (McpeSetSpawnPosition) == message.GetType())
{
McpeSetSpawnPosition msg = (McpeSetSpawnPosition) message;
_spawn = new Vector3(msg.x, msg.y, msg.z);
_level.SpawnX = (int) _spawn.X;
_level.SpawnY = (int) _spawn.Y;
_level.SpawnZ = (int) _spawn.Z;
//.........这里部分代码省略.........
示例13: HandlePackage
private void HandlePackage(Package message)
{
if (typeof(McpeBatch) == message.GetType())
{
OnBatch(message);
return;
}
//TraceReceive(message);
if (typeof(UnknownPackage) == message.GetType())
{
return;
}
else if (typeof(McpeDisconnect) == message.GetType())
{
McpeDisconnect msg = (McpeDisconnect)message;
Log.InfoFormat("Disconnect {1}: {0}", msg.message, Username);
//SendDisconnectionNotification();
StopClient();
return;
}
else if (typeof(ConnectedPing) == message.GetType())
{
ConnectedPing msg = (ConnectedPing)message;
SendConnectedPong(msg.sendpingtime);
return;
}
else if (typeof(McpeFullChunkData) == message.GetType())
{
OnFullChunkData(message);
return;
}
else if (typeof(ConnectionRequestAccepted) == message.GetType())
{
OnConnectionRequestAccepted();
return;
}
else if (typeof(McpeSetSpawnPosition) == message.GetType())
{
OnMcpeSetSpawnPosition(message);
return;
}
else if (typeof(McpeStartGame) == message.GetType())
{
OnMcpeStartGame(message);
return;
}
else if (typeof(McpeTileEvent) == message.GetType())
{
OnMcpeTileEvent(message);
return;
}
else if (typeof(McpeAddEntity) == message.GetType())
{
OnMcpeAddEntity(message);
return;
}
else if (typeof(McpeAddPlayer) == message.GetType())
{
OnMcpeAddPlayer(message);
return;
}
else if (typeof(McpeSetEntityData) == message.GetType())
{
OnMcpeSetEntityData(message);
return;
}
else if (typeof(McpeMovePlayer) == message.GetType())
{
//OnMcpeMovePlayer(message);
return;
}
else if (typeof(McpeUpdateBlock) == message.GetType())
{
OnMcpeUpdateBlock(message);
return;
}
else if (typeof(McpeLevelEvent) == message.GetType())
{
OnMcpeLevelEvent(message);
return;
}
else if (typeof(McpeMobEffect) == message.GetType())
//.........这里部分代码省略.........
示例14: HandlePackage
internal void HandlePackage(int datagramSequenceNumber, Package message, PlayerNetworkSession playerSession)
{
TraceReceive(message);
message.DatagramSequenceNumber = datagramSequenceNumber;
if (typeof (UnknownPackage) == message.GetType())
{
message.PutPool();
return;
}
if (typeof (McpeBatch) == message.GetType())
{
McpeBatch batch = (McpeBatch) message;
var messages = new List<Package>();
// Get bytes
byte[] payload = batch.payload;
// Decompress bytes
MemoryStream stream = new MemoryStream(payload);
if (stream.ReadByte() != 0x78)
{
throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C");
}
stream.ReadByte();
using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false))
{
// Get actual package out of bytes
MemoryStream destination = new MemoryStream();
defStream2.CopyTo(destination);
byte[] internalBuffer = destination.ToArray();
messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer));
}
foreach (var msg in messages)
{
HandlePackage(datagramSequenceNumber, msg, playerSession);
}
batch.PutPool();
return;
}
message.Source = "HandlePackage";
playerSession.Player.HandlePackage(message);
message.PutPool();
}