public override Action Handle(Packet packet) { var authPacket = AuthAction.Parse(packet); if (authPacket == null || authPacket.Action == AuthType.Null || authPacket.OpenPort == null) { return(base.Handle(packet)); } int port = authPacket.OpenPort ?? 0; var responce = resolveAuthAction(authPacket); return(() => AuthRequested?.Invoke(responce, new IPEndPoint(packet.Sender.Address, port))); }
public override Action Handle(Packet packet) { var authPacket = AuthAction.Parse(packet); if (authPacket == null || authPacket.Nickname == null) { return(base.Handle(packet)); } if (authPacket.OpenPort == null) { return () => { new Exception("Server doesn't provided open port"); } } ; var ip = new IPEndPoint(IPAddress.Loopback, authPacket.OpenPort.Value); switch (authPacket.Action) { case AuthType.UserExisting: return(() => { Error?.Invoke("Login is already reeserved"); }); case AuthType.WrongCredentials: return(() => { Error?.Invoke("Wrong password"); }); case AuthType.Success: { if (authPacket.Id == null) { return () => { new Exception("Server could not generete UUID"); } } ; Guid id = authPacket.Id.Value; return(() => { Success?.Invoke(new PublicUser(ip, id, authPacket.Nickname)); }); } default: return(() => { }); } } }