Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 /// <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);
 }