public void Test() { ServerInstance si = new ServerInstance( UOM.ServerName, false, 0, 32 ); ClientInstance ci = new ClientInstance( UOM.ServerName, false ); ci.AddRecvFilterEvent += Ci_AddRecvFilterEvent; si.SendCommand( Command.AddRecvFilterConditional, new PacketFilterInfo(0xF3, new PacketFilterCondition[] { new PacketFilterCondition( 0, new byte[] { 0xF3 }, 1 ) } ).Serialize()); while (true) ; }
public void PacketFilterTest() { ServerInstance si = new ServerInstance(UOM.ServerName, false, 0, 32); ClientInstance ci = new ClientInstance(UOM.ServerName, false); ci.AddRecvFilterEvent += Ci_AddRecvFilterEvent; ci.SendPacketEvent += Ci_SendPacketEvent; si.SendCommand(Command.AddRecvFilterConditional, new PacketFilterInfo(0xFF, new PacketFilterCondition[] { new PacketFilterCondition(2, new byte[] { 0x12, 0x34, 0x56, 0x78 }, 4) }).Serialize()); byte[] packet = new byte[] { 0xFF, 0x01, 0x12, 0x34, 0x56, 0x78, }; byte[] packet2 = new byte[] { 0xFF, 0x00, 0x78, 0x56, 0x34, 0x12, }; si.SendCommand(Command.SendPacket, 0, (byte)PacketType.Server, packet); si.SendCommand(Command.SendPacket, 0, (byte)PacketType.Server, packet2); lock (m_FinishedLock) { Monitor.Wait(m_FinishedLock); } ci.Dispose(); si.Dispose(); }
public void PacketFilterTest() { ServerInstance si = new ServerInstance( UOM.ServerName, false, 0, 32 ); ClientInstance ci = new ClientInstance( UOM.ServerName, false ); ci.AddRecvFilterEvent += Ci_AddRecvFilterEvent; ci.SendPacketEvent += Ci_SendPacketEvent; si.SendCommand( Command.AddRecvFilterConditional, new PacketFilterInfo( 0xFF, new PacketFilterCondition[] { new PacketFilterCondition( 2, new byte[] { 0x12, 0x34, 0x56, 0x78 }, 4 ) } ).Serialize() ); byte[] packet = new byte[] { 0xFF, 0x01, 0x12, 0x34, 0x56, 0x78, }; byte[] packet2 = new byte[] { 0xFF, 0x00, 0x78, 0x56, 0x34, 0x12, }; si.SendCommand( Command.SendPacket, 0, (byte) PacketType.Server, packet ); si.SendCommand( Command.SendPacket, 0, (byte) PacketType.Server, packet2 ); lock (m_FinishedLock) { Monitor.Wait( m_FinishedLock ); } ci.Dispose(); si.Dispose(); }
public void Test() { ServerInstance si = new ServerInstance(UOM.ServerName, false, 0, 32); ClientInstance ci = new ClientInstance(UOM.ServerName, false); ci.AddRecvFilterEvent += Ci_AddRecvFilterEvent; si.SendCommand(Command.AddRecvFilterConditional, new PacketFilterInfo(0xF3, new PacketFilterCondition[] { new PacketFilterCondition(0, new byte[] { 0xF3 }, 1) }).Serialize()); while (true) { ; } }
protected override void OnMessage(MessageEventArgs e) { try { if (!e.IsText) { return; } var msg = JsonConvert.DeserializeObject <Message>(e.Data); if (!Authentificated) { if (msg.Type == MessageType.AuthRequest) { var authData = JsonConvert.DeserializeObject <MessageAuth>(e.Data); if (authData.Password == Program.Config.RemoteManager.Password && authData.Username == Program.Config.RemoteManager.Username) { Authentificated = true; Program.Clients.Add(this); SendMessage(new Message() { Type = MessageType.AuthCorrect }); SendServerList(); } else { SendMessage(new Message() { Type = MessageType.AuthIncorrect }); } } else { SendMessage(new Message() { Type = MessageType.AuthRequired }); } return; } string serverName; ServerInstance server; switch (msg.Type) { case MessageType.UnsubscribeServer: if (SubscribedServer != null) { SubscribedServer.UnsubscribeClient(this); } SubscribedServer = null; break; case MessageType.SubscribeServer: serverName = JsonConvert.DeserializeObject <MessageServerName>(e.Data).Name; server = Program.Server.Find(s => s.Name == serverName); if (server != null) { if (SubscribedServer != null) { SubscribedServer.UnsubscribeClient(this); } SubscribedServer = server; server.SubscribeClient(this); } break; case MessageType.StartServer: serverName = JsonConvert.DeserializeObject <MessageServerName>(e.Data).Name; server = Program.Server.Find(s => s.Name == serverName); if (server != null) { server.Start(); } break; case MessageType.StopServer: serverName = JsonConvert.DeserializeObject <MessageServerName>(e.Data).Name; server = Program.Server.Find(s => s.Name == serverName); if (server != null) { server.Stop(); } break; case MessageType.RestartServer: serverName = JsonConvert.DeserializeObject <MessageServerName>(e.Data).Name; server = Program.Server.Find(s => s.Name == serverName); if (server != null) { server.Restart(); } break; case MessageType.ServerCommand: if (SubscribedServer != null) { string command = JsonConvert.DeserializeObject <MessageServerCommand>(e.Data).Command; SubscribedServer.SendCommand(command); } break; case MessageType.RequestServerList: SendServerList(); break; default: break; } } catch (JsonException jsonEx) { Console.WriteLine("Message json parse error: " + jsonEx.Message); } catch (Exception ex) { Console.WriteLine("Message error: " + ex.ToString()); } }