/// <summary> /// Set language object. /// </summary> private static void SetLang(string typeName) { if (string.IsNullOrEmpty(typeName)) { typeName = ConfigManager.Configger.GetFirstOrAddConfig <AppServerSection>().LanguageTypeName; } var obj = ScriptEngines.Execute(null, typeName); if (obj != null) { _instance = obj; return; } //get default lang typeName = ConfigManager.Configger.GetFirstOrAddConfig <AppServerSection>().LanguageTypeName; var type = Type.GetType(typeName, false, false); if (type != null) { _instance = type.CreateInstance(); } else { TraceLog.WriteWarn("Can not find the corresponding language configuration,typeName:{0}", typeName);//By Seamoon } }
internal static BaseStruct FindScriptRoute(HttpGet httpGet, int actionID) { string scriptTypeName = string.Format(GameEnvironment.Setting.ScriptTypeName, actionID); string scriptCode = ""; if (!ScriptEngines.DisablePython) //By Seamoon 在Python禁用的情况下,就没有必要再加载了 { scriptCode = string.Format("{0}/action/action{1}.py", ScriptEngines.PythonDirName, actionID); dynamic scriptScope = ScriptEngines.Execute(scriptCode, null); if (scriptScope != null) { bool ignoreAuthorize = _ignoreAuthorizeSet.Contains(actionID); return(new ScriptAction((short)actionID, httpGet, scriptScope, ignoreAuthorize)); } } scriptCode = string.Format("{0}/action/action{1}.cs", ScriptEngines.CSharpDirName, actionID); BaseStruct baseStruct = ScriptEngines.Execute(scriptCode, scriptTypeName, httpGet); if (baseStruct != null) { return(baseStruct); } return(null); }
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> /// Inits the task. /// </summary> /// <returns><c>true</c>, if task was inited, <c>false</c> otherwise.</returns> protected bool InitTask() { TNet.Cache.Generic.CacheList <string> st; _taskScope = ScriptEngines.Execute("Lib.Task", null); return(_taskScope != null); }
public static CaseStep Create(string formatType, string stepName, int index) { string typeName = string.Format(formatType, stepName); string code = string.Format(ConfigUtils.GetSetting("CaseStep.Script.Format", "Case.Step{0}.cs"), stepName); var instance = ScriptEngines.Execute(code, typeName); //var instance = type.CreateInstance<CaseStep>(); if (instance == null) { throw new NullReferenceException(string.Format("Get CaseStep object is null, type:{1}, script code:{0}", code, typeName)); } instance.Action = stepName; instance.netWriter = new NetWriter(); instance.netReader = new NetReader(new CustomHeadFormater()); instance.indentify = index; if (instance.isCustom) { GameRanking.Pack.MessagePack headPack = new GameRanking.Pack.MessagePack() { MsgId = 1, ActionId = int.Parse(stepName), SessionId = "", UserId = 0 }; byte[] header = ProtoBufUtils.Serialize(headPack); instance.netWriter.SetHeadBuffer(header); instance.netWriter.SetBodyData(null); } return(instance); }
public static T Create(string formatType, string stepName) { string typeName = string.Format(formatType, stepName); string code = string.Format(ConfigUtils.GetSetting("CaseStep.Script.Format", "Case.Step{0}.cs"), stepName); var instance = ScriptEngines.Execute(code, typeName); //var instance = type.CreateInstance<CaseStep>(); if (instance == null) { throw new NullReferenceException(string.Format("Get CaseStep object is null, type:{1}, script code:{0}", code, typeName)); } instance.Action = stepName; return(instance); }
/// <summary> /// Processes the cmd. /// </summary> /// <param name="args">Arguments.</param> protected override void ProcessCmd(string[] args) { string routeName = string.Format("Gm.{0}", _cmd); dynamic scriptScope = ScriptEngines.Execute(routeName, null); if (scriptScope != null) { try { scriptScope.processCmd(UserID, args); } catch (Exception ex) { TraceLog.WriteError("Gm:{0} process error:{1}", _cmd, ex); } } }
/// <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.DisablePython) { routeFile = string.Format("{0}/Remote/{1}.py", ScriptEngines.PythonDirName, routeName); dynamic scope = ScriptEngines.Execute(routeFile, typeName); if (scope != null) { var funcHandle = scope.GetVariable <RemoteHandle>(funcName); if (funcHandle != null) { funcHandle(httpGet, head, response); response.WriteBuffer(head); return; } } } routeFile = string.Format("{0}/Remote/{1}.cs", ScriptEngines.CSharpDirName, 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); } }
private void DoTableTimer(object state) { try { if (state is TableData) { int outcardPeroid = ConfigEnvSet.GetInt("Game.Table.AIOutCardTime", 5000); var temp = state as TableData; TableData table; RoomData roomData = GetRoomData(temp.RoomId); if (!roomData.Tables.TryGetValue(temp.TableId, out table)) { return; } if (table.IsTimeRunning) { return; } table.IsTimeRunning = true; if (table.IsClosed || table.IsDisposed) { //检查是否出完牌 table.StopTimer(); table.IsTimeRunning = false; return; } if (!table.IsStarting) { //AI Join dynamic scope = ScriptEngines.Execute(AIScriptCode, null); if (scope != null) { HashSet <string> nickSet = new HashSet <string>(); foreach (var pos in table.Positions) { if (pos.UserId == 0) { int aiId = 100 + pos.Id; string nickName = "雪舞枫红"; string head = "head_1001"; try { var nameList = scope.AIConfig.getConfig("nickName"); if (nameList != null && nameList.Count > 0) { for (int i = 0; i < 5; i++) { int index = RandomUtils.GetRandom(0, nameList.Count); nickName = nameList[index]; if (!nickSet.Contains(nickName)) { nickSet.Add(nickName); break; } } } var headList = scope.AIConfig.getConfig("head"); if (headList != null && headList.Count > 0) { int index = RandomUtils.GetRandom(0, headList.Count); head = headList[index]; } } catch (Exception ex) { TraceLog.WriteError("AI get nickname error:{0}", ex.ToString()); //Console.WriteLine(ex.Message); } pos.InitAI(table.RoomId, table.TableId, aiId, nickName, head); } } SyncNotifyAction(ActionIDDefine.Cst_Action2003, table, null, c => { CheckStart(table); int periodFirstCall = ConfigEnvSet.GetInt("Game.Table.AIFirstOutCardTime", 20000); table.ReStartTimer(periodFirstCall); //发牌等待20秒 }); } } else if (!table.IsCallEnd) { //叫地主 var pos = table.Positions[table.CallLandlordPos]; if (pos != null && !pos.IsAI && table.IsOperationTimeout) { //超时自动托管 pos.IsAI = true; NotifyAutoAiUser(pos.UserId, true); } if (pos != null && pos.IsAI) { //Console.WriteLine("Table:{0} is ai", table.TableId); dynamic scope = ScriptEngines.Execute(AIScriptCode, null); if (scope != null) { bool iscall = false; try { var myClass = scope.GetVariable <Func <int, int, int, dynamic> >("CardAILogic"); var myInstance = myClass(table.RoomId, table.TableId, pos.Id); iscall = (bool)myInstance.checkCall(); } catch (Exception e) { TraceLog.WriteError("桌子:{0}Timer error:{1}", table.TableId, e.ToString()); //Console.WriteLine("Table:{0} is error:{1}", table.TableId, e.ToString()); } CallCard(pos.Id, table, iscall); table.ReStartTimer(outcardPeroid); } } } else { //出牌 var pos = table.Positions[table.OutCardPos]; if (pos != null && !pos.IsAI && table.IsOperationTimeout) { //超时自动托管 pos.IsAI = true; NotifyAutoAiUser(pos.UserId, true); } if (pos != null && pos.IsAI && pos.CardData.Count > 0) { try { dynamic scope = ScriptEngines.Execute(AIScriptCode, null); if (scope != null) { var myClass = scope.GetVariable <Func <int, int, int, dynamic> >("CardAILogic"); var myInstance = myClass(table.RoomId, table.TableId, pos.Id); var outList = (IronPython.Runtime.List)myInstance.searchOutCard(); string cards = string.Empty; if (outList != null) { object[] cardArr = new object[outList.Count]; outList.CopyTo(cardArr, 0); cards = string.Join(",", cardArr); } if (!OutCard(pos.UserId, pos.Id, table, cards)) { table.StopTimer(); TraceLog.WriteError("桌子:{0}玩家{1}-{2}托管出牌:\"{3}\"出错,上一手出牌:\"{4}\"", table.TableId, pos.Id, pos.NickName, cards, (table.PreCardData != null ? string.Join(",", table.PreCardData.Cards) : "")); OutCard(pos.UserId, pos.Id, table, ""); } table.ReStartTimer(outcardPeroid); } } catch (Exception e) { TraceLog.WriteError("Table:{0} is error:{1}", table.TableId, e); //Console.WriteLine("Table:{0} is error:{1}", table.TableId, e.ToString()); //出错过牌 OutCard(pos.UserId, pos.Id, table, ""); table.ReStartTimer(outcardPeroid); } } } table.IsTimeRunning = false; table.DoTimeNumber(); } } catch (Exception ex) { TraceLog.WriteError("Timer error:{0}", ex.ToString()); } }
/// <summary> /// Inits the task. /// </summary> /// <returns><c>true</c>, if task was inited, <c>false</c> otherwise.</returns> protected bool InitTask() { _taskScope = ScriptEngines.Execute(ScriptEngines.PythonDirName + "/Lib/Task.py", null); return(_taskScope != null); }
/// <summary> /// Inits the task. /// </summary> /// <returns><c>true</c>, if task was inited, <c>false</c> otherwise.</returns> protected bool InitTask() { _taskScope = ScriptEngines.Execute("Lib.Task", null); return(_taskScope != null); }