private MatchHistoryLobbySlot GetPlayer(LobbySlot lobbySlot) { var player = new MatchHistoryLobbySlot { Name = lobbySlot.Name, SSteamId = lobbySlot.User?.SteamId.ToString(), Position = lobbySlot.Position, ProfilePrivate = lobbySlot.User != null ? lobbySlot.User.ProfilePrivate: false }; if (lobbySlot.User != null) { if (lobbySlot.Lobby.Ranked == 2) { player.Rank = lobbySlot.RankDM; player.TotalGames = lobbySlot.GamesStartedDM; player.WinRatio = lobbySlot.GamesStartedDM > 0 ? lobbySlot.GamesWonDM * 100 / lobbySlot.GamesStartedDM : 0; player.DropRatio = lobbySlot.GamesStartedDM > 0 ? (lobbySlot.GamesStartedDM - lobbySlot.GamesEndedDM) * 100 / lobbySlot.GamesStartedDM : 0; } else { player.Rank = lobbySlot.RankRM; player.TotalGames = lobbySlot.GamesStartedRM; player.WinRatio = lobbySlot.GamesStartedRM > 0 ? lobbySlot.GamesWonRM * 100 / lobbySlot.GamesStartedRM : 0; player.DropRatio = lobbySlot.GamesStartedRM > 0 ? (lobbySlot.GamesStartedRM - lobbySlot.GamesEndedRM) * 100 / lobbySlot.GamesStartedRM : 0; } player.GameStats = UserUtils.GetGameStats(lobbySlot.GamesStartedRM, lobbySlot.GamesStartedDM, lobbySlot.GamesWonRM, lobbySlot.GamesWonDM, lobbySlot.GamesEndedRM, lobbySlot.GamesEndedDM); LobbyUtils.CalculateUserFieldColors(player, 0); } return(player); }
void INotifyCreated.Created(Actor self) { separateTeamSpawns = self.World.LobbyInfo.GlobalSettings .OptionOrDefault("separateteamspawns", info.SeparateTeamSpawnsCheckboxEnabled); var spawns = new List <CPos>(); foreach (var n in self.World.Map.ActorDefinitions) { if (n.Value.Value == "mpspawn") { spawns.Add(new ActorReference(n.Key, n.Value.ToDictionary()).GetValue <LocationInit, CPos>()); } } spawnLocations = spawns.ToArray(); // Initialize the list of unoccupied spawn points for AssignSpawnLocations to pick from availableSpawnPoints = LobbyUtils.AvailableSpawnPoints(spawnLocations.Length, self.World.LobbyInfo); foreach (var kv in self.World.LobbyInfo.Slots) { var client = self.World.LobbyInfo.ClientInSlot(kv.Key); if (client == null || client.SpawnPoint == 0) { continue; } availableSpawnPoints.Remove(client.SpawnPoint); occupiedSpawnPoints.Add(client.SpawnPoint, client); } }
static bool StartGame(S server, Connection conn, Session.Client client, string s) { lock (server.LobbyInfo) { if (!client.IsAdmin) { server.SendOrderTo(conn, "Message", "Only the host can start the game."); return(true); } if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null)) { server.SendOrderTo(conn, "Message", "Unable to start the game until required slots are full."); return(true); } if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && server.LobbyInfo.NonBotPlayers.Count() < 2) { server.SendOrderTo(conn, "Message", server.TwoHumansRequiredText); return(true); } if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo)) { server.SendOrderTo(conn, "Message", "Unable to start the game until more spawn points are enabled."); return(true); } server.StartGame(); return(true); } }
private void ProcessLobbySessionStart() { LobbyUtils.ResetLobbyData(); Variables.LobbySession = true; if (Variables.OverlayWindow == null) { Variables.OverlayThread = new Thread(() => { Variables.OverlayApp = new Application(); Variables.OverlayWindow = new MainWindow(); Task.Delay(500).ContinueWith(task => Variables.OverlayWindow.UpdateConfiguration(Variables.Config, Variables.LobbySession)); Variables.OverlayWindow.RegisterHotKeyHooks(CopyPlayerStats, CalculateBalancedTeamsRank, CalculateBalancedTeamsTotalGames, CalculateBalancedTeamsWinRatio); Variables.OverlayApp.Run(Variables.OverlayWindow); }); Variables.OverlayThread.SetApartmentState(ApartmentState.STA); Variables.OverlayThread.Start(); } else { Variables.OverlayWindow.UpdateConfiguration(Variables.Config, Variables.LobbySession); } if (Variables.ReplayMode) { Task.Factory.StartNew(() => new NetHookDumpReaderJob()); } else { SteamUtils.CheckNethookPaths(); Task.Delay(5000).ContinueWith(t => SteamUtils.CheckNethookPaths()); //In case NetHook didn't start up fast enough } }
static void CheckAutoStart(S server) { lock (server.LobbyInfo) { var nonBotPlayers = server.LobbyInfo.NonBotPlayers; // Are all players and admin (could be spectating) ready? if (nonBotPlayers.Any(c => c.State != Session.ClientState.Ready) || server.LobbyInfo.Clients.First(c => c.IsAdmin).State != Session.ClientState.Ready) { return; } // Does server have at least 2 human players? if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && nonBotPlayers.Count() < 2) { return; } // Are the map conditions satisfied? if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null)) { return; } if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo)) { return; } server.StartGame(); } }
public IEnumerable <Player> Get() { //Secondary where clause is done in memory because there seems to be an EF bug var users = _repository.Users.Where(u => u.Games > 0).ToList().Where(u => u.SteamId > 0).Select(u => new Player { Name = u.Name, RankRM = u.RankRM, RankDM = u.RankDM, SSteamId = u.SteamId.ToString(), GameStats = UserUtils.GetGameStats(u.GamesStartedRM, u.GamesStartedDM, u.GamesWonRM, u.GamesWonDM, u.GamesEndedRM, u.GamesEndedDM), Profile = new PlayerProfile { Location = u.Location, ProfilePrivate = u.ProfilePrivate, ProfileDataFetched = u.ProfileDataFetched }, ReputationStats = new PlayerReputationStats { Games = u.Games, NegativeReputation = u.NegativeReputation, PositiveReputation = u.PositiveReputation } }).ToList(); foreach (var user in users) { LobbyUtils.CalculateUserFieldColors(user, 0); } return(users); }
private void ProcessLeaderBoardUpdate(NetHookItem item) { var msg = item.ReadAsProtobufMsg <CMsgClientLBSSetScore>(); if (msg.Body.leaderboard_id == 180533) { LobbyUtils.StartLobby(Variables.Lobby); } }
private void ReadFile(FileInfo file) { var item = new NetHookItem(); if (item.LoadFromFile(file)) { switch (item.Direction) { case NetHookItem.PacketDirection.In: switch (item.EMsg) { case EMsg.ClientMMSLobbyData: ProcessLobbyUpdate(item); SetLobbyPresence(true); break; case EMsg.ClientMMSCreateLobbyResponse: ProcessCreateLobbyResponse(item); break; case EMsg.ClientMMSJoinLobbyResponse: ProcessJoinLobbyResponse(item); break; } break; case NetHookItem.PacketDirection.Out: switch (item.EMsg) { case EMsg.ClientMMSCreateLobby: case EMsg.ClientMMSJoinLobby: LobbyUtils.ResetLobbyData(); SetLobbyPresence(true); ClearOverlayTeams(); break; case EMsg.ClientMMSLeaveLobby: ProcessLobbyLeave(); SetLobbyPresence(false); break; case EMsg.ClientLBSSetScore: ProcessLeaderBoardUpdate(item); break; } break; } } else { throw new Exception("Failed to read"); } }
public NetHookDumpReaderJob() { LobbyUtils.ResetLobbyData(); if (Variables.ReplayMode) { ReadNewFiles(); } else { StartJob(); } }
public User Get(string id) { var user = _repository.Users.Include(u => u.LobbySlots).ThenInclude(ls => ls.Lobby).Include(u => u.Reputations).ThenInclude(ur => ur.Reputation).Include(u => u.Reputations).ThenInclude(u => u.Lobby).Select(u => new User { Id = u.Id, SSteamId = u.SteamId.ToString(), Name = u.Name, Location = u.Location, Games = u.Games, PositiveReputation = u.PositiveReputation, NegativeReputation = u.NegativeReputation, RankRM = u.RankRM, RankDM = u.RankDM, GamesStartedRM = u.GamesStartedRM, GamesEndedRM = u.GamesEndedRM, GamesWonRM = u.GamesWonRM, GamesStartedDM = u.GamesStartedDM, GamesEndedDM = u.GamesEndedDM, GamesWonDM = u.GamesWonDM, ProfilePrivate = u.ProfilePrivate, ProfileDataFetched = u.ProfileDataFetched.HasValue ? u.ProfileDataFetched.Value.ToString("d") : null, KnownNames = u.LobbySlots.Select(ls => ls.Name).Distinct().OrderBy(ls => ls).ToList(), ReputationStats = new PlayerReputationStats() { Games = u.Games, PositiveReputation = u.PositiveReputation, NegativeReputation = u.NegativeReputation }, Reputations = u.Reputations.OrderByDescending(r => r.Added).Select(ur => new UserReputation { Id = ur.Id, Comment = ur.Comment, Added = ur.Added.ToString("d"), Reputation = new Reputation { Id = ur.Reputation.Id, Name = ur.Reputation.Name, Type = ur.Reputation.Type, }, Lobby = ur.Lobby != null ? new Models.Lobby { Id = ur.Lobby.Id, Name = ur.Lobby.Name } : null }).ToList(), Matches = u.LobbySlots.Where(ls => ls.Lobby.Started.HasValue && ls.Position > 0).OrderByDescending(ls => ls.Lobby.Joined).Select(ls => new MatchHistory { Id = ls.Lobby.Id, Name = ls.Lobby.Name, Joined = ls.Lobby.Joined.ToString("d") }).ToList() }).FirstOrDefault(u => u.SSteamId == id); user.GameStats = UserUtils.GetGameStats(user.GamesStartedRM, user.GamesStartedDM, user.GamesWonRM, user.GamesWonDM, user.GamesEndedRM, user.GamesEndedDM); LobbyUtils.CalculateUserFieldColors(user, 0); return(user); }
public object Put(int id, [FromBody] string payload = null) { switch (id) { case (int)Commands.IN.LOBBY_SESSION_START: ProcessLobbySessionStart(); return(new { }); case (int)Commands.IN.LOBBY_SESSION_STOP: ProcessLobbySessionStop(); return(new { }); case (int)Commands.IN.SET_UP: return(SetUp()); case (int)Commands.IN.START_LOBBY_MANUALLY: LobbyUtils.StartLobby(Variables.Lobby); return(new { }); case (int)Commands.IN.SEAL_LOBBY: SealLobby(payload); return(new { }); case (int)Commands.IN.GET_UNSEALED_LOBBY: return(GetUnsealedLobby()); case (int)Commands.IN.CALCULATE_BALANCED_TEAMS_BASED_ON_RANK: return(BalancingUtils.CalculateBalancedTeamsBasedOnRank()); case (int)Commands.IN.CALCULATE_BALANCED_TEAMS_BASED_ON_TOTAL_GAMES: return(BalancingUtils.CalculateBalancedTeamsBasedOnTotalGames()); case (int)Commands.IN.CALCULATE_BALANCED_TEAMS_BASED_ON_WIN_RATIO: return(BalancingUtils.CalculateBalancedTeamsBasedOnWinRatio()); case (int)Commands.IN.COPY_PLAYER_STATS: return(BalancingUtils.CopyPlayerStats()); default: throw new Exception("Command not recognized: " + id); } }
object IAssignSpawnPointsInfo.InitializeState(MapPreview map, Session lobbyInfo) { var state = new AssignSpawnLocationsState(); // Initialize the list of unoccupied spawn points for AssignSpawnLocations to pick from state.SpawnLocations = map.SpawnPoints; state.AvailableSpawnPoints = LobbyUtils.AvailableSpawnPoints(map.SpawnPoints.Length, lobbyInfo); foreach (var kv in lobbyInfo.Slots) { var client = lobbyInfo.ClientInSlot(kv.Key); if (client == null || client.SpawnPoint == 0) { continue; } state.AvailableSpawnPoints.Remove(client.SpawnPoint); state.OccupiedSpawnPoints.Add(client.SpawnPoint, client); } return(state); }
private void StartJob() { _job = new Timer(state => { if (!_jobRunning) { _jobRunning = true; try { if (Variables.OverlayWindow != null) { lock (Variables.LobbyPlayers) { LobbyUtils.CalculateLobbyPlayerFieldColors(); Variables.OverlayWindow.UpdatePlayers(Variables.LobbyPlayers, Variables.Teams, Variables.Lobby.Ranked == 2); } } } catch (Exception e) { Console.WriteLine("Error while running overlay updater job"); Console.WriteLine(e.ToString()); } finally { _jobRunning = false; } } }, null, 0, 500); }
public Lobby Get(string id) { if (id == "0") { if (Variables.Lobby != null) { lock (Variables.LobbyPlayers) { LobbyUtils.CalculateLobbyPlayerFieldColors(); Variables.Lobby.Players = Variables.LobbyPlayers.OrderBy(lp => lp.Position); Variables.Lobby.SLobbyId = Variables.Lobby.LobbyId.ToString(); foreach (var player in Variables.Lobby.Players) { player.SSteamId = player.SteamId.ToString(); } return(Variables.Lobby); } } else { return(null); } } else { var longLobbyId = ulong.Parse(id); var runningLobby = _repository.Lobbies.Include(l => l.Players).ThenInclude(ls => ls.User).FirstOrDefault(l => l.LobbyId == longLobbyId); var lobby = new Commons.Models.Lobby { LobbyId = runningLobby.LobbyId, SLobbyId = runningLobby.LobbyId.ToString(), GameType = runningLobby.GameType, Name = runningLobby.Name, Ranked = runningLobby.Ranked, Players = runningLobby.Players.Where(p => p.Position > 0).OrderBy(p => p.Position).Select(p => new Player { Name = p.Name, SteamId = p.User != null ? p.User.SteamId : 0, SSteamId = p.User?.SteamId.ToString(), LobbySlotId = p.Id, Position = p.Position, Rank = runningLobby.Ranked == 2 ? p.RankDM : p.RankRM, RankRM = p.RankRM, RankDM = p.RankDM, Profile = p.User != null ? new PlayerProfile { Location = p.User.Location, ProfileDataFetched = p.User.ProfileDataFetched, ProfilePrivate = p.User.ProfilePrivate } : null, ReputationStats = p.User != null ? new PlayerReputationStats { Games = p.User.Games, PositiveReputation = p.User.PositiveReputation, NegativeReputation = p.User.NegativeReputation } : null, GameStats = p.User != null ? UserUtils.GetGameStats(p.GamesStartedRM, p.GamesStartedDM, p.GamesWonRM, p.GamesWonDM, p.GamesEndedRM, p.GamesEndedDM) : null, }).ToList() }; foreach (var player in lobby.Players) { LobbyUtils.CalculateUserFieldColors(player, lobby.Ranked); } return(lobby); } }
private void ProcessLobbySessionStop() { LobbyUtils.LobbySessionStop(); }
private void ProcessLobbyUpdate(NetHookItem item) { var msg = item.ReadAsProtobufMsg <CMsgClientMMSLobbyData>(); if (msg == null || msg.Body == null) { return; } var lobbyData = new KeyValue(); using (var stream1 = new MemoryStream(msg.Body.metadata)) { if (!lobbyData.TryReadAsBinary(stream1)) { throw new Exception("Failed to read lobby metadata"); } else { if (lobbyData == null || lobbyData.Children == null || lobbyData.Children.Count == 0) { return; } TryExtractLobbyData(lobbyData); if (msg.Body.members.Count > 0) { this.ClearOverlayTeams(); var lobbyMembers = new List <Player>(); foreach (var playerData in msg.Body.members) { var memberData = new KeyValue(); using (var stream2 = new MemoryStream(playerData.metadata)) { try { if (memberData.TryReadAsBinary(stream2)) { var player = new Player() { SteamId = playerData.steam_id, Name = playerData.persona_name }; try { player.RankRM = int.Parse(memberData.Children.SingleOrDefault(c => c.Name == "STAT_ELO_RM").Value); } catch { } try { player.RankDM = int.Parse(memberData.Children.SingleOrDefault(c => c.Name == "STAT_ELO_DM").Value); } catch { } lobbyMembers.Add(player); } } catch (Exception e) { Console.WriteLine("Error while processing lobby member: " + playerData.persona_name); Console.WriteLine(e.ToString()); } } } Variables.LobbyMembers = lobbyMembers; } if (lobbyData.Children.Any(c => c.Name == "player0_desc")) { foreach (var lobbyMember in Variables.LobbyMembers) { lobbyMember.Position = 0; } var lobbyPlayers = new List <Player>(); for (var i = 0; i < 8; i++) { try { var player = new Player() { Position = i + 1 }; TryExtractNameAndRank(player, lobbyData.Children.SingleOrDefault(c => c.Name == "player" + i + "_desc")?.Value, Variables.Lobby.Ranked > 0); var lobbyMember = Variables.LobbyMembers.FirstOrDefault(lm => lm.Name == player.Name && lm.Position == 0); if (lobbyMember != null) { lobbyMember.Position = i + 1; player.SteamId = lobbyMember.SteamId; if (player.Rank == 0) { if (Variables.Lobby.Ranked != 2) { player.Rank = lobbyMember.RankRM; } else { player.Rank = lobbyMember.RankDM; } } player.RankRM = lobbyMember.RankRM; player.RankDM = lobbyMember.RankDM; } if (player.SteamId != 0) { try { using (IRepository repository = new Repository()) { var lobbySlot = repository.LobbySlots.Include(ls => ls.User).GetLobbySlot(player.SteamId, Variables.Lobby.LobbyId).FirstOrDefault(); if (lobbySlot == null) { var user = UserUtils.GetUser(repository, player); var lobby = repository.Lobbies.FirstOrDefault(l => l.LobbyId == Variables.Lobby.LobbyId); if (lobby == null) { throw new Exception("Lobby not found in database: " + Variables.Lobby.LobbyId); } lobbySlot = new LobbySlot() { Name = player.Name, RankDM = player.RankDM, RankRM = player.RankRM, User = user, Lobby = lobby }; repository.Add(lobbySlot); repository.SaveChanges(); LobbyUtils.AssignLobbySlotId(lobbySlot, player); } else { LobbyUtils.AssignLobbySlotId(lobbySlot, player); } } } catch (Exception e) { LogUtils.Error(string.Format("Failed to persist player joining to lobby event - Player: {0}({1}) - Lobby: {2}", player.Name, player.SteamId, Variables.Lobby.LobbyId), e); } } lobbyPlayers.Add(player); UserUtils.FetchUserGameStats(player); UserUtils.FetchUserProfile(player); UserUtils.FetchUserReputationStats(player); } catch (Exception e) { Console.WriteLine("Error while processing lobby player in slot: " + i); Console.WriteLine(e.ToString()); } lock (Variables.LobbyPlayers) { Variables.LobbyPlayers = lobbyPlayers; } } } } } if (Variables.ReplayMode) { Thread.Sleep(500); } }