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(); }