public void Connect() { if (InputField.text == "") { return; } ENetClient.Connect(InputField.text); SceneManager.LoadScene("Connecting"); }
public async void Connect() { // LOGIN if (sendingRequest || ConnectingENet) { return; } if (inputFieldLoginName.text.Equals("")) { UpdateText("Please enter a username for login.."); return; } if (inputFieldLoginPass.text.Equals("")) { UpdateText("Please enter a password for login.."); return; } string name = inputFieldLoginName.text; string pass = inputFieldLoginPass.text; animateDots = StartCoroutine(AnimateDots("Sending request to web server")); sendingRequest = true; //Network.Send(PacketType.ClientLoginAccount, PacketFlags.Reliable, inputFieldLoginName.text, inputFieldLoginPass.text); WebUser user = new WebUser(); user.Name = name; user.Password = pass; string data = await WebServer.Post("/api/login", user); WebResponse response = JsonConvert.DeserializeObject <WebResponse>(data); StopCoroutine(animateDots); sendingRequest = false; if (response.Error == 1) { UpdateText("An error occured while sending the request"); return; } StatusCode code = (StatusCode)response.Status; if (code == StatusCode.LOGIN_DOESNT_EXIST) { UpdateText($"Login for account '{name}' does not exist"); return; } if (code == StatusCode.LOGIN_WRONG_PASSWORD) { UpdateText($"Failed to login to account '{name}', wrong password"); return; } if (code == StatusCode.LOGIN_SUCCESS) { UpdateText($"Successfully logged into account '{name}'"); //SceneManager.LoadScene("Account"); //StartCoroutine(ASyncLoadGame()); } // CONNECT string IP = "127.0.0.1"; int index = dropdownRegions.value; if (index == 0) // Auto { //TODO } if (index == 1) // Canada { IP = "142.160.70.176"; } animateDots = StartCoroutine(AnimateDots("Attempting to connect to ENet server")); ENetClient.Connect(IP); ConnectingENet = true; StartCoroutine(ENetConnect()); }