本文整理汇总了C#中Packet.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.ToString方法的具体用法?C# Packet.ToString怎么用?C# Packet.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Raw
/// <summary>Packet factory that adds multiple arguments to the pakcet</summary>
public static Packet Raw(string command, params string[] args)
{
Packet p = new Packet(command);
foreach (string arg in args)
p.Add(arg);
return Parse(p.ToString());
}
示例2: Send
/// <summary>
/// Sends <see cref="Packet"/> to remote service.
/// </summary>
/// <param name="p"><see cref="Packet"/> to send.</param>
internal static void Send( Packet p )
{
if ( Connection != null && Connection.Connected )
Connection.Send(p);
else
{
Logger.WriteLine(Source.InnerNetwork, "Failed to send packet to cache service, connection isn't active.");
Logger.WriteLine(p.ToString());
}
}
示例3: Handle
/// <summary>
/// Handles incoming <see cref="Packet"/>.
/// </summary>
/// <param name="p"><see cref="Packet"/> to handle.</param>
internal void Handle( Packet p )
{
switch ( p.FirstOpcode )
{
case ServiceLayer.Identity:
{
switch ( p.SecondOpcode )
{
case ServiceLayer.InitializeRequest:
{
Logger.WriteLine(Source.InnerNetwork, "Connected service requests connection initialization.");
return;
}
case ServiceLayer.SetSettingsRequest:
{
// set settings here
return;
}
}
break;
}
case WorldDataLayer.Identity:
{
switch ( p.SecondOpcode )
{
case WorldDataLayer.SetWorldActiveRequest:
{
Realtime.RealtimeManager.WorldsInfo.SetActive(Service.ServiceID);
Send(new SetWorldActiveResponse().ToPacket());
Logger.WriteLine(Source.InnerNetwork, "World 0x{0:x2} allowed to accept user connections", Service.ServiceID);
return;
}
}
break;
}
default:
{
break;
}
}
Logger.WriteLine(Source.InnerNetwork, "Unknown packet received from {0} service:{1}{2}", ServiceType.GameService, Environment.NewLine, p.ToString());
}
示例4: Handle
/// <summary>
/// Handles incoming <see cref="Packet"/>.
/// </summary>
/// <param name="p"><see cref="Packet"/> to handle.</param>
internal void Handle( Packet p )
{
switch ( p.FirstOpcode )
{
case ServiceLayer.Identity:
{
switch ( p.SecondOpcode )
{
default:
break;
}
break;
}
}
Logger.WriteLine("Unknown packet received: {0}", p.ToString());
}
示例5: HandlePacketTest
public void HandlePacketTest()
{
var ServerManager = new ServerManager();
for (int n = 0; n < 2; n++)
{
var ReceivedPacket = new Packet(
Packet.PacketType.GetRankingIdByName,
new MemoryStream().PreservePositionAndLock((Stream) =>
{
Stream.WriteStringz("-index1");
}
).ToArray()
);
var PacketToSend = new Packet(Packet.PacketType.GetRankingIdByName);
(new GetRankingIdByNameHandler()).HandlePacket(ServerManager, ReceivedPacket, PacketToSend);
Assert.AreEqual(
"Packet(Type=GetRankingIdByName, Data=00000000)",
PacketToSend.ToString()
);
}
for (int n = 0; n < 2; n++)
{
var ReceivedPacket = new Packet(
Packet.PacketType.GetRankingIdByName,
new MemoryStream().PreservePositionAndLock((Stream) =>
{
Stream.WriteStringz("+index1");
}
).ToArray()
);
var PacketToSend = new Packet(Packet.PacketType.GetRankingIdByName);
(new GetRankingIdByNameHandler()).HandlePacket(ServerManager, ReceivedPacket, PacketToSend);
Assert.AreEqual(
"Packet(Type=GetRankingIdByName, Data=01000000)",
PacketToSend.ToString()
);
}
}
示例6: Handle
/// <summary>
/// Handles incoming <see cref="Packet"/> objects.
/// </summary>
/// <param name="p"><see cref="Packet"/> to handle.</param>
internal void Handle( Packet p )
{
Logger.WriteLine("Received {0}", p.ToString());
switch ( p.FirstOpcode )
{
case ServiceLayer.Identity:
{
switch ( p.SecondOpcode )
{
case ServiceLayer.InitializeRequest:
{
return; // login service not handles incoming connections.
}
case ServiceLayer.InitializeResponse: // connection init response
{
InitializeResponse data = new InitializeResponse(p);
switch ( data.Answer )
{
case InitializeResponse.Accepted:
{
Logger.WriteLine(Source.InnerNetwork, "Connected to {0} (0x{1})", GameServiceConnection.Connection.ServiceType, GameServiceConnection.Connection.ServiceID.ToString("x2"));
return;
}
case InitializeResponse.Rejected:
{
Logger.WriteLine(Source.InnerNetwork, "Connection rejected by remote service {0} (0x{1})", ( ServiceType )data.RemoteServiceType, data.RemoteServiceID);
return;
}
}
return;
}
}
break;
}
}
Logger.WriteLine("Unknown packet received from {0} service on layer 0x{1}:{2}{3}", ServiceType.GameService, p.FirstOpcode.ToString("x2"), Environment.NewLine, p.ToString());
}
示例7: HandleChangeMap
public static void HandleChangeMap(Client pClient, Packet pPacket)
{
Console.WriteLine(pPacket.ToString());
Map Map = pClient.Character.ChannelMaps[pClient.Character.MapId];
byte Unk = pPacket.ReadByte();
int Opcode = pPacket.ReadInt();
int ToMap = pPacket.ReadInt();
switch (Opcode)
{
case 0:
{
if (pClient.Character.HP == 0)
{
//pClient.Character.HandleDeath();
}
break;
}
case -1:
{
string PortalName = pPacket.ReadMapleString();
if (Map.Portals.ContainsKey(PortalName)){
Portal Portal = Map.Portals[PortalName];
Portal To = Master.Instance.DataProvider.Maps[Portal.ToMapID].Portals[Portal.ToName];
pClient.Character.ChangeMap(Portal.ToMapID, To);
}
break;
}
default:
{
// Change to map if admin.
}
break;
}
}
示例8: Request
public IPacketCache Request(Packet request) {
IPacketCache cache = null;
if (request.IsResponse == false) {
var key = request.ToString();
lock (this.CacheLock) {
// Have we got it cached and is it valid?
if (this.Cache.ContainsKey(key) == true) {
if (this.Cache[key].Response != null) {
// Yes, we do. Return this.
cache = this.Cache[key];
}
// else return null
}
// No, check if we should cache it.
else {
this.CacheIfApplicable(key, request);
}
}
}
return cache;
}
示例9: AddSentPacket
public void AddSentPacket(string packetName, byte[] buffer, string callStack)
{
packetName = "[S] " + packetName;
lock (PacketsLock)
{
if (Packets == null)
return;
Packet packet = new Packet(true, packetName, buffer, callStack);
Packets.Add(packet);
Dispatcher.Invoke(() =>
{
ListBoxItem item = new ListBoxItem
{
Content = packet.ToString(),
Background = new SolidColorBrush(Colors.LightBlue)
};
PacketsListBox.Items.Add(item);
});
}
}
示例10: AddRecvPacket
public void AddRecvPacket(string packetName, byte[] buffer, string callStack)
{
packetName = "[C] " + packetName;
lock (PacketsLock)
{
if (Packets == null)
return;
Packet packet = new Packet(false, packetName, buffer, callStack);
Packets.Add(packet);
Dispatcher.BeginInvoke(new System.Threading.ThreadStart(delegate
{
ListBoxItem item = new ListBoxItem
{
Content = packet.ToString(),
Background = new SolidColorBrush(Colors.WhiteSmoke)
};
PacketsListBox.Items.Add(item);
}));
}
}
示例11: Handle
internal static void Handle( Packet p )
{
switch ( p.FirstOpcode )
{
case ServiceLayer.Identity:
{
switch ( p.SecondOpcode )
{
case ServiceLayer.InitializeRequest:
{
return; // login service not handles incoming connections.
}
case ServiceLayer.InitializeResponse: // connection init response
{
InitializeResponse data = new InitializeResponse(p);
switch ( data.Answer )
{
case InitializeResponse.Accepted:
{
CacheServiceConnection.Connection.SetRemoteService(data.RemoteServiceID, ( ServiceType )data.RemoteServiceType);
Logger.WriteLine(Source.InnerNetwork, "Connected to {0} (0x{1})", CacheServiceConnection.Connection.ServiceType, CacheServiceConnection.Connection.ServiceID.ToString("x2"));
// send set-settings request
//CacheServiceConnection.Send
// (
// new SetSettingsRequest().ToPacket
// (
// new LoginServiceSettings
// (
// Service.LocalServiceUniqueId,
// Service.AutoCreateUsers,
// Service.DefaultAccessLevel
// )
// )
// );
return;
}
case InitializeResponse.Rejected:
{
Logger.WriteLine(Source.InnerNetwork, "Connection rejected by remote service {0} (0x{1})", ( ServiceType )data.RemoteServiceType, data.RemoteServiceID);
return;
}
}
return;
}
case ServiceLayer.SetSettingsRequest:
{
return; // login service not handles remote service settings request
}
case ServiceLayer.SetSettingsResponse:
{
SetSettingsResponse response = new SetSettingsResponse(p);
switch ( response.Response )
{
case SetSettingsResponse.Accepted:
{
Logger.WriteLine(Source.InnerNetwork, "Cache service accepted service settings.");
//UserConnectionsListener.Enable(); // start listen incoming user connections
return;
}
default:
{
Service.Terminate(new ServiceShutdownEventArgs("Cache service rejected settings setup."));
return;
}
}
}
default:
{
Logger.WriteLine("Unknown packet received on layer 0x{0}: {1}", ServiceLayer.Identity.ToString("x2"), p.ToString());
return;
}
}
}
}
}
示例12: Handle
internal static void Handle( Packet p )
{
Logger.WriteLine(Source.InnerNetwork, "Unknown packet received from {0} service:{1}{2}", ServiceType.NpcService, Environment.NewLine, p.ToString());
}
示例13: Send
/// <summary>
/// Sends packet to client.
/// </summary>
/// <param name="p"><see cref="Packet"/> to send.</param>
internal void Send( Packet p )
{
p.Prepare(sizeof(short));
Logger.WriteLine(Source.OuterNetwork, "Sending: \r\n{0}", p.ToString());
SendData(p.GetBuffer());
}
示例14: Handle
/// <summary>
/// Handles incoming packet.
/// </summary>
/// <param name="packet">Incoming packet.</param>
protected override void Handle( Packet packet )
{
Logger.WriteLine(Source.OuterNetwork, "Received: {0}", packet.ToString());
//Logger.WriteLine(Source.Debug, "packet.FirstOpcode = {0}", packet.FirstOpcode);
switch ( State )
{
case UserConnectionState.Disconnected:
throw new InvalidOperationException();
case UserConnectionState.Connected:
{
switch ( packet.FirstOpcode )
{
case 0x0e: // protocol
{
int revision = packet.ReadInt();
//Logger.WriteLine(Source.Debug, "Protocol Revision: {0}", revision);
if ( revision == -2 )
{
CloseConnection();
// remove from active connections list
}
if ( revision < Settings.Default.WorldMinProtoRev || revision > Settings.Default.WorldMaxProtoRev )
{
CloseConnection();
// remove from active connections, log
}
byte[] keyIN = BlowFishKeygen.GetNext();
//byte[] keyOUT = BlowFishKeygen.GetNext();
m_Crypt = new GameCrypt();
m_Crypt.setKey(keyIN);
SendNoCrypt(KeyPacket.Create(keyIN));
BeginReceive();
break;
}
case 0x2b: // login
{
new AuthLogin(packet).RunImpl();
break;
}
default:
{
Logger.WriteLine(Source.OuterNetwork, "Unknown packet on state {0}: Opcode = {1}", State, packet.FirstOpcode);
break;
}
}
return;
}
case UserConnectionState.Authed:
{
switch (packet.FirstOpcode)
{
default:
{
Logger.WriteLine(Source.OuterNetwork, "Unknown packet on state {0}: Opcode = {1}", State, packet.FirstOpcode);
break;
}
}
return;
}
}
}
示例15: LogPacket
// LogPacket: dump a packet to the console
private void LogPacket(Packet packet, IPEndPoint endPoint, Direction direction)
{
string packetText = packet.ToString();
if (logGrep == null || (logGrep != null && Regex.IsMatch(packetText, logGrep)))
{
string line = String.Format("{0} {1,21} {2,5} {3}{4}{5}"
, direction == Direction.Incoming ? "<--" : "-->"
, endPoint
, packet.Header.Sequence
, InterpretOptions(packet.Header.Flags)
, Environment.NewLine
, packetText
);
Console.WriteLine(line);
if (output != null)
output.WriteLine(line);
}
}