internal static BaseStruct FindRoute(string typeExpression, HttpGet httpGet, int actionID) { string typeName = string.Format(typeExpression, actionID); ScriptRoute scriptRoute = new ScriptRoute(actionID); RouteItem routeItem; var pythonManager = PythonScriptManager.Current; if (pythonManager.TryGetAction(actionID, out routeItem)) { if (scriptRoute.TryLoadAction(routeItem.ScriptPath)) { return new ScriptAction((short)actionID, httpGet, scriptRoute, routeItem.IgnoreAuthorize); } //中间件路由配置 if (!string.IsNullOrEmpty(routeItem.TypeName)) { typeName = routeItem.TypeName; } } Type actionType = Type.GetType(typeName); if (actionType != null) { try { return actionType.CreateInstance<BaseStruct>(new object[] { httpGet }); //return (BaseStruct)Activator.CreateInstance(actionType, new object[] { httpGet }); } catch(Exception ex) { throw ex; } } throw new NullReferenceException(string.Format("未找到Action处理对象的类型:{0}!", typeName)); }
/// <summary> /// / /// </summary> /// <param name="aActionId"></param> /// <param name="httpGet"></param> /// <param name="scriptRoute"></param> /// <param name="ignoreAuthorize">忽略授权</param> public ScriptAction(short aActionId, HttpGet httpGet, ScriptRoute scriptRoute, bool ignoreAuthorize) : base(aActionId, httpGet) { _scriptRoute = scriptRoute; _ignoreAuthorize = ignoreAuthorize; }
/// <summary> /// 请求脚本处理 /// </summary> /// <param name="httpGet">请求参数对象</param> /// <param name="response">字节输出处理</param> /// <param name="userFactory">创建user对象工厂,可为Null</param> public static void RequestScript(HttpGet httpGet, IGameResponse response, Func<int, BaseUser> userFactory) { int actionID = httpGet.GetInt("actionId"); string errorInfo = ""; try { bool isRl = BaseStruct.CheckRunloader(httpGet); if (isRl || httpGet.CheckSign()) { ScriptRoute scriptRoute = new ScriptRoute(actionID); RouteItem routeItem; var pythonManager = PythonScriptManager.Current; if (pythonManager.TryGetAction(actionID, out routeItem)) { if (scriptRoute.TryLoadAction(routeItem.ScriptPath)) { var baseStruct = new ScriptAction((short)actionID, httpGet, scriptRoute, routeItem.IgnoreAuthorize); Process(baseStruct, httpGet, response, userFactory); return; } } } else { errorInfo = "签名验证失败"; TraceLog.WriteError("Action request error:{2},rl:{0},param:{1}", isRl, httpGet.ParamString, errorInfo); } } catch (Exception ex) { TraceLog.WriteError("Action request error:{0}\r\nparam:{1}", ex, httpGet.ParamString); } RequestError(response, actionID, errorInfo); }