protected override void Run() { // Get host EndPoint string[] domain = GetDomain(m_request); IPEndPoint hostEndPoint = GetHostEndPoint(domain[0], domain[1]); if (hostEndPoint == null) { ExitInstance(); return; } // Connect to remote host and authenticate connection TcpClient server = new TcpClient(); server.Connect(hostEndPoint); // Accept tunneling byte[] AcceptConnection = Encoding.ASCII.GetBytes("HTTP/1.1 200 Established\r\n\r\n"); ProxyOperation.Write(m_client.GetStream(), AcceptConnection, 0, AcceptConnection.Length); StreamState streamState = new StreamState() { ClientStream = m_client.GetStream(), ServerStream = server.GetStream(), }; Thread DoTransfer = new Thread(DoTransferData) { Name = "HTTPS Transfer Data", IsBackground = true }; DoTransfer.Start(streamState); List <byte> ReceivedBytes; do { ReceivedBytes = ProxyOperation.ReadRequest(m_client.GetStream()); int errCode = ProxyOperation.Write(server.GetStream(), ReceivedBytes.ToArray(), 0, ReceivedBytes.Count); if (errCode < 0) { ReceivedBytes.Clear(); Logging.Log(string.Format("Socket Exception with error code: {0}", errCode), LoggingLevel.Error); } } while (ReceivedBytes.Count != 0); ExitInstance(); }
public void ProcessData() { try { if (this.Socket != null) { if (this.Socket.Available <= 0) { return; } int byteCount = this.Socket.Receive(this.Buffer, this.Buffer.Length, SocketFlags.None); if (byteCount <= 0) { return; } ReceivedBytes.AddRange(this.Buffer); } } catch (Exception ex) { Console.WriteLine(ex.Message); } byte[] data = ReceivedBytes.ToArray(); IncomingPacket[] packets = IncomingPacket.SplitLoginServerPackets(data); foreach (IncomingPacket packet in packets) { if (packet == null) { return; } if (m_RemainingBytes != null) { byte[] buffer = new byte[m_RemainingBytes.Length + packet.Buffer.Length]; Array.Copy(m_RemainingBytes, 0, buffer, 0, m_RemainingBytes.Length); Array.Copy(packet.Buffer, 0, buffer, 0, packet.Buffer.Length); packet.Buffer = buffer; m_RemainingBytes = null; } if (!packet.VerifyHeaders((int)SessionKey)) { m_RemainingBytes = packet.Buffer; } else { packet.Position = PacketHeader.Size; // Ignore headers uint header = packet.ReadUInt(); switch (header) { case SharpFly_Packet_Library.Packets.LoginServer.Incoming.OpCodes.LOGIN_REQUEST: LoginRequest(packet); break; case SharpFly_Packet_Library.Packets.LoginServer.Incoming.OpCodes.PING: break; case SharpFly_Packet_Library.Packets.LoginServer.Incoming.OpCodes.SOCK_FIN: break; case SharpFly_Packet_Library.Packets.LoginServer.Incoming.OpCodes.RELOG_REQUEST: RelogRequest(packet); break; default: Console.WriteLine(String.Format("Unknown packet header {0:X08}", header)); break; } } } ReceivedBytes.Clear(); }
public void ProcessData() { if (!SocketChecker.IsSocketConnected(this.Socket)) { this.Dispose(); return; } if (this.Socket != null) { if (!this.Socket.Connected) { this.Dispose(); return; } if (this.Socket.Available <= 0) { return; } int byteCount = this.Socket.Receive(this.Buffer, this.Buffer.Length, SocketFlags.None); if (byteCount <= 0) { return; } ReceivedBytes.AddRange(this.Buffer); } byte[] data = ReceivedBytes.ToArray(); IncomingPacket[] packets = IncomingPacket.SplitClusterServerPackets(data); foreach (IncomingPacket packet in packets) { if (packet == null) { return; } if (m_RemainingBytes != null) { byte[] buffer = new byte[m_RemainingBytes.Length + packet.Buffer.Length]; Array.Copy(m_RemainingBytes, 0, buffer, 0, m_RemainingBytes.Length); Array.Copy(packet.Buffer, 0, buffer, 0, packet.Buffer.Length); packet.Buffer = buffer; m_RemainingBytes = null; } if (!packet.VerifyHeaders((int)SessionKey)) { m_RemainingBytes = packet.Buffer; } else { packet.Position = PacketHeader.DataStartPosition; // Ignore headers and -1 integer uint header = packet.ReadUInt(); switch (header) { case SharpFly_Packet_Library.Packets.ClusterServer.Incoming.OpCodes.QUERY_TICK_COUNT: OnQueryTickCount(packet); break; case SharpFly_Packet_Library.Packets.ClusterServer.Incoming.OpCodes.AUTH_QUERY: OnAuthQuery(packet); break; case SharpFly_Packet_Library.Packets.ClusterServer.Incoming.OpCodes.PING: OnPing(packet); break; case SharpFly_Packet_Library.Packets.ClusterServer.Incoming.OpCodes.CHARACTER_LIST: OnCharacterListRequest(packet); break; case SharpFly_Packet_Library.Packets.ClusterServer.Incoming.OpCodes.DELETE_CHARACTER: OnDeleteCharacter(packet); break; case SharpFly_Packet_Library.Packets.ClusterServer.Incoming.OpCodes.CREATE_CHARACTER: OnCreateCharacter(packet); break; case SharpFly_Packet_Library.Packets.ClusterServer.Incoming.OpCodes.WORLD_TRANSFER: Console.WriteLine("World transfer packet"); break; default: Console.WriteLine(String.Format("Unknown packet header {0:X08}", header)); break; } } } ReceivedBytes.Clear(); }