Example #1
0
 public async Task OnServerGameChanged(string game)
 {
     UpdateQueues();
     await server.Broadcast(new MatchMakerSetup()
     {
         PossibleQueues = possibleQueues
     });
 }
Example #2
0
 public async Task OnServerGameChanged(string game)
 {
     foreach (var pq in possibleQueues)
     {
         pq.Game = game;
     }
     await server.Broadcast(new MatchMakerSetup()
     {
         PossibleQueues = possibleQueues
     });
 }
 public void TopPlayersUpdated(IEnumerable <Account> players)
 {
     cachedLadderList = new LadderList()
     {
         LadderItems = players.Select(x => x.ToLadderItem()).ToList()
     };
     server.Broadcast(cachedLadderList);
 }
        private async Task AddToParty(Party party, params string[] names)
        {
            var isChange = false;

            foreach (var n in names)
            {
                if (!party.UserNames.Contains(n))
                {
                    var conus = server.ConnectedUsers.Get(n);
                    var lobus = conus?.User;
                    if (lobus != null)
                    {
                        lobus.PartyID = party.PartyID;
                    }
                    party.UserNames.Add(n);
                    isChange = true;

                    if (conus != null)
                    {
                        await conus.Process(new JoinChannel()
                        {
                            ChannelName = party.ChannelName
                        });
                    }
                }
            }

            var ps = new OnPartyStatus()
            {
                PartyID = party.PartyID, UserNames = party.UserNames
            };

            if (isChange)
            {
                // remove all people from this party from mm
                if (await server.MatchMaker.RemoveUser(names.First(), true))
                {
                    await server.UserLogSay($"Removed {names.First()}'s party from MM because someone joined the party");
                }
            }


            await server.Broadcast(AddFriendsBy(party.UserNames), ps);
        }
Example #5
0
        private async void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            try
            {
                timer.Stop();
                var counts =
                    new HashSet <Tuple <int, int, int> >(
                        server.Battles.Values.Where(x => x != null).Select(x => Tuple.Create(x.BattleID, x.NonSpectatorCount, x.SpectatorCount)));

                foreach (var c in counts)
                {
                    if (!storedCounts.Contains(c))
                    {
                        await
                        server.Broadcast(new BattleUpdate()
                        {
                            Header = new BattleHeader()
                            {
                                BattleID = c.Item1, PlayerCount = c.Item2, SpectatorCount = c.Item3
                            }
                        });
                    }
                }

                storedCounts = counts;
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error in playerlist updater: {0}", ex);
            }

            finally
            {
                timer.Start();
            }
        }
Example #6
0
        public async Task Process(JoinChannel joinChannel)
        {
            if (!IsLoggedIn)
            {
                return;
            }

            if (!await server.ChannelManager.CanJoin(User.AccountID, joinChannel.ChannelName))
            {
                await
                SendCommand(new JoinChannelResponse()
                {
                    Success     = false,
                    Reason      = "you don't have permission to join this channel",
                    ChannelName = joinChannel.ChannelName
                });

                return;
            }

            var channel = server.Channels.GetOrAdd(joinChannel.ChannelName, (n) => new Channel()
            {
                Name = joinChannel.ChannelName,
            });

            if (!string.IsNullOrEmpty(channel.Password) && (channel.Password != joinChannel.Password))
            {
                await SendCommand(new JoinChannelResponse()
                {
                    Success = false, Reason = "invalid password", ChannelName = joinChannel.ChannelName
                });

                return;
            }

            var added = channel.Users.TryAdd(Name, User);

            if (!added)
            {
                await
                SendCommand(new JoinChannelResponse()
                {
                    Success     = false,
                    Reason      = "You are already in this channel",
                    ChannelName = joinChannel.ChannelName
                });

                return;
            }
            var visibleUsers = !channel.IsDeluge ? channel.Users.Keys.ToList() : channel.Users.Keys.Where(x => server.CanUserSee(Name, x)).ToList();
            var canSeeMe     = !channel.IsDeluge ? channel.Users.Keys.ToList() : channel.Users.Keys.Where(x => server.CanUserSee(x, Name)).ToList();

            await server.TwoWaySyncUsers(Name, canSeeMe); // mutually sync user statuses

            // send response with the list
            await SendCommand(new JoinChannelResponse()
            {
                Success     = true,
                ChannelName = joinChannel.ChannelName,
                Channel     =
                    new ChannelHeader()
                {
                    ChannelName = channel.Name,
                    Password    = channel.Password,
                    Topic       = channel.Topic,
                    Users       = visibleUsers,   // for zk use cansee test to not send all users
                    IsDeluge    = channel.IsDeluge
                }
            });

            // send missed messages
            server.OfflineMessageHandler.SendMissedMessagesAsync(this, SayPlace.Channel, joinChannel.ChannelName, User.AccountID, channel.IsDeluge ? OfflineMessageHandler.DelugeMessageResendCount : OfflineMessageHandler.MessageResendCount);

            // send self to other users who can see
            if (added)
            {
                await server.Broadcast(canSeeMe, new ChannelUserAdded { ChannelName = channel.Name, UserName = Name });
            }
        }
 public void OnNewsChanged()
 {
     CacheNewsList();
     server.Broadcast(cachedNewsList);
 }
Example #8
0
        public async Task Process(SetRectangle rect)
        {
            if (!IsLoggedIn)
            {
                return;
            }

            var bat = MyBattle;

            if (bat == null || (bat.Founder != User && !User.IsAdmin))
            {
                await Respond("No rights to set rectangle");

                return;
            }

            if (rect.Rectangle == null)
            {
                BattleRect org;
                bat.Rectangles.TryRemove(rect.Number, out org);
            }
            else
            {
                bat.Rectangles[rect.Number] = rect.Rectangle;
            }
            await state.Broadcast(bat.Users.Keys, rect);
        }
        public async Task Process(Login login)
        {
            var user     = new User();
            var response = await Task.Run(() => state.LoginChecker.Login(user, login, this));

            if (response.ResultCode == LoginResponse.Code.Ok)
            {
                connectedUser = state.ConnectedUsers.GetOrAdd(user.Name, (n) => new ConnectedUser(state, user));
                connectedUser.Connections.TryAdd(this, true);
                connectedUser.User = user;

                Trace.TraceInformation("{0} login: {1}", this, response.ResultCode.Description());

                await state.Broadcast(state.ConnectedUsers.Values, connectedUser.User); // send self to all

                await SendCommand(response);                                            // login accepted

                foreach (var c in state.ConnectedUsers.Values.Where(x => x != connectedUser))
                {
                    await SendCommand(c.User);                                                                           // send others to self
                }
                foreach (var b in state.Battles.Values)
                {
                    if (b != null)
                    {
                        await
                        SendCommand(new BattleAdded()
                        {
                            Header =
                                new BattleHeader()
                            {
                                BattleID       = b.BattleID,
                                Engine         = b.EngineVersion,
                                Game           = b.ModName,
                                Founder        = b.Founder.Name,
                                Map            = b.MapName,
                                Ip             = b.Ip,
                                Port           = b.HostPort,
                                Title          = b.Title,
                                SpectatorCount = b.SpectatorCount,
                                MaxPlayers     = b.MaxPlayers,
                                Password       = b.Password != null ? "?" : null
                            }
                        });

                        foreach (var u in b.Users.Values.Select(x => x.ToUpdateBattleStatus()).ToList())
                        {
                            await SendCommand(new JoinedBattle()
                            {
                                BattleID = b.BattleID, User = u.Name
                            });
                        }
                    }
                }


                await state.OfflineMessageHandler.SendMissedMessages(this, SayPlace.User, Name, user.AccountID);

                foreach (var chan in await state.ChannelManager.GetDefaultChannels(user.AccountID))
                {
                    await connectedUser.Process(new JoinChannel()
                    {
                        ChannelName = chan,
                        Password    = null
                    });
                }
            }
            else
            {
                await SendCommand(response);

                if (response.ResultCode == LoginResponse.Code.Banned)
                {
                    transport.RequestClose();
                }
            }
        }