protected override void OnRequested(HttpGet httpGet, IGameResponse response) { try { var actionId = httpGet.GetString("ActionID").ToInt(); var uid = httpGet.GetString("uid"); Console.WriteLine("Action{0} from {1} {2}", actionId, httpGet.RemoteAddress, uid); ActionFactory.Request(httpGet, response, userId => new GameDataCacheSet<GameUser>().FindKey(userId.ToNotNullString())); } catch (Exception ex) { TraceLog.WriteError("{0}", ex); } }
protected void Page_Load(object sender, EventArgs e) { System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;//new HttpResponse(sw); response.Charset = "unicode";// "unicode"; HttpGet httpGet = new HttpGet(); String ActionID = string.Empty; if (httpGet.GetString("ActionID", ref ActionID)) { try { string actionName = string.Concat("Action", ActionID); string sname = string.Concat("ZyGames.DirCenter.Action." + actionName); object[] args = new object[1]; args[0] = response; BaseStruct obj = (BaseStruct) Activator.CreateInstance(Type.GetType(sname), new object[] { httpGet }); if (obj.ReadUrlElement() && obj.DoAction() && !obj.GetError()) { obj.BuildPacket(); obj.WriteAction(); } else { obj.WriteErrorAction(); return; } } catch (Exception ex) { BaseLog oBaseLog = new BaseLog("DirCenterErrMain"); oBaseLog.SaveLog(ex); } } }
protected void Page_Load(object sender, EventArgs e) { System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; //new HttpResponse(sw); response.Charset = "unicode"; // "unicode"; HttpGet httpGet = new HttpGet(); String ActionID = string.Empty; if (httpGet.GetString("ActionID", ref ActionID)) { try { string actionName = string.Concat("Action", ActionID); string sname = string.Concat("ZyGames.DirCenter.Action." + actionName); object[] args = new object[1]; args[0] = response; BaseStruct obj = (BaseStruct)Activator.CreateInstance(Type.GetType(sname), new object[] { httpGet }); if (obj.ReadUrlElement() && obj.DoAction() && !obj.GetError()) { obj.BuildPacket(); obj.WriteAction(); } else { obj.WriteErrorAction(); return; } } catch (Exception ex) { BaseLog oBaseLog = new BaseLog("DirCenterErrMain"); oBaseLog.SaveLog(ex); } } }
protected void Page_Load(object sender, EventArgs e) { HttpGet httpGet = new HttpGet(); String ActionID = string.Empty; if (httpGet.GetString("ActionID", ref ActionID)) { try { string actionName = string.Concat("Action", ActionID); string sname = string.Concat("FzCompany.HXSC.BLL.Action." + actionName); Assembly a = Assembly.Load("FzCompany.HXSC.BLL"); BaseAction obj = (BaseAction)Assembly.Load("FzCompany.HXSC.BLL").CreateInstance(sname, true, BindingFlags.Default, null, new object[] { httpGet }, null, null); if (obj.ReadUrlElement() && obj.DoAction()) { obj.BuildPacket(); //obj.WriteAction(); } else { //obj.WriteErrorAction(); //return; } obj.WritePacket(); } catch (Exception ex) { LogHelper.WriteException("接口请求出错", ex); } } }
public LoginProxy(HttpGet httpGet) { this._httpGet = httpGet; if (_httpGet != null) { _httpGet.GetString("RetailID", ref retailID); } }
protected override void OnRequested(HttpGet httpGet, IGameResponse response) { try { var actionId = httpGet.ActionId; var uid = httpGet.GetString("uid"); Console.WriteLine("Action{0} from {1} {2}", actionId, httpGet.RemoteAddress, uid); ActionFactory.Request(httpGet, response, GetUser); } catch (Exception ex) { TraceLog.WriteError("{0}", ex); } }
/// <summary> /// 读取Url参数 /// </summary> /// <returns></returns> public bool ReadUrlElement() { httpGet.GetString("key", ref key); if (!httpGet.CheckSign()) { return(SetError("签名验证出错!")); } if (!GetUrlElement()) { basePack.ErrorCode = 1001; basePack.ErrorMsg = "请求参数有错"; return(false); } return(true); }
private object[] GetArgs(string argsStr) { List <object> args = new List <object>(); string[] paramList = argsStr.Split(new char[] { ',' }); foreach (string param in paramList) { string paramVal = string.Empty; if (_httpGet != null) { _httpGet.GetString(param, ref paramVal); } args.Add(paramVal); } return(args.ToArray()); }
/// <summary> /// /// </summary> /// <param name="actionId"></param> /// <param name="sessionList"></param> /// <param name="package"></param> /// <param name="complateHandle"></param> /// <param name="onlineInterval"></param> /// <returns></returns> public static async System.Threading.Tasks.Task BroadcastAction(int actionId, GameSession session, object parameter, Action <GameSession, SocketAsyncResult> complateHandle, int onlineInterval) { try { sbyte opCode = OpCode.Binary; RequestPackage package = parameter is Parameters ? ActionFactory.GetResponsePackage(actionId, session, parameter as Parameters, opCode, null) : ActionFactory.GetResponsePackage(actionId, session, null, opCode, parameter); if (session.Equals(null)) { throw new ArgumentNullException("Session is a null value."); } IActionDispatcher actionDispatcher = new ScutActionDispatcher(); package.Bind(session); var actionGetter = new HttpGet(package, session); byte[] data = ProcessActionResponse(actionDispatcher, actionId, actionGetter); GameSession temp = session; try { if (onlineInterval <= 0 || session.LastActivityTime > MathUtils.Now.AddSeconds(-onlineInterval)) { byte userRet = 0; string userSid = string.Empty; if (actionGetter.GetByte("UserRet", ref userRet) && userRet == (byte)1 && actionGetter.GetString("UserSid", ref userSid)) { var switchSession = ServerSsMgr.GetSwitchSession(); //未连接上路由服,则发给大厅服,由大厅服转发 if (switchSession == null) { var paramStr = "ActionId=100&MsgId=0&UserSid=" + userSid; string sign = SignUtils.EncodeSign(paramStr, RequestParam.SignKey); paramStr += string.Format("&{0}={1}", "sign", sign); var postData = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr)); byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length]; Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length); Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length); Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length); await session.SendAsync(package.OpCode, paramBytes, 0, paramBytes.Length, result => { if (complateHandle != null) { complateHandle(temp, result); } }); } //已连接上路由服,则直接发给路由服 else { var paramStr = "ActionId=101&MsgId=0&UserSid=" + userSid; string sign = SignUtils.EncodeSign(paramStr, RequestParam.SignKey); paramStr += string.Format("&{0}={1}", "sign", sign); var postData = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr)); byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length]; Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length); Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length); Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length); await switchSession.SendAsync(package.OpCode, paramBytes, 0, paramBytes.Length, result => { if (complateHandle != null) { complateHandle(temp, result); } }); } } else { await session.SendAsync(package.OpCode, data, 0, data.Length, result => { if (complateHandle != null) { complateHandle(temp, result); } }); } } else { if (complateHandle != null) { complateHandle(temp, new SocketAsyncResult(data) { Result = ResultCode.Close }); } } } catch (Exception ex) { if (complateHandle != null) { complateHandle(temp, new SocketAsyncResult(data) { Result = ResultCode.Error, Error = ex }); } TraceLog.WriteError("SocialBroadCastActionFactory BroadcastAction action:{0} userId:{1} error:{2}", actionId, session.UserId, ex); } } catch (Exception ex) { TraceLog.WriteError("SocialBroadCastActionFactory BroadcastAction action:{0} error:{1}", actionId, ex); } }