protected MasterClientPeer(InitRequest initRequest, bool derived) : base(initRequest) { this.SetCurrentOperationHandler(OperationHandlerInitial.Instance); this.ExpectedProtocol = initRequest.NetworkProtocol; this.RequestFiber.Enqueue(() => { if (MasterApplication.AppStats != null) { MasterApplication.AppStats.IncrementMasterPeerCount(); MasterApplication.AppStats.AddSubscriber(this); } } ); this.HttpRpcCallsLimit = CommonSettings.Default.WebRpcHttpCallsLimit; AuthenticationToken authToken; if (initRequest.InitObject is string token) { ErrorCode errorCode; string errorMsg; authToken = AuthOnInitHandler.DoAuthUsingInitObject(token, this, initRequest, ((MasterApplication)MasterApplication.Instance).TokenCreator, out errorCode, out errorMsg); if (authToken == null) { this.RequestFiber.Enqueue( () => this.SendOperationResponseAndDisconnect(new OperationResponse((byte)OperationCode.AuthOnce) { DebugMessage = errorMsg, ReturnCode = (short)errorCode }, new SendParameters())); return; } } else if (initRequest.DecryptedAuthToken != null) { authToken = (AuthenticationToken)initRequest.DecryptedAuthToken; this.binaryTokenUsed = true; } else { this.StartWaitForAuthRequest(); return; } if (authToken != null) { if (!derived && !ConnectionRequirementsChecker.Check(this, authToken.ApplicationId, authToken, true)) { log.Warn(secureConnectionLogGuard, $"Client used non secure connection type when it is required. appId:{authToken.ApplicationId}, Connection: {this.NetworkProtocol}. AuthOnce"); return; } var app = (MasterApplication)ApplicationBase.Instance; if (app.DefaultApplication.IsActorExcluded(authToken.UserId)) { if (log.IsDebugEnabled) { log.DebugFormat("MasterClientPeer, actor '{0}' is excluded", authToken.UserId); } this.RequestFiber.Enqueue( () => this.SendOperationResponseAndDisconnect(new OperationResponse((byte)OperationCode.AuthOnce) { DebugMessage = "User blocked", ReturnCode = (short)ErrorCode.UserBlocked, }, new SendParameters())); return; } this.authOnceUsed = true; this.unencryptedAuthToken = authToken; this.UserId = authToken.UserId; } }
protected GameClientPeer(InitRequest initRequest, GameApplication application, bool derived) : base(initRequest) { this.application = application; if (this.application.AppStatsPublisher != null) { this.application.AppStatsPublisher.IncrementPeerCount(); } this.HttpRpcCallsLimit = CommonSettings.Default.WebRpcHttpCallsLimit; var token = initRequest.InitObject as string; AuthenticationToken authToken = null; if (!string.IsNullOrEmpty(token)) { ErrorCode errorCode; string errorMsg; authToken = AuthOnInitHandler.DoAuthUsingInitObject(token, this, initRequest, application.TokenCreator, out errorCode, out errorMsg); if (authToken == null) { this.RequestFiber.Enqueue(() => this.SendOperationResponse(new OperationResponse((byte)OperationCode.AuthOnce) { DebugMessage = errorMsg, ReturnCode = (short)errorCode }, new SendParameters())); this.ScheduleDisconnect(); } } else if (initRequest.DecryptedAuthToken != null) { authToken = (AuthenticationToken)initRequest.DecryptedAuthToken; this.binaryTokenUsed = true; } if (authToken != null) { this.authOnceUsed = true; this.AuthToken = authToken; if (!derived) { if (!ConnectionRequirementsChecker.Check(this, authToken.ApplicationId, authToken, this.authOnceUsed)) { log.Warn(secureConnectionLogGuard, $"Client used non secure connection type when it is required. appId:{authToken.ApplicationId}, Connection: {this.NetworkProtocol}. AuthOnce"); return; } this.SetupPeer(this.AuthToken); this.RequestFiber.Enqueue(() => { var responseObject = new AuthenticateResponse { QueuePosition = 0 }; this.SendOperationResponse(new OperationResponse((byte)OperationCode.AuthOnce, responseObject), new SendParameters()); }); } } }