public void GetConfig(string resource, WebCallback action) { var path = GetServerPath() + _configEndpoint + resource; var req = UnityWebRequest.Get(path); StartCoroutine(Download(req, action)); }
public void GetBarType(WebCallback cb) { String path = GetServerPath() + _barEndpoint; var req = UnityWebRequest.Get(path); StartCoroutine(Download(req, cb)); }
public UnityWebRequest DELETE(string url, WebCallback callback) { UnityWebRequest www = UnityWebRequest.Delete(url); WaitForRequest(www, callback); return(www); }
public void AddEventListener(string name, WebCallback callback) { if (this.webCallbacks.Any(s => s.Key == name)) { this.webCallbacks[name] = callback; } }
public UnityWebRequest PUT(string url, string data, WebCallback callback) { UnityWebRequest www = UnityWebRequest.Put(url, System.Text.Encoding.UTF8.GetBytes(data)); WaitForRequest(www, callback); return(www); }
public void LoadGame(int playerId, WebCallback <PlayerEntity> webCallback) { WWWForm form = new WWWForm(); form.AddField("playerId", playerId); StartCoroutine(DB_Request("loadGame", form, webCallback)); }
public void GetUserPlayer(int userId, WebCallback <PlayerEntity[]> webCallback) { WWWForm form = new WWWForm(); form.AddField("userId", userId); StartCoroutine(DB_Request("getUserPlayer", form, webCallback)); }
public void GetTrial(int id, WebCallback cb) { string path = GetServerPath() + _trialEndpoint + id; var req = UnityWebRequest.Get(path); StartCoroutine(Download(req, cb)); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <param name="webCallback"></param> public void AddUser(string username, string password, WebCallback <UserEntity> webCallback) { WWWForm form = new WWWForm(); form.AddField("username", username); form.AddField("password", password); StartCoroutine(DB_Request("addUser", form, webCallback)); }
public FormWebStep(String name = null, HtmlElementLocator locator = null, Dictionary <string, string> parameters = null, string method = "submit", WebValidator validator = null, WebCallback preElementLocatorCallback = null) : base(name) { this.ElementLocator = locator; this.Method = method; this.Parameters = parameters; this.Validator = validator; this.PreElementLocatorCallback = preElementLocatorCallback; }
public void GetNumberOfLevels(WebCallback action, string set = null) { string req = "levelCount"; if (set != null) { req += "?set=" + set; } GetConfig(req, action); }
public static IEnumerator PostMeCurrentMission(int mission, WebCallback callbackSuccess = null, WebCallback callbackError = null) { if (!string.IsNullOrEmpty(FB.UserId)) { WWW hs_get = new WWW(postLevelURL + "mission=" + WWW.EscapeURL("" + mission) + "&fb_id=" + WWW.EscapeURL(FB.UserId)); float tempTime = 0; while (!hs_get.isDone && hs_get.error == null && tempTime < TimeOut) { tempTime += Time.deltaTime; //Debug.Log("tempTime...." + tempTime); yield return(0); } if (hs_get.error != null || tempTime >= TimeOut) { if (callbackError == null) { if (DataMissionControlNew.test) { if (tempTime >= TimeOut) { Debug.LogError("---ERROR RESPONE---: Timeout"); } else { Debug.LogError("---ERROR RESPONE---: " + hs_get.error); } } } else { callbackError(hs_get); } } else { if (callbackSuccess == null) { Debug.Log(JsonHelper.FormatJson(hs_get.text)); } else { callbackSuccess(hs_get); } } //hs_get.Dispose(); } else { if (DataMissionControlNew.test) { Debug.LogError("---ERROR---: UserId"); } } }
public static IEnumerator GetAllCurrentMission(string fb_ids, WebCallback callbackSuccess = null, WebCallback callbackError = null) { //Debug.Log("DAnh sach ban be lay current mission " + fb_ids); WWW hs_get = new WWW(getLevelURL + "fb_ids=" + WWW.EscapeURL("" + fb_ids)); float tempTime = 0; while (!hs_get.isDone && hs_get.error == null && tempTime < TimeOut) { tempTime += Time.deltaTime; //Debug.Log("tempTime...." + tempTime); yield return(0); } if (hs_get.error != null || tempTime >= TimeOut) { if (callbackError == null) { if (DataMissionControlNew.test) { if (tempTime >= TimeOut) { Debug.LogError("---ERROR RESPONE---: Timeout"); } else { Debug.LogError("---ERROR RESPONE---: " + hs_get.error); } } } else { callbackError(hs_get); } } else { if (callbackSuccess == null) { Debug.Log(JsonHelper.FormatJson(hs_get.text)); } else { callbackSuccess(hs_get); } } //hs_get.Dispose(); }
IEnumerator Download(UnityWebRequest req, WebCallback cb) { Debug.Log("GET " + req.url); req.chunkedTransfer = false; req.Send(); yield return(new WaitUntil(() => req.isDone && req.downloadHandler.isDone)); if (req.isError) { LogNetworkError(req); } else if (req.isDone) { Debug.Log("New data downloaded: " + req.downloadHandler.text); cb(req.downloadHandler.text); } }
// remember to use StartCoroutine when calling this function! //public static IEnumerator PostMeScoreMission(int mission, string fb_id, string star, string score, WebCallback callbackSuccess = null, WebCallback callbackError = null) //{ // Debug.Log("Submit data to server mission " + mission + " score " + score + " star " + star); // //string hash = Md5Sum(name + score + secretKey); // //string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash; // string post_url = addScoreURL + "mission=" + WWW.EscapeURL("" + mission) + "&fb_id=" + WWW.EscapeURL(fb_id) + "&score=" + WWW.EscapeURL(score) + "&star=" + WWW.EscapeURL(star); // WWW hs_post = new WWW(post_url); // yield return hs_post; // Wait until the download is done // if (hs_post.error != null) // { // if (callbackError == null) // Debug.Log("There was an error posting the high score: " + hs_post.error); // else // callbackError(hs_post); // } // else // { // if (callbackSuccess == null) // { // Debug.Log("Post score " + hs_post.text); // } // else // { // callbackSuccess(hs_post); // } // } //} // Get the scores from the MySQL DB to display in a GUIText. // remember to use StartCoroutine when calling this function! //public static IEnumerator GetScores(int mission,string fb_ids = "", WebCallback callbackSuccess = null, WebCallback callbackError = null) //{ // WWW hs_get = new WWW(highscoreURL + "mission=" + WWW.EscapeURL("" + mission) + "&fb_ids=" + WWW.EscapeURL(fb_ids)); // yield return hs_get; // if (hs_get.error != null) // { // if (callbackError == null) // Debug.Log("There was an error getting the high score: " + hs_get.error); // else // callbackError(hs_get); // } // else // { // if (callbackSuccess == null) // { // Debug.Log(JsonHelper.FormatJson(hs_get.text)); // } // else // { // callbackSuccess(hs_get); // } // } //} public static IEnumerator GetRankingMission(int mission, string fb_ids = "", WebCallback callbackSuccess = null, WebCallback callbackError = null) { WWW hs_get = new WWW(highscoreURL + "mission=" + WWW.EscapeURL("" + mission) + "&fb_ids=" + WWW.EscapeURL(fb_ids)); float tempTime = 0; while (!hs_get.isDone && hs_get.error == null && tempTime < TimeOut) { tempTime += Time.deltaTime; //Debug.Log("tempTime...." + tempTime); yield return(0); } if (hs_get.error != null || tempTime >= TimeOut) { if (callbackError == null) { if (DataMissionControlNew.test) { if (tempTime >= TimeOut) { Debug.LogError("---ERROR RESPONE---: Timeout"); } else { Debug.LogError("---ERROR RESPONE---: " + hs_get.error); } } } else { callbackError(hs_get); } } else { if (callbackSuccess == null) { Debug.Log(JsonHelper.FormatJson(hs_get.text)); } else { callbackSuccess(hs_get); } } //hs_get.Dispose(); }
IEnumerator DB_Request <E>(string url, WWWForm form, WebCallback <E> webCallback) { WWW www = new WWW(baseUrl + url, form); if (!PanelManager.instance.IsShown <LoadingPanel>()) { PanelManager.instance.TogglePanel <LoadingPanel>(); } //KeyValuesUpdate kv = new KeyValuesUpdate("UpdateProcess", 0f); //while (!www.isDone) //{ // kv.Values = www.progress; //} //kv.Values = 1; //MessageCenter.instance.SendMessage("LoadingPanel", kv); KeyValuesUpdate kv = new KeyValuesUpdate("Loading", "StartLoading"); MessageCenter.instance.SendMessage("LoadingPanel", kv); yield return(www); kv.Values = "EndLoading"; MessageCenter.instance.SendMessage("LoadingPanel", kv); if (PanelManager.instance.IsShown <LoadingPanel>()) { PanelManager.instance.TogglePanel <LoadingPanel>(); } Debug.Log(www.text); RemoteResult <E> result = JsonConvert.DeserializeObject <RemoteResult <E> >(www.text); if (result == null) { Debug.LogError("网络请求出错!"); KeyValuesUpdate keyvalue = new KeyValuesUpdate("Error", "网络请求出错!"); MessageCenter.instance.SendMessage("ErrorPanel", keyvalue); } else { webCallback(result); } }
private static void ResponseCallback(IAsyncResult result, WebCallback callback) { var request = (HttpWebRequest)result.AsyncState; HttpWebResponse response = null; try { response = (HttpWebResponse)request.EndGetResponse(result); } catch (WebException ex) { response = (HttpWebResponse)ex.Response; } finally { using (StreamReader responseStream = GetStreamForResponse(response)) { callback(responseStream.ReadToEnd(), response.StatusCode); } } }
IEnumerator DB_RequestJson <E>(string url, string jsonStr, WebCallback <E> webCallback) { Dictionary <string, string> headers = new Dictionary <string, string> { { "Content-Type", "application/json" } }; byte[] bs = System.Text.UTF8Encoding.UTF8.GetBytes(jsonStr); WWW www = new WWW(baseUrl + url, bs, headers); if (!PanelManager.instance.IsShown <LoadingPanel>()) { PanelManager.instance.TogglePanel <LoadingPanel>(); } KeyValuesUpdate kv = new KeyValuesUpdate("Loading", "StartLoading"); MessageCenter.instance.SendMessage("LoadingPanel", kv); yield return(www); kv.Values = "EndLoading"; MessageCenter.instance.SendMessage("LoadingPanel", kv); if (PanelManager.instance.IsShown <LoadingPanel>()) { PanelManager.instance.TogglePanel <LoadingPanel>(); } Debug.Log(www.text); RemoteResult <E> result = JsonConvert.DeserializeObject <RemoteResult <E> >(www.text); if (result == null) { Debug.LogError("网络请求出错!"); KeyValuesUpdate keyvalue = new KeyValuesUpdate("Error", "网络请求出错!"); MessageCenter.instance.SendMessage("ErrorPanel", keyvalue); } webCallback(result); }
private IEnumerator SendRequest(string url, string payload, WebCallback callback = null, UnityAction error = null) { byte[] body = System.Text.Encoding.UTF8.GetBytes(payload); UnityWebRequest request = new UnityWebRequest(url, "POST") { uploadHandler = new UploadHandlerRaw(body), downloadHandler = new DownloadHandlerBuffer() }; request.SetRequestHeader("Content-Type", "application/json"); yield return(request.SendWebRequest()); if (!request.isNetworkError) { callback?.Invoke(request.downloadHandler.text); } else { error?.Invoke(); } }
public FormWebStep(String name = null, HtmlElementLocator locator = null, Dictionary<string, string> parameters = null, string method = "submit", WebValidator validator = null, WebCallback preElementLocatorCallback = null) : base(name) { this.ElementLocator = locator; this.Method = method; this.Parameters = parameters; this.Validator = validator; this.PreElementLocatorCallback = preElementLocatorCallback; }
public void Request(string url, string method, WebCallback callback) { this.Request(url, method, null, callback); }
public void Request(string url, string method, Dictionary <string, string> data, WebCallback callback) { this.Request(url, method, data, null, callback); }
public void Request(string url, string method, Dictionary <string, string> data, CookieContainer cookies, WebCallback callback) { this.Request(url, method, data, cookies, null, callback); }
public void Request(string url, string method, Dictionary <string, string> data, CookieContainer cookies, WebHeaderCollection headers, WebCallback callback) { this.Request(url, method, data, cookies, headers, ApiEndpoints.COMMUNITY_BASE, callback); }
public void Request(string url, string method, Dictionary <string, string> data, CookieContainer cookies, WebHeaderCollection headers, string referer, WebCallback callback) { this.RegisterCall(url, method, data, cookies, headers, referer, callback)(); object[] response = (object[])this.GetResponse(url, method, data, cookies, headers, referer)() ?? new object[] { null, HttpStatusCode.NotFound }; callback((string)response[0], (HttpStatusCode)response[1]); }
public void MobileLoginRequest(string url, string method, WebCallback callback) { this.MobileLoginRequest(url, method, null, callback); }
public void MobileLoginRequest(string url, string method, Dictionary <string, string> data, CookieContainer cookies, WebHeaderCollection headers, WebCallback callback) { const string referer = ApiEndpoints.COMMUNITY_BASE + "/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client"; this.RegisterCall(url, method, data, cookies, headers, referer, callback)(); object[] response = (object[])this.GetResponse(url, method, data, cookies, headers, referer)() ?? new object[] { null, HttpStatusCode.NotFound }; callback((string)response[0], (HttpStatusCode)response[1]); }
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception) { returnValue = CefV8Value.CreateNull(); exception = null; try { var context = CefV8Context.GetCurrentContext(); var runner = CefTaskRunner.GetForCurrentThread(); var browser = context.GetBrowser(); var frame = browser.GetMainFrame(); if (name == "Protocols") // && arguments.Length == 1 { //CefV8Value callback = arguments[0]; var Handler = CefV8Value.CreateObject(); //if (callback.IsFunction) { if (protocol != null && protocol.Keys.Contains("domains")) { foreach (JsonData _domain in protocol["domains"]) { if (_domain.Keys.Contains("domain")) { var DomainHandler = CefV8Value.CreateObject(); var domainName = _domain["domain"].ToString(); if (_domain.Keys.Contains("commands")) { foreach (JsonData command in _domain["commands"]) { var commandName = command["name"].ToString(); DomainHandler.SetValue(commandName, CefV8Value.CreateFunction(domainName + "." + commandName, this), CefV8PropertyAttribute.None); } } if (_domain.Keys.Contains("events")) { foreach (JsonData @event in _domain["events"]) { var eventName = @event["name"].ToString(); DomainHandler.SetValue(eventName, CefV8Value.CreateFunction(domainName + "." + eventName, this), CefV8PropertyAttribute.None); } } if (_domain.Keys.Contains("types")) { foreach (JsonData @type in _domain["types"]) { var typeName = @type["id"].ToString(); DomainHandler.SetValue(typeName, CefV8Value.CreateFunction(domainName + "." + typeName, this), CefV8PropertyAttribute.None); } } Handler.SetValue(domainName, DomainHandler, CefV8PropertyAttribute.None); } } } //new Task(() => //{ // context.Enter(); // runner.PostTask(new CallbackTask(context, callback)); // context.Exit(); //}).Start(); } returnValue = Handler; } else { if (frame != null) { var sock = this.DevToolsSockets.FirstOrDefault(s => s.Url == frame.Url); if (sock != null) { string @params = "{}"; CefV8Value callback = null; if (arguments.Length >= 1) { if (arguments[0].IsFunction) { callback = arguments[0]; } else { @params = Extension.CefV8ValueToJson(arguments[0]); if (arguments.Length >= 2 && arguments[1].IsFunction) { callback = arguments[1]; } } } WebCallback webSocketCallback = null; if (callback != null && callback.IsFunction) { webSocketCallback = new WebCallback(context, runner, callback); } sock.Query(name, @params, webSocketCallback); } } } return(true); } catch (Exception ex) { returnValue = CefV8Value.CreateNull(); exception = ex.Message; return(true); } }
public void DoLogin(SteamWeb web, LoginCallback callback) { var postData = new Dictionary <string, string>(); CookieContainer cookies = this._cookies; WebCallback hasCookies = (res, code) => { postData.Add("username", this.Username); web.MobileLoginRequest(ApiEndpoints.COMMUNITY_BASE + "/login/getrsakey", "POST", postData, cookies, (rsaRawResponse, rsaCode) => { if (rsaRawResponse == null || rsaCode != HttpStatusCode.OK || rsaRawResponse.Contains("<BODY>\nAn error occurred while processing your request.")) { callback(LoginResult.GeneralFailure); return; } var rsaResponse = JsonConvert.DeserializeObject <RSAResponse>(rsaRawResponse); if (!rsaResponse.Success) { callback(LoginResult.BadRsa); return; } var mod = new BigInteger(rsaResponse.Modulus, 16); var exp = new BigInteger(rsaResponse.Exponent, 16); var encryptEngine = new Pkcs1Encoding(new RsaEngine()); var rsaParams = new RsaKeyParameters(false, mod, exp); encryptEngine.Init(true, rsaParams); byte[] passwordArr = Encoding.UTF8.GetBytes(this.Password); string encryptedPassword = Convert.ToBase64String(encryptEngine.ProcessBlock(passwordArr, 0, passwordArr.Length)); postData.Clear(); postData.Add("username", this.Username); postData.Add("password", encryptedPassword); postData.Add("twofactorcode", this.TwoFactorCode ?? ""); postData.Add("captchagid", this.RequiresCaptcha ? this.CaptchaGID : "-1"); postData.Add("captcha_text", this.RequiresCaptcha ? this.CaptchaText : ""); postData.Add("emailsteamid", this.Requires2FA || this.RequiresEmail ? this.SteamID.ToString() : ""); postData.Add("emailauth", this.RequiresEmail ? this.EmailCode : ""); postData.Add("rsatimestamp", rsaResponse.Timestamp); postData.Add("remember_login", "false"); postData.Add("oauth_client_id", "DE45CD61"); postData.Add("oauth_scope", "read_profile write_profile read_client write_client"); postData.Add("loginfriendlyname", "#login_emailauth_friendlyname_mobile"); postData.Add("donotcache", Util.GetSystemUnixTime().ToString()); web.MobileLoginRequest(ApiEndpoints.COMMUNITY_BASE + "/login/dologin", "POST", postData, cookies, (rawLoginResponse, loginCode) => { LoginResponse loginResponse = null; if (rawLoginResponse != null && loginCode == HttpStatusCode.OK) { loginResponse = JsonConvert.DeserializeObject <LoginResponse>(rawLoginResponse); } if (loginResponse == null) { callback(LoginResult.GeneralFailure); return; } if (loginResponse.Message != null && loginResponse.Message.Contains("Incorrect login")) { callback(LoginResult.BadCredentials); return; } if (loginResponse.CaptchaNeeded) { this.RequiresCaptcha = true; this.CaptchaGID = loginResponse.CaptchaGid; callback(LoginResult.NeedCaptcha); return; } if (loginResponse.EmailAuthNeeded) { this.RequiresEmail = true; this.SteamID = loginResponse.EmailSteamId; callback(LoginResult.NeedEmail); return; } if (loginResponse.TwoFactorNeeded && !loginResponse.Success) { this.Requires2FA = true; callback(LoginResult.Need2Fa); return; } if (loginResponse.Message != null && loginResponse.Message.Contains("too many login failures")) { callback(LoginResult.TooManyFailedLogins); return; } if (string.IsNullOrEmpty(loginResponse.OAuthData?.OAuthToken)) { callback(LoginResult.GeneralFailure); return; } if (!loginResponse.LoginComplete) { callback(LoginResult.BadCredentials); return; } CookieCollection readableCookies = cookies.GetCookies(new Uri("https://steamcommunity.com")); OAuth oAuthData = loginResponse.OAuthData; this.Session = new SessionData { OAuthToken = oAuthData.OAuthToken, SteamID = oAuthData.SteamId, SteamLogin = oAuthData.SteamId + "%7C%7C" + oAuthData.SteamLogin, SteamLoginSecure = oAuthData.SteamId + "%7C%7C" + oAuthData.SteamLoginSecure, WebCookie = oAuthData.Webcookie, SessionID = readableCookies["sessionid"].Value, Username = this.Username }; this.LoggedIn = true; callback(LoginResult.LoginOkay); }); }); }; if (cookies.Count == 0) { //Generate a SessionID const string url = "https://steamcommunity.com/login?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client"; cookies.Add(SteamWeb.uri, new Cookie("mobileClientVersion", "0 (2.1.3)", "/")); cookies.Add(SteamWeb.uri, new Cookie("mobileClient", "android", "/")); cookies.Add(SteamWeb.uri, new Cookie("Steam_Language", "english", "/")); var headers = new WebHeaderCollection { ["X-Requested-With"] = "com.valvesoftware.android.steam.community" }; web.MobileLoginRequest(url, "GET", null, cookies, headers, hasCookies); } else { hasCookies("", HttpStatusCode.OK); } }
public void GetConfig(string lvl, string set, WebCallback action) { GetConfig(lvl + "?set=" + set, action); }
/// <summary> /// Adds a callback for the specified type. /// </summary> /// <param name="type">The type to callback on when deserialized</param> /// <param name="callback">The callback to call</param> public void AddCallback(Type type, WebCallback callback) { callbacks[type] = callback; }