예제 #1
0
        /// <summary>
        /// The game service start.
        /// </summary>
        /// <param name="setting">Environment setting.</param>
        /// <param name="cacheSetting">Cache setting.</param>
        public static void Start(EnvironmentSetting setting, CacheSetting cacheSetting)
        {
            if (_isRunning == 1)
            {
                return;
            }

            _setting = setting;
            RedisConnectionPool.Initialize();
            if (!RedisConnectionPool.CheckConnect())
            {
                string error = string.Format("Error: the redis server is not started.");
                Console.WriteLine(error);
                TraceLog.WriteError(error);
                return;
            }
            DbConnectionProvider.Initialize();
            EntitySchemaSet.CacheGlobalPeriod = _setting.CacheGlobalPeriod;
            EntitySchemaSet.CacheUserPeriod   = _setting.CacheUserPeriod;
            if (_setting.EntityAssembly != null)
            {
                ProtoBufUtils.LoadProtobufType(_setting.EntityAssembly);
                EntitySchemaSet.LoadAssembly(_setting.EntityAssembly);
            }
            EntitySchemaSet.StartCheckTableTimer();
            ZyGameBaseConfigManager.Intialize();
            //init script.
            if (_setting.ScriptSysAsmReferences.Length > 0)
            {
                ScriptEngines.AddSysReferencedAssembly(_setting.ScriptSysAsmReferences);
            }
            ScriptEngines.AddReferencedAssembly("ZyGames.Framework.Game.dll");
            if (_setting.ScriptAsmReferences.Length > 0)
            {
                ScriptEngines.AddReferencedAssembly(_setting.ScriptAsmReferences);
            }
            ScriptEngines.RegisterModelChangedBefore(OnModelChangeBefore);
            ScriptEngines.RegisterModelChangedAfter(OnModelChangeAtfer);
            ScriptEngines.Initialize();
            Language.SetLang();
            CacheFactory.Initialize(cacheSetting);
            Global = new ContextCacheSet <CacheItem>("__gameenvironment_global");
            Interlocked.Exchange(ref _isRunning, 1);
        }
예제 #2
0
        //定时器
        private static void TimeDo_1s(object sender, System.Timers.ElapsedEventArgs e)
        {
            _secCnt++;
            int intHour   = e.SignalTime.Hour;
            int intMinute = e.SignalTime.Minute;
            int intSecond = e.SignalTime.Second;

            //Redis检查
            if ((_secCnt + 1) % 5 == 0)
            {
                var isEffect = RedisConnectionPool.CheckConnect();
                if (GameEnvironment.IsRedisReady != isEffect)
                {
                    if (isEffect)
                    {
                        isEffect = isRedisRdbWork();
                    }
                    GameEnvironment.IsRedisReady = isEffect;
                }
            }
            if ((_secCnt + 2) % 30 == 0)
            {
                if (!isRedisRdbWork())
                {
                    GameEnvironment.IsRedisReady = false;
                    TraceLog.WriteError("Redis dump.rdb 文件长时间未被修改...");
                }
            }
            if ((_secCnt + 3) % 300 == 0)
            {
                //监听端口参数信息
                var mainClass = ZyGames.Framework.Script.ScriptEngines.GetCurrentMainScript();
                if (mainClass != null)
                {
                    Console.WriteLine("监听端口参数信息:" + ((dynamic)mainClass).GetSocketHostInfo());
                }
            }
        }
예제 #3
0
 public void RedisConnect()
 {
     Assert.IsTrue(RedisConnectionPool.Ping("127.0.0.1"));
     Assert.IsTrue(RedisConnectionPool.CheckConnect());
 }