Beispiel #1
0
        public async Task PlayAsync(PlayPacket playPacket)
        {
            _cache.TryGetFromCache(playPacket.Id, out var track);
            if (track is null)
            {
                var(isEnabled, response) = await _sources
                                           .HandleRequestAsync(track.Provider, track.Url ?? track.Title)
                                           .ConfigureAwait(false);

                if (isEnabled)
                {
                    LogHandler <AudioEngine> .Log
                    .Error($"{track.Provider} is disabled in configuration.");

                    return;
                }

                track = response.Tracks
                        .FirstOrDefault(x => x.Url == track.Url || x.Title.Contains(track.Title));
            }

            if (track is null)
            {
                LogHandler <AudioEngine> .Log.Error($"Unable to play the requested track: {track.Title}");

                return;
            }

            if (playPacket.StartTime > track.Duration || playPacket.StartTime < 0 ||
                playPacket.EndTime > track.Duration)
            {
                LogHandler <AudioEngine> .Log.Error($"Client sent out-of-bounds start or end time.");

                return;
            }

            _currentTrack = track;
            var stream = await _sources.GetStreamAsync(track).ConfigureAwait(false);

            await stream.CopyToAsync(_stream)
            .ConfigureAwait(false);

            await _stream.FlushAsync()
            .ConfigureAwait(false);

            SpinWait.SpinUntil(() => IsPlaybackCompleted);

            await _socket.SendAsync(new BaseResponse
            {
                Op   = OperationType.TrackFinished,
                Data = new PlayerResponse
                {
                    GuildId = _voiceClient.GuildId,
                    Track   = _currentTrack
                }
            })
            .ConfigureAwait(false);

            _currentTrack = default;
        }
Beispiel #2
0
    public void Play(int charId)
    {
        PlayPacket packet = new PlayPacket();

        packet.id     = localID;
        packet.charId = charId;
        socket.Emit("spawn", JsonUtility.ToJson(packet));
        try {
            ToggleSocial(false);
            ToggleAds(false);
        } catch (Exception ex) {
            Debug.Log(ex.Message + " | " + ex.StackTrace);
        }
    }
Beispiel #3
0
    public void startGame(Packet packet)
    {
        PlayPacket playPacket = JsonConvert.DeserializeObject <PlayPacket>(packet.data);
        // 5 times number of players plus 5
        Lobby     gameLobby = lobbies[playPacket.lobbyID];
        GameState game      = new GameState(20, 5 * gameLobby.numPlayers + 5); // wat

        game.start_time = DateTime.Now.Millisecond;
        Dictionary <int, Player> players = new Dictionary <int, Player>();

        switch (gameLobby.botCount)
        {
        case 1:
            gameLobby.bot = new SingleBot();
            break;

        case 2:
            gameLobby.bot = new DoubleBot();
            break;

        case 3:
            gameLobby.bot = new TripleBot();
            break;

        default:
            gameLobby.bot = null;
            break;
        }
        // gameLobby.bot = new SingleBot();
        for (int i = 0; i < gameLobby.players.Count; i++)
        {
            players[gameLobby.players[i].id] = gameLobby.players[i];
        }
        game.players   = players;
        gameLobby.game = game;
        // update all players that game will start
        alertLobby(0, playPacket.lobbyID, Packets.START);
        gameLobby.lobbyState = LobbyState.PLAYING;
    }