private static FriendStatus getFriendStatus(string steamid) { // TODO: Add idle status var browser = Browsers.Find(m => m.user != null && m.user.steam.steamid == steamid).FirstOrDefault(); if (browser != null) { if (browser.lobby != null) { if (browser.lobby.status > LobbyStatus.Queue) { return(FriendStatus.InGame); } else { return(FriendStatus.InLobby); } } else { return(FriendStatus.Online); } } else { return(FriendStatus.Offline); } }
void DeregisterClient(object se, OnClientDisconnectArgs e) { if (UID == null) { return; } var browsers = Browser.Find(m => m.user != null && m.user.Id == UID); foreach (var browser in browsers) { browser.SendManagerStatus(false); } }
public static void JoinParty(BrowserController c, JObject jdata, string steamid) { var party = Browsers.Find(m => m.user != null && m.party != null && m.user.steam.steamid == steamid).FirstOrDefault().party; if (party == null) { c.RespondError(jdata, "Can't find that party."); return; } if (party.invitedUsers.Contains(c.user.steam.steamid)) { if (party.users.Count() < party.users.Capacity) { lock (party.users) party.users.Add(PartyMember.FromUser(c.user)); c.party = party; } else { c.RespondError(jdata, "Party is full"); return; } } else { c.RespondError(jdata, "You are not invited to that party."); return; } TransmitPartyUpdate(party, new[] { "users" }); }
private string HandleStatsPlayers() { JObject data = new JObject(); var browsers = Browsers.Find(m => m.user != null); data["online"] = browsers.Count(); if (lastMonth == 0 || (DateTime.UtcNow - lastupdated).TotalHours > 1) { data["lastmonth"] = lastMonth = (int)Mongo.Users.Count(Query.GT("steam.lastlogoff", DateTime.UtcNow.AddDays(-30).ToUnixTime())); lastupdated = DateTime.UtcNow; } else { data["lastmonth"] = lastMonth; } data["playing"] = browsers.Count(m => m.lobby != null); return(data.ToString(Formatting.Indented)); }
private static void doMatchmake() { Matchmake[] mmArray; List <Matchmake> deleted = new List <Matchmake>(5); //we can't lock the whole thing, will make scale a pain lock (inMatchmaking) mmArray = inMatchmaking.ToArray(); foreach (var match in mmArray) { //if the match was moved to the other queue, simply ignore it if (match.Status == MatchmakeStatus.TeamQueue) { continue; } if (deleted.Contains(match)) { continue; } // Find match with a similar rating (search margin increases every try), enough free slots and a common mod var matchFound = mmArray.FirstOrDefault(x => x != match && match.IsMatch(x) && !deleted.Contains(x)); if (matchFound != null) { // Merge everything to the new match match.MergeMatches(matchFound); deleted.Add(matchFound); match.UpdateRating(); // update the browsers with the new match foreach (var browser in Browsers.Find(b => b.user != null && b.matchmake != null && b.matchmake.id == matchFound.id)) { browser.matchmake = match; } log.InfoFormat( "Matchmake merged from {0} players to {1} players after {2} tries. New rating: {3}", matchFound.Users.Count, match.Users.Count, match.TryCount, string.Join(", ", match.Ratings.Values)); //remove the old match, we dont need it lock (inMatchmaking) inMatchmaking.Remove(matchFound); //if we are crowded if (match.Users.Count == TEAM_PLAYERS) { //reset the tries and dont ignore it match.TryCount = 1; //move to team MM lock (inMatchmaking) inMatchmaking.Remove(match); lock (inTeamMatchmaking) inTeamMatchmaking.Add(match); match.Status = MatchmakeStatus.TeamQueue; TransmitMatchmakeUpdate(match, new[] { "Status", "UserCount" }); } else { TransmitMatchmakeUpdate(match, new[] { "UserCount" }); } } // match is already full, add to teamMM, should only happen if TEAM_PLAYERS is 1 or when changing values in debug mode. else if (match.Users.Count == TEAM_PLAYERS) { //reset the tries and dont ignore it match.TryCount = 1; //move to team MM lock (inMatchmaking) inMatchmaking.Remove(match); lock (inTeamMatchmaking) inTeamMatchmaking.Add(match); match.Status = MatchmakeStatus.TeamQueue; TransmitMatchmakeUpdate(match, new[] { "Status", "UserCount" }); } else { //no match found, open the possibilities match.TryCount++; } } }