示例#1
0
        private void OnGameClientOperationResponse(object sender, OperationResponseEventArgs e)
        {
            if (e.OperationResponse.ReturnCode != 0)
            {
                log.WarnFormat(
                    "GAME: Received error response: code={0}, result={1}, msg={2}",
                    e.OperationResponse.OperationCode,
                    e.OperationResponse.ReturnCode,
                    e.OperationResponse.DebugMessage);
                return;
            }

            switch (e.OperationResponse.OperationCode)
            {
            case (byte)Operations.OperationCode.JoinRandomGame:
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("GAME: Successfully joined random game.");
                }
                break;
            }

            case (byte)Operations.OperationCode.CreateGame:
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("GAME: Successfully created game.");
                }
                break;
            }

            case (byte)Operations.OperationCode.JoinGame:
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("GAME: Successfully joined game.");
                }
                break;
            }

            default:
            {
                log.WarnFormat("GAME: received response for unexpected operation: " + e.OperationResponse.OperationCode);
                return;
            }
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("GAME: Sending random events.");
            }

            ThreadPool.QueueUserWorkItem(this.SendEvents);
        }
示例#2
0
        private void OnGameClientOperationResponse(object sender, OperationResponseEventArgs e)
        {
            if (e.OperationResponse.ReturnCode != 0)
            {
                log.WarnFormat(
                    "TestClient({3}): Received error response: code={0}, result={1}, msg={2}",
                    e.OperationResponse.OperationCode,
                    e.OperationResponse.ReturnCode,
                    e.OperationResponse.DebugMessage,
                    userId);
                return;
            }

            switch (e.OperationResponse.OperationCode)
            {
            case (byte)OperationCode.Authenticate:
            {
                this.connectionState = TestClientConnectionState.Authenticated;

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("TestClient({0}): Successfully authenticated", userId);
                }

                JoinOrCreateGameOnGameServer();
                break;
            }

            case (byte)Operations.OperationCode.JoinGame:
            {
                this.connectionState = TestClientConnectionState.InGame;

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("TestClient({0}): Successfully joined/created game '{1}'", userId, gameId);
                }
                break;
            }

            default:
            {
                log.WarnFormat("TestClient({1}): received response for unexpected operation: {0}", e.OperationResponse.OperationCode, userId);
                return;
            }
            }
        }
 /// <summary>
 ///   Callback for operation response.
 /// </summary>
 /// <param name = "sender">
 ///   The sender.
 /// </param>
 /// <param name = "e">
 ///   The event args.
 /// </param>
 private void TcpClient_OnOperationResponse(object sender, OperationResponseEventArgs e)
 {
     ////log.Info("Response" + e.OperationResponse.OperationCode);
     if (e.OperationResponse.OperationCode == (byte)OperationCode.Join)
     {
         if (Interlocked.Increment(ref this.counter) == ClientCount)
         {
             this.autoReset.Set();
         }
     }
     else if (e.OperationResponse.OperationCode == (byte)OperationCode.Ping)
     {
         if (Interlocked.Increment(ref this.counter) == ClientCount * LoopCount)
         {
             this.autoReset.Set();
         }
     }
 }
示例#4
0
        private void OnMasterClientOperationResponse(object sender, OperationResponseEventArgs e)
        {
            if (e.OperationResponse.ReturnCode != 0)
            {
                log.WarnFormat(
                    "MASTER: Received error response: opCode={0}, err={1}, msg={2}",
                    e.OperationResponse.OperationCode,
                    e.OperationResponse.ReturnCode,
                    e.OperationResponse.DebugMessage);
                return;
            }

            string address;

            switch (e.OperationResponse.OperationCode)
            {
            case (byte)Operations.OperationCode.JoinRandomGame:
                address     = e.OperationResponse.Parameters[(byte)ParameterCode.Address] as string;
                this.gameId = e.OperationResponse.Parameters[(byte)ParameterCode.GameId] as string;
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("MASTER: Join random response: address={0}, gameId={1}", address, this.gameId);
                }
                this.masterClient.Disconnect();
                this.gameServerConnection.Start(address, this.gameId, "Join");
                break;

            case (byte)Operations.OperationCode.CreateGame:
                address     = e.OperationResponse.Parameters[(byte)ParameterCode.Address] as string;
                this.gameId = e.OperationResponse.Parameters[(byte)ParameterCode.GameId] as string;
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("MASTER: Create game response: address={0}, gameId={1}", address, this.gameId);
                }
                this.masterClient.Disconnect();
                this.gameServerConnection.Start(address, this.gameId, "Create");

                break;

            case (byte)Operations.OperationCode.JoinLobby:
                break;
            }
        }
示例#5
0
        private void OnGameClientOperationResponse(object sender, OperationResponseEventArgs e)
        {
            if (e.OperationResponse.ReturnCode != 0)
            {
                log.WarnFormat(
                    "GAME: Received error response: code={0}, result={1}, msg={2}",
                    e.OperationResponse.OperationCode,
                    e.OperationResponse.ReturnCode,
                    e.OperationResponse.DebugMessage);
                return;
            }

            switch (e.OperationResponse.OperationCode)
            {
                case (byte)Operations.OperationCode.JoinRandomGame:
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("GAME: Successfully joined random game.");
                        }
                        break;
                    }
                case (byte)Operations.OperationCode.CreateGame:
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("GAME: Successfully created game.");
                        }
                        break;
                    }
                case (byte)Operations.OperationCode.JoinGame:
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("GAME: Successfully joined game.");
                        }
                        break;
                    }
                default:
                    {
                        log.WarnFormat("GAME: received response for unexpected operation: " + e.OperationResponse.OperationCode);
                        return;
                    }
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("GAME: Sending random events.");
            }

            ThreadPool.QueueUserWorkItem(this.SendEvents);
        }
示例#6
0
        private void OnMasterClientOperationResponse(object sender, OperationResponseEventArgs e)
        {
            if (e.OperationResponse.ReturnCode != 0)
            {
                log.WarnFormat(
                    "MASTER: Received error response: opCode={0}, err={1}, msg={2}",
                    e.OperationResponse.OperationCode,
                    e.OperationResponse.ReturnCode,
                    e.OperationResponse.DebugMessage);
                return;
            }

            string address;

            switch (e.OperationResponse.OperationCode)
            {
                case (byte)Operations.OperationCode.JoinRandomGame:
                    address = e.OperationResponse.Parameters[(byte)ParameterCode.Address] as string;
                    this.gameId = e.OperationResponse.Parameters[(byte)ParameterCode.GameId] as string;
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("MASTER: Join random response: address={0}, gameId={1}", address, this.gameId);
                    }
                    this.gameServerConnection.Start(address, this.gameId, "Join");
                    break;

                case (byte)Operations.OperationCode.CreateGame:
                    address = e.OperationResponse.Parameters[(byte)ParameterCode.Address] as string;
                    this.gameId = e.OperationResponse.Parameters[(byte)ParameterCode.GameId] as string;
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("MASTER: Create game response: address={0}, gameId={1}", address, this.gameId);
                    }

                    this.gameServerConnection.Start(address, this.gameId, "Create");

                    break;

                case (byte)Operations.OperationCode.JoinLobby:
                    break;
            }
        }
 /// <summary>
 ///   Callback for operation response.
 /// </summary>
 /// <param name = "sender">
 ///   The sender.
 /// </param>
 /// <param name = "e">
 ///   The event args.
 /// </param>
 private void TcpClient_OnOperationResponse(object sender, OperationResponseEventArgs e)
 {
     ////log.Info("Response" + e.OperationResponse.OperationCode);
     if (e.OperationResponse.OperationCode == (byte)OperationCode.Join)
     {
         if (Interlocked.Increment(ref this.counter) == ClientCount)
         {
             this.autoReset.Set();
         }
     }
     else if (e.OperationResponse.OperationCode == (byte)OperationCode.Ping)
     {
         if (Interlocked.Increment(ref this.counter) == ClientCount * LoopCount)
         {
             this.autoReset.Set();
         }
     }
 }