/// <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) { return; } TraceLog.WriteLine("{0} Server is starting...", DateTime.Now.ToString("HH:mm:ss")); _setting = setting; if (!RedisConnectionPool.Ping("127.0.0.1")) { string error = string.Format("Error: NIC is not connected or no network."); TraceLog.WriteLine(error); TraceLog.WriteError(error); return; } RedisConnectionPool.Initialize(_setting.Serializer); if (!RedisConnectionPool.CheckConnect()) { string error = string.Format("Error: the redis server is not started."); TraceLog.WriteLine(error); TraceLog.WriteError(error); return; } TraceLog.WriteLine("{0} Redis server connect successfully.", DateTime.Now.ToString("HH:mm:ss")); DbConnectionProvider.Initialize(); TraceLog.WriteLine("{0} DB server connect successfully.", DateTime.Now.ToString("HH:mm:ss")); EntitySchemaSet.CacheGlobalPeriod = _setting.CacheGlobalPeriod; EntitySchemaSet.CacheUserPeriod = _setting.CacheUserPeriod; if (_setting.EntityAssembly != null) { ProtoBufUtils.LoadProtobufType(_setting.EntityAssembly); EntitySchemaSet.LoadAssembly(_setting.EntityAssembly); } 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.OnLoaded += OnScriptLoaded; ScriptEngines.Initialize(); Language.SetLang(); CacheFactory.Initialize(cacheSetting, _setting.Serializer); EntitySchemaSet.StartCheckTableTimer(); Global = new ContextCacheSet <CacheItem>("__gameenvironment_global"); }
/// <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; 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(); LoadGameEntitySchema(); 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); }