Ejemplo n.º 1
0
        protected virtual OperationResponse HandleDebugGame(MasterClientPeer peer, OperationRequest operationRequest)
        {
            var operation = new DebugGameRequest(peer.Protocol, operationRequest);
            OperationResponse response;

            if (OperationHelper.ValidateOperation(operation, log, out response) == false)
            {
                return(response);
            }

            GameState gameState;

            if (this.GameList.TryGetGame(operation.GameId, out gameState) == false)
            {
                return(new OperationResponse
                {
                    OperationCode = operationRequest.OperationCode,
                    ReturnCode = (short)ErrorCode.GameIdNotExists,
                    DebugMessage = LBErrorMessages.GameIdDoesNotExist
                });
            }

            var debugGameResponse = this.GetDebugGameResponse(peer, gameState);

            log.InfoFormat("DebugGame: {0}", debugGameResponse.Info);

            return(new OperationResponse(operationRequest.OperationCode, debugGameResponse));
        }
        protected override void HandleDebugGameOperation(OperationRequest operationRequest, SendParameters sendParameters)
        {
            if (!GameServerSettings.Default.AllowDebugGameOperation)
            {
                this.SendOperationResponse(new OperationResponse(operationRequest.OperationCode)
                {
                    ReturnCode   = (short)ErrorCode.OperationDenied,
                    DebugMessage = LBErrorMessages.NotAuthorized
                }, sendParameters);
                return;
            }

            var debugRequest = new DebugGameRequest(this.Protocol, operationRequest);

            if (this.ValidateOperation(debugRequest, sendParameters) == false)
            {
                return;
            }

            string debug = string.Format("DebugGame called from PID {0}. {1}", this.ConnectionId, this.GetRoomCacheDebugString(debugRequest.GameId));

            operationRequest.Parameters.Add((byte)ParameterCode.Info, debug);


            if (this.RoomReference == null)
            {
                Room room;
                // get a room without obtaining a reference:
                if (!this.TryGetRoomWithoutReference(debugRequest.GameId, out room))
                {
                    var response = new OperationResponse
                    {
                        OperationCode = (byte)OperationCode.DebugGame,
                        ReturnCode    = (short)ErrorCode.GameIdNotExists,
                        DebugMessage  = HiveErrorMessages.GameIdDoesNotExist
                    };


                    this.SendOperationResponse(response, sendParameters);
                    return;
                }

                room.EnqueueOperation(this, debugRequest, sendParameters);
            }
            else
            {
                this.RoomReference.Room.EnqueueOperation(this, debugRequest, sendParameters);
            }
        }
Ejemplo n.º 3
0
        protected override void ExecuteOperation(HivePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            try
            {
                //if (Log.IsDebugEnabled)
                //{
                //    Log.DebugFormat("Executing operation {0}", operationRequest.OperationCode);
                //}

                switch (operationRequest.OperationCode)
                {
                // Lite operation code for join is not allowed in load balanced games.
                case (byte)Photon.Hive.Operations.OperationCode.Join:
                    this.SendErrorResponse(peer, operationRequest.OperationCode,
                                           ErrorCode.OperationDenied, HiveErrorMessages.InvalidOperationCode, sendParameters);
                    if (Log.IsDebugEnabled)
                    {
                        Log.DebugFormat("Game '{0}' userId '{1}' failed to join. msg:{2}", this.Name, peer.UserId,
                                        HiveErrorMessages.InvalidOperationCode);
                    }
                    break;

                case (byte)OperationCode.DebugGame:
                    var debugGameRequest = new DebugGameRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(debugGameRequest, sendParameters) == false)
                    {
                        return;
                    }

                    this.LogOperation(peer, operationRequest);

                    debugGameRequest.OnStart();
                    this.HandleDebugGameOperation(peer, debugGameRequest, sendParameters);
                    debugGameRequest.OnComplete();
                    break;

                // all other operation codes will be handled by the Lite game implementation
                default:
                    base.ExecuteOperation(peer, operationRequest, sendParameters);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
Ejemplo n.º 4
0
        protected virtual void HandleDebugGameOperation(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var debugRequest = new DebugGameRequest(this.Protocol, operationRequest);

            if (this.ValidateOperation(debugRequest, sendParameters) == false)
            {
                return;
            }

            string debug = string.Format("DebugGame called from PID {0}. {1}", this.ConnectionId, this.GetRoomCacheDebugString(debugRequest.GameId));

            operationRequest.Parameters.Add((byte)ParameterCode.Info, debug);


            if (this.RoomReference == null)
            {
                Room room;
                // get a room without obtaining a reference:
                if (!this.TryGetRoomWithoutReference(debugRequest.GameId, out room))
                {
                    var response = new OperationResponse
                    {
                        OperationCode = (byte)OperationCode.DebugGame,
                        ReturnCode    = (short)ErrorCode.GameIdNotExists,
                        DebugMessage  = "Game does not exist in RoomCache"
                    };


                    this.SendOperationResponse(response, sendParameters);
                    return;
                }

                room.EnqueueOperation(this, operationRequest, sendParameters);
            }
            else
            {
                this.RoomReference.Room.EnqueueOperation(this, operationRequest, sendParameters);
            }
        }
Ejemplo n.º 5
0
        protected virtual void HandleDebugGameOperation(LitePeer peer, DebugGameRequest request, SendParameters sendParameters)
        {
            // Room: Properties; # of cached events
            // Actors:  Count, Last Activity, Actor #, Peer State, Connection ID
            // Room Reference

            // get info from request (was gathered in Peer class before operation was forwarded to the game):
            var peerInfo  = request.Info;
            var debugInfo = peerInfo + this;

            if (Log.IsInfoEnabled)
            {
                Log.Info("DebugGame: " + debugInfo);
            }

            this.logQueue.WriteLog();

            var debugGameResponse = new DebugGameResponse {
                Info = debugInfo
            };

            peer.SendOperationResponse(new OperationResponse(request.OperationRequest.OperationCode, debugGameResponse), sendParameters);
        }
Ejemplo n.º 6
0
        protected virtual void HandleDebugGameOperation(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var debugRequest = new DebugGameRequest(this.Protocol, operationRequest);
            if (this.ValidateOperation(debugRequest, sendParameters) == false)
            {
                return;
            }

            string debug = string.Format("DebugGame called from PID {0}. {1}", this.ConnectionId, this.GetRoomCacheDebugString(debugRequest.GameId));
            operationRequest.Parameters.Add((byte)ParameterCode.Info, debug);

            if (this.RoomReference == null)
            {
                Room room;
                // get a room without obtaining a reference:
                if (!this.TryGetRoomWithoutReference(debugRequest.GameId, out room))
                {
                    var response = new OperationResponse
                    {
                        OperationCode = (byte)OperationCode.DebugGame,
                        ReturnCode = (short)ErrorCode.GameIdNotExists,
                        DebugMessage = HiveErrorMessages.GameIdDoesNotExist
                    };

                    this.SendOperationResponse(response, sendParameters);
                    return;
                }

                room.EnqueueOperation(this, operationRequest, sendParameters);
            }
            else
            {
                this.RoomReference.Room.EnqueueOperation(this, operationRequest, sendParameters);
            }
        }
Ejemplo n.º 7
0
        protected override void ExecuteOperation(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            try
            {
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Executing operation {0}", operationRequest.OperationCode);
                }

                switch (operationRequest.OperationCode)
                {
                case (byte)OperationCode.CreateGame:
                    var createGameRequest = new JoinRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(createGameRequest, sendParameters) == false)
                    {
                        return;
                    }

                    if (this.logQueue.Log.IsDebugEnabled)
                    {
                        this.logQueue.Add(
                            new LogEntry(
                                "ExecuteOperation: " + (OperationCode)operationRequest.OperationCode,
                                "Peer=" + peer.ConnectionId));
                    }
                    this.HandleCreateGameOperation(peer, createGameRequest, sendParameters);
                    break;

                case (byte)OperationCode.JoinGame:
                    var joinGameRequest = new JoinRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(joinGameRequest, sendParameters) == false)
                    {
                        return;
                    }

                    if (this.logQueue.Log.IsDebugEnabled)
                    {
                        this.logQueue.Add(
                            new LogEntry(
                                "ExecuteOperation: " + (OperationCode)operationRequest.OperationCode,
                                "Peer=" + peer.ConnectionId));
                    }
                    this.HandleJoinGameOperation(peer, joinGameRequest, sendParameters);
                    break;

                // Lite operation code for join is not allowed in load balanced games.
                case (byte)Lite.Operations.OperationCode.Join:
                    var response = new OperationResponse
                    {
                        OperationCode = operationRequest.OperationCode,
                        ReturnCode    = (short)ErrorCode.OperationDenied,
                        DebugMessage  = "Invalid operation code"
                    };
                    peer.SendOperationResponse(response, sendParameters);
                    break;

                case (byte)OperationCode.DebugGame:
                    var debugGameRequest = new DebugGameRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(debugGameRequest, sendParameters) == false)
                    {
                        return;
                    }

                    if (this.logQueue.Log.IsDebugEnabled)
                    {
                        this.logQueue.Add(
                            new LogEntry(
                                "ExecuteOperation: " + (OperationCode)operationRequest.OperationCode,
                                "Peer=" + peer.ConnectionId));
                    }

                    this.HandleDebugGameOperation(peer, debugGameRequest, sendParameters);
                    break;

                // all other operation codes will be handled by the Lite game implementation
                default:
                    base.ExecuteOperation(peer, operationRequest, sendParameters);
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }