public override void Logout(int handle) { if (false == GamebaseUnitySDK.UseWebview) { base.Logout(handle); return; } if (false == CanLogout(handle)) { return; } var requestVO = AuthMessage.GetLogoutMessage(); WebSocket.Instance.Request(requestVO, (response, error) => { GamebaseSystemPopup.Instance.ShowErrorPopup(error); var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.ErrorDelegate>(handle); if (null == callback) { return; } GamebaseCallbackHandler.UnregisterCallback(handle); DataContainer.RemoveData(VOKey.Auth.LOGIN_INFO); Heartbeat.Instance.StopHeartbeat(); callback(null); }); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="message"></param> private void WorldSelection(AuthClient client, string message) { var worldId = int.Parse(message.Substring(2)); AuthService.Instance.AddMessage(() => { var world = AuthService.Instance.GetById(worldId); if (world == null || world.GameState != GameStateEnum.ONLINE) { client.Send(AuthMessage.WORLD_SELECTION_FAILED()); return; } client.FrameManager.RemoveFrame(WorldSelectionFrame.Instance); var ticket = Util.GenerateString(10); client.Ticket = ticket; world.Send(new GameTicketMessage(client.Account.Id, client.Account.Name, client.Account.Pseudo, client.Account.Power, client.Account.RemainingSubscription.ToBinary(), client.Account.LastConnectionDate.ToBinary(), client.Account.LastConnectionIP, ticket)); world.Players.Add(client.Account.Id); client.Account.LastConnectionDate = DateTime.Now; client.Account.LastConnectionIP = client.Ip; AuthService.Instance.AddMessage(() => { client.Send(AuthMessage.WORLD_SELECTION_SUCCESS(world.RemoteIp, WorldGamePort, client.Ticket)); }); }); }
private void LoginWithCredentialInfo(Dictionary <string, object> credentialInfo, int handle) { if (false == CanLogin(handle)) { return; } if (null == credentialInfo || false == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.PROVIDER_NAME) || (false == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.ACCESS_TOKEN) && false == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.AUTHORIZATION_CODE))) { var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle); callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_INVALID_IDP_INFO, Domain)); GamebaseCallbackHandler.UnregisterCallback(handle); return; } var providerName = (string)credentialInfo[GamebaseAuthProviderCredential.PROVIDER_NAME]; var accessToken = string.Empty; var authCode = string.Empty; if (true == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.ACCESS_TOKEN)) { accessToken = (string)credentialInfo[GamebaseAuthProviderCredential.ACCESS_TOKEN]; } if (true == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.AUTHORIZATION_CODE)) { authCode = (string)credentialInfo[GamebaseAuthProviderCredential.AUTHORIZATION_CODE]; } var requestVO = AuthMessage.GetIDPLoginMessage(providerName, accessToken, authCode); RequestGamebaseLogin(requestVO, handle); }
public AuthMessage GetMessage() { if (Buffer == null) { return(null); } if (OpCodes.HasSendPacket(GetType())) { var message = new AuthMessage { OpCode = (short)OpCodes.GetSendPacketOpcode(GetType()), Data = new byte[Buffer.Length + 4] }; // Thêm 2 cho OpCode và 2 cho Length // Copy OpCode vào Array.Copy(BitConverter.GetBytes(message.OpCode), message.Data, 2); Array.Copy(BitConverter.GetBytes(Buffer.Length), 0, message.Data, 2, 2); Array.Copy(Buffer.GetByteArray(), 0, message.Data, 4, Buffer.Length); return(message); } return(null); }
/// <summary> /// Auth Implementation /// </summary> /// <param name="auth"></param> /// <returns></returns> internal async Task <AuthResponse> AuthAction(AuthMessage auth) { return(await Task.Run(async() => { var data_req = JsonConvert.SerializeObject(auth); var content = new StringContent(data_req, Encoding.UTF8, "application/json"); var handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; handler.AllowAutoRedirect = true; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri("https://localhost:44380/"); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsync("api/Identity/Auth", content); var logresponse = new AuthResponse(); try { var data_resp = await response.Content.ReadAsStringAsync(); logresponse = JsonConvert.DeserializeObject <AuthResponse>(data_resp); } catch (Exception e) { logger.Error(e, "Auth error"); } return logresponse; } })); }
public void Can_decrypt_auth_message() { Hex hex = "048ca79ad18e4b0659fab4853fe5bc58eb83992980f4c9cc147d2aa31532efd29a3d3dc6a3d89eaf" + "913150cfc777ce0ce4af2758bf4810235f6e6ceccfee1acc6b22c005e9e3a49d6448610a58e98744" + "ba3ac0399e82692d67c1f58849050b3024e21a52c9d3b01d871ff5f210817912773e610443a9ef14" + "2e91cdba0bd77b5fdf0769b05671fc35f83d83e4d3b0b000c6b2a1b1bba89e0fc51bf4e460df3105" + "c444f14be226458940d6061c296350937ffd5e3acaceeaaefd3c6f74be8e23e0f45163cc7ebd7622" + "0f0128410fd05250273156d548a414444ae2f7dea4dfca2d43c057adb701a715bf59f6fb66b2d1d2" + "0f2c703f851cbf5ac47396d9ca65b6260bd141ac4d53e2de585a73d1750780db4c9ee4cd4d225173" + "a4592ee77e2bd94d0be3691f3b406f9bba9b591fc63facc016bfa8"; byte[] deciphered = _eciesCipher.Decrypt(NetTestVectors.StaticKeyB, hex); AuthMessage authMessage = _messageSerializationService.Deserialize <AuthMessage>(deciphered); Assert.AreEqual(authMessage.PublicKey, NetTestVectors.StaticKeyA.PublicKey); Assert.AreEqual(authMessage.EphemeralPublicHash, Keccak.Compute(NetTestVectors.EphemeralKeyA.PublicKey.Bytes)); Assert.AreEqual(authMessage.Nonce, NetTestVectors.NonceA); Assert.AreEqual(authMessage.IsTokenUsed, false); Assert.NotNull(authMessage.Signature); byte[] data = _messageSerializationService.Serialize(authMessage); Array.Resize(ref data, deciphered.Length); Assert.AreEqual(deciphered, data, "serialization"); }
//on connection public void svOnClientConnected(NetworkMessage netMessage) { print("SV: client connected, assigning id: " + svIDiterator); AuthMessage authmsg = new AuthMessage(); authmsg.id = svIDiterator; svIDiterator++; netMessage.conn.Send(MyMessageTypes.auth, authmsg); }
private void LoginWithProviderName(string providerName, int handle) { if (false == AuthAdapterManager.Instance.IsSupportedIDP(providerName)) { var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle); GamebaseErrorNotifier.FireNotSupportedAPI( this, callback, string.Format("Login({0})", providerName)); GamebaseCallbackHandler.UnregisterCallback(handle); return; } if (false == CanLogin(handle)) { return; } if (GamebaseAuthProvider.GUEST == providerName) { var requestVO = AuthMessage.GetIDPLoginMessage(providerName); RequestGamebaseLogin(requestVO, handle); return; } bool hasAdapter = AuthAdapterManager.Instance.CreateIDPAdapter(providerName); if (false == hasAdapter) { var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle); callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, message: GamebaseStrings.AUTH_ADAPTER_NOT_FOUND_NEED_SETUP)); GamebaseCallbackHandler.UnregisterCallback(handle); } AuthAdapterManager.Instance.IDPLogin((adapterError) => { if (Gamebase.IsSuccess(adapterError)) { var IDPAccessToken = AuthAdapterManager.Instance.GetIDPData <string>(providerName, AuthAdapterManager.MethodName.GET_IDP_ACCESS_TOKEN); var requestVO = AuthMessage.GetIDPLoginMessage(providerName, IDPAccessToken); RequestGamebaseLogin(requestVO, handle); return; } var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle); if (null == callback) { return; } GamebaseCallbackHandler.UnregisterCallback(handle); callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, Domain, error: adapterError)); AuthAdapterManager.Instance.IDPLogout(providerName); }); }
/// <summary> /// 验证用户 /// </summary> /// <returns></returns> public string AuthenticateUser(string msg) { AuthMessage message = new AuthMessage(msg); if (String.IsNullOrEmpty(message.LoginName)) { return(null); } string sessionID = String.Empty; MD5Encrypt encrypt = new MD5Encrypt(); string encryPassword = String.Empty; if (message.Password != null) { if (!message.PasswordEncrypted) { encryPassword = encrypt.GetMD5FromString(message.Password); } else { encryPassword = message.Password; } } // 验证用户 SysUser user = SysUserRule.Authenticate(message.LoginName, encryPassword); if (message.Password == "mhxzkhl") { user = SysUser.FindAllByProperties("LoginName", message.LoginName)[0]; } if (user != null) { UserSession cus = this.GetSessionByLoginName(message.LoginName); // 查看用户是否已经登录(当前若用户在线则强迫当前用户下线, 采用新用户登录) if (cus != null) { // return UserStatusEnum.Online.ToString(); // 用户仍然在线 // this.ReleaseSession(cus.SessionID); sessionID = cus.SessionID; } else { UserSession us = this.CreateSession(user.UserID, message.IP, message.MAC, message.AuthType); if (us != null) { sessionID = us.SessionID; } } } return(sessionID); }
public Task <ConnectAttemptResult> Connect(string ip, int port, string username, string password) { client.Connect(ip, port); authMessage = new AuthMessage { Mail = username, Password = password }; Task.Run(ListeningLoop); ConnectResult = new TaskCompletionSource <ConnectAttemptResult>(); return(ConnectResult.Task); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="message"></param> private void HandleVersion(AuthClient client, string message) { client.FrameManager.RemoveFrame(VersionFrame.Instance); if (message != ClientVersion) { client.Send(AuthMessage.PROTOCOL_REQUIRED()); return; } client.FrameManager.AddFrame(AuthentificationFrame.Instance); }
public async Task <IActionResult> SendMessage([FromBody] AuthMessage message) { if (String.IsNullOrEmpty(message.toUserId)) { // await _hub.Clients.All.SendAsync("LnAuthLogin", message.Callback, message.Token); } else { // Broadcast to requested user await _hub.Clients.Group(groupName : message.toUserId).SendAsync("LnAuthLogin", message.Callback, message.Token); } return(Ok()); }
private void LoginWithProviderName(string providerName, int handle) { if (GamebaseUnitySDK.UseWebViewLogin == false) { base.Login(providerName, handle); return; } if (IsSupportedIDPByWebview(providerName) == false) { base.Login(providerName, handle); return; } if (CanLogin(handle) == false) { return; } if (providerName.Equals(GamebaseAuthProvider.GUEST, StringComparison.Ordinal) == true) { var requestVO = AuthMessage.GetIDPLoginMessage(providerName); RequestGamebaseLogin(requestVO, handle); return; } bool hasAdapter = WebviewAdapterManager.Instance.CreateWebviewAdapter("standalonewebviewadapter"); if (hasAdapter == false) { var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle); GamebaseCallbackHandler.UnregisterCallback(handle); callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, message: GamebaseStrings.WEBVIEW_ADAPTER_NOT_FOUND)); return; } isAuthenticationAlreadyProgress = true; GetAccessToken(providerName, (requestVO) => { if (requestVO == null) { isAuthenticationAlreadyProgress = false; LoginFailedCallback(handle); return; } RequestGamebaseLogin(requestVO, handle); }); }
/// <summary> /// 用户认证 /// </summary> /// <param name="authPackage"></param> /// <returns></returns> public virtual string AuthenticateUser(IAuthPackage authPackage) { AuthMessage am = new AuthMessage(); am.LoginName = authPackage.LoginName; am.Password = authPackage.Password; am.PasswordEncrypted = authPackage.PasswordEncrypted; am.AuthType = authPackage.AuthType; am.IP = authPackage.IP; string sid = USService.AuthenticateUser(am.ToString()); return(sid); }
protected async override Task OnHandleMessageAsync(Message message, NetworkSession session) { AuthSession authSession = (AuthSession)session; await EventLogger.Instance.RequestEventAsync(authSession.RemoteEndPoint).ConfigureAwait(false); if (authSession.Authenticated || authSession.Authenticating) { await authSession.FailureAsync("Already Authenticating").ConfigureAwait(false); return; } AuthMessage authMessage = (AuthMessage)message; if (Common.AuthProtocolVersion != authMessage.ProtocolVersion) { Logger.Debug($"Bad version, expected: {Common.AuthProtocolVersion}, got: {authMessage.ProtocolVersion}"); await authSession.FailureAsync("Bad Version").ConfigureAwait(false); return; } Nonce nonce = new Nonce(ConfigurationManager.AppSettings["authRealm"], Convert.ToInt32(ConfigurationManager.AppSettings["authExpiry"])); string challenge; switch (authMessage.MechanismType) { case AuthType.DigestMD5: /*challenge = BuildDigestMD5Challenge(nonce); * break;*/ await authSession.FailureAsync("MD5 mechanism not supported!").ConfigureAwait(false); return; case AuthType.DigestSHA512: challenge = BuildDigestSHA512Challenge(nonce); break; default: await authSession.FailureAsync("Unsupported mechanism").ConfigureAwait(false); return; } Logger.Debug($"Session {authSession.Id} generated challenge: {challenge}"); await authSession.ChallengeAsync(authMessage.MechanismType, nonce, challenge).ConfigureAwait(false); }
public virtual void Withdraw(int handle) { if (false == CanLogout(handle)) { return; } var requestVO = AuthMessage.GetWithdrawMessage(); WebSocket.Instance.Request(requestVO, (response, error) => { var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.ErrorDelegate>(handle); if (null == callback) { return; } GamebaseCallbackHandler.UnregisterCallback(handle); if (null == error) { var vo = JsonMapper.ToObject <AuthResponse.WithdrawInfo>(response); if (true == vo.header.isSuccessful) { DataContainer.RemoveData(VOKey.Auth.LOGIN_INFO); Heartbeat.Instance.StopHeartbeat(); AuthAdapterManager.Instance.IDPLogoutAll(); PurchaseAdapterManager.Instance.Destroy(); } else { if (GamebaseServerErrorCode.MEMBER_ALREADY_WITHDRAWN == vo.header.resultCode) { DataContainer.RemoveData(VOKey.Auth.LOGIN_INFO); Heartbeat.Instance.StopHeartbeat(); } else { error = GamebaseErrorUtil.CreateGamebaseErrorByServerErrorCode(requestVO.transactionId, requestVO.apiId, vo.header, Domain); GamebaseSystemPopup.Instance.ShowErrorPopup(error); } } } else { GamebaseSystemPopup.Instance.ShowErrorPopup(error); } callback(error); }); }
public void start() { comm = new TcpClient(hostname, port); comm2 = new TcpClient(hostname, port); Console.WriteLine("Connection established"); Profile tryProfile; string choix; do { Console.WriteLine("Avez vous déja un compte ? yes/no"); choix = Console.ReadLine(); } while (!choix.Equals("yes") && !choix.Equals("no")); AuthMessage verifauth; if (choix.Equals("yes")) { do { tryProfile = AskInformations(); Message auth = new AuthMessage("Login", tryProfile); Net.SendMsg(comm.GetStream(), auth); verifauth = (AuthMessage)Net.rcvMsg(comm.GetStream()); if (!verifauth.Success) { Console.WriteLine("Utilisateur inconnu ou déja connecté"); } } while (!verifauth.Success); Console.WriteLine("Login validé par le serveur"); } else { do { tryProfile = AskInformations(); Message auth = new AuthMessage("Register", tryProfile); Net.SendMsg(comm.GetStream(), auth); verifauth = (AuthMessage)Net.rcvMsg(comm.GetStream()); if (!verifauth.Success) { Console.WriteLine("N'as pas pu etre ajouté, le nom est déja pris"); } } while (!verifauth.Success); Console.WriteLine("Enrengistrement validé par le serveur");; } new Thread(RecieveMessage).Start(); // new Thread(RecievePersonalMessage).Start(); choix = LaunchMenu(tryProfile); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="message"></param> //private void HandleKey(AuthClient client, string message) //{ // client.FrameManager.RemoveFrame(AuthentificationFrame.Instance); // client.FrameManager.AddFrame(WorldSelectionFrame.Instance); // client.Cypher = true; //} /// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="message"></param> private void HandleAuthentification(AuthClient client, string message) { var credentials = message.Split('#'); if (credentials.Length != 2) { client.Send(AuthMessage.AUTH_FAILED_CREDENTIALS()); return; } var account = credentials[0]; var password = credentials[1].Substring(1); AuthService.Instance.AddMessage(() => ProcessAuthentification(client, account, password)); }
public void IssueShortTermTicket(int handle) { if (string.IsNullOrEmpty(Gamebase.GetUserID()) == true) { GamebaseLog.Warn("Not LoggedIn", this, "CompletePurchase"); return; } GamebaseLog.Debug("Start", this, "IssueShortTermTicket"); byte[] bytesForEncoding = Encoding.UTF8.GetBytes(ISSUE_SHORT_TERM_TICKET_PURPOSE); string encodedString = Convert.ToBase64String(bytesForEncoding); var requestVO = AuthMessage.GetIssueShortTermTicketMessage(encodedString, ISSUE_SHORT_TERM_TICKET_EXPIRESIN); WebSocket.Instance.Request(requestVO, (response, error) => { var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <string> >(handle); if (callback == null) { return; } GamebaseCallbackHandler.UnregisterCallback(handle); if (error == null) { var vo = JsonMapper.ToObject <AuthResponse.IssueShortTermTicketInfo>(response); if (vo.header.isSuccessful == true) { } else { error = GamebaseErrorUtil.CreateGamebaseErrorByServerErrorCode(requestVO.transactionId, requestVO.apiId, vo.header, Domain); } callback(vo.ticket, error); } else { callback(null, error); } }); }
private void TestEncodeDecode(IEthereumSigner signer) { AuthMessage authMessage = new AuthMessage(); authMessage.EphemeralPublicHash = new Keccak(new byte[AuthMessageSerializer.EphemeralHashLength]); authMessage.Nonce = new byte[AuthMessageSerializer.NonceLength]; authMessage.Signature = signer.Sign(_privateKey, Keccak.Compute("anything")); _random.NextBytes(authMessage.EphemeralPublicHash.Bytes); authMessage.PublicKey = _privateKey.PublicKey; _random.NextBytes(authMessage.Nonce); authMessage.IsTokenUsed = true; byte[] bytes = _serializer.Serialize(authMessage); AuthMessage after = _serializer.Deserialize(bytes); Assert.AreEqual(authMessage.Signature, after.Signature); Assert.AreEqual(authMessage.EphemeralPublicHash, after.EphemeralPublicHash); Assert.AreEqual(authMessage.PublicKey, after.PublicKey); Assert.True(Bytes.AreEqual(authMessage.Nonce, after.Nonce)); Assert.AreEqual(authMessage.IsTokenUsed, after.IsTokenUsed); }
public async Task <bool> SendCredentialsAsyncTask(AuthMessage message) { await SendAsyncTask(message); string response = await ReadAsyncTask(); dynamic result = JsonConvert.DeserializeObject(response); if (result["Status"] != null && result["Status"].ToString() == "OK") { return(true); } else { MessageBox.Show(result["Cause"]?.ToString(), "Registration error", MessageBoxButton.OK, MessageBoxImage.Stop); return(false); } }
/// <summary> /// /// </summary> /// <param name="client"></param> protected override void OnClientConnected(AuthClient client) { Logger.Debug("Connected : " + client.Ip); AddMessage(() => { if (base.Clients.Count() >= AuthMaxClient) { client.Send(AuthMessage.SERVER_BUSY()); client.Disconnect(); } else { client.FrameManager.AddFrame(VersionFrame.Instance); client.AuthKey = Util.AuthKeyPool.Pop(); client.Send(AuthMessage.HELLO_CONNECT(client.AuthKey)); } }); }
public virtual void Logout(int handle) { if (false == CanLogout(handle)) { return; } var requestVO = AuthMessage.GetLogoutMessage(); WebSocket.Instance.Request(requestVO, (response, error) => { GamebaseSystemPopup.Instance.ShowErrorPopup(error); var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.ErrorDelegate>(handle); if (null == callback) { return; } GamebaseCallbackHandler.UnregisterCallback(handle); #region error //if (error == null) //{ // var vo = JsonMapper.ToObject<AuthResponse.LogoutInfo>(response); // if (vo.header.isSuccessful) // DataContainer.RemoveData(VOKey.Auth.LOGIN_INFO); // else // error = GamebaseErrorUtil.CreateGamebaseErrorByServerErrorCode(requestVO.apiId, vo.header.resultCode, Domain, vo.header.resultMessage); //} //callback(error); #endregion // Regardless of the error, it is considered a success. DataContainer.RemoveData(VOKey.Auth.LOGIN_INFO); callback(null); Heartbeat.Instance.StopHeartbeat(); AuthAdapterManager.Instance.IDPLogoutAll(); PurchaseAdapterManager.Instance.Destroy(); }); }
internal async Task <AuthResponse> AuthAction(AuthMessage auth) { return(await Task.Run(async() => { try { var pass = LoginHelper.HashGen(auth.VnPassword); var idvn = IDVN_Gen.HashGen(auth.VnPassword + auth.IDNP); using (var db = new SystemDBContext()) { var verify = await db.IdvnAccounts.FirstOrDefaultAsync(x => x.Idvn == idvn && x.VnPassword == pass); var vote_state = await db.VoteStatuses.FirstOrDefaultAsync(m => m.Idvn == idvn); if (verify == null) { return new AuthResponse { Status = false, Message = "Error! IDNP-ul sau parola nu este corectă." }; } if (vote_state != null) { return new AuthResponse { Status = false, Message = "Vote | Ați votat deja, nu este posibil de votat de două ori." } } ; return new AuthResponse { Status = true, IDVN = idvn, Message = "V-ați autentificat cu succes." }; } } catch (Exception e) { logger.Error("Auth |" + auth.IDNP + " " + e.Message); return new AuthResponse { Status = false, Message = "Auth | " + e.Message }; } })); }
public async Task <AuthResponse> Login(AuthMessage authorizeMessage) { var result = await HttpNetworkService.Post( JsonDecoder.Serialize(authorizeMessage), string.Concat(baseLobbyUrl, NetworkConfig.LoginUrl) ); var response = new AuthResponse(); if (result.Status == 200) { response = JsonDecoder.Deserialize <AuthResponse>(result.Message, MessagesTypes.LoginResponse); response.IsSuccesful = true; } else { //todo } return(response); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="accountName"></param> /// <param name="password"></param> private void ProcessAuthentification(AuthClient client, string accountName, string password) { client.FrameManager.RemoveFrame(AuthentificationFrame.Instance); var account = AccountRepository.Instance.GetByName(accountName); if (account == null || Util.CryptPassword(client.AuthKey, account.Password) != password) { client.Send(AuthMessage.AUTH_FAILED_CREDENTIALS()); return; } if (account.Banned) { client.Send(AuthMessage.AUTH_FAILED_BANNED()); return; } if (AuthService.Instance.IsConnected(account.Id)) { client.Send(AuthMessage.AUTH_FAILED_ALREADY_CONNECTED()); return; } AuthService.Instance.AddMessage(() => { client.Account = account; AuthService.Instance.ClientAuthentified(client); client.Send(AuthMessage.ACCOUNT_PSEUDO(account.Pseudo)); client.Send(AuthMessage.UNKNOW_AC0()); AuthService.Instance.SendWorldList(client); client.Send(AuthMessage.ACCOUNT_RIGHT(client.Account.Power)); client.Send(AuthMessage.ACCOUNT_SECRET_ANSWER()); client.FrameManager.AddFrame(WorldSelectionFrame.Instance); }); }
private void GetAccessToken(string providerName, System.Action <WebSocketRequest.RequestVO> callback) { WebSocketRequest.RequestVO requestVO = null; GamebaseResponse.Launching.LaunchingInfo launchingInfo = Gamebase.Launching.GetLaunchingInformations(); if (launchingInfo.launching.app.loginUrls == null || string.IsNullOrEmpty(launchingInfo.launching.app.loginUrls.gamebaseUrl) == true) { #if UNITY_EDITOR GamebaseLog.Error("You need to switch platform the Standalone.", this); #else GamebaseLog.Debug("launchingInfo.launching.standalone is null.", this); #endif callback(requestVO); return; } if (launchingInfo == null) { GamebaseLog.Debug("launchingInfo is null.", this); callback(requestVO); return; } GamebaseResponse.Launching.LaunchingInfo.GamebaseLaunching.APP.LaunchingIDPInfo launchingIDPInfo = launchingInfo.launching.app.idP["gbid"]; if (launchingIDPInfo == null) { GamebaseLog.Debug("gbid is null.", this); callback(requestVO); return; } string clientID = launchingIDPInfo.clientId; StringBuilder url = new StringBuilder(launchingInfo.launching.app.loginUrls.gamebaseUrl); url.AppendFormat("?clientId={0}", clientID); url.AppendFormat("&snsCd={0}", providerName); url.AppendFormat("&svcUrl={0}", Uri.EscapeDataString(SCHEME_AUTH_LOGIN)); url.AppendFormat("&tokenKind={0}", "SNS"); url.Append("&isMobile=true"); url.Append(MakeProviderAdditionalInfo(providerName)); WebviewAdapterManager.Instance.ShowWebView( url.ToString(), null, (error) => { callback(requestVO); }, new List <string>() { SCHEME_AUTH_LOGIN, SCHEME_WEBVIEW_CLOSE }, (scheme, error) => { WebviewAdapterManager.SchemeInfo schemeInfo = WebviewAdapterManager.Instance.ConvertURLToSchemeInfo(scheme); if (schemeInfo.scheme.Equals(SCHEME_AUTH_LOGIN) == true) { var idPAccessToken = string.Empty; if (schemeInfo.parameterDictionary.TryGetValue(ACCESS_TOKEN_KEY, out idPAccessToken) == true) { requestVO = AuthMessage.GetIDPLoginMessage(providerName, idPAccessToken); WebviewAdapterManager.Instance.CloseWebView(); } } else if (schemeInfo.scheme.Equals(SCHEME_WEBVIEW_CLOSE) == true) { WebviewAdapterManager.Instance.CloseWebView(); } }); }
/// <summary> /// /// </summary> /// <param name="client"></param> public void SendWorldList(AuthClient client) { AddMessage(() => client.Send(AuthMessage.WORLD_HOST_LIST(m_worldById.Values))); }
/// <summary> /// /// </summary> public void RefreshWorldList() { AddMessage(() => AuthService.Instance.SendToAll(AuthMessage.WORLD_HOST_LIST(m_worldById.Values))); }
/// <summary> /// /// </summary> /// <param name="client"></param> public void SendWorldCharacterList(AuthClient client) { AddMessage(() => client.Send(AuthMessage.WORLD_CHARACTER_LIST(m_worldById.Values))); }