private async Task RemoveFromParty(Party party, params string[] names) { if (party.UserNames.Count == 2 && names.Any(x => party.UserNames.Contains(x))) names = party.UserNames.ToArray(); // party has just two people and we remove one of them -> remove all await server.MatchMaker.RemoveUser(names.First(), true); // removing user before changing party removes all party users var broadcastNames = party.UserNames.ToList(); foreach (var n in names) { var lobus = server.ConnectedUsers.Get(n)?.User; if (lobus != null) lobus.PartyID = null; party.UserNames.Remove(n); broadcastNames.Add(n); } var ps = new OnPartyStatus() { PartyID = party.PartyID, UserNames = party.UserNames }; if (party.UserNames.Count == 0) parties.Remove(party); await server.Broadcast(AddFriendsBy(broadcastNames), ps); }
private async Task AddToParty(Party party, params string[] names) { var isChange = false; foreach (var n in names) if (!party.UserNames.Contains(n)) { var lobus = server.ConnectedUsers.Get(n)?.User; if (lobus != null) lobus.PartyID = party.PartyID; party.UserNames.Add(n); isChange = true; } var ps = new OnPartyStatus() { PartyID = party.PartyID, UserNames = party.UserNames }; if (isChange) await server.MatchMaker.RemoveUser(names.First(), true); // remove all people from this party from mm await server.Broadcast(AddFriendsBy(party.UserNames), ps); }