public override void GetGameStats(IRpcController controller, bnet.protocol.game_master.GetGameStatsRequest request, Action <bnet.protocol.game_master.GetGameStatsResponse> done) { var response = bnet.protocol.game_master.GetGameStatsResponse.CreateBuilder() .AddStatsBucket(GameFactoryManager.GetGameStats(request).Build()) .Build(); done(response); }
//FIXME: MATCH_ALL_MOST_SPECIFIC not implemented /dustinconrad public static bnet.protocol.game_master.GameStatsBucket.Builder GetGameStats(bnet.protocol.game_master.GetGameStatsRequest request) { String version = String.Empty; int difficulty = 0; int currentQuest = 0; foreach (bnet.protocol.attribute.Attribute attribute in request.Filter.AttributeList) { switch (attribute.Name) { case "version": version = attribute.Value.StringValue; break; case "Game.Difficulty": difficulty = (int)attribute.Value.IntValue; break; case "Game.CurrentQuest": currentQuest = (int)attribute.Value.IntValue; break; } } Func <bool, bool, bool, bool> matchOp; switch (request.Filter.Op) { case bnet.protocol.attribute.AttributeFilter.Types.Operation.MATCH_ANY: matchOp = (bool b1, bool b2, bool b3) => b1 || b2 || b3; break; case bnet.protocol.attribute.AttributeFilter.Types.Operation.MATCH_NONE: matchOp = (bool b1, bool b2, bool b3) => !b1 && !b2 && !b3; break; case bnet.protocol.attribute.AttributeFilter.Types.Operation.MATCH_ALL: default: //default to match all, fall through is on purpose matchOp = (bool b1, bool b2, bool b3) => b1 && b2 && b3; break; } uint games = 0; int players = 0; foreach (GameFactory game in GameCreators.Values) { if (game.InGame != null && !game.GameCreateParams.IsPrivate) { if (matchOp(version == game.Version, difficulty == game.GameCreateParams.Coop.DifficultyLevel, currentQuest == game.GameCreateParams.Coop.SnoQuest)) { games++; players += game.InGame.Players.Count; } } } var bucket = bnet.protocol.game_master.GameStatsBucket.CreateBuilder() .SetWaitMilliseconds(200) .SetActiveGames(games) .SetActivePlayers((uint)players) .SetFormingGames(0) .SetWaitingPlayers(0); return(bucket); }