internal static BaseStruct FindScriptRoute(ActionGetter actionGetter, int actionID) { string scriptTypeName = string.Format(GameEnvironment.Setting.ScriptTypeName, actionID); string scriptCode = ""; if (!ScriptEngines.SettupInfo.DisablePython) //By Seamoon 在Python禁用的情况下,就没有必要再加载了 { scriptCode = string.Format("action.action{0}", actionID); dynamic scriptScope = ScriptEngines.ExecutePython(scriptCode); if (scriptScope != null) { bool ignoreAuthorize = _ignoreAuthorizeSet.Contains(actionID); return(new ScriptAction(ScriptType.Python, actionID, actionGetter, scriptScope, ignoreAuthorize)); } } if (!ScriptEngines.SettupInfo.DisableLua) { scriptCode = string.Format("Action{0}", actionID); dynamic scriptScope = ScriptEngines.ExecuteLua("GetTable", scriptCode, actionID); if (scriptScope != null) { bool ignoreAuthorize = _ignoreAuthorizeSet.Contains(actionID); return(new LuaAction(actionID, actionGetter, scriptScope, ignoreAuthorize)); } } scriptCode = string.Format("action.action{0}", actionID); BaseStruct baseStruct = ScriptEngines.Execute(scriptCode, scriptTypeName, actionGetter); if (baseStruct != null) { return(baseStruct); } return(null); }
/// <summary> /// Call remote method /// </summary> /// <param name="routePath"></param> /// <param name="actionGetter"></param> /// <param name="response"></param> protected virtual void OnCallRemote(string routePath, ActionGetter actionGetter, MessageStructure response) { try { string[] mapList = routePath.Split('.'); string funcName = ""; string routeName = routePath; if (mapList.Length > 1) { funcName = mapList[mapList.Length - 1]; routeName = string.Join("/", mapList, 0, mapList.Length - 1); } string routeFile = ""; int actionId = actionGetter.GetActionId(); MessageHead head = new MessageHead(actionId); if (!ScriptEngines.SettupInfo.DisablePython) { routeFile = string.Format("Remote.{0}", routeName); dynamic scope = ScriptEngines.ExecutePython(routeFile); if (scope != null) { var funcHandle = scope.GetVariable <RemoteHandle>(funcName); if (funcHandle != null) { funcHandle(actionGetter, head, response); response.WriteBuffer(head); return; } } } string typeName = string.Format(TNet.Runtime.GameZone.Setting.RemoteTypeName, routeName); routeFile = string.Format("Remote.{0}", routeName); var args = new object[] { actionGetter, response }; var instance = (object)ScriptEngines.Execute(routeFile, typeName, args); if (instance is RemoteStruct) { var target = instance as RemoteStruct; target.DoRemote(); } } catch (Exception ex) { TraceLog.WriteError("OnCallRemote error:{0}", ex); } }
private void OnCallRemote(string route, HttpGet httpGet, MessageStructure response) { try { string[] mapList = route.Split('.'); string funcName = ""; string routeName = ""; if (mapList.Length > 1) { funcName = mapList[mapList.Length - 1]; routeName = string.Join("/", mapList, 0, mapList.Length - 1); } string routeFile = ""; string typeName = string.Format("Game.Script.Remote.{0}", routeName); int actionId = httpGet.ActionId; MessageHead head = new MessageHead(actionId); if (!ScriptEngines.SettupInfo.DisablePython) { routeFile = string.Format("Remote.{0}", routeName); dynamic scope = ScriptEngines.ExecutePython(routeFile); if (scope != null) { var funcHandle = scope.GetVariable <RemoteHandle>(funcName); if (funcHandle != null) { funcHandle(httpGet, head, response); response.WriteBuffer(head); return; } } } routeFile = string.Format("Remote.{0}", routeName); var instance = (object)ScriptEngines.Execute(routeFile, typeName); if (instance != null) { var result = ObjectAccessor.Create(instance, true)[funcName]; } } catch (Exception ex) { TraceLog.WriteError("{0}", ex); } }