123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
-
- 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();
-
-
-
- private IZone zone;
-
-
-
- private bool isInit = false;
-
-
-
- private Logger log;
-
- 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;
-
-
- 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("----------------------- 启动场景管理器");
-
- string zoneClass = class_config.Get("zone");
- this.zone = ReflectionUtil.CreateInterface<IZone>(zoneClass);
-
- zone.Start(zoneConfig);
- }
-
- {
- Console.WriteLine("----------------------- 启动FastStream");
-
- FastStream.init(class_config.Get("faststream"));
- FastStream.instance().Start(fastStreamConfig, zone);
- }
-
- {
- Console.WriteLine("----------------------- 启动Ice");
- Dictionary<string, Ice.ObjectImpl> proxys = new Dictionary<string, Ice.ObjectImpl>();
- 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<Ice.ObjectImpl>(iceImpConfig[key]);
- }
- IceManager.instance().Start(iceConfig, proxys);
- }
-
- }
-
- return 0;
- }
- public int close()
- {
-
- IceManager.instance().Stop();
-
- FastStream.instance().Stop();
-
- zone.Stop();
- return 0;
- }
-
-
-
-
-
- public async Task<object> init(dynamic input)
- {
-
- ZoneConfig zoneConfig = new ZoneConfig();
- LogConfig logConfig = new LogConfig();
- IceConfig iceConfig = new IceConfig();
- FastStreamConfig fastStreamConfig = new FastStreamConfig();
- try
- {
-
- zoneConfig.startPath = (string)input.zoneConfig.startPath;
- zoneConfig.assetPath = (string)input.zoneConfig.assetPath;
-
- 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;
-
- iceConfig.host = (string)input.iceConfig.host;
- iceConfig.port = (int)input.iceConfig.port;
-
- 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<object> fini(dynamic input)
- {
- return await Task.Run(() =>
- {
- return close();
- });
- }
- }
- }
|