예제 #1
0
 public void OnPing(ILoginClient client, PingPacket pingPacket)
 {
     if (!pingPacket.IsTimeOut)
     {
         _loginPacketFactory.SendPong(client, pingPacket.Time);
     }
 }
예제 #2
0
        public AccountController()
        {
            _tokenContainer = new TokenContainer();
            var apiClient = new ApiClient(HttpClientInstance.Instance, _tokenContainer);

            _loginClient = new LoginClient(apiClient);
        }
예제 #3
0
 public static Task <LobbyItem[]> GetLobbyRoomsAsync(this Client client, ILoginClient loginClient, string roomType)
 {
     return(client.Multiplayer
            .ListRoomsAsync(roomType, null, 0, 0)
            .Then(r => r.Result
                  .Select(room => new LobbyItem(loginClient, room))
                  .ToArray())
            .ToSafeTask());
 }
예제 #4
0
 public static Task<LobbyItem[]> GetLobbyRoomsAsync(this Client client, ILoginClient loginClient, string roomType)
 {
     return client.Multiplayer
         .ListRoomsAsync(roomType, null, 0, 0)
         .Then(r => r.Result
             .Select(room => new LobbyItem(loginClient, room))
             .ToArray())
         .ToSafeTask();
 }
예제 #5
0
        public LobbyItem(ILoginClient client, RoomInfo roomInfo)
        {
            this._client = client;

            this.Id     = roomInfo.Id;
            this.Online = roomInfo.OnlineUsers;
            foreach (var data in roomInfo.RoomData)
            {
                switch (data.Key)
                {
                case "name":
                    this.Name = data.Value;
                    break;

                case "plays":
                    this.Plays = int.Parse(data.Value);
                    break;

                case "Likes":
                    this.Likes = int.Parse(data.Value);
                    break;

                case "Favorites":
                    this.Favorites = int.Parse(data.Value);
                    break;

                case "description":
                    this.Description = data.Value;
                    break;

                case "openworld":
                    this.OpenWorld = bool.Parse(data.Value);
                    break;

                case "needskey":
                    this.NeedsKey = (data.Value == "yep");
                    break;

                case "beta":
                    this.Beta = int.Parse(data.Value);
                    break;

                case "IsFeatured":
                    this.Featured = bool.Parse(data.Value);
                    break;

                case "IsCampaign":
                    this.Campaign = bool.Parse(data.Value);
                    break;

                case "LobbyPreviewEnabled":
                    this.LobbyPreviewEnabled = bool.Parse(data.Value);
                    break;
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Sends an authentication failed packet to the client.
        /// </summary>
        /// <param name="client">Client.</param>
        /// <param name="error">Authentication error type.</param>
        /// <param name="reason">Authentication error reason.</param>
        /// <param name="disconnectClient">A boolean value that indicates if we disconnect the client or not.</param>
        private void AuthenticationFailed(ILoginClient client, ErrorType error, string reason, bool disconnectClient = true)
        {
            _logger.LogWarning($"Unable to authenticate user from {client.Socket.RemoteEndPoint}. Reason: {reason}");
            _loginPacketFactory.SendLoginError(client, error);

            if (disconnectClient)
            {
                client.Disconnect();
            }
        }
예제 #7
0
        /// <inheritdoc />
        public void SendLoginError(ILoginClient client, ErrorType error)
        {
            using (var packet = new FFPacket())
            {
                packet.WriteHeader(PacketType.ERROR);
                packet.Write((int)error);

                client.Send(packet);
            }
        }
예제 #8
0
        /// <inheritdoc />
        public void SendPong(ILoginClient client, int time)
        {
            using (var packet = new FFPacket())
            {
                packet.WriteHeader(PacketType.PING);
                packet.Write(time);

                client.Send(packet);
            }
        }
예제 #9
0
        /// <inheritdoc />
        public void SendWelcome(ILoginClient client, uint sessionId)
        {
            using (var packet = new FFPacket())
            {
                packet.WriteHeader(PacketType.WELCOME);
                packet.Write(sessionId);

                client.Send(packet);
            }
        }
예제 #10
0
        public void OnCloseExistingConnection(ILoginClient client, CloseConnectionPacket closeConnectionPacket)
        {
            var otherConnectedClient = _loginServer.GetClientByUsername(closeConnectionPacket.Username);

            if (otherConnectedClient == null)
            {
                _logger.LogWarning($"Cannot find user with username '{closeConnectionPacket.Username}'.");
                return;
            }

            // TODO: disconnect client from server and ISC.
        }
예제 #11
0
        public void OnCertify(ILoginClient client, CertifyPacket certifyPacket)
        {
            if (certifyPacket.BuildVersion != _loginConfiguration.BuildVersion)
            {
                AuthenticationFailed(client, ErrorType.ILLEGAL_VER, "bad client build version");
                return;
            }

            DbUser user = _database.Users.FirstOrDefault(x => x.Username.Equals(certifyPacket.Username));
            AuthenticationResult authenticationResult = Authenticate(user, certifyPacket.Password);

            switch (authenticationResult)
            {
            case AuthenticationResult.BadUsername:
                AuthenticationFailed(client, ErrorType.FLYFF_ACCOUNT, "bad username");
                break;

            case AuthenticationResult.BadPassword:
                AuthenticationFailed(client, ErrorType.FLYFF_PASSWORD, "bad password");
                break;

            case AuthenticationResult.AccountSuspended:
                // TODO
                break;

            case AuthenticationResult.AccountTemporarySuspended:
                // TODO
                break;

            case AuthenticationResult.AccountDeleted:
                AuthenticationFailed(client, ErrorType.ILLEGAL_ACCESS, "logged in with deleted account");
                break;

            case AuthenticationResult.Success:
                if (_loginServer.IsClientConnected(certifyPacket.Username))
                {
                    AuthenticationFailed(client, ErrorType.DUPLICATE_ACCOUNT, "client already connected", disconnectClient: false);
                    return;
                }

                user.LastConnectionTime = DateTime.UtcNow;
                _database.Users.Update(user);
                _database.SaveChanges();

                _loginPacketFactory.SendServerList(client, certifyPacket.Username, _coreServer.GetConnectedClusters());
                client.SetClientUsername(certifyPacket.Username);
                _logger.LogInformation($"User '{client.Username}' logged succesfully from {client.Socket.RemoteEndPoint}.");
                break;

            default:
                break;
            }
        }
예제 #12
0
 public App(IConfiguration config, IConsole console,
            ICountryClient countryClient,
            IInitialAppClient initialAppClient,
            ILoginClient loginClient,
            IBatteryStatusClient batteryStatusClient)
 {
     _config              = config;
     _console             = console;
     _countryClient       = countryClient;
     _initialAppClient    = initialAppClient;
     _loginClient         = loginClient;
     _batteryStatusClient = batteryStatusClient;
 }
예제 #13
0
        public ApplicationManager(ILoginClient i_LoginClient)
        {
            m_loginClient = InputGuard.CheckNullArgument(i_LoginClient, nameof(i_LoginClient));
            m_ExitSignal  = false;

            try
            {
                m_AppSettings = AppXmlSettingsHandler.Instance.LoadSettingsFromFile();
            }
            catch
            {
                useDefaultSettings();
            }
        }
예제 #14
0
 protected Hashtable GenParamHash(ILoginClient login, Profile profile) => new Hashtable
 {
     { "auth_player_name", login.Username },
     { "version_name", "vanilla" },
     { "game_directory", profile.GameDir },
     { "assets_root", $"{profile.GameDir}/assets" },
     { "assets_index_name", (string)vdata["assetIndex"]["id"] },
     { "auth_uuid", login.ID },
     { "auth_access_token", login.AccessToken },
     { "user_type", "mojang" },
     { "version_type", (string)vdata["type"] },
     { "resolution_width", profile.Width },
     { "resolution_height", profile.Height },
     { "natives_directory", $"{VID}/{VID}-natives" },
     { "launcher_name", "WTFMC" },
     { "launcher_version", "" },
     { "classpath", GenerateClasspath() }
 };
예제 #15
0
        public ApiClient(HttpClient httpClient, IConfiguration configuration)
        {
            var apiConfigurations = new ApiConfigurations();

            new ConfigureFromConfigurationOptions <ApiConfigurations>(configuration.GetSection("ApiConfigurations"))
            .Configure(apiConfigurations);

            _apiEndpoint = apiConfigurations.BaseURL;

            if (!_apiEndpoint.EndsWith("/"))
            {
                _apiEndpoint += "/";
            }

            httpClient.DefaultRequestHeaders.Authorization
                = new AuthenticationHeaderValue("Bearer", apiConfigurations.Token);

            BasketClient       = new BasketClient(_apiEndpoint, httpClient);
            ProductGroupClient = new ProductGroupClient(_apiEndpoint, httpClient);
            ProductClient      = new ProductClient(_apiEndpoint, httpClient);
            LoginClient        = new LoginClient(_apiEndpoint, httpClient);
        }
예제 #16
0
파일: Version21.cs 프로젝트: mcendu/wtfmc
        public override List <string> GenerateArgs(ILoginClient login, Profile profile)
        {
            List <string> arguments = new List <string>();
            RuleReader    rr        = new RuleReader
            {
                Login = login
            };
            Hashtable arghash = GenParamHash(login, profile);
            // Apply default parameters.
            JArray input = (JArray)vdata["arguments"]["game"];

            foreach (JToken i in input)
            {
                if (i.HasValues)
                {
                    rr.Execute((JArray)(i["rules"]), () =>
                    {
                        if (i["value"].HasValues)
                        {
                            foreach (string v in i["value"])
                            {
                                arguments.Add(new Formatter().Format(v, arghash));
                            }
                        }
                        else
                        {
                            arguments.Add(new Formatter().Format((string)i["value"], arghash));
                        }
                    });
                }
                else
                {
                    // Boilerplate code found here...
                    arguments.Add(new Formatter().Format((string)i, arghash));
                }
            }
            return(arguments);
        }
예제 #17
0
 private void SetUpLoginData(ILoginClient login)
 {
     if (login == null)
     {
         way.IsEnabled    = true;
         access.Text      = "";
         access.Focusable = true;
     }
     access.Text = login.Username;
     if (login.LoginType == LoginType.Mojang)
     {
         way.IsEnabled     = false;
         access.Focusable  = false;
         way.SelectedIndex = 1;
     }
     else if (login.LoginType == LoginType.Offline)
     {
         way.IsEnabled     = true;
         access.Focusable  = true;
         way.SelectedIndex = 0;
     }
     ShowPassword();
 }
예제 #18
0
        /// <inheritdoc />
        public void SendServerList(ILoginClient client, string username, IEnumerable <ClusterServerInfo> clusters)
        {
            using (var packet = new FFPacket())
            {
                packet.WriteHeader(PacketType.SRVR_LIST);
                packet.Write(0);
                packet.Write <byte>(1);
                packet.Write(username);
                packet.Write(clusters.Sum(x => x.Worlds.Count) + clusters.Count());

                foreach (ClusterServerInfo cluster in clusters)
                {
                    packet.Write(-1);
                    packet.Write(cluster.Id);
                    packet.Write(cluster.Name);
                    packet.Write(cluster.Host);
                    packet.Write(0);
                    packet.Write(0);
                    packet.Write(1);
                    packet.Write(0);

                    foreach (WorldServerInfo world in cluster.Worlds)
                    {
                        packet.Write(cluster.Id);
                        packet.Write(world.Id);
                        packet.Write(world.Name);
                        packet.Write(world.Host);
                        packet.Write(0);
                        packet.Write(0);
                        packet.Write(1);
                        packet.Write(100); // Capacity
                    }
                }

                client.Send(packet);
            }
        }
예제 #19
0
        public LobbyItem(ILoginClient client, RoomInfo roomInfo)
        {
            this._client = client;


            this.Id     = roomInfo.Id;
            this.Online = roomInfo.OnlineUsers;
            foreach (var data in roomInfo.RoomData)
            {
                switch (data.Key)
                {
                case "name":
                    this.Name = data.Value;
                    break;

                case "plays":
                    this.Plays = int.Parse(data.Value);
                    break;

                case "woots":
                    this.Woots = int.Parse(data.Value);
                    break;

                case "owned":
                    this.Owned = bool.Parse(data.Value);
                    break;

                case "needskey":
                    this.HasCode = (data.Value == "yep");
                    break;

                case "IsFeatured":
                    this.Featured = bool.Parse(data.Value);
                    break;
                }
            }
        }
예제 #20
0
 public static Task CreateOpenWorldAsync(this ILoginClient client, string name)
 {
     return(client.CreateOpenWorldAsync(name, CancellationToken.None));
 }
예제 #21
0
 public static Task JoinRoomAsync(this ILoginClient client, string roomId)
 {
     return(client.JoinRoomAsync(roomId, CancellationToken.None));
 }
예제 #22
0
 public static void CreateOpenWorld(this ILoginClient client, string name, CancellationToken ct)
 {
     client.CreateOpenWorldAsync(name, ct).WaitEx();
 }
예제 #23
0
 public static void JoinRoom(this ILoginClient client, string roomId, CancellationToken ct)
 {
     client.JoinRoomAsync(roomId, ct).WaitEx();
 }
예제 #24
0
 public static PlayerData GetPlayerData(this ILoginClient client)
 {
     return(client.GetPlayerDataAsync().GetResultEx());
 }
예제 #25
0
 public static LobbyItem[] GetLobbyRooms(this ILoginClient client)
 {
     return(client.GetLobbyRoomsAsync().GetResultEx());
 }
예제 #26
0
 public static Task CreateOpenWorldAsync(this ILoginClient client, string name)
 {
     return(client.CreateOpenWorldAsync("OW" + GenerateUniqueRoomId(name), name));
 }
예제 #27
0
 public static DatabaseWorld LoadWorld(this ILoginClient client, string roomId)
 {
     return(client.LoadWorldAsync(roomId).GetResultEx());
 }
예제 #28
0
 public LoginModel(ILoginClient loginClient)
 {
     LoginClient = loginClient;
 }
예제 #29
0
 public LoginWorkflow(ILoginRepository loginRepository, ILoginClient loginClient)
 {
     this.loginRepository = loginRepository;
     this.loginClient = loginClient;
 }
예제 #30
0
 // nonasync
 public static void CreateJoinRoom(this ILoginClient client, string roomId)
 {
     client.CreateJoinRoomAsync(roomId).WaitEx();
 }
예제 #31
0
 // async ct
 public static Task CreateOpenWorldAsync(this ILoginClient client, string name, CancellationToken ct)
 {
     return(client.CreateJoinOpenWorldAsync("OW" + GenerateUniqueRoomId(name), name, ct));
 }
예제 #32
0
 public static void CreateOpenWorld(this ILoginClient client, string name)
 {
     client.CreateOpenWorldAsync(name).WaitEx();
 }