Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Game"/> class.
        /// </summary>
        /// <param name="application">The photon application instance the game belongs to.</param>
        /// <param name="gameId">The game id.</param>
        /// <param name="roomCache">The room cache the game belongs to.</param>
        /// <param name="pluginManager">plugin creator</param>
        /// <param name="pluginName">Plugin name which client expects to be loaded</param>
        /// <param name="environment">different environment parameters</param>
        /// <param name="executionFiber">Fiber which will execute all rooms actions</param>
        public Game(
            GameApplication application,
            string gameId,
            Hive.Caching.RoomCacheBase roomCache = null,
            IPluginManager pluginManager         = null,
            string pluginName = "",
            Dictionary <string, object> environment = null,
            ExtendedPoolFiber executionFiber        = null
            )
            : base(
                gameId,
                roomCache,
                null,
                GameServerSettings.Default.MaxEmptyRoomTTL,
                pluginManager,
                pluginName,
                environment,
                GameServerSettings.Default.LastTouchSecondsDisconnect * 1000,
                GameServerSettings.Default.LastTouchCheckIntervalSeconds * 1000,
                DefaultHttpRequestQueueOptions,
                executionFiber
                )
        {
            this.Application = application;

            if (this.Application.AppStatsPublisher != null)
            {
                this.Application.AppStatsPublisher.IncrementGameCount();
            }

            this.HttpForwardedOperationsLimit = GameServerSettings.Default.HttpForwardLimit;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Game"/> class.
        /// </summary>
        /// <param name="application">The photon application instance the game belongs to.</param>
        /// <param name="gameId">The game id.</param>
        /// <param name="roomCache">The room cache the game belongs to.</param>
        /// <param name="pluginManager">plugin creator</param>
        /// <param name="pluginName">Plugin name which client expects to be loaded</param>
        /// <param name="environment">different environment parameters</param>
        /// <param name="executionFiber">Fiber which will execute all rooms actions</param>
        public Game(
            GameApplication application,
            string gameId,
            Hive.Caching.RoomCacheBase roomCache = null,
            IPluginManager pluginManager = null,
            string pluginName = "",
            Dictionary<string, object> environment = null,
            ExtendedPoolFiber executionFiber = null
            )
            : base(gameId,
                roomCache,
                null,
                GameServerSettings.Default.MaxEmptyRoomTTL,
                pluginManager,
                pluginName,
                environment,
                GameServerSettings.Default.LastTouchSecondsDisconnect * 1000,
                GameServerSettings.Default.LastTouchCheckIntervalSeconds * 1000,
                DefaultHttpRequestQueueOptions,
                executionFiber)
        {
            this.Application = application;

            if (this.Application.AppStatsPublisher != null)
            {
                this.Application.AppStatsPublisher.IncrementGameCount();
            }

            this.HttpForwardedOperationsLimit = GameServerSettings.Default.HttpForwardLimit;
        }
Example #3
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "Room" /> class.
        /// </summary>
        /// <param name = "name">
        ///   The room name.
        /// </param>
        /// <param name = "executionFiber">
        ///   The execution fiber used to synchronize access to this instance.
        /// </param>
        /// <param name="roomCache">
        ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Fatory for game state</param>
        /// <param name="maxEmptyRoomTTL">
        ///   A value indicating how long the room instance will be keeped alive
        ///   in the room cache after all peers have left the room.
        /// </param>
        protected Room(string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0)
        {
            this.name = name;

            this.gameStateFactory = gameStateFactory ?? defaultFactory;
            this.roomState        = this.gameStateFactory.Create();
            this.ExecutionFiber   = executionFiber ?? new ExtendedPoolFiber();

            this.roomCache       = roomCache;
            this.MaxEmptyRoomTTL = maxEmptyRoomTTL;
        }
Example #4
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "Room" /> class.
        /// </summary>
        /// <param name = "name">
        ///   The room name.
        /// </param>
        /// <param name = "executionFiber">
        ///   The execution fiber used to synchronize access to this instance.
        /// </param>
        /// <param name="roomCache">
        ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Fatory for game state</param>
        /// <param name="maxEmptyRoomTTL">
        ///   A value indicating how long the room instance will be keeped alive
        ///   in the room cache after all peers have left the room.
        /// </param>
        protected Room(string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0)
        {
            this.name = name;

            this.gameStateFactory = gameStateFactory ?? defaultFactory;
            this.roomState        = this.gameStateFactory.Create();
            this.ExecutionFiber   = executionFiber ?? new ExtendedPoolFiber();

            this.roomCache       = roomCache;
            this.MaxEmptyRoomTTL = maxEmptyRoomTTL;
            this.UtcCreated      = DateTime.UtcNow;

            this.RoomCreationTS = Stopwatch.GetTimestamp();
        }
 public LBGameCreateOptions(GameApplication application,
                            string gameId,
                            Hive.Caching.RoomCacheBase roomCache         = null,
                            IPluginManager pluginManager                 = null,
                            Dictionary <string, object> environment      = null,
                            ExtendedPoolFiber executionFiber             = null,
                            IPluginLogMessagesCounter logMessagesCounter = null
                            )
     : this()
 {
     this.Application       = application;
     this.GameCreateOptions = new GameCreateOptions(gameId, roomCache, pluginManager, GameServerSettings.Default.MaxEmptyRoomTTL)
     {
         HttpRequestQueueOptions = DefaultHttpRequestQueueOptions,
         Environment             = environment,
         ExecutionFiber          = executionFiber,
         LogMessagesCounter      = logMessagesCounter
     };
 }
Example #6
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "HiveGame" /> class.
        /// </summary>
        /// <param name = "gameName">
        ///     The name of the game.
        /// </param>
        /// <param name="roomCache">
        ///     The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Custom factory for GameState. if null is set, default factory is used</param>
        /// <param name="maxEmptyRoomTTL">
        ///     A value indicating how long the room instance will be kept alive 
        ///     in the room cache after all peers have left the room.
        /// </param>
        /// <param name="lastTouchLimitMilliseconds">
        ///     Specifies to maximum value for a peers GetLastTouch in milliseconds before a peer will removed from the room.
        ///     If set to zero no check will bew performed.
        /// </param>
        /// <param name="lastTouchCheckIntervalMilliseconds">
        ///     Specifies the in interval in milliseconds to check peer in the room for the GetLastTouched value.
        ///     If set to zero no check will be performed.
        /// </param>
        /// <param name="executionFiber"></param>
        public HiveGame(string gameName, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, 
            int maxEmptyRoomTTL = 0, int lastTouchLimitMilliseconds = 0, int lastTouchCheckIntervalMilliseconds = 0, ExtendedPoolFiber executionFiber = null)
            : base(gameName, executionFiber, roomCache, gameStateFactory, maxEmptyRoomTTL)
        {
            this.ExecutionFiber.Start();

            this.MasterClientId = 0;
            this.IsOpen = true;
            this.IsVisible = true;
            this.LastTouchLimitMilliseconds = lastTouchLimitMilliseconds;
            this.LastTouchCheckIntervalMilliseconds = lastTouchCheckIntervalMilliseconds;

            if (this.LastTouchLimitMilliseconds > 0 && this.LastTouchCheckIntervalMilliseconds > 0)
            {
                this.ExecutionFiber.ScheduleOnInterval(this.CheckPeerStates, this.LastTouchCheckIntervalMilliseconds, this.LastTouchCheckIntervalMilliseconds);
            }

            this.EventCache.SetGameAppCounters(NullHiveGameAppCounters.Instance);
            this.EventCache.Slice = 0;

            this.LogQueue = new LogQueue("Game " + gameName, LogQueue.DefaultCapacity);
        }
Example #7
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 #8
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "Room" /> class without a room name.
 /// </summary>
 /// <param name = "name">
 ///   The room name.
 /// </param>
 /// <param name="roomCache">
 ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
 /// </param>
 /// <param name="gameStateFactory">Fatory for game state</param>
 /// <param name="maxEmptyRoomTTL">
 ///   A value indicating how long the room instance will be keeped alive
 ///   in the room cache after all peers have left the room.
 /// </param>
 /// <param name="executionFiber">Fiber which will execute rooms actions</param>
 public Room(string name, RoomCacheBase roomCache = null, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0, ExtendedPoolFiber executionFiber = null)
     : this(name, executionFiber, roomCache, gameStateFactory, maxEmptyRoomTTL)
 {
     this.ExecutionFiber.Start();
     RemoveRoomPath = RemoveState.Alive;
 }
Example #9
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "Room" /> class without a room name.
 /// </summary>
 /// <param name = "name">
 ///   The room name.
 /// </param>
 /// <param name="roomCache">
 ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
 /// </param>
 /// <param name="gameStateFactory">Fatory for game state</param>
 /// <param name="maxEmptyRoomTTL">
 ///   A value indicating how long the room instance will be keeped alive 
 ///   in the room cache after all peers have left the room.
 /// </param>
 /// <param name="executionFiber">Fiber which will execute rooms actions</param>
 public Room(string name, RoomCacheBase roomCache = null, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0, ExtendedPoolFiber executionFiber = null)
     : this(name, executionFiber, roomCache, gameStateFactory, maxEmptyRoomTTL)
 {
     this.ExecutionFiber.Start();
     RemoveRoomPath = RemoveState.Alive;
 }
Example #10
0
        /// <summary>
        ///   Initializes a new instance of the <see cref = "Room" /> class.
        /// </summary>
        /// <param name = "name">
        ///   The room name.
        /// </param>
        /// <param name = "executionFiber">
        ///   The execution fiber used to synchronize access to this instance.
        /// </param>
        /// <param name="roomCache">
        ///   The <see cref="RoomCacheBase"/> instance to which the room belongs.
        /// </param>
        /// <param name="gameStateFactory">Fatory for game state</param>
        /// <param name="maxEmptyRoomTTL">
        ///   A value indicating how long the room instance will be keeped alive 
        ///   in the room cache after all peers have left the room.
        /// </param>
        protected Room(string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory = null, int maxEmptyRoomTTL = 0)
        {
            this.name = name;

            this.gameStateFactory = gameStateFactory ?? defaultFactory;
            this.roomState = this.gameStateFactory.Create();
            this.ExecutionFiber = executionFiber ?? new ExtendedPoolFiber();

            this.roomCache = roomCache;
            this.MaxEmptyRoomTTL = maxEmptyRoomTTL;
        }