Esempio n. 1
0
        public void OnLobbyJoin(BanchoLobbyJoinArgs args)
        {
            var lobbyStream = _ps.GetStream("lobby");
            var rooms       = _ms.GetRooms();

            foreach (var room in rooms)
            {
                args.pr += new MatchNew(room);
            }

            lobbyStream.Join(args.pr);
        }
Esempio n. 2
0
        public void OnBanchoExit(BanchoExitArgs args)
        {
            var mainStream = _pss.GetStream("main");

            Logger.Info(
                "%#F94848%" + args.pr.User.Username,
                "%#B342F4%(", args.pr.User.Id, "%#B342F4%)",
                "%#FFFFFF%has Disconnected!"
                );

            mainStream?.Broadcast(
                new HandleUserQuit(new UserQuitStruct {
                UserId = args.pr.User.Id, ErrorState = args.err
            }), args.pr
                );
        }
Esempio n. 3
0
        public Task RunAsync()
        {
            _botPresence = new Presence(_cs)
            {
                User   = Users.GetUser(_factory, 100),
                Status = new UserStatus
                {
                    Status          = Status.Watching,
                    Playmode        = PlayMode.Osu,
                    BeatmapChecksum = "nothing",
                    BeatmapId       = 0,
                    StatusText      = "over you!",
                    CurrentMods     = Mod.TouchDevice
                },
                LeaderboardRx    = LeaderboardRx.GetLeaderboard(_factory, 100),
                LeaderboardStd   = LeaderboardStd.GetLeaderboard(_factory, 100),
                Timezone         = 0,
                BlockNonFriendDm = false,
                Lon         = 0d,
                Lat         = 0d,
                BotPresence = true
            };

            var stream = _pss.GetStream("main");

            if (stream != null)
            {
                stream.Broadcast(new PresenceSingle(_botPresence.User.Id));
                stream.Broadcast(new UserPresence(_botPresence));
                stream.Broadcast(new HandleUpdate(_botPresence));
            }

            _ps.BeginPresence(_botPresence);

            Logger.Info("Hey, I'm Sora! I'm a bot and i say Hello World!");

            return(Task.CompletedTask);
        }
Esempio n. 4
0
 public void Update()
 {
     _pss.GetStream("lobby").Broadcast(new MatchUpdate(this));
     Broadcast(new MatchUpdate(this));
 }
Esempio n. 5
0
        public void OnLoginRequest(BanchoLoginRequestArgs args)
        {
            try
            {
                var sw = new Stopwatch();
                sw.Start();

                var loginData = LoginParser.ParseLogin(args.Reader);
                if (loginData == null)
                {
                    Exception(args.Writer);
                    return;
                }

                var cacheKey = $"sora:user:{loginData.GetHashCode()}";

                var presence = _cache.Get <Presence>(cacheKey);
                if (presence == null)
                {
                    var user = Users.GetUser(_factory, loginData.Username);
                    if (user == null)
                    {
                        LoginFailed(args.Writer);
                        return;
                    }

                    if (!user.IsPassword(loginData.Password))
                    {
                        LoginFailed(args.Writer);
                        return;
                    }

                    if (args.IPAddress != "127.0.0.1" && args.IPAddress != "0.0.0.0")
                    {
                        var data = Localisation.GetData(args.IPAddress);

                        args.pr.CountryId = Localisation.StringToCountryId(data.Country.IsoCode);

                        args.pr.Lon = data.Location.Longitude ?? 0;
                        args.pr.Lat = data.Location.Latitude ?? 0;
                    }

                    args.pr.User = user;

                    args.pr.LeaderboardRx  = LeaderboardRx.GetLeaderboard(_factory, args.pr.User);
                    args.pr.LeaderboardStd = LeaderboardStd.GetLeaderboard(_factory, args.pr.User);

                    args.pr.Rank = args.pr.LeaderboardStd.GetPosition(_factory, PlayMode.Osu);

                    args.pr.Timezone         = loginData.Timezone;
                    args.pr.BlockNonFriendDm = loginData.BlockNonFriendDMs;

                    args.pr.Status.BeatmapId       = 0;
                    args.pr.Status.StatusText      = "";
                    args.pr.Status.CurrentMods     = 0;
                    args.pr.Status.BeatmapChecksum = "";
                    args.pr.Status.Playmode        = PlayMode.Osu;
                    args.pr.Status.Status          = Status.Idle;

                    args.pr.Rank = args.pr.LeaderboardStd.GetPosition(_factory, PlayMode.Osu);

                    _cache.Set(cacheKey, args.pr, TimeSpan.FromMinutes(30));
                }
                else
                {
                    var t = args.pr.Token;
                    args.pr       = presence;
                    args.pr.Token = t;
                }

                _pcs += args.pr;

                Success(args.Writer, args.pr.User.Id);

                args.pr += new ProtocolNegotiation();
                args.pr += new UserPresence(args.pr);
                args.pr += new HandleUpdate(args.pr);

                if ((args.pr.ClientPermissions & LoginPermissions.Supporter) == 0)
                {
                    if (_cfg.Server.FreeDirect)
                    {
                        args.pr += new LoginPermission(LoginPermissions.User | LoginPermissions.Supporter);
                    }
                }
                else
                {
                    args.pr += new LoginPermission(args.pr.ClientPermissions);
                }

                args.pr += new FriendsList(Database.Models.Friends.GetFriends(_factory, args.pr.User.Id).ToList());
                args.pr += new PresenceBundle(_pcs.GetUserIds(args.pr).ToList());
                foreach (var opr in _pcs.AllPresences)
                {
                    args.pr += new PresenceSingle(opr.User.Id);
                    args.pr += new UserPresence(opr);
                    args.pr += new HandleUpdate(opr);
                }

                foreach (var chanAuto in _cs.ChannelsAutoJoin)
                {
                    if (chanAuto.AdminOnly && args.pr.User.Permissions == Permission.ADMIN_CHANNEL)
                    {
                        args.pr += new ChannelAvailableAutojoin(chanAuto);
                    }
                    else if (!chanAuto.AdminOnly)
                    {
                        args.pr += new ChannelAvailableAutojoin(chanAuto);
                    }

                    if (chanAuto.JoinChannel(args.pr))
                    {
                        args.pr += new ChannelJoinSuccess(chanAuto);
                    }
                    else
                    {
                        args.pr += new ChannelRevoked(chanAuto);
                    }
                }

                foreach ((string _, Channel value) in _cs.Channels)
                {
                    if (value.AdminOnly && args.pr.User.Permissions == Permission.ADMIN_CHANNEL)
                    {
                        args.pr += new ChannelAvailable(value);
                    }
                    else if (!value.AdminOnly)
                    {
                        args.pr += new ChannelAvailable(value);
                    }
                }

                var stream = _ps.GetStream("main");
                if (stream == null)
                {
                    Exception(args.Writer);
                    return;
                }

                stream.Broadcast(new PresenceSingle(args.pr.User.Id));
                stream.Broadcast(new UserPresence(args.pr));
                stream.Broadcast(new HandleUpdate(args.pr));
                stream.Join(args.pr);

                args.pr
                .GetOutput()
                .WriteTo(args.Writer.BaseStream);

                sw.Stop();
                Logger.Info("MS: ", sw.Elapsed.TotalMilliseconds);

                Logger.Info(
                    "%#F94848%" + args.pr.User.Username, "%#B342F4%(", args.pr.User.Id,
                    "%#B342F4%) %#FFFFFF%has logged in!"
                    );
            } catch (Exception ex)
            {
                Logger.Err(ex);
                Exception(args.Writer);
            }
        }