Пример #1
0
 public static void Init(Logger log, Properties config)
 {
     if (ZoneFactory == null)
     {
         log.Info("********************************************************");
         log.Info("# 初始化战斗编辑器扩展 ");
         log.Info("********************************************************");
         ZoneFactory = ReflectionUtil.CreateInterface <InstanceZoneFactory>(config["ZoneFactory"]);
         TemplateManager.SetFactory(ZoneFactory);
         ZoneServerFactory = ReflectionUtil.CreateInterface <ZoneNodeFactory>(config["ZoneServerFactory"]);
         log.Info(" 战斗编辑器插件 : " + ZoneFactory);
         log.Info(" 战斗服务器插件 : " + ZoneServerFactory);
     }
     if (NodeConfig == null)
     {
         log.Info("********************************************************");
         log.Info("# 加载配置文件");
         log.Info("********************************************************");
         NodeConfig = ZoneServerFactory.GetConfig();
         var node_cfg = config.SubProperties("ZoneNodeConfig.");
         if (node_cfg != null)
         {
             node_cfg.LoadFields(NodeConfig);
         }
     }
     if (DataRoot == null)
     {
         log.Info("********************************************************");
         log.Info("# 加载模板数据");
         log.Info("********************************************************");
         try
         {
             DataRoot = TemplateManager.Factory.CreateEditorTemplates(config["DataRootPath"]);
             DataRoot.LoadAllTemplates();
             DataRoot.CacheAllScenes();
         }
         catch (Exception err)
         {
             throw new Exception("EditorTemplates init error : " + err.Message + "\n" + err.StackTrace, err);
         }
         log.Info("********************************************************");
     }
 }
Пример #2
0
 public BotRunner(RPGClient c, BotConfig cfg, AddBotConfig add, string account)
 {
     this.log     = new ListLogger("bot[" + account + "]-");
     this.cfg     = cfg;
     this.add     = add;
     this.account = account;
     this.client  = c;
     this.client.OnGateEntered += on_gate_connect_callback;
     this.client.GateClient.Listen <ClientEnterGateInQueueNotify>(on_gate_in_queue);
     foreach (var type in BotFactory.Instance.GetModuleTypes())
     {
         var m = ReflectionUtil.CreateInterface <BotModule>(type, this);
         modules.Add(m.GetType(), m);
     }
     client.AddTimePeriodicMS(10000, (e) =>
     {
         if (client.CurrentZoneLayer != null && client.GameClient != null && client.GameClient.IsHandshake)
         {
             client.GameClient.Request <ClientPong>(new ClientPing(), (s, a) => { });
         }
     });
 }
Пример #3
0
 public ConnectServer(ServiceStartInfo start) : base(start)
 {
     this.log = LoggerFactory.GetLogger(start.Address.ServiceName);
     {
         var client_codec = ReflectionUtil.CreateInterface <IExternalizableFactory>(start.Config["NetCodec"].ToString());
         if (ConnectServer.ClientCodec == null)
         {
             ConnectServer.ClientCodec = new IOStreamPool(client_codec);
         }
         ConnectServer.KickOnError = GlobalConfig.GetAsBool("KickOnError");
         var factory = ServerFactory.Instance;
         if (!string.IsNullOrEmpty(DeepMMO.Server.GlobalConfig.ReplaceNetHost))
         {
             start.Config["Host"] = DeepMMO.Server.GlobalConfig.ReplaceNetHost;
         }
         this.acceptor_host = start.Config["Host"].ToString();
         this.acceptor_port = int.Parse(start.Config["HostPort"].ToString());
         this.acceptor      = factory.CreateServer(new HashMap <string, string>(start.Config), client_codec);
         this.acceptor.OnSessionConnected    += Acceptor_OnSessionConnected;
         this.acceptor.OnSessionDisconnected += Acceptor_OnSessionDisconnected;
         this.acceptor.OnServerError         += Acceptor_OnServerError;
         this.current_token = Guid.NewGuid().ToString();
     }
 }
Пример #4
0
        public virtual void Init()
        {
            try
            {
                EditorTemplates.RUNTIME_IN_SERVER = true;
                RPGServerTemplateManager.Instance.ToString();
                if (ZoneFactory == null)
                {
                    log.Info("********************************************************");
                    log.Info("# 初始化战斗编辑器扩展 ");
                    log.Info("********************************************************");
                    DataFactory = ReflectionUtil.CreateInterface <ZoneDataFactory>(GlobalConfig.ZoneDataFactory);
                    ZoneFactory = ReflectionUtil.CreateInterface <ZoneHostFactory>(GlobalConfig.InstanceZoneFactory, GlobalConfig.GameEditorRoot);
                    log.Info(" 战斗编辑器插件 : " + ZoneFactory);
                }
                if (NodeConfig == null)
                {
                    log.Info("********************************************************");
                    log.Info("# 加载配置文件");
                    log.Info("********************************************************");
                    NodeConfig = ZoneFactory.GetServerConfig();
                    var node_cfg = GlobalConfig.ZoneNodeConfig;
                    if (node_cfg != null)
                    {
                        log.Info(node_cfg.ToString());
                        node_cfg.LoadFields(NodeConfig);
                    }
                }
                if (DataRoot == null)
                {
                    log.Info("********************************************************");
                    log.Info("# 加载模板数据");
                    log.Info("********************************************************");
                    try
                    {
                        DataRoot         = DataFactory.CreateEditorTemplates(GlobalConfig.BattleDataRoot);
                        DataRoot.Verbose = true;
                        DataRoot.LoadAllTemplates();
                        DataRoot.CacheAllScenes();
                        Templates = DataRoot.Templates;
                    }
                    catch (Exception err)
                    {
                        throw new Exception("EditorTemplates init error : " + err.Message + "\n" + err.StackTrace, err);
                    }

                    if (CACHE_ALL_VOXEL)
                    {
                        GC.Collect();
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        GC.WaitForFullGCApproach();
                        GC.WaitForFullGCComplete();
                        log.Info("********************************************************");
                        log.Info("# 缓存体素");
                        log.Info("********************************************************");
                        var list   = new HashMap <string, SceneData>();
                        var caches = new ConcurrentDictionary <string, VoxelWorld>();
                        foreach (var sd in DataRoot.CacheAllScenes())
                        {
                            if (string.IsNullOrEmpty(sd.VoxelFileName) is false)
                            {
                                list.TryAdd(GlobalConfig.GameEditorRoot + sd.VoxelFileName, sd);
                            }
                        }
                        var cacheTasks = new ActionBlock <KeyValuePair <string, SceneData> >(run_CacheScene, new ExecutionDataflowBlockOptions()
                        {
                            MaxDegreeOfParallelism    = Environment.ProcessorCount - 1,
                            SingleProducerConstrained = false,
                        });
                        var watch = Stopwatch.StartNew();
                        foreach (var path in list)
                        {
                            cacheTasks.Post(path);
                        }
                        void run_CacheScene(KeyValuePair <string, SceneData> sd)
                        {
                            try
                            {
                                log.Info($"Cache voxel data : {sd.Key}");
                                var wx = VoxelWorld.LoadFromFile(sd.Key);
                                caches.TryAdd(sd.Key, wx);
                                log.Info($"Cache voxel data : {sd.Key} : OK ({caches.Count}/{list.Count})");
                            }
                            catch (Exception err)
                            {
                                log.Error($"Load Voxel Error : >>>{sd.Value}<<< {sd.Key}");
                                log.Error(err);
                            }
                        }
                        cacheTasks.Complete();
                        cacheTasks.Completion.Wait();
                        watch.Stop();
                        log.Warn($"Load Voxel Complete Use : {watch.Elapsed}");
                        VoxelWorldManager.Instance.CacheAll(caches);
                    }

                    log.Info("********************************************************");
                    log.Info("# 从地图配置表重新构建场景传送点");
                    log.Info("********************************************************");
                    FillSceneTransport();
                    SceneGrapAstar = new MapSceneGrapAstar(RPGServerTemplateManager.Instance.AllMapTemplates);
                }
                {
                    log.Info("********************************************************");
                    log.Info("# 战斗编解码器");
                    log.Info("********************************************************");
                    if (DataFactory.MessageCodec is MessageFactoryGenerator)
                    {
                        log.Info(DataFactory.MessageCodec);
                    }
                }
                log.Info("********************************************************");
            }
            catch
            {
                log.Error("检查战斗编辑器是否重新保存");

                throw;
            }
        }