示例#1
0
        public override Task OnActivateAsync()
        {
            N = new Shared.BigInteger("B79B3E2A87823CAB8F5EBFBF8EB10108535006298B5BADBD5B53E1895E644B89", 16);
            g = new Shared.BigInteger(7);
            s = new Shared.BigInteger(new Random(), 256);

            var streamProvider = base.GetStreamProvider("PacketStream");

            if (streamProvider == null)
            {
                throw new Exception("Session failed to initialise stream: GetStreamProvider failed");
            }

            _stream = new SessionStream();
            _stream.PacketStream  = streamProvider.GetStream <byte[]>(this.GetPrimaryKey(), "SessionPacketStream");
            _stream.CommandStream = streamProvider.GetStream <SocketCommand>(this.GetPrimaryKey(), "SessionCommandStream");

            if (_stream.PacketStream == null)
            {
                throw new Exception("Session failed to initialise stream: GetStream failed");
            }
            if (_stream.CommandStream == null)
            {
                throw new Exception("Session failed to initialise stream: GetStream failed");
            }

            DelayDeactivation(TimeSpan.FromDays(1)); //don't automatically gobble me up please!

            return(TaskDone.Done);
        }
示例#2
0
        public async Task RemoveSession(ISession s, bool disconnect = false)
        {
            var type = await s.GetSessionType();

            switch (type)
            {
            case SessionType.AuthSession:
            {
                AuthSession       = null;
                AuthSessionStream = null;
            }
            break;

            case SessionType.RealmSession:
            {
                RealmSession       = null;
                RealmSessionStream = null;
            }
            break;
            }

            ActiveSessions.Remove(s);

            if (disconnect)
            {
                await s.Disconnect();
            }
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EthernetServer"/> class.
 /// </summary>
 /// <param name="logger">An <see cref="ILogger"/> instance used for logging.</param>
 /// <param name="connectionLogger">An <see cref="ILogger"/> instance used for logging in connections.</param>
 public EthernetServer(ILogger <EthernetServer> logger, ILogger <EthernetConnection> connectionLogger)
     : base(logger)
 {
     this.connectionLogger         = connectionLogger;
     listClients                   = new List <IEthernetConnection>();
     clientDisconnectSessionStream = SessionStream.Where(x => !x.IsConnected && x.Value != null).Subscribe(x => listClients.Remove(x.Value !));
 }
示例#4
0
        public async Task StartAsync()
        {
            while (true)
            {
                if (Session.State == MediaSessionState.Authenticated && Tracks.Count > 0)
                {
                    MusicTrack currentTrack = Tracks[0];

                    if (currentTrack.DownloadTask != null)
                    {
                        await currentTrack.DownloadTask;
                    }

                    if (CurrentTrackStream == null)
                    {
                        CurrentTrackStream = DiscordVoiceUtils.GetAudioStream(currentTrack.FilePath);
                    }

                    try
                    {
                        SessionStream.CopyFrom(CurrentTrackStream);

                        Tracks.RemoveAt(0);
                        CurrentTrackStream.Flush();
                        CurrentTrackStream = null;
                    }
                    catch { }
                }
                else
                {
                    await Task.Delay(100);
                }
            }
        }
示例#5
0
 public Task OnLogout()
 {
     if (_Stream != null)
     {
         _Stream.CommandStream.OnNextAsync(new SocketCommand(SocketCommands.ClearPlayer));
     }
     _Stream = null;
     return(TaskDone.Done);
 }
示例#6
0
        public async Task AddSession(ISession s)
        {
            var type = await s.GetSessionType();

            var stream = await s.GetSessionStream();

            if (stream != null && stream.CommandStream != null)
            {
                await
                stream.CommandStream.OnNextAsync(new SocketCommand(SocketCommands.SetAccount,
                                                                   new object[] { this.AsReference <IAccount>() }));
            }

            switch (type)
            {
            case SessionType.AuthSession:
            {
                if (AuthSession != s)
                {
                    if (AuthSession != null)
                    {
                        await RemoveSession(AuthSession, true);
                    }
                    if (RealmSession != null)
                    {
                        await RemoveSession(RealmSession, true);
                    }
                }
                AuthSession = s;
                if (AuthSession != null)
                {
                    AuthSessionStream = await AuthSession.GetSessionStream();
                }
            }
            break;

            case SessionType.RealmSession:
            {
                if (RealmSession != null && s != RealmSession)
                {
                    await RemoveSession(RealmSession, true);
                }
                RealmSession = s;
                if (RealmSession != null)
                {
                    RealmSessionStream = await RealmSession.GetSessionStream();

                    RealmSessionRealmID = await RealmSession.GetRealmID();
                }
            }
            break;
            }

            ActiveSessions.Add(s);
        }
示例#7
0
        public async Task OnLogin()
        {
            var account = GrainFactory.GetGrain <IAccount>(State.Account);
            var session = await account.GetRealmSession();

            _Stream = await session.GetSessionStream(); //cache this to send packets without tonnes of copying

            if (_Stream != null)
            {
                await
                _Stream.CommandStream.OnNextAsync(new SocketCommand(SocketCommands.SetPlayer,
                                                                    new object[] { this.AsReference <IPlayer>() }));
            }
        }