//unity www的设计是:new出来的瞬间,请求就立即发起了 //由于排队的需求,只能推迟new的时机 private void BeginRequest(WWWRequest req) { WWW www = null; switch (req.Type) { case RequestType.Login: www = new WWW(req.Url, req.Data); break; case RequestType.Get: www = new WWW(req.Url, null, req.Headers); break; case RequestType.Post: www = new WWW(req.Url, req.Data, req.Headers); break; default: InfoTips.LogWarning("undefined type: " + req.Type.ToString()); break; } req.RawWWW = www; req.StartTime = DateTime.Now; sendingRequests.Add(requestIdGen++, req); }
public override WWWResponse ProcessRequest(WWWRequest request) { if (request._request.QueryString ["openid.ns"] != null) { ulong steamId = Validate(request._request); if (steamId > 0) { if (GameManager.Instance.adminTools.IsWhitelisted(steamId.ToString())) { request.User.SetType("steam_user"); return(new WWWResponse("/", 302)); } else { return(new WWWResponse("You are not whitelisted")); } } else { return(new WWWResponse("Auth Failed")); } } return(new WWWResponse("/login/", 302)); }
/// <summary> /// Start a new download request. /// ��ʼһ���µ��������� /// </summary> /// <param name="url">���ص�url������ʹһ�����Ի������url</param> /// <param name="priority">�������ȼ�</param> public void StartDownload(string url, int priority) { url = bundlePacketResouse(url); string newUrl = stripBundleSuffix(url) + ".assetBundle"; CurrentDownloadAllBundle.Add(newUrl); if (!isProgressBackcallRunning) { StartCoroutine(progressBackcall()); if (progressManager != null && progressManager.setAllProgressEvent != null) { progressManager.setAllProgressEvent(0); } } WWWRequest request = new WWWRequest(); request.requestString = url; request.url = url; request.priority = priority; if (!ConfigLoaded) { if (!isInBeforeInitList(url)) { requestedBeforeInit.Add(request); } } else { download(request); } }
/// <summary> /// ��ȡ��Ӧurl��WWWʵ�� /// @return ����null˵��������û�гɹ� /// </summary> /// <param name="url"></param> /// <returns></returns> public WWW GetWWW(string url) { url = bundlePacketResouse(url); if (!ConfigLoaded) { return(null); } url = formatUrl(url, false); if (succeedRequest.ContainsKey(url)) { WWWRequest request = succeedRequest[url]; prepareDependBundles(stripBundleSuffix(request.requestString)); return(request.www); } else { string url1 = formatUrl(url, true); if (succeedRequest.ContainsKey(url1)) { WWWRequest request = succeedRequest[url1]; prepareDependBundles(stripBundleSuffix(request.requestString)); return(request.www); } else { return(null); } } }
/// <summary> /// Coroutine for download waiting. /// Эͬ����ȴ����� /// You should use it like this, /// ʹ�÷��� yield return StartCoroutine(DownloadManager.Instance.WaitDownload("bundle1.assetbundle")); /// If this url didn't been requested, the coroutine will start a new request. /// �����url��Ҫ��Эͬ�������һ���µ����� /// </summary> /// <param name="url"></param> /// <param name="priority"></param> /// <returns></returns> public IEnumerator WaitDownload(string url, int priority) { url = bundlePacketResouse(url); string newUrl = stripBundleSuffix(url) + ".assetBundle"; CurrentDownloadAllBundle.Add(newUrl); if (!isProgressBackcallRunning) { StartCoroutine(progressBackcall()); if (progressManager != null && progressManager.setAllProgressEvent != null) { progressManager.setAllProgressEvent(0); } } while (!ConfigLoaded) { yield return(null); } WWWRequest request = new WWWRequest(); request.requestString = url; request.url = formatUrl(url, false); request.priority = priority; download(request); while (isDownloadingWWW(request.url)) { yield return(null); } }
private void WWWHandler(WWWRequest kRequest) { if (null == kRequest || null == kRequest.WWWObj) { return; } if (kRequest.WWWObj.responseHeaders.ContainsKey("SET-COOKIE")) { mHeaderCookie = kRequest.WWWObj.responseHeaders["SET-COOKIE"]; if (mHeaderCookie.Contains(@"; ")) { mHeaderCookie = mHeaderCookie.Substring(0, mHeaderCookie.IndexOf(@"; ")); } mHeader["Cookie"] = mHeaderCookie; Log.E(mHeaderCookie); } if (null != kRequest.CallbackFunc) { if (kRequest.CallbackFunc is LuaFunction) { LuaFunction kFunc = kRequest.CallbackFunc as LuaFunction; kFunc.Call(kRequest.WWWObj.error, kRequest.WWWObj.text); } } else { // "Network.OnHttpRequestCb",this,kRequest.WWWObj.error,kRequest.WWWObj.text } }
public void Post(string resource, string jsonString, OnHttpResponse callback) { var fullURL = GetHttpPrefix() + resource; var headers = GetAuthHeader(); headers.Add("Content-Type", "application/json"); var postJson = jsonString;//.ToString(); InfoTips.LogInfo("[HttpPost] " + fullURL); InfoTips.LogInfo("postJson:" + postJson + "--Headers:" + headers); var formData = Encoding.UTF8.GetBytes(jsonString); var req = new WWWRequest() { Data = formData, Headers = headers, RespCallback = RespWrapper(callback), Type = RequestType.Post, Url = fullURL }; waitingRequests.Enqueue(req); }
// Use this for initialization void Start() { gameStatus = GameStatus.getInstance(); request = new WWWRequest(); rooms = new ArrayList(); roomButtons = new ArrayList(); roomLabels = new ArrayList(); pageSize = (Screen.height - 90) / 40; roomTitles = new List <string>(); for (int t = 0; t < pageSize; t++) { roomTitles.Add(""); } StartCoroutine(request.RequestUser()); /* */ /* */ //GameObject obj = new GameObject("Button"); //obj.layer = layerUI; //Button button1 = obj.AddComponent<Button>(); //GameObject Button1 = (GameObject) Instantiate(prefab); //Button1.transform.SetParent(parentPanel, false); //Button1.transform.localScale = new Vector3(1, 1, 1); //Button Button = Button1.GetComponent<Button>(); //Button.name = "Button1"; //Button.transform.position = new Vector2(Screen.width / 2, Screen.height / 2); //Button.onClick.AddListener(listener); //roomButtons.Add(Button); }
public override WWWResponse ProcessRequest(WWWRequest request) { string nodeName = ""; string steamId = ""; bool allowed = true; if (request.Form.Count > 0) { nodeName = request.Form ["node"]; steamId = request.Form ["steam_id"]; if (!request.Form.ContainsKey("allowed")) { allowed = false; } if (nodeName == null || nodeName == "" || steamId == null || steamId == "") { return(new WWWResponse("/settings/experm", 302)); } if (API.Permissions.Users.ContainsKey(steamId)) { PermissionUser pUser = API.Permissions.Users [steamId]; if (pUser.Permissions.Exists(nodeName)) { pUser.Permissions.Remove(nodeName); } pUser.Permissions.Set(nodeName, allowed); API.Permissions.Save(); return(new WWWResponse("/settings/experm/user?user="******"/settings/experm", 302)); }
/// <summary> /// 添加请求下载列表 /// </summary> /// <param name="request"></param> private void addRequestToWaitingList(WWWRequest request) { if (succeedRequest.ContainsKey(request.url) || isInWaitingList(request.url)) { return; } waitingRequests.Add(request); }
static internal void Lua_System_Action_1_WWWRequest(LuaFunction ld, WWWRequest a1) { IntPtr l = ld.L; int error = pushTry(l); pushValue(l, a1); ld.pcall(1, error); LuaDLL.lua_settop(l, error - 1); }
IEnumerator RequestProcess() { while (true) { WWWRequest kRequest = null; if (mRequestList.Count > 0) { kRequest = mRequestList.First.Value; yield return(kRequest.WWWObj); mRequestList.RemoveFirst(); bool bHandled = false; if (null != kRequest.WWWObj.responseHeaders && kRequest.WWWObj.responseHeaders.Count > 0) { if (string.IsNullOrEmpty(kRequest.WWWObj.error)) { WWWHandler(kRequest); mRequestPool.Recyle(kRequest); bHandled = true; } } if (false == bHandled) { WWW kWWW = new WWW(kRequest.WWWObj.url); kRequest.WWWObj.Dispose(); kRequest.WWWObj = kWWW; kRequest.OnFailed(); if (kRequest.RetryMaxCount()) { // Process Lost Connection; OnLostConnection(); mRequestList.AddFirst(kRequest); } else { //process time out OnTimeOut(); } } if (0 == mRequestList.Count) { // Process No Request OnNoRequest(); } } else { yield return(null); } } }
public override WWWResponse ProcessRequest(WWWRequest request) { string nodeName = ""; string groupName = ""; if (request.Form.Count > 0) { nodeName = request.Form ["node"]; groupName = request.Form ["group"]; if (nodeName == null || nodeName == "" || groupName == null || groupName == "") { return(new WWWResponse("/settings/experm", 302)); } if (API.Permissions.Groups.ContainsKey(groupName)) { PermissionGroup pGroup = API.Permissions.Groups [groupName]; if (pGroup.Permissions.Exists(nodeName)) { pGroup.Permissions.Remove(nodeName); API.Permissions.Save(); return(new WWWResponse("/settings/experm/group?group=" + groupName, 302)); } else { return(new WWWResponse("/settings/experm", 302)); } } } else { if (request._request.QueryString ["node"] != null) { nodeName = request._request.QueryString ["node"]; } if (request._request.QueryString ["group"] != null) { groupName = request._request.QueryString ["group"]; } if (nodeName == null || nodeName == "" || groupName == null || groupName == "") { return(new WWWResponse("/settings/experm", 302)); } } string html = Servers.HTTP.WWW._templates["expermgroupremovenode"]; html = html.Replace("{group_name}", groupName); html = html.Replace("{node_name}", nodeName); return(new WWWResponse(html)); }
public void LoadURL(string strURL, WWWCallback callback, object param = null, bool bCache = false) { WWWRequest req = new WWWRequest(); req.strURL = strURL; req.callback = callback; req.m_bCache = bCache; req.m_param = param; wwwRequest.Add(req); checkQueue(); }
static public int CreatWWW(IntPtr l) { try { WWWRequest self = (WWWRequest)checkSelf(l); self.CreatWWW(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
/// <summary> /// 登录,其他所有操作都要在登录成功后进行 /// 跟其他http谓词都不一样,没有排队,直接发送了 /// </summary> public void Login(string name, string password, OnHttpResponse cb) { var queryString = string.Format("email={0}&password={1}", name, password); var fullURL = LoginAddress + "?" + queryString; var seemsUselessBytes = Encoding.UTF8.GetBytes(queryString); var req = new WWWRequest() { Data = seemsUselessBytes, Headers = null, RespCallback = www => { if (www == null) { cb(GenTimeoutResp()); return; } var resp = new HttpResp(); if (!string.IsNullOrEmpty(www.error)) { resp.Error = HttpResp.ErrorType.NetworkError; resp.ErrorText = www.error; } else { var loginResp = JsonUtility.FromJson <LoginResp>(www.text); if (!string.IsNullOrEmpty(loginResp.error)) { resp.Error = HttpResp.ErrorType.LogicError; resp.ErrorText = loginResp.error; } else { resp.Error = HttpResp.ErrorType.None; //set global identity userId = loginResp.user_id; accessToken = loginResp.access_token; } } resp.WwwText = www.text; cb(resp); }, Type = RequestType.Login, Url = fullURL }; waitingRequests.Enqueue(req); }
static public int get_url(IntPtr l) { try { WWWRequest self = (WWWRequest)checkSelf(l); pushValue(l, true); pushValue(l, self.url); return(2); } catch (Exception e) { return(error(l, e)); } }
void addRequestToWaitingList(WWWRequest request) { if (succeedRequest.ContainsKey(request.url) || isInWaitingList(request.url)) { return; } int insertPos = waitingRequests.FindIndex(x => x.priority < request.priority); insertPos = insertPos == -1 ? waitingRequests.Count : insertPos; waitingRequests.Insert(insertPos, request); }
public virtual void Request(string strURL, string strBody, object kFunc) { if (mHeader.ContainsKey("Cookie")) { Log.E(mHeader["Cookie"]); } WWWRequest kRequest = mRequestPool.Get(); kRequest.WWWObj = new WWW(strURL, System.Text.Encoding.UTF8.GetBytes(strBody), mHeader); kRequest.CallbackFunc = kFunc; mRequestList.AddLast(kRequest); }
public void GetData(DataCallback callback) { this.callback = callback; var serverRequestForm = new WWWRequestForm(); AddDefaultToServerRequestForm(serverRequestForm); var serverRequest = new WWWRequest(monoBehaviour, methodServerUrl, serverRequestForm); monoBehaviour.StartCoroutine(RequestData(serverRequest)); }
public override WWWResponse ProcessRequest(WWWRequest request) { //GameManager.Instance.adminTools.IsWhiteListEnabled WWWResponse response = null; if (!request.Form.ContainsKey("password") || request.Form["password"] == "") { string loginTemplate = WWW._templates ["loginform"]; if (GameManager.Instance.adminTools.IsWhiteListEnabled()) { string steamButton = WWW._templates["steambutton"]; string hostAndPort = "http://" + request._request.Url.Host + ":" + request._request.Url.Port; string steamLoginUrl = EndPoint_SteamLogin.GetSteamLoginUrl(hostAndPort, hostAndPort + "/steam"); steamButton = steamButton.Replace("{login_url}", steamLoginUrl); loginTemplate = loginTemplate.Replace("{steam_button}", steamButton); loginTemplate = loginTemplate.Replace("{steam_button_title}", "Login with Steam"); } else { loginTemplate = loginTemplate.Replace("{steam_button}", ""); } response = new WWWResponse(loginTemplate); } else { string pw = request.Form["password"]; if (pw == GamePrefs.GetString(EnumGamePrefs.ServerPassword)) { request.User.SetType("user"); response = new WWWResponse("/", 302); } else { if (pw == GamePrefs.GetString(EnumGamePrefs.ControlPanelPassword)) { request.User.SetType("admin"); response = new WWWResponse("/", 302); } else { response = new WWWResponse("/login/?err=InvalidPassword", 302); } } } return(response); }
// This private method should be called after init void download(WWWRequest request) { request.url = formatUrl(request.url); if (isDownloadingWWW(request.url) || succeedRequest.ContainsKey(request.url)) { return; } if (isBundleUrl(request.url)) { string bundleName = stripBundleSuffix(request.requestString); if (!bundleDict.ContainsKey(bundleName)) { Debug.LogError("Cannot download bundle [" + bundleName + "]. It's not in the bundle config."); return; } List <string> dependlist = getDependList(bundleName); foreach (string bundle in dependlist) { string bundleRequestStr = bundle + "." + bmConfiger.bundleSuffix; string bundleUrl = formatUrl(bundleRequestStr); if (!processingRequest.ContainsKey(bundleUrl) && !succeedRequest.ContainsKey(bundleUrl)) { WWWRequest dependRequest = new WWWRequest(); dependRequest.bundleData = bundleDict[bundle]; dependRequest.bundleBuildState = buildStatesDict[bundle]; dependRequest.requestString = bundleRequestStr; dependRequest.url = bundleUrl; dependRequest.priority = dependRequest.bundleData.priority; addRequestToWaitingList(dependRequest); } } request.bundleData = bundleDict[bundleName]; request.bundleBuildState = buildStatesDict[bundleName]; if (request.priority == -1) { request.priority = request.bundleData.priority; // User didn't change the default priority } addRequestToWaitingList(request); } else { if (request.priority == -1) { request.priority = 0; // User didn't give the priority } addRequestToWaitingList(request); } }
static public int constructor(IntPtr l) { try { WWWRequest o; o = new WWWRequest(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <summary> /// 是否在等待下载列表里 /// </summary> /// <param name="url"></param> /// <returns></returns> private bool isInWaitingList(string url) { for (int i = 0; i < waitingRequests.Count; i++) { WWWRequest request = waitingRequests[i]; if (request.url.Equals(url)) { return(true); } } return(false); }
static internal bool Lua_System_Predicate_1_WWWRequest(LuaFunction ld, WWWRequest a1) { IntPtr l = ld.L; int error = pushTry(l); pushValue(l, a1); ld.pcall(1, error); bool ret; checkType(l, error + 1, out ret); LuaDLL.lua_settop(l, error - 1); return(ret); }
/** * Coroutine for download waiting. * You should use it like this, * yield return StartCoroutine(DownloadManager.Instance.WaitDownload("bundle1.assetbundle")); * If this url didn't been requested, the coroutine will start a new request. */ public IEnumerator WaitDownload(string url, int priority) { while(!ConfigLoaded) yield return null; url = formatUrl(url); WWWRequest request = new WWWRequest(); request.url = url; request.priority = priority; download(request); while(isDownloadingWWW(url)) yield return null; }
static internal int Lua_System_Comparison_1_WWWRequest(LuaFunction ld, WWWRequest a1, WWWRequest a2) { IntPtr l = ld.L; int error = pushTry(l); pushValue(l, a1); pushValue(l, a2); ld.pcall(2, error); int ret; checkType(l, error + 1, out ret); LuaDLL.lua_settop(l, error - 1); return(ret); }
static public int set_priority(IntPtr l) { try { WWWRequest self = (WWWRequest)checkSelf(l); System.Int32 v; checkType(l, 2, out v); self.priority = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_bundleData(IntPtr l) { try { WWWRequest self = (WWWRequest)checkSelf(l); BundleSmallData v; checkType(l, 2, out v); self.bundleData = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_url(IntPtr l) { try { WWWRequest self = (WWWRequest)checkSelf(l); System.String v; checkType(l, 2, out v); self.url = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_www(IntPtr l) { try { WWWRequest self = (WWWRequest)checkSelf(l); UnityEngine.WWW v; checkType(l, 2, out v); self.www = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
/** * Start a new download request. * @param url The url for download. Can be a absolute or relative url. * @param priority Priority for this request. */ public void StartDownload(string url, int priority) { WWWRequest request = new WWWRequest(); request.url = url; request.priority = priority; if(!ConfigLoaded) { if(!isInBeforeInitList(url)) requestedBeforeInit.Add(request); } else download(request); }
// This private method should be called after init void download(WWWRequest request) { request.url = formatUrl(request.url); if(isDownloadingWWW(request.url) || succeedRequest.ContainsKey(request.url)) return; if(isBundleUrl(request.url)) { string bundleName = Path.GetFileNameWithoutExtension(request.url); if(!bundleDict.ContainsKey(bundleName)) { Debug.LogError("Cannot download bundle [" + bundleName + "]. It's not in the bundle config."); return; } List<string> dependlist = getDependList(bundleName); foreach(string bundle in dependlist) { string bundleUrl = formatUrl(bundle + "." + bmConfiger.bundleSuffix); if(!processingRequest.ContainsKey(bundleUrl) && !succeedRequest.ContainsKey(bundleUrl)) { WWWRequest dependRequest = new WWWRequest(); dependRequest.bundleData = bundleDict[bundle]; dependRequest.bundleBuildState = buildStatesDict[bundle]; dependRequest.url = bundleUrl; dependRequest.priority = dependRequest.bundleData.priority; addRequestToWaitingList(dependRequest); } } request.bundleData = bundleDict[bundleName]; request.bundleBuildState = buildStatesDict[bundleName]; if(request.priority == -1) request.priority = request.bundleData.priority; // User didn't change the default priority addRequestToWaitingList(request); } else { if(request.priority == -1) request.priority = 0; // User didn't give the priority addRequestToWaitingList(request); } }
void addRequestToWaitingList(WWWRequest request) { if(succeedRequest.ContainsKey(request.url) || isInWaitingList(request.url)) return; int insertPos = waitingRequests.FindIndex(x => x.priority < request.priority); insertPos = insertPos == -1 ? waitingRequests.Count : insertPos; waitingRequests.Insert(insertPos, request); }