Example #1
0
        public HiveHostGame(
            string gameName,
            RoomCacheBase roomCache,
            IGameStateFactory gameStateFactory = null,
            int maxEmptyRoomTTL = 0,
            IPluginManager pluginManager = null,
            string pluginName = "",
            Dictionary<string, object> environment = null,
            int lastTouchLimitMilliseconds = 0,
            int lastTouchCheckIntervalMilliseconds = 0,
            HttpRequestQueueOptions httpRequestQueueOptions = null,
            ExtendedPoolFiber executionFiber = null
            )
            : base(gameName, roomCache, gameStateFactory, maxEmptyRoomTTL, lastTouchLimitMilliseconds, lastTouchCheckIntervalMilliseconds, executionFiber)
        {
            this.pluginManager = pluginManager;

            if (httpRequestQueueOptions == null)
            {
                httpRequestQueueOptions = new HttpRequestQueueOptions();
            }

            this.httpRequestQueue.MaxErrorRequests = httpRequestQueueOptions.HttpQueueMaxTimeouts;
            this.httpRequestQueue.MaxTimedOutRequests = httpRequestQueueOptions.HttpQueueMaxErrors;
            this.httpRequestQueue.ReconnectInterval = TimeSpan.FromMilliseconds(httpRequestQueueOptions.HttpQueueReconnectInterval);
            this.httpRequestQueue.QueueTimeout = TimeSpan.FromMilliseconds(httpRequestQueueOptions.HttpQueueQueueTimeout);
            this.httpRequestQueue.MaxQueuedRequests = httpRequestQueueOptions.HttpQueueMaxQueuedRequests;
            this.httpRequestQueue.MaxBackoffInMilliseconds = httpRequestQueueOptions.HttpQueueMaxBackoffTime;
            this.httpRequestQueue.MaxConcurrentRequests = httpRequestQueueOptions.HttpQueueMaxConcurrentRequests;

            this.httpQueueRequestTimeout = httpRequestQueueOptions.HttpQueueRequestTimeout;

            this.httpRequestQueue.SetCounters(this);

            this.Environment = environment ?? new Dictionary<string, object>
                                       {
                                           {"AppId", GetHwId()},
                                           {"AppVersion", ""},
                                           {"Region", ""},
                                           {"Cloud", ""},
                                       };
            this.InitPlugin(pluginName);
            if (this.Plugin == null)
            {
                throw new Exception(string.Format("Failed to craete plugin '{0}'", pluginName));
            }

            var errorPlugin = this.Plugin as ErrorPlugin;
            if (errorPlugin != null)
            {
                Log.ErrorFormat("Game {0} is created with ErrorPlugin. message:{1}", this.Name, errorPlugin.Message);
            }

            this.customTypeCache.TypeMapper = this;
            this.callEnv = new CallEnv(this.Plugin, this.Name);
        }
Example #2
0
        protected bool ReinitGame()
        {
            if (this.Plugin == null)
            {
                Log.ErrorFormat("Reinit failed for game '{0}'. No plugin is set", this.Name);
                return false;
            }

            var pluginName = this.Plugin.Name;
            this.InitPlugin(pluginName);

            if (this.Plugin != null)
            {
                this.roomState = this.gameStateFactory.Create();

                this.EventCache.SetGameAppCounters(gameAppCounters);

                this.isClosed = false;
                this.allowSetGameState = true;
                this.failureOnCreate = false;
                this.callEnv = new CallEnv(this.Plugin, this.Name);
                return true;
            }

            Log.ErrorFormat("Reinit failed for game '{0}'. Failed to recreate plugin:'{1}'", this.Name, pluginName);
            return false;
        }