//慎用 public string sendDataToServer(string url, string data, bool ifProcessData = false) { string host = Models.SimpleUserInfo.host; string outdatacode = AuthCode.Encode(data, Models.SimpleUserInfo.sign); string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", Models.SimpleUserInfo.uid, HttpUtility.UrlEncode(outdatacode), CommonHelper.ConvertDateTimeInt(DateTime.Now, true)); Console.WriteLine(requeststring); string result = doPost(host + url, requeststring); string nresult = AuthCode.Decode(result, Models.SimpleUserInfo.sign); if (String.IsNullOrEmpty(nresult)) { nresult = result; } if (ifProcessData) { var par = System.Web.HttpUtility.ParseQueryString(requeststring); par["outdatacode"] = data; im.listener.processMainData(url.ToString(), par, nresult); } return(nresult); }
//慎用 public string SendDataToServer(string url, string data, bool ifProcessData = false) { string host = Models.SimpleInfo.host; string outdatacode = AuthCode.Encode(data, Models.SimpleInfo.sign); string requeststring = String.Format("uid={0}&outdatacode={1}&req_id={2}", Models.SimpleInfo.uid, HttpUtility.UrlEncode(outdatacode), ++Models.SimpleInfo.reqid); im.logger.Log(requeststring); string result = DoPost(host + url, requeststring); string nresult = AuthCode.Decode(result, Models.SimpleInfo.sign); if (String.IsNullOrEmpty(nresult)) { nresult = result; } if (ifProcessData) { var par = System.Web.HttpUtility.ParseQueryString(requeststring); par["outdatacode"] = data; im.listener.processMainData(url.ToString(), par, nresult); } return(nresult); }
private void processData(Session obj) { string host = obj.Request.Headers.Host; KeyValuePair <string, string> server = im.serverHelper.getServerFromDictionary(host); if (server.Key == "" && server.Value == "") { return; } string api = obj.Request.RequestLine.URI.Substring(server.Key.Length - ("http://" + host).Length); Console.WriteLine(api); switch (api) { case RequestUrls.GetDigitalUid: { string data = obj.Response.BodyAsString; string decoded = AuthCode.Decode(data, "yundoudou"); Console.WriteLine(decoded); dynamic jsonobj = DynamicJson.Parse(decoded); token = jsonobj.sign; uid = jsonobj.uid; //wtf? Models.SimpleUserInfo.sign = token; Models.SimpleUserInfo.uid = uid; im.uiHelper.setStatusBarText_InThread(String.Format("已登录服务器: {0},token: {1},uid: {2}", server.Value, token, uid)); Models.SimpleUserInfo.host = server.Key; break; } case RequestUrls.GetServerTime: //同步服务器时间 { if (String.IsNullOrEmpty(token) || String.IsNullOrEmpty(uid)) { im.uiHelper.setStatusBarText_InThread("未获取到token!请重新登录游戏以使本工具正常工作!"); break; } if (String.IsNullOrEmpty(token)) { break; } string decoded = AuthCode.Decode(obj.Response.BodyAsString, token); dynamic jsonobj = DynamicJson.Parse(decoded); Console.WriteLine("Server: " + jsonobj.now + " \nClient: " + CommonHelper.ConvertDateTimeInt(DateTime.Now)); SimpleUserInfo.timeoffset = Convert.ToInt32(jsonobj.now) - CommonHelper.ConvertDateTimeInt(DateTime.Now); //server = local + offset Console.WriteLine("Set timeoffset: " + SimpleUserInfo.timeoffset); break; } default: { if (String.IsNullOrEmpty(token) || String.IsNullOrEmpty(uid)) { im.uiHelper.setStatusBarText_InThread("未获取到token!请重新登录游戏以使本工具正常工作!"); } else { try { StringBuilder sb = new StringBuilder(); sb.Append("api: " + api + "\n"); NameValueCollection clientdata = new NameValueCollection(); string serverdata = AuthCode.Decode(obj.Response.BodyAsString, token); if (String.IsNullOrEmpty(serverdata)) //没有加密 { serverdata = obj.Response.BodyAsString; } if (!String.IsNullOrEmpty(obj.Response.BodyAsString)) { clientdata = HttpUtility.ParseQueryString(obj.Request.BodyAsString); if (clientdata.AllKeys.Contains("outdatacode")) { clientdata["outdatacode"] = AuthCode.Decode(clientdata["outdatacode"], token, SimpleUserInfo.timeoffset); Console.WriteLine("outdatacode: " + clientdata["outdatacode"]); sb.Append("client: " + clientdata["outdatacode"] + "\n"); } else { clientdata["outdatacode"] = "[]"; } sb.Append("server: " + serverdata); im.logger.Log(sb.ToString()); } if (serverdata.Length < 100) { Console.WriteLine("Serverdata: " + serverdata); } processMainData(api, clientdata, serverdata); } catch (Exception e) { Console.WriteLine(e); } } break; } } }