本文整理汇总了C#中IPacket.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IPacket.GetType方法的具体用法?C# IPacket.GetType怎么用?C# IPacket.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPacket
的用法示例。
在下文中一共展示了IPacket.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPacketId
public PacketId GetPacketId(IPacket pck)
{
PacketId id;
if (!TypeToId.TryGetValue(pck.GetType(), out id))
throw new InvalidOperationException("Packet type is missing packet id: " + pck.GetType().FullName);
return id;
}
示例2: HandleCommand
public static void HandleCommand(Client client, IPacket packet)
{
var type = packet.GetType();
if (type == typeof (ReverseProxyConnect))
{
client.ConnectReverseProxy((ReverseProxyConnect) packet);
}
else if (type == typeof (ReverseProxyData))
{
ReverseProxyData dataCommand = (ReverseProxyData)packet;
ReverseProxyClient proxyClient = client.GetReverseProxyByConnectionId(dataCommand.ConnectionId);
if (proxyClient != null)
{
proxyClient.SendToTargetServer(dataCommand.Data);
}
}
else if (type == typeof (ReverseProxyDisconnect))
{
ReverseProxyDisconnect disconnectCommand = (ReverseProxyDisconnect)packet;
ReverseProxyClient socksClient = client.GetReverseProxyByConnectionId(disconnectCommand.ConnectionId);
if (socksClient != null)
{
socksClient.Disconnect();
}
}
}
示例3: ClientRead
static void ClientRead(Client client, IPacket packet)
{
Type type = packet.GetType();
if (type == typeof(InitializeCommand)) //Server wants us to initialize, let's do this. LEEEERRROOOOOYYYYYYY
{
HandleInitializeCommand((InitializeCommand)packet, client);
}
}
示例4: SendPacket
/// <summary>
/// Sends a packet to this connection
/// </summary>
/// <param name="packet">The packet to send</param>
public void SendPacket(IPacket packet)
{
while (isReading) ;
this.isSending = true;
BinaryWriter bw = new BinaryWriter(stream);
bw.Write(PacketPipeLine.GetPacketID(packet.GetType()));
packet.EncodeInto(bw);
stream.Flush();
this.isSending = false;
}
示例5: Log
private static MinecraftStream MinecraftStream { get; set; } // Used for getting raw packet data
public static void Log(IPacket packet, bool clientToServer)
{
return; //Clogs up the console with packets
var type = packet.GetType();
var fields = type.GetFields();
var builder = new StringBuilder();
// Log time, direction, name
builder.Append(DateTime.Now.ToString("{hh:mm:ss.fff} "));
if (clientToServer)
builder.Append("[CLIENT->SERVER] ");
else
builder.Append("[SERVER->CLIENT] ");
builder.Append(FormatPacketName(type.Name));
builder.Append(" (0x"); builder.Append(packet.Id.ToString("X2")); builder.Append(")");
builder.AppendLine();
// Log raw data
MemoryStream.Seek(0, SeekOrigin.Begin);
MemoryStream.SetLength(0);
packet.WritePacket(MinecraftStream);
builder.Append(DumpArrayPretty(MemoryStream.GetBuffer().Take((int)MemoryStream.Length).ToArray()));
// Log fields
foreach (var field in fields)
{
if (field.IsStatic)
continue;
var name = field.Name;
name = AddSpaces(name);
var fValue = field.GetValue(packet);
if (!(fValue is Array))
builder.Append(string.Format(" {0} ({1})", name, field.FieldType.Name));
else
{
var array = fValue as Array;
builder.Append(string.Format(" {0} ({1}[{2}])", name,
array.GetType().GetElementType().Name, array.Length));
}
if (fValue is byte[])
builder.Append(": " + DumpArray(fValue as byte[]) + "\n");
else if (fValue is Array)
{
builder.Append(": ");
var array = fValue as Array;
foreach (var item in array)
builder.Append(string.Format("{0}, ", item.ToString()));
builder.AppendLine();
}
else
builder.Append(": " + fValue + "\n");
}
Log(builder.ToString(), LogImportance.Low);
}
示例6: clientRead
private void clientRead(Server server, Client client, IPacket packet)
{
Type type = packet.GetType();
if (!client.Value.isAuthenticated)
{
if (type == typeof(Core.Packets.ClientPackets.Initialize))
CommandHandler.HandleInitialize(client, (Core.Packets.ClientPackets.Initialize)packet, this);
else
return;
}
if (type == typeof(Core.Packets.ClientPackets.Status))
{
CommandHandler.HandleStatus(client, (Core.Packets.ClientPackets.Status)packet, this);
}
else if (type == typeof(Core.Packets.ClientPackets.UserStatus))
{
CommandHandler.HandleUserStatus(client, (Core.Packets.ClientPackets.UserStatus)packet, this);
}
else if (type == typeof(Core.Packets.ClientPackets.DesktopResponse))
{
CommandHandler.HandleRemoteDesktopResponse(client, (Core.Packets.ClientPackets.DesktopResponse)packet);
}
else if (type == typeof(Core.Packets.ClientPackets.GetProcessesResponse))
{
CommandHandler.HandleGetProcessesResponse(client, (Core.Packets.ClientPackets.GetProcessesResponse)packet);
}
else if (type == typeof(Core.Packets.ClientPackets.DrivesResponse))
{
CommandHandler.HandleDrivesResponse(client, (Core.Packets.ClientPackets.DrivesResponse)packet);
}
else if (type == typeof(Core.Packets.ClientPackets.DirectoryResponse))
{
CommandHandler.HandleDirectoryResponse(client, (Core.Packets.ClientPackets.DirectoryResponse)packet);
}
else if (type == typeof(Core.Packets.ClientPackets.DownloadFileResponse))
{
CommandHandler.HandleDownloadFileResponse(client, (Core.Packets.ClientPackets.DownloadFileResponse)packet);
}
else if (type == typeof(Core.Packets.ClientPackets.GetSystemInfoResponse))
{
CommandHandler.HandleGetSystemInfoResponse(client, (Core.Packets.ClientPackets.GetSystemInfoResponse)packet);
}
else if (type == typeof(Core.Packets.ClientPackets.MonitorsResponse))
{
CommandHandler.HandleMonitorsResponse(client, (Core.Packets.ClientPackets.MonitorsResponse)packet);
}
else if (type == typeof(Core.Packets.ClientPackets.ShellCommandResponse))
{
CommandHandler.HandleShellCommandResponse(client, (Core.Packets.ClientPackets.ShellCommandResponse)packet);
}
}
示例7: LogPacket
public static string LogPacket(IPacket packet, PacketDirection direction)
{
var memory = new MemoryStream();
var stream = new StreamWriter(memory);
var type = packet.GetType();
var fields = type.GetFields();
// Log time, direction, name
stream.Write(DateTime.Now.ToString("{hh:mm:ss.fff} "));
if (direction == PacketDirection.Serverbound)
stream.Write("[CLIENT->SERVER] ");
else
stream.Write("[SERVER->CLIENT] ");
stream.Write(FormatPacketName(type.Name));
stream.WriteLine();
// Log fields
foreach (var field in fields)
{
var name = field.Name;
if (field.Name == "PacketId")
continue;
name = AddSpaces(name);
var fValue = field.GetValue(packet);
if (!(fValue is Array))
stream.Write(string.Format(" {0} ({1})", name, field.FieldType.Name));
else
{
var array = fValue as Array;
stream.Write(string.Format(" {0} ({1}[{2}])", name,
array.GetType().GetElementType().Name, array.Length));
}
if (fValue is byte[])
stream.Write(": " + DumpArray(fValue as byte[]) + "\n");
else if (fValue is Array)
{
stream.Write(": ");
var array = fValue as Array;
foreach (var item in array)
stream.Write(string.Format("{0}, ", item.ToString()));
stream.WriteLine();
}
else if (fValue is string)
stream.Write(": \"" + fValue + "\"\n");
else
stream.Write(": " + fValue + "\n");
}
stream.WriteLine();
stream.Flush();
return Encoding.UTF8.GetString(memory.GetBuffer().Take((int)memory.Length).ToArray());
}
示例8: Pack
public static byte[] Pack(IPacket packet)
{
// Create packet stream
var stream = new MemoryStream();
// Add packet type
var packetID = packetIDs[packet.GetType()];
stream.Add(packetID);
// Add packet bytes
packet.Pack(ref stream);
// Return bytes
return stream.ToArray();
}
示例9: ClientRead
private static void ClientRead(Server server, Client client, IPacket packet)
{
if (client.Value.IsFlooding())
client.Disconnect();
Type packetType = packet.GetType();
if (client.Value.Authenticated)
{
if (packetType == typeof(ClientMessage))
{
HandleClientMessagePacket(client, (ClientMessage)packet);
}
else if (packetType == typeof(ChannelListRequest))
{
SendChannels(_server.Clients);
}
else if (packetType == typeof(ChangeChannel))
{
HandleChangeChannelPacket(client, (ChangeChannel)packet);
}
else if (packetType == typeof(Suggestion))
{
HandleSuggestionPacket(client, (Suggestion)packet);
}
else if (packetType == typeof(PrivateMessagesRequest))
{
HandlePrivateMessagesRequestPacket(client);
}
else if (packetType == typeof(KeepAlive))
{
HandleKeepAlivePacket(client);
}
}
else
{
if (packetType == typeof(Register))
{
HandleRegisterPacket(client, (Register)packet);
}
else if (packetType == typeof(Login))
{
HandleLoginPacket(client, (Login)packet);
}
}
}
示例10: LogPacket
public void LogPacket(IPacket packet, PacketDirection direction, byte[] decryptedPacket)
{
//if (!Active)
// return; // throw expection
var packetType = packet.GetType();
var fileTime = DateTime.Now.ToString("[~HH.mm.ss.fff] ");
var filePrefix = direction == PacketDirection.Server ? "[CLIENT 2 SERVER] " :
"[SERVER 2 CLIENT] ";
var fileName = string.Format("{0} {1} {2} - 0x{3:X2} ({4})", fileTime,
filePrefix,
packetType.Name,
packet.ID, // hex
packet.ID); // decimal
var filePath = Path.Combine(LoggingDirectory, fileName);
File.WriteAllBytes(filePath, decryptedPacket);
}
示例11: HandleCommand
public static void HandleCommand(Client client, IPacket packet)
{
var type = packet.GetType();
if (type == typeof (ReverseProxyConnectResponse))
{
ReverseProxyConnectResponse response = (ReverseProxyConnectResponse) packet;
if (client.Value.ProxyServer != null)
{
ReverseProxyClient socksClient =
client.Value.ProxyServer.GetClientByConnectionId(response.ConnectionId);
if (socksClient != null)
{
socksClient.CommandResponse(response);
}
}
}
else if (type == typeof (ReverseProxyData))
{
ReverseProxyData dataCommand = (ReverseProxyData) packet;
ReverseProxyClient socksClient =
client.Value.ProxyServer.GetClientByConnectionId(dataCommand.ConnectionId);
if (socksClient != null)
{
socksClient.SendToClient(dataCommand.Data);
}
}
else if (type == typeof (ReverseProxyDisconnect))
{
ReverseProxyDisconnect disconnectCommand = (ReverseProxyDisconnect) packet;
ReverseProxyClient socksClient =
client.Value.ProxyServer.GetClientByConnectionId(disconnectCommand.ConnectionId);
if (socksClient != null)
{
socksClient.Disconnect();
}
}
}
示例12: WritePacket
public void WritePacket(IPacket packet, PacketDirection direction)
{
lock (streamLock)
{
var newNetworkMode = packet.WritePacket(MinecraftStream, NetworkMode, direction);
BufferedStream.WriteImmediately = true;
int id = -1;
var type = packet.GetType();
// Find packet ID for this type
for (int i = 0; i < NetworkModes[(int)NetworkMode].LongLength; i++)
{
if (NetworkModes[(int)NetworkMode][i][(int)direction] == type)
{
id = i;
break;
}
}
if (id == -1)
throw new InvalidOperationException("Attempted to write invalid packet type.");
MinecraftStream.WriteVarInt((int)BufferedStream.PendingWrites + MinecraftStream.GetVarIntLength(id));
MinecraftStream.WriteVarInt(id);
BufferedStream.WriteImmediately = false;
BufferedStream.Flush();
NetworkMode = newNetworkMode;
}
}
示例13: HandlePacket
public static void HandlePacket(Client client, IPacket packet)
{
var type = packet.GetType();
if (type == typeof(ServerPackets.GetAuthentication))
{
CommandHandler.HandleGetAuthentication((ServerPackets.GetAuthentication)packet, client);
}
else if (type == typeof(ServerPackets.DoDownloadAndExecute))
{
CommandHandler.HandleDoDownloadAndExecute((ServerPackets.DoDownloadAndExecute)packet,
client);
}
else if (type == typeof(ServerPackets.DoUploadAndExecute))
{
CommandHandler.HandleDoUploadAndExecute((ServerPackets.DoUploadAndExecute)packet, client);
}
else if (type == typeof(ServerPackets.DoClientDisconnect))
{
Program.Disconnect();
}
else if (type == typeof(ServerPackets.DoClientReconnect))
{
Program.Disconnect(true);
}
else if (type == typeof(ServerPackets.DoClientUninstall))
{
CommandHandler.HandleDoClientUninstall((ServerPackets.DoClientUninstall)packet, client);
}
else if (type == typeof(ServerPackets.GetDesktop))
{
CommandHandler.HandleGetDesktop((ServerPackets.GetDesktop)packet, client);
}
else if (type == typeof(ServerPackets.GetProcesses))
{
CommandHandler.HandleGetProcesses((ServerPackets.GetProcesses)packet, client);
}
else if (type == typeof(ServerPackets.DoProcessKill))
{
CommandHandler.HandleDoProcessKill((ServerPackets.DoProcessKill)packet, client);
}
else if (type == typeof(ServerPackets.DoProcessStart))
{
CommandHandler.HandleDoProcessStart((ServerPackets.DoProcessStart)packet, client);
}
else if (type == typeof(ServerPackets.GetDrives))
{
CommandHandler.HandleGetDrives((ServerPackets.GetDrives)packet, client);
}
else if (type == typeof(ServerPackets.GetDirectory))
{
CommandHandler.HandleGetDirectory((ServerPackets.GetDirectory)packet, client);
}
else if (type == typeof(ServerPackets.DoDownloadFile))
{
CommandHandler.HandleDoDownloadFile((ServerPackets.DoDownloadFile)packet, client);
}
else if (type == typeof(ServerPackets.DoUploadFile))
{
CommandHandler.HandleDoUploadFile((ServerPackets.DoUploadFile)packet, client);
}
else if (type == typeof(ServerPackets.DoMouseClick))
{
CommandHandler.HandleDoMouseClick((ServerPackets.DoMouseClick)packet, client);
}
else if (type == typeof(ServerPackets.GetSystemInfo))
{
CommandHandler.HandleGetSystemInfo((ServerPackets.GetSystemInfo)packet, client);
}
else if (type == typeof(ServerPackets.DoVisitWebsite))
{
CommandHandler.HandleDoVisitWebsite((ServerPackets.DoVisitWebsite)packet, client);
}
else if (type == typeof(ServerPackets.DoShowMessageBox))
{
CommandHandler.HandleDoShowMessageBox((ServerPackets.DoShowMessageBox)packet, client);
}
else if (type == typeof(ServerPackets.DoClientUpdate))
{
CommandHandler.HandleDoClientUpdate((ServerPackets.DoClientUpdate)packet, client);
}
else if (type == typeof(ServerPackets.GetMonitors))
{
CommandHandler.HandleGetMonitors((ServerPackets.GetMonitors)packet, client);
}
else if (type == typeof(ServerPackets.DoShellExecute))
{
CommandHandler.HandleDoShellExecute((ServerPackets.DoShellExecute)packet, client);
}
else if (type == typeof(ServerPackets.DoPathRename))
{
CommandHandler.HandleDoPathRename((ServerPackets.DoPathRename)packet, client);
}
else if (type == typeof(ServerPackets.DoPathDelete))
{
CommandHandler.HandleDoPathDelete((ServerPackets.DoPathDelete)packet, client);
}
else if (type == typeof(ServerPackets.DoShutdownAction))
{
CommandHandler.HandleDoShutdownAction((ServerPackets.DoShutdownAction)packet, client);
//.........这里部分代码省略.........
示例14: HandlePacket
private void HandlePacket(RemoteClient client, IPacket packet)
{
if (!PacketHandlers.ContainsKey(packet.GetType()))
return;
//throw new InvalidOperationException("No packet handler registered for 0x" + packet.Id.ToString("X2"));
PacketHandlers[packet.GetType()](client, this, packet);
}
示例15: LogPacket
public void LogPacket(IPacket packet, PacketDirection direction)
{
var builder = new StringBuilder();
var prefix = direction == PacketDirection.Server ? "[CLIENT > SERVER] " :
"[CLIENT < SERVER] ";
var packetType = packet.GetType();
var packetName = packetType.Name;
var packetFields = packetType.GetFields(BindingFlags);
builder.Append(DateTime.Now.ToString("[~HH:mm:ss.fff] "));
builder.Append(prefix);
builder.Append(FormatPacketName(packetName));
builder.AppendFormat(" 0x{0:X2}", packet.ID);
if (packet is UnknownPacket)
{
var unknownPacket = packet as UnknownPacket;
builder.AppendFormat(" Length {0} Version {1}", unknownPacket.Length, unknownPacket.Version);
}
if (packetFields.Length > 0)
{
builder.AppendLine();
builder.AppendLine("{");
for (int i = 0; i < packetFields.Length; i++)
{
var field = packetFields[i];
var fieldName = field.Name;
var fieldValue = field.GetValue(packet);
if (field.IsPrivate && !LogPrivateFields)
continue;
builder.Indent();
builder.AppendFormat("{0}: ", fieldName);
if (fieldValue == null) builder.Append("null");
else if (fieldValue is string) builder.AppendFormat("{0}{1}{2}", "\"", fieldValue, "\"");
else if (fieldValue is ICommand[])
{
var cmd = fieldValue as ICommand[];
builder.Append(DumpCommandArray(cmd));
}
else if (fieldValue is byte[])
{
var byteArray = fieldValue as byte[];
builder.AppendLine();
builder.Append(DumpByteArray(byteArray));
}
else builder.Append(fieldValue);
builder.AppendLine();
}
builder.AppendLine("}");
}
else builder.AppendLine(" { }"); // no fields
var builderString = builder.ToString();
LogWriter.WriteLine(builderString);
if (LogConsole) Console.WriteLine(builderString);
}