Пример #1
0
        public virtual async void SetSelectedSongAsync(PlayerInfo sender, SongInfo song)
        {
            if (sender.Equals(roomHost))
            {
                selectedSong = song;

                NetOutgoingMessage outMsg = HubListener.ListenerServer.CreateMessage();

                if (selectedSong == null)
                {
                    switch (roomSettings.SelectionType)
                    {
                    case SongSelectionType.Manual:
                    {
                        roomState = RoomState.SelectingSong;

                        outMsg.Write((byte)CommandType.SetSelectedSong);
                        outMsg.Write((int)0);

                        BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered);
                        BroadcastWebSocket(CommandType.SetSelectedSong, null);
                    }
                    break;

                    case SongSelectionType.Random:
                    {
                        roomState = RoomState.Preparing;
                        Random rand = new Random();

                        randomSongTask = BeatSaver.GetRandomSong();
                        selectedSong   = await randomSongTask;
                        randomSongTask = null;

                        outMsg.Write((byte)CommandType.SetSelectedSong);
                        selectedSong.AddToMessage(outMsg);

                        BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered);
                        BroadcastWebSocket(CommandType.SetSelectedSong, selectedSong);
                        ReadyStateChanged(roomHost, true);
                    }
                    break;
                    }
                }
                else
                {
                    roomState = RoomState.Preparing;

                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    selectedSong.AddToMessage(outMsg);

                    BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered);
                    BroadcastWebSocket(CommandType.SetSelectedSong, selectedSong);
                    ReadyStateChanged(roomHost, true);
                }
            }
            else
            {
                Logger.Instance.Warning($"{sender.playerName}:{sender.playerId} tried to select song, but he is not the host");
            }
        }
Пример #2
0
        public virtual void StartLevel(PlayerInfo sender, LevelOptionsInfo options, SongInfo song)
        {
            if (sender.Equals(roomHost))
            {
                selectedSong   = song;
                startLevelInfo = options;

                SongWithOptions songWithDifficulty = new SongWithOptions(selectedSong, startLevelInfo);

                NetOutgoingMessage outMsg = HubListener.ListenerServer.CreateMessage();

                outMsg.Write((byte)CommandType.StartLevel);
                startLevelInfo.AddToMessage(outMsg);
                selectedSong.AddToMessage(outMsg);

                BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                BroadcastWebSocket(CommandType.StartLevel, songWithDifficulty);

                roomState      = RoomState.InGame;
                _songStartTime = DateTime.Now;
                _readyPlayers.Clear();
            }
            else
            {
                Logger.Instance.Warning($"{sender.playerName}({sender.playerId}) tried to start the level, but he is not the host");
            }
        }
Пример #3
0
        public virtual void SetSelectedSong(PlayerInfo sender, SongInfo song)
        {
            if (sender.Equals(roomHost))
            {
                selectedSong = song;

                NetOutgoingMessage outMsg = HubListener.ListenerServer.CreateMessage();

                if (selectedSong == null)
                {
                    switch (roomSettings.SelectionType)
                    {
                    case SongSelectionType.Manual:
                    {
                        roomState = RoomState.SelectingSong;

                        outMsg.Write((byte)CommandType.SetSelectedSong);
                        outMsg.Write((int)0);

                        BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                        BroadcastWebSocket(CommandType.SetSelectedSong, null);
                    }
                    break;

                    case SongSelectionType.Random:
                    {
                        if (!requestedRandomSong && roomClients.Count > 0 && roomClients.Any(x => roomHost.Equals(x.playerInfo)))
                        {
                            requestedRandomSong = true;

                            outMsg.Write((byte)CommandType.GetRandomSongInfo);

                            roomClients.First(x => roomHost.Equals(x.playerInfo)).playerConnection.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);

                            BroadcastWebSocket(CommandType.GetRandomSongInfo, null);
                        }
                    }
                    break;
                    }
                }
                else
                {
                    requestedRandomSong = false;

                    roomState = RoomState.Preparing;

                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    selectedSong.AddToMessage(outMsg);

                    BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                    BroadcastWebSocket(CommandType.SetSelectedSong, selectedSong);
                    ReadyStateChanged(roomHost, true);
                }
            }
            else
            {
                Logger.Instance.Warning($"{sender.playerName}({sender.playerId}) tried to select song, but he is not the host");
            }
        }
Пример #4
0
        public void SendSongDuration(SongInfo info)
        {
            if (connected && networkClient != null)
            {
                NetOutgoingMessage outMsg = networkClient.CreateMessage();
                outMsg.Write((byte)CommandType.GetSongDuration);
                info.AddToMessage(outMsg);

                networkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
            }
        }
Пример #5
0
        public void RemoveRequestedSong(SongInfo info)
        {
            if (connected && networkClient != null)
            {
                NetOutgoingMessage outMsg = networkClient.CreateMessage();
                outMsg.Write((byte)CommandType.RemoveRequestedSong);
                info.AddToMessage(outMsg);

                networkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                Plugin.log.Debug($"Sent remove request for song \"{info.songName}\"!");
            }
        }
Пример #6
0
        public void SendSongDuration(SongInfo info)
        {
            if (Connected && NetworkClient != null)
            {
                NetOutgoingMessage outMsg = NetworkClient.CreateMessage();
                outMsg.Write((byte)CommandType.GetSongDuration);
                info.AddToMessage(outMsg);

                NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
#if DEBUG
                Misc.Logger.Info("Requested ChannelInfo...");
#endif
            }
        }
Пример #7
0
        public void StartLevel(IPreviewBeatmapLevel song, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, GameplayModifiers modifiers)
        {
            if (connected && networkClient != null)
            {
                Plugin.log.Debug("Starting level...");

                NetOutgoingMessage outMsg = networkClient.CreateMessage();
                outMsg.Write((byte)CommandType.StartLevel);

                new LevelOptionsInfo(difficulty, modifiers, characteristic.serializedName).AddToMessage(outMsg);
                SongInfo selectedSong = new SongInfo(song);
                selectedSong.songDuration = selectedSong.songDuration / modifiers.songSpeedMul;
                selectedSong.AddToMessage(outMsg);

                networkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
            }
        }
Пример #8
0
        public void StartLevel(BeatmapLevelSO song, BeatmapCharacteristicSO characteristic, BeatmapDifficulty difficulty, GameplayModifiers modifiers)
        {
            if (Connected && NetworkClient != null)
            {
#if DEBUG
                Misc.Logger.Info("Starting level...");
#endif
                NetOutgoingMessage outMsg = NetworkClient.CreateMessage();
                outMsg.Write((byte)CommandType.StartLevel);

                new StartLevelInfo(difficulty, modifiers, characteristic.serializedName).AddToMessage(outMsg);
                SongInfo selectedSong = new SongInfo(song);
                selectedSong.songDuration = selectedSong.songDuration / modifiers.songSpeedMul;
                selectedSong.AddToMessage(outMsg);

                NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
            }
        }
Пример #9
0
        public void SetSelectedSong(SongInfo song)
        {
            if (connected && networkClient != null)
            {
                NetOutgoingMessage outMsg = networkClient.CreateMessage();
                if (song == null)
                {
                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    outMsg.Write((byte)0);

                    networkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                }
                else
                {
                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    song.AddToMessage(outMsg);

                    networkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                }
                Plugin.log.Debug("Sending SongInfo for selected song...");
            }
        }
Пример #10
0
        public void SetSelectedSong(SongInfo song)
        {
            if (Connected && NetworkClient != null)
            {
                NetOutgoingMessage outMsg = NetworkClient.CreateMessage();
                if (song == null)
                {
                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    outMsg.Write((byte)0);

                    NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                }
                else
                {
                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    song.AddToMessage(outMsg);

                    NetworkClient.SendMessage(outMsg, NetDeliveryMethod.ReliableOrdered, 0);
                }
#if DEBUG
                Misc.Logger.Info("Sending SongInfo for selected song...");
#endif
            }
        }
Пример #11
0
        public virtual async void RoomLoopAsync(object sender, HighResolutionTimerElapsedEventArgs e)
        {
            if (randomSongTask != null)
            {
                return;
            }

            NetOutgoingMessage outMsg = HubListener.ListenerServer.CreateMessage();

            switch (roomState)
            {
            case RoomState.InGame:
            {
                if (DateTime.Now.Subtract(_songStartTime).TotalSeconds >= selectedSong.songDuration)
                {
                    roomState         = RoomState.Results;
                    _resultsStartTime = DateTime.Now;

                    outMsg.Write((byte)CommandType.GetRoomInfo);
                    GetRoomInfo().AddToMessage(outMsg);

                    BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered);

                    if (roomClients.Count > 0)
                    {
                        BroadcastWebSocket(CommandType.GetRoomInfo, GetRoomInfo());
                    }
                }
            }
            break;

            case RoomState.Results:
            {
                if (DateTime.Now.Subtract(_resultsStartTime).TotalSeconds >= resultsShowTime)
                {
                    roomState    = RoomState.SelectingSong;
                    selectedSong = null;

                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    outMsg.Write((int)0);

                    BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered);
                    BroadcastWebSocket(CommandType.SetSelectedSong, null);
                }
            }
            break;

            case RoomState.SelectingSong:
            {
                switch (roomSettings.SelectionType)
                {
                case SongSelectionType.Random:
                {
                    roomState = RoomState.Preparing;
                    Random rand = new Random();

                    randomSongTask = BeatSaver.GetRandomSong();
                    selectedSong   = await randomSongTask;
                    randomSongTask = null;

                    outMsg.Write((byte)CommandType.SetSelectedSong);
                    selectedSong.AddToMessage(outMsg);

                    BroadcastPacket(outMsg, NetDeliveryMethod.ReliableOrdered);

                    BroadcastWebSocket(CommandType.SetSelectedSong, selectedSong);
                    ReadyStateChanged(roomHost, true);
                }
                break;
                }
            }
            break;
            }

            if (outMsg.LengthBytes > 0)
            {
                outMsg = HubListener.ListenerServer.CreateMessage();
            }

            outMsg.Write((byte)CommandType.UpdatePlayerInfo);

            switch (roomState)
            {
            case RoomState.SelectingSong:
            {
                outMsg.Write((float)0);
                outMsg.Write((float)0);
            }
            break;

            case RoomState.Preparing:
            {
                outMsg.Write((float)0);
                outMsg.Write((float)0);
            }
            break;

            case RoomState.InGame:
            {
                outMsg.Write((float)DateTime.Now.Subtract(_songStartTime).TotalSeconds);
                outMsg.Write(selectedSong.songDuration);
            }
            break;

            case RoomState.Results:
            {
                outMsg.Write((float)DateTime.Now.Subtract(_resultsStartTime).TotalSeconds);
                outMsg.Write(resultsShowTime);
            }
            break;
            }

            outMsg.Write(roomClients.Count);

            for (int i = 0; i < roomClients.Count; i++)
            {
                if (i < roomClients.Count)
                {
                    if (roomClients[i] != null)
                    {
                        roomClients[i].playerInfo.AddToMessage(outMsg);
                    }
                }
            }

            BroadcastPacket(outMsg, NetDeliveryMethod.UnreliableSequenced);

            if (roomClients.Count > 0)
            {
                BroadcastWebSocket(CommandType.UpdatePlayerInfo, roomClients.Select(x => x.playerInfo).ToArray());
            }
        }