/// <summary>
        /// Sets AccountSettings for this account.
        /// </summary>
        /// <param name="value">A AccountSettings instance.</param>
        /// <param name="client">A RippleRestClient used for this request.</param>
        /// <returns>AccountSettings instance</returns>
        /// <exception cref="RippleRestException">Request failed.</exception>
        public AccountSettings SetSettings(RippleRestClient client, AccountSettings value)
        {
            var data = new SetSettingsRequest
            {
                Settings = value,
                Secret = this.Secret
            };

            var result = client.RestClient.Execute<GetSettingsResponse>(client.CreatePostRequest(data, "v1/accounts/{0}/settings", Address));
            client.HandleRestResponseErrors(result);

            result.Data.Settings.Account = this.Address;
            return result.Data.Settings;
        }
        /// <inheritdoc/>
        public virtual void SetSetting <TSettingValue>(string settingFullCode, TSettingValue value, CultureInfo cultureInfo)
        {
            SetSettingsRequest request;

            switch (value)
            {
            case string sValue:
                request = new SetSettingsRequest
                {
                    FullCode            = settingFullCode,
                    CheckSettingType    = true,
                    NeedSetDefaultValue = false,
                    SettingType         = SettingType.String.Code,
                    Value = sValue,
                };
                break;

            case int sValue:
                request = new SetSettingsRequest
                {
                    FullCode            = settingFullCode,
                    CheckSettingType    = true,
                    NeedSetDefaultValue = false,
                    SettingType         = SettingType.Int.Code,
                    Value = sValue.ToString(cultureInfo),
                };
                break;

            case bool sValue:
                request = new SetSettingsRequest
                {
                    FullCode            = settingFullCode,
                    CheckSettingType    = true,
                    NeedSetDefaultValue = false,
                    SettingType         = SettingType.Bool.Code,
                    Value = sValue.ToString(cultureInfo),
                };
                break;

            case PowerMode sValue:
                request = new SetSettingsRequest
                {
                    FullCode            = settingFullCode,
                    CheckSettingType    = true,
                    NeedSetDefaultValue = false,
                    SettingType         = SettingType.PowerMode.Code,
                    Value = sValue.ToString(),
                };
                break;

            default:
                request = new SetSettingsRequest
                {
                    FullCode = settingFullCode,
                    Value    = value.ToString(),
                };
                break;
            }

            SetSettings(new List <SetSettingsRequest> {
                request
            });
        }
Beispiel #3
0
        /// <summary>
        /// Handles incoming <see cref="Packet"/>.
        /// </summary>
        /// <param name="p"><see cref="Packet"/> to handle.</param>
        internal void Handle(Packet p)
        {
            switch (p.FirstOpcode)
            {
            case ServiceLayer.Identity:
            {
                switch (p.SecondOpcode)
                {
                case ServiceLayer.InitializeRequest:
                {
                    Logger.WriteLine(Source.InnerNetwork, "Connected service requests connection initialization.");
                    return;
                }

                case ServiceLayer.SetSettingsRequest:
                {
                    LoginServiceSettings settings = ( LoginServiceSettings )SetSettingsRequest.FromPacket(p, ServiceType.LoginService);
                    ConnectionsManager.SetServiceSettings(settings);
                    return;
                }
                }

                break;
            }

            case UserDataLayer.Identity:
            {
                switch (p.SecondOpcode)
                {
                case UserDataLayer.AuthenticateUser:
                {
                    UserAuthenticationRequest request = new UserAuthenticationRequest(p);

                    if (RealtimeManager.ConnectedUsers.Connected(request.SessionID))
                    {
                        Send(new UserAuthenticationResponse(request.RequestID, UserAuthenticationResponseType.AccessFailed).ToPacket());
                        return;
                    }

                    if (RealtimeManager.ConnectedUsers.Connected(request.Login))
                    {
                        Send(new UserAuthenticationResponse(request.RequestID, UserAuthenticationResponseType.AccountInUse).ToPacket());
                        return;
                    }

                    Send(DataProvider.DataBase.User_Auth(request, ( LoginServiceSettings )Service.RemoteServiceSettings).ToPacket());

                    return;
                }

                case UserDataLayer.CacheUserSessionRequest:
                {
                    CacheUserSessionRequest request = new CacheUserSessionRequest(p);

                    if (RealtimeManager.ConnectedUsers.Connected(request.Session.ID) || RealtimeManager.ConnectedUsers.Connected(request.Session.AccountName))
                    {
                        Send(new CacheUserSessionResponse(request.RequestID, CacheUserSessionResponse.Failed).ToPacket());
                        return;
                    }

                    RealtimeManager.ConnectedUsers.Register(request.Session);

                    Send(new CacheUserSessionResponse(request.RequestID, CacheUserSessionResponse.Accepted).ToPacket());

                    return;
                }

                case UserDataLayer.WorldsListRequest:
                {
                    WorldsListRequest request = new WorldsListRequest(p);
                    Send(new WorldsListResponse(request.RequestID, RealtimeManager.WorldsInfo.Get()).ToPacket());
                    return;
                }

                case UserDataLayer.UnCacheUser:
                {
                    UnCacheUser request = new UnCacheUser(p);

                    // update user login / logout / used_time values in database.

                    UserSession session = RealtimeManager.ConnectedUsers.Find(request.SessionID);

                    if (session != UserSession.Null)
                    {
                        DataProvider.DataBase.User_Logout(session.AccountID, session.StartTime, session.IPAddress, session.LastWorld);
                        RealtimeManager.ConnectedUsers.Unregister(request.SessionID);
                    }

                    return;
                }

                case UserDataLayer.JoinWorldRequest:
                {
                    // check access level

                    JoinWorldRequest request = new JoinWorldRequest(p);

                    if (!RealtimeManager.ConnectedUsers.Connected(request.SessionID))
                    {
                        Send(new JoinWorldResponse(request.RequestID, JoinWorldRequestResult.AccessFailed).ToPacket());
                        return;
                    }

                    if (!RealtimeManager.WorldsInfo.Contains(request.WorldID) || !RealtimeManager.WorldsInfo.IsOnline(request.WorldID))
                    {
                        Send(new JoinWorldResponse(request.RequestID, JoinWorldRequestResult.SystemError).ToPacket());
                        return;
                    }

                    if (RealtimeManager.WorldsInfo.IsFull(request.WorldID))
                    {
                        Send(new JoinWorldResponse(request.RequestID, JoinWorldRequestResult.TooManyPlayers).ToPacket());
                        return;
                    }

                    Send(new JoinWorldResponse(request.RequestID, JoinWorldRequestResult.Accepted).ToPacket());
                    return;
                }
                }

                break;
            }

            default:
            {
                break;
            }
            }

            Logger.WriteLine(Source.InnerNetwork, "Unknown packet received from {0} service:{1}{2}", ServiceType.LoginService, Environment.NewLine, p.ToString());
        }