public static void Handle(byte[] packet, SystemSocket socket) { ushort packetLength = BitConverter.ToUInt16(packet, 0); ushort packetType = BitConverter.ToUInt16(packet, 2); Console.WriteLine("Package received! User UID: {0} Length: {1} | Type: {2}", socket.UID, packetLength, (PacketType) packetType); switch ((PacketType) packetType) { case PacketType.Login: Process_LoginPacket(new LoginPacket(packet), socket); break; } }
private static void Process_LoginPacket(LoginPacket packet, SystemSocket socket) { var account = DataContext.Account.GetByUsername(packet.Username); bool loginSucess = account != null && account.Password == packet.Password; socket.Send(new ConnectPacket(loginSucess).Data); }
public void InvokeDisconect(SystemSocket client) { if (client.Connected) { client.Socket.Shutdown(SocketShutdown.Both); client.Socket.Close(); } else { OnDisconnect.SafeInvoke(client, null); client.Owner = null; } }