public void RegisterUI() { if (!Validation.IsValidEmail(uiRegisterEmail.text)) { UIMessageGlobal.Open(Language.v["validEmail"]); } else if (!Validation.IsValidNick(uiRegisterNick.text)) { UIMessageGlobal.Open(Language.v["validNick"], Language.v["validNickDetail"]); } else if (!Validation.IsValidPassword(uiRegisterPassword.text)) { UIMessageGlobal.Open(Language.v["validPass"], Language.v["validPassDetail"]); } else if (uiRegisterPassword.text != uiRegisterPasswordConfirm.text) { UIMessageGlobal.Open(Language.v["validPassMatch"]); } else { Register(); } }
public void ResetUI() { if (!Validation.IsValidEmail(uiResetEmail.text)) { UIMessageGlobal.Open(Language.v["validEmail"]); } else { Reset(); } }
public void RegisterCodeUI() { if (!Validation.IsValidCode(uiRegisterCodeCode.text)) { UIMessageGlobal.Open(Language.v["validCode"]); } else { RegisterCode(); } }
/// <summary> /// Chooses a character for the match /// </summary> /// <param name="cid"></param> /// <param name="r"></param> /// <returns></returns> public bool Choose(int cid, UDPPacket r = null) { if (r == null) { // if the user is not logged in or match type is none, restart if (!Account.IsLoggedIn() || cid == 0) { Kill2Live.Restart(); return(false); } Debug.Log("Choosing a character: " + cid.ToString() + " ..."); Event e = Match.self.activeEvent; e.User = Account.GetUser(); e.Me = new Player { Character = cid }; // request string j = JsonConvert.SerializeObject(e); UDP.Request(new UDPPacket { Service = UDPService.Match, Action = UDPAction.Choose, Request = j, }); return(false); } else { if (r.Error != 0 || r.Response == null) { UIMessageGlobal.Open(Language.v["choosefailed"], Language.v["choosefaileddesc"]); Debug.LogWarning(r.ToString()); return(false); } Debug.Log("Chosen: " + r.Response); Event e = JsonConvert.DeserializeObject <Event>(r.Response); Match.self.activeEvent.Me.Character = e.Me.Character; UIPlayers.Set(Account.GetUser().Nickname, e.Me.Character); // TODO update ui uiChoose.SetActive(false); return(true); } }
IEnumerator Start() { UIMessageGlobal.Load(); while (!Ready()) { yield return(null); } // start with login screen if (initialPanel != "") { GetComponent <Account>().PanelShow(initialPanel); } }
public bool Leave(UDPPacket r = null, bool quit = false) { if (r == null) { // if the user is not logged in, restart if (!Account.IsLoggedIn()) { if (!quit) { Kill2Live.Restart(); } return(false); } Debug.Log("Leaving the match..."); Reset(); uiPlay.SetActive(false); uiJoin.SetActive(true); Event e = new Event { User = Account.GetUser(), }; // request string j = JsonConvert.SerializeObject(e); UDP.Request(new UDPPacket { Service = UDPService.Match, Action = UDPAction.Leave, Request = j, }); return(false); } else { if (r.Error != 0) { if (r.Error >= (int)ServiceError.MatchUnknown) { UIMessageGlobal.Open(Language.v["leavefailed"], Language.v["leavefaileddesc"]); Debug.LogWarning(r.ToString()); } return(false); } return(true); } }
private void FixedUpdate() { if (self != null && self.isFocused && !UIMessageGlobal.IsActive()) { if (Input.GetKeyDown(KeyCode.Tab)) { next.Select(); } else if (enter != null && (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))) { enter.onClick.Invoke(); } } }
public void LoginUI() { if (!Validation.IsValidEmail(uiLoginEmail.text)) { UIMessageGlobal.Open(Language.v["validEmail"]); } else if (!Validation.IsValidPassword(uiLoginPassword.text)) { UIMessageGlobal.Open(Language.v["validPass"], Language.v["validPassDetail"]); } else { Login(); } }
/// <summary> /// Handles the items in queue /// </summary> void Update() { #if UNITY_EDITOR // special case for the editor // if it is running on the editor, a compilation on play mode will // make Unity crash if (Application.isEditor && EditorApplication.isCompiling) { if (listener.IsAlive) { listener.Abort(); } if (client != null) { client.Close(); } } #endif lock (pQueue.SyncRoot) { if (pQueue.Count > 0) { UDPPacket p = (UDPPacket)pQueue.Dequeue(); Debug.Log("Processing: " + p.ID); requests.Remove(p.ID); if (loadingFull != null) { loadingFull.SetActive(false); } if (loadingSmall != null) { loadingSmall.SetActive(false); } if (p.Error != 0 && p.Error < 100) { UIMessageGlobal.Open( (server == null) ? Language.v["requesttimeout"] : "Request Timeout"); } Action(p); } } }
/// <summary> /// Logs in a user /// </summary> /// <param name="r">UDPPacket</param> public bool Login(UDPPacket r = null) { if (r == null) { Debug.Log("Signin in..."); User user = new User { Email = uiLoginEmail.text, Password = Encryption.Hash(uiLoginPassword.text), }; UDP.Request(new UDPPacket { Service = UDPService.Account, Action = UDPAction.Login, Request = JsonConvert.SerializeObject(user), }); uiLoginPassword.text = ""; return(false); } else { if (r.Error != 0) { if (r.Error >= (int)ServiceError.AccountUnknown) { UIMessageGlobal.Open(Language.v["loginfailed"], Language.v["loginfaileddesc"]); Debug.LogWarning(r.ToString()); } return(false); } user = JsonConvert.DeserializeObject <User>(r.Response); user.Status(UserStatus.Logined); nick.text = user.Nickname; Debug.Log("Signed: " + user.Email); return(true); } }
/// <summary> /// Resets a password with the code which is sent by e-mail /// </summary> /// <param name="r"></param> public bool ResetCode(UDPPacket r = null) { if (r == null) { Debug.Log("Resetting a password with code..."); int code = 0; if (int.TryParse(uiResetCodeCode.text, out code)) { User user = new User { Email = uiResetEmail.text, Reset = code, Password = Encryption.Hash(uiResetCodePassword.text), }; UDP.Request(new UDPPacket { Service = UDPService.Account, Action = UDPAction.ResetCode, Request = JsonConvert.SerializeObject(user), }); } return(false); } else { if (r.Error != 0) { if (r.Error >= (int)ServiceError.AccountUnknown) { UIMessageGlobal.Open(Language.v["resetcodefailed"], Language.v["resetcodefaileddesc"]); Debug.LogWarning(r.ToString()); } return(false); } Debug.Log("Password reset is completed."); return(true); } }
/// <summary> /// Activates a registered user with the code which is sent by e-mail /// </summary> /// <param name="r"></param> /// <returns></returns> public bool RegisterCode(UDPPacket r = null) { if (r == null) { Debug.Log("Activating an account..."); int code = 0; if (int.TryParse(uiRegisterCodeCode.text, out code)) { User user = new User { Email = uiRegisterEmail.text, Reset = code, }; UDP.Request(new UDPPacket { Service = UDPService.Account, Action = UDPAction.RegisterCode, Request = JsonConvert.SerializeObject(user), }); } return(false); } else { if (r.Error != 0) { if (r.Error >= (int)ServiceError.AccountUnknown) { UIMessageGlobal.Open(Language.v["registercodefailed"], Language.v["registercodefaileddesc"]); Debug.LogWarning(r.ToString()); } return(false); } Debug.Log("Registered user is activated."); // TODO success message return(true); } }
public void ResetCodeUI() { if (!Validation.IsValidCode(uiResetCodeCode.text)) { UIMessageGlobal.Open(Language.v["validCode"]); } else if (!Validation.IsValidPassword(uiResetCodePassword.text)) { UIMessageGlobal.Open(Language.v["validPass"], Language.v["validPassDetail"]); } else if (uiResetCodePassword.text != uiResetCodePasswordConfirm.text) { UIMessageGlobal.Open(Language.v["validPassMatch"]); } else { ResetCode(); } }
/// <summary> /// Registers a user with e-mail /// </summary> /// <param name="r"></param> public bool Register(UDPPacket r = null) { if (r == null) { Debug.Log("Creating a new account..."); User user = new User { Email = uiRegisterEmail.text, Password = Encryption.Hash(uiRegisterPassword.text), Nickname = uiRegisterNick.text, }; UDP.Request(new UDPPacket { Service = UDPService.Account, Action = UDPAction.Register, Request = JsonConvert.SerializeObject(user), }); uiRegisterPassword.text = ""; uiRegisterPasswordConfirm.text = ""; return(false); } else { if (r.Error != 0) { if (r.Error >= (int)ServiceError.AccountUnknown) { UIMessageGlobal.Open(Language.v["registerfailed"], Language.v["registerfaileddesc"]); Debug.LogWarning(r.ToString()); } return(false); } Debug.Log("Registration is successful"); return(true); } }
/// <summary> /// Sends a password reset code to user's e-mail (if exists) /// </summary> /// <param name="r"></param> public bool Reset(UDPPacket r = null) { if (r == null) { Debug.Log("Resetting password..."); User user = new User { Email = uiResetEmail.text, }; UDP.Request(new UDPPacket { Service = UDPService.Account, Action = UDPAction.Reset, Request = JsonConvert.SerializeObject(user), }); return(false); } else { if (r.Error != 0) { if (r.Error >= (int)ServiceError.AccountUnknown) { UIMessageGlobal.Open(Language.v["resetfailed"], Language.v["resetfaileddesc"]); Debug.LogWarning(r.ToString()); } return(false); } Debug.Log("Password reset link is sent"); return(true); } }
/// <summary> /// Sends a packet to given service /// </summary> /// <param name="p"></param> /// <returns></returns> private IEnumerator Send(UDPPacket p) { if (Kill2Live.quiting) { yield return(0); } int port = 0; switch (p.Service) { case UDPService.Account: port = config.servicePorts.account; break; case UDPService.Match: port = config.servicePorts.match; break; case UDPService.Characters: port = config.servicePorts.characters; break; case UDPService.Priv: port = config.servicePorts.priv; break; } IPEndPoint service = new IPEndPoint( Dns.GetHostAddresses(config.host)[0], port); try { string json = JsonConvert.SerializeObject(p); byte[] data = Encoding.UTF8.GetBytes(json); if (client != null) { client.Send(data, data.Length, service); } } catch (Exception exc) { p.Error = (int)UDPErrorType.RequestFailed; p.ErrorExc = exc; Debug.LogError(p.ErrorExc); } yield return(new WaitForSeconds(config.requestTimeout / 1000)); if (client != null && requests.ContainsKey(p.ID)) { p.Error = (int)UDPErrorType.RequestTimeout; Debug.LogWarning(p.ToString()); requests.Remove(p.ID); if (loadingFull != null) { loadingFull.SetActive(false); } if (loadingSmall != null) { loadingSmall.SetActive(false); } if (main != null) { UIMessageGlobal.Open( (server == null) ? Language.v["requesttimeout"] : "Request Timeout"); } Action(p); } }
/// <summary> /// Find and join into a game. /// </summary> /// <param name="type"></param> /// <param name="r"></param> public bool Join(MatchType typ = MatchType.None, UDPPacket r = null) { if (r == null) { // if the user is not logged in or match type is none, restart if (!Account.IsLoggedIn()) { Kill2Live.Restart(); return(false); } Debug.Log("Finding a match for " + typ.ToString() + " ..."); Event e = new Event { User = Account.GetUser(), M = new Game { Typ = typ, } }; // request string j = JsonConvert.SerializeObject(e); UDP.Request(new UDPPacket { Service = UDPService.Match, Action = UDPAction.Join, Request = j, }); return(false); } else { if (r.Error != 0) { if (r.Error == (int)ServiceError.AlreadyJoined) { // continue // no return here because of this situation } else if (r.Error >= (int)ServiceError.MatchUnknown) { UIMessageGlobal.Open(Language.v["joinfailed"], Language.v["joinfaileddesc"]); Debug.LogWarning(r.ToString()); return(false); } } Debug.Log("Joining: " + r.Response); Event e = JsonConvert.DeserializeObject <Event>(r.Response); if (e.M.Typ == MatchType.None) { return(false); } activeEvent = e; if (e.M.Status == MatchStatus.Reserved) // still creating a match { if (!refreshing) { refreshing = true; InvokeRepeating("PlayersLoop", 0f, refresh); } } else { if (e.M.Status == MatchStatus.Ready || e.M.Status == MatchStatus.Play) { Players(); } else if (e.M.Status == MatchStatus.End || e.M.Status == MatchStatus.Released) { activeEvent = null; UIPlayers.Clear(); return(false); } } return(true); } }