private static GetLobbyStatsResponse LobbyListToLobbyStatsData(AppLobby[] lobbyList)
        {
            var lobbyStats = new GetLobbyStatsResponse();

            var count = lobbyList.Length;
            lobbyStats.LobbyNames = new string[count];
            lobbyStats.LobbyTypes = new byte[count];
            lobbyStats.PeerCount = new int[count];
            lobbyStats.GameCount = new int[count];

            for (int i = 0; i < lobbyList.Length; i++)
            {
                var item = lobbyList[i];
                lobbyStats.LobbyNames[i] = item.LobbyName;
                lobbyStats.LobbyTypes[i] = (byte)item.LobbyType;
                lobbyStats.PeerCount[i] = item.PeerCount + item.PlayerCount;
                lobbyStats.GameCount[i] = item.GameCount;
            }

            return lobbyStats;
        }
        private void ExecuteGetStatsRequest(PeerBase peer, GetLobbyStatsRequest statsRequest, SendParameters sendParameter)
        {
            try
            {
                OperationResponse errorresponse;
                if (this.ValidateRequest(statsRequest, out errorresponse) == false)
                {
                    peer.SendOperationResponse(errorresponse, sendParameter);
                    return;
                }

                var response = new GetLobbyStatsResponse();
                AppLobby[] lobbies;

                short returnCode = 0;
                string debugMessage = null;

                if (statsRequest.LobbyNames == null)
                {
                    lobbies = this.lobbyFactory.GetLobbies(this.maxLobbyStatsCount);
                    response = LobbyListToLobbyStatsData(lobbies);
                }
                else
                {
                    // Check if lobby stats limit is exceeded.
                    // If Limit is exceeded the complete list will be returned anyway but with the response result code set to -4.
                    // This behaviour might change in future versions.
                    if (this.maxLobbyStatsCount > 0 && statsRequest.LobbyNames.Length > this.maxLobbyStatsCount)
                    {
                        returnCode = (short)ErrorCode.ArgumentOutOfRange;
                        debugMessage = string.Format("LobbyStats limit of {0} exceeded", this.maxLobbyStatsCount);
                    }

                    lobbies = this.lobbyFactory.GetLobbies(statsRequest.LobbyNames, statsRequest.LobbyTypes);

                    var count = lobbies.Length;
                    response.PeerCount = new int[count];
                    response.GameCount = new int[count];

                    for (int i = 0; i < lobbies.Length; i++)
                    {
                        if (lobbies[i] != null)
                        {
                            response.PeerCount[i] = lobbies[i].PeerCount + lobbies[i].PlayerCount;
                            response.GameCount[i] = lobbies[i].GameCount;
                        }
                        else
                        {
                            response.PeerCount[i] = 0;
                            response.GameCount[i] = 0;
                        }
                    }
                }

                var operationResponse = new OperationResponse((byte)OperationCode.LobbyStats, response)
                    {
                        ReturnCode = returnCode,
                        DebugMessage = debugMessage
                    };

                peer.SendOperationResponse(operationResponse, sendParameter);
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }