public void SendSongList(List <IPreviewBeatmapLevel> levels) { if (client != null && client.Connected) { var subpacketList = new List <PreviewBeatmapLevel>(); subpacketList.AddRange( levels.Select(x => { var level = new PreviewBeatmapLevel(); level.LevelId = x.levelID; level.Name = x.songName; return(level); }) ); var songList = new SongList(); songList.Levels = subpacketList.ToArray(); client.Send(new Packet(songList).ToBytes()); } else { Logger.Debug("Skipped sending songs because there is no server connected"); } }
private void songDetail_didChangeDifficultyBeatmapEvent(IDifficultyBeatmap beatmap) { var level = beatmap.level; //Assemble new match info and update the match var matchLevel = new PreviewBeatmapLevel() { LevelId = level.levelID, Name = level.songName }; List <Characteristic> characteristics = new List <Characteristic>(); foreach (var beatmapSet in level.previewDifficultyBeatmapSets) { characteristics.Add(new Characteristic() { SerializedName = beatmapSet.beatmapCharacteristic.serializedName, Difficulties = beatmapSet.beatmapDifficulties.Select(x => (SharedConstructs.BeatmapDifficulty)x).ToArray() }); } matchLevel.Characteristics = characteristics.ToArray(); Match.SelectedLevel = matchLevel; Match.SelectedCharacteristic = Match.SelectedLevel.Characteristics.First(x => x.SerializedName == beatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName); Match.SelectedDifficulty = (SharedConstructs.BeatmapDifficulty)beatmap.difficulty; if (isHost) { Plugin.client.UpdateMatch(Match); } }
private void ConnectToServer() { try { client = new Network.Client(10155); client.PacketRecieved += Client_PacketRecieved; client.ServerDisconnected += Client_ServerDisconnected; client.Start(); //Send the server the master list if we can if (Plugin.masterLevelList != null) { var subpacketList = new List <PreviewBeatmapLevel>(); subpacketList.AddRange( Plugin.masterLevelList.Select(x => { var level = new PreviewBeatmapLevel(); level.Name = x.songName; level.LevelId = x.levelID; return(level); }) ); var songList = new SongList(); songList.Levels = subpacketList.ToArray(); client.Send(new Packet(songList).ToBytes()); } } catch (Exception e) { Logger.Debug(e.ToString()); } }
private void songDetail_didChangeDifficultyBeatmapEvent(IDifficultyBeatmap beatmap) { var level = beatmap.level; //Assemble new match info and update the match var matchLevel = new PreviewBeatmapLevel() { LevelId = level.levelID, Name = level.songName }; List <Characteristic> characteristics = new List <Characteristic>(); foreach (var beatmapSet in level.previewDifficultyBeatmapSets) { var c = new Characteristic() { SerializedName = beatmapSet.beatmapCharacteristic.serializedName, }; c.Difficulties.AddRange(beatmapSet.beatmapDifficulties.Select(x => (TournamentAssistantShared.Models.BeatmapDifficulty)x)); characteristics.Add(c); } matchLevel.Characteristics.AddRange(characteristics); Match.SelectedLevel = matchLevel; Match.SelectedCharacteristic = Match.SelectedLevel.Characteristics.First(x => x.SerializedName == beatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName); Match.SelectedDifficulty = (TournamentAssistantShared.Models.BeatmapDifficulty)beatmap.difficulty; if (isHost) { Plugin.client.UpdateMatch(Match); } }
private void Client_PacketRecieved(Packet packet) { if (packet.Type == PacketType.PlaySong) { PlaySong playSong = packet.SpecificPacket as PlaySong; var desiredLevel = Plugin.masterLevelList.First(x => x.levelID == playSong.levelId); var desiredCharacteristic = desiredLevel.previewDifficultyBeatmapSets.GetBeatmapCharacteristics().First(x => x.serializedName == playSong.characteristic.SerializedName); var desiredDifficulty = (BeatmapDifficulty)playSong.difficulty; SaberUtilities.PlaySong(desiredLevel, desiredCharacteristic, desiredDifficulty, playSong); } else if (packet.Type == PacketType.LoadSong) { LoadSong loadSong = packet.SpecificPacket as LoadSong; Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { var loadedSong = new LoadedSong(); var beatmapLevel = new PreviewBeatmapLevel(); beatmapLevel.Characteristics = loadedLevel.beatmapLevelData.difficultyBeatmapSets.ToList().Select(x => { var characteristic = new Characteristic(); characteristic.SerializedName = x.beatmapCharacteristic.serializedName; characteristic.difficulties = loadedLevel.beatmapLevelData.difficultyBeatmapSets .First(y => y.beatmapCharacteristic.serializedName == x.beatmapCharacteristic.serializedName) .difficultyBeatmaps.Select(y => (Characteristic.BeatmapDifficulty)y.difficulty).ToArray(); return(characteristic); }).ToArray(); beatmapLevel.LevelId = loadedLevel.levelID; beatmapLevel.Name = loadedLevel.songName; beatmapLevel.Loaded = true; loadedSong.level = beatmapLevel; client.Send(new Packet(loadedSong).ToBytes()); }; LoadSong(loadSong.levelId, SongLoaded); } else if (packet.Type == PacketType.Command) { Command command = packet.SpecificPacket as Command; if (command.commandType == Command.CommandType.ReturnToMenu) { SaberUtilities.ReturnToMenu(); } } }
public void SongLoaded(PreviewBeatmapLevel level) { if (InvokeRequired) { Invoke(new SongLoadedDelegate(SongLoaded), level); } else { masterLevelList[masterLevelList.FindIndex(x => x.LevelId == level.LevelId)] = level; currentSelection = level; level.Characteristics.ToList().ForEach(x => characteristicDropdown.Items.Add(x.SerializedName)); characteristicDropdown.SelectedIndex = 0; //We'll assume we've currently selected the 0th checkbox, since, well, we have difficultyDropdown.Items.Clear(); level .Characteristics.First() .difficulties.ToList().ForEach(x => difficultyDropdown.Items.Add(x.ToString())); difficultyDropdown.SelectedIndex = difficultyDropdown.Items.Count - 1; } }
private void songListView_SelectedIndexChangedAsync(object sender, EventArgs e) { if (songListView.SelectedItems.Count >= 1) { var levelID = songListView.SelectedItems[0].ImageKey; PreviewBeatmapLevel level = masterLevelList.Where(x => x.LevelId == levelID).First(); //Clear out old info characteristicDropdown.Items.Clear(); difficultyDropdown.Items.Clear(); //Load IBeatmapLevel if (!level.Loaded) { var loadLevel = new LoadSong(); loadLevel.levelId = level.LevelId; server.Send(new Packet(loadLevel).ToBytes()); } else { SongLoaded(level); } } }
private void MockClient_LoadedSong(PreviewBeatmapLevel level) { lastLoadedLevel = level; }
protected override void Client_PacketRecieved(Packet packet) { base.Client_PacketRecieved(packet); if (packet.Type == PacketType.PlaySong) { PlaySong playSong = packet.SpecificPacket as PlaySong; PlaySong?.Invoke(playSong.Beatmap); } else if (packet.Type == PacketType.Command) { Command command = packet.SpecificPacket as Command; if (command.CommandType == Command.CommandTypes.ReturnToMenu) { if ((Self as Player).PlayState == Player.PlayStates.InGame) { ReturnToMenu?.Invoke(); } } } else if (packet.Type == PacketType.LoadSong) { LoadSong loadSong = packet.SpecificPacket as LoadSong; //Send updated download status (Self as Player).DownloadState = Player.DownloadStates.Downloading; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); var hash = HashFromLevelId(loadSong.LevelId); BeatSaverDownloader.DownloadSongInfoThreaded(hash, (successfulDownload) => { if (successfulDownload) { var song = new DownloadedSong(hash); var mapFormattedLevelId = $"custom_level_{hash.ToUpper()}"; var matchMap = new PreviewBeatmapLevel() { LevelId = mapFormattedLevelId, Name = song.Name }; List <Characteristic> characteristics = new List <Characteristic>(); foreach (var characteristic in song.Characteristics) { characteristics.Add(new Characteristic() { SerializedName = characteristic, Difficulties = song.GetBeatmapDifficulties(characteristic) }); } matchMap.Characteristics = characteristics.ToArray(); //Send updated download status (Self as Player).DownloadState = Player.DownloadStates.Downloaded; playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); LoadedSong?.Invoke(matchMap); Logger.Debug($"SENT DOWNLOADED SIGNAL {(playerUpdate.ChangedObject as Player).DownloadState}"); } else { //Send updated download status (Self as Player).DownloadState = Player.DownloadStates.DownloadError; playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); } } ); } }
private void Client_PacketRecieved(Packet packet) { if (packet.Type == PacketType.PlaySong) { PlaySong playSong = packet.SpecificPacket as PlaySong; var desiredLevel = Plugin.masterLevelList.First(x => x.levelID == playSong.levelId); var desiredCharacteristic = desiredLevel.beatmapCharacteristics.First(x => x.serializedName == playSong.characteristic.SerializedName); var desiredDifficulty = (BeatmapDifficulty)playSong.difficulty; var playerSpecificSettings = new PlayerSpecificSettings(); playerSpecificSettings.advancedHud = playSong.playerSettings.advancedHud; playerSpecificSettings.leftHanded = playSong.playerSettings.leftHanded; playerSpecificSettings.noTextsAndHuds = playSong.playerSettings.noTextsAndHuds; playerSpecificSettings.reduceDebris = playSong.playerSettings.reduceDebris; playerSpecificSettings.staticLights = playSong.playerSettings.staticLights; var gameplayModifiers = new GameplayModifiers(); gameplayModifiers.batteryEnergy = playSong.gameplayModifiers.batteryEnergy; gameplayModifiers.disappearingArrows = playSong.gameplayModifiers.disappearingArrows; gameplayModifiers.failOnSaberClash = playSong.gameplayModifiers.failOnSaberClash; gameplayModifiers.fastNotes = playSong.gameplayModifiers.fastNotes; gameplayModifiers.ghostNotes = playSong.gameplayModifiers.ghostNotes; gameplayModifiers.instaFail = playSong.gameplayModifiers.instaFail; gameplayModifiers.noBombs = playSong.gameplayModifiers.noBombs; gameplayModifiers.noFail = playSong.gameplayModifiers.noFail; gameplayModifiers.noObstacles = playSong.gameplayModifiers.noObstacles; gameplayModifiers.songSpeed = (GameplayModifiers.SongSpeed)playSong.gameplayModifiers.songSpeed; SaberUtilities.PlaySong(desiredLevel, desiredCharacteristic, desiredDifficulty, gameplayModifiers, playerSpecificSettings); } else if (packet.Type == PacketType.LoadSong) { LoadSong loadSong = packet.SpecificPacket as LoadSong; Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { var loadedSong = new LoadedSong(); var beatmapLevel = new PreviewBeatmapLevel(); beatmapLevel.Characteristics = loadedLevel.beatmapCharacteristics.ToList().Select(x => { var characteristic = new Characteristic(); characteristic.SerializedName = x.serializedName; characteristic.difficulties = loadedLevel.beatmapLevelData.difficultyBeatmapSets .First(y => y.beatmapCharacteristic.serializedName == x.serializedName) .difficultyBeatmaps.Select(y => (Characteristic.BeatmapDifficulty)y.difficulty).ToArray(); return(characteristic); }).ToArray(); beatmapLevel.LevelId = loadedLevel.levelID; beatmapLevel.Name = loadedLevel.songName; beatmapLevel.Loaded = true; loadedSong.level = beatmapLevel; client.Send(new Packet(loadedSong).ToBytes()); }; LoadSong(loadSong.levelId, SongLoaded); } else if (packet.Type == PacketType.Command) { Command command = packet.SpecificPacket as Command; if (command.commandType == Command.CommandType.ReturnToMenu) { SaberUtilities.ReturnToMenu(); } } }