/// <summary> /// Refreshes player list /// </summary> /// <param name="r"></param> /// <returns></returns> public bool Players(UDPPacket r = null) { if (r == null) { // if the user is not logged in or there is no event, skip if (!Account.IsLoggedIn() || activeEvent == null) { return(false); } Event e = new Event { User = Account.GetUser(), M = new Game { ID = activeEvent.M.ID, Key = activeEvent.M.Key } }; // request string j = JsonConvert.SerializeObject(e); UDP.Request(new UDPPacket { Service = UDPService.Match, Action = UDPAction.Players, Request = j, }); return(false); } else { if (r.Error != 0) { Debug.LogWarning(r.ToString()); return(false); } Event e = JsonConvert.DeserializeObject <Event>(r.Response); activeEvent.M.Status = e.M.Status; activeEvent.Players = e.Players; UIPlayers.loaded = false; UIPlayers.Load(); if (e.M.Status == MatchStatus.Ready || e.M.Status == MatchStatus.Play) { CancelInvoke(); StartCoroutine(UIPlayers.self.Ready()); } return(true); } }
/// <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); } }
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); } }
/// <summary> /// Load characters from the server /// </summary> private IEnumerator Start() { yield return(new WaitUntil(() => UDP.ready == true)); Debug.Log("Fetching characters..."); // request UDP.Request(new UDPPacket { Service = UDPService.Characters, Action = UDPAction.Characters, Request = {}, }); }
/// <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); } }
/// <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); } }
private IEnumerator Debugger() { yield return(new WaitUntil(() => UDP.ready == true)); // account Debug.Log("Requesting debug user..."); Event a = new Event { User = new User { ID = debugAccountId } }; string ja = JsonConvert.SerializeObject(a); UDP.Request(new UDPPacket { Service = UDPService.Priv, Action = UDPAction.Account, Request = ja, }); }
private IEnumerator Start() { yield return(new WaitUntil(() => UDP.ready == true)); if (mid != "") { Event x = new Event { M = new Game { ID = mid } }; string j = JsonConvert.SerializeObject(x); UDP.Request(new UDPPacket { Service = UDPService.Priv, Action = UDPAction.Match, Request = j, }); } }
public void DebugAccount(UDPPacket r) { if (r == null) { return; } if (r.Error != 0) { Debug.LogError("Debug account can not be fetched!"); return; } Event x = JsonConvert.DeserializeObject <Event>(r.Response); e.User = x.User; e.User.Status(UserStatus.Logined); Debug.Log("Debug user: "******"Requesting debug match..."); Event m = new Event { M = new Game { ID = debugMatchId } }; string jm = JsonConvert.SerializeObject(m); UDP.Request(new UDPPacket { Service = UDPService.Priv, Action = UDPAction.Match, Request = jm, }); }
public void OnClientConnect(int cid) { connectedClients.Add(cid); Event x = new Event { M = new Game { ID = mid }, Me = new Player { CID = cid } }; string j = JsonConvert.SerializeObject(x); UDP.Request(new UDPPacket { Service = UDPService.Priv, Action = UDPAction.CID, Request = j, }); }
/// <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> /// 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); } }