using CommonLang; using CommonLang.Log; using CommonLang.Property; using System; using System.Collections.Generic; using System.Dynamic; using System.Threading; using System.Threading.Tasks; namespace Pomelo { public class EdgeJS { private static object locker = new object(); /// /// zone接口 /// private IZone zone; /// /// 是否初始化 /// private bool isInit = false; /// /// 日志 /// private Logger log; /** public int open_old(ZoneConfig zoneConfig, LogConfig logConfig, IceConfig iceConfig, FastStreamConfig fastStreamConfig) { lock (locker) { if (this.isInit) { return 0; } this.isInit = true; //-------------------------------------------------------------------------------------------------------- //加载所有dll ReflectionUtil.LoadDlls(new System.IO.DirectoryInfo(zoneConfig.startPath)); //-------------------------------------------------------------------------------------------------------- //创建日志 try { LoggerFactory.SetFactory(new PomeloLog(logConfig)); } catch (Exception err) { Console.WriteLine(err.Message); } this.log = LoggerFactory.GetLogger("PomeloService"); //-------------------------------------------------------------------------------------------------------- Properties class_config = Properties.LoadFromResource(zoneConfig.startPath + "/class_config.properties"); //-------------------------------------------------------------------------------------------------------- { //初始化IZone string zoneClass = class_config.Get("zone"); this.zone = ReflectionUtil.CreateInterface(zoneClass); //启动场景管理器 zone.Start(zoneConfig); } //-------------------------------------------------------------------------------------------------------- { //启动FastStream FastStream.init(class_config.Get("faststream")); FastStream.instance().Start(fastStreamConfig, zone); } //-------------------------------------------------------------------------------------------------------- { //启动Ice Dictionary proxys = new Dictionary(); proxys["zoneManager"] = new ZoneManagerI(this.zone); Properties iceImpConfig = class_config.SubProperties("ice."); foreach (string key in iceImpConfig.Keys) { log.Info(string.Format("load Ice Imp {0} = {1}", key, iceImpConfig[key])); proxys[key] = ReflectionUtil.CreateInterface(iceImpConfig[key]); } IceManager.instance().Start(iceConfig, proxys); } } // Console.WriteLine("after isTraceNetwork:" + iceConfig.isTraceNetwork); return 0; } */ public int open(ZoneConfig zoneConfig, LogConfig logConfig, IceConfig iceConfig, FastStreamConfig fastStreamConfig) { lock (locker) { Console.WriteLine("----------------------- 启动服务【" + logConfig.serverId +"】, (" + fastStreamConfig.port + ", " + iceConfig.port + ")"); if (this.isInit) { log.Error("重复启动游戏!"); return 0; } this.isInit = true; //-------------------------------------------------------------------------------------------------------- //加载所有dll ReflectionUtil.LoadDlls(new System.IO.DirectoryInfo(zoneConfig.startPath)); //-------------------------------------------------------------------------------------------------------- //创建日志 try { Console.WriteLine("----------------------- 创建日志"); LoggerFactory.SetFactory(new PomeloLog(logConfig)); } catch (Exception err) { Console.WriteLine(err.Message); } this.log = LoggerFactory.GetLogger("PomeloService"); //-------------------------------------------------------------------------------------------------------- Properties class_config = Properties.LoadFromResource(zoneConfig.startPath + "/class_config.properties"); //-------------------------------------------------------------------------------------------------------- { Console.WriteLine("----------------------- 启动场景管理器"); //初始化IZone string zoneClass = class_config.Get("zone"); this.zone = ReflectionUtil.CreateInterface(zoneClass); //启动场景管理器 zone.Start(zoneConfig); } //-------------------------------------------------------------------------------------------------------- { Console.WriteLine("----------------------- 启动FastStream"); //启动FastStream FastStream.init(class_config.Get("faststream")); FastStream.instance().Start(fastStreamConfig, zone); } //-------------------------------------------------------------------------------------------------------- { //启动Ice Console.WriteLine("----------------------- 启动Ice"); Dictionary proxys = new Dictionary(); proxys["zoneManager"] = new ZoneManagerI(this.zone); Properties iceImpConfig = class_config.SubProperties("ice."); foreach (string key in iceImpConfig.Keys) { log.Info(string.Format("load Ice Imp {0} = {1}", key, iceImpConfig[key])); proxys[key] = ReflectionUtil.CreateInterface(iceImpConfig[key]); } IceManager.instance().Start(iceConfig, proxys); } //Console.WriteLine("-----------------------END"); } return 0; } public int close() { //关闭Ice IceManager.instance().Stop(); //关闭FastStream FastStream.instance().Stop(); //关闭场景管理器 zone.Stop(); return 0; } /// /// 初始化 /// /// /// public async Task init(dynamic input) { //解析参数 ZoneConfig zoneConfig = new ZoneConfig(); LogConfig logConfig = new LogConfig(); IceConfig iceConfig = new IceConfig(); FastStreamConfig fastStreamConfig = new FastStreamConfig(); try { //zone配置 zoneConfig.startPath = (string)input.zoneConfig.startPath; zoneConfig.assetPath = (string)input.zoneConfig.assetPath; //fastStream配置 fastStreamConfig.port = (int)input.fastStreamConfig.port; //日志配置 logConfig.configFile = (string)input.logConfig.configFile; logConfig.outputPath = (string)input.logConfig.outputPath; logConfig.level = (uint)input.logConfig.level; logConfig.serverId = (string)input.logConfig.serverId; //ice配置 iceConfig.host = (string)input.iceConfig.host; iceConfig.port = (int)input.iceConfig.port; // Console.WriteLine("before isTraceNetwork:"+input.iceConfig.isTraceNetwork); try { iceConfig.isWarnConnections = (bool)input.iceConfig.isWarnConnections; iceConfig.isTraceNetwork = (bool)input.iceConfig.isTraceNetwork; iceConfig.isTraceProtocol = (bool)input.iceConfig.isTraceProtocol; } catch (Exception e) { Console.Error.WriteLine(e); } } catch (Exception e) { Console.Error.WriteLine(e); return 0; } return await Task.Run(() => { return open(zoneConfig, logConfig, iceConfig, fastStreamConfig); }); } /// /// 结束 /// /// /// public async Task fini(dynamic input) { return await Task.Run(() => { return close(); }); } } }