void Update() { uint size; try { while (SteamNetworking.IsP2PPacketAvailable(out size)) { var buffer = new byte[size]; uint bytesRead; CSteamID remoteId; if (SteamNetworking.ReadP2PPacket(buffer, size, out bytesRead, out remoteId)) { var message = Encoding.UTF8.GetString(buffer).Replace(" ", ""); PlayerInfo info = new PlayerInfo(message); if (info.voip != null && info.voip.Length > 0) { if (VoipEnabled) { PlayVoip(info.voip); } info.voip = new byte[0]; } if (info.playerId != SteamAPI.GetUserID() && SteamAPI.getLobbyID().m_SteamID != 0) { UpsertPlayer(info); } } } } catch (Exception e) { Data.Logger.Error(e); } }
private void CreateSettingsMenu() { var settingsMenu = SettingsUI.CreateSubMenu(Plugin.instance.Name); var AutoStartLobby = settingsMenu.AddBool("Auto-Start Lobby", "Opens up a lobby when you launch the game"); AutoStartLobby.GetValue += delegate { return(Config.Instance.AutoStartLobby); }; AutoStartLobby.SetValue += delegate(bool value) { Config.Instance.AutoStartLobby = value; }; var IsPublic = settingsMenu.AddBool("Auto-Start Privacy", "Configures the privacy of lobbies that are auto-started"); IsPublic.DisabledText = "Friends Only"; IsPublic.EnabledText = "Public"; IsPublic.GetValue += delegate { return(Config.Instance.IsPublic); }; IsPublic.SetValue += delegate(bool value) { Config.Instance.IsPublic = value; }; var MaxLobbySite = settingsMenu.AddInt("Lobby Size", "Configure the amount of users you want to be able to join your lobby.", 2, 15, 1); MaxLobbySite.GetValue += delegate { return(Config.Instance.MaxLobbySize); }; MaxLobbySite.SetValue += delegate(int value) { SteamMatchmaking.SetLobbyMemberLimit(SteamAPI.getLobbyID(), value); Config.Instance.MaxLobbySize = value; }; var AvatarsInLobby = settingsMenu.AddBool("Enable Avatars In Lobby", "Turns avatars on for you in the waiting lobby"); AvatarsInLobby.GetValue += delegate { return(Config.Instance.AvatarsInLobby); }; AvatarsInLobby.SetValue += delegate(bool value) { Config.Instance.AvatarsInLobby = value; }; var AvatarsInGame = settingsMenu.AddBool("Enable Avatars In Game", "Turns avatars on for you while playing songs"); AvatarsInGame.GetValue += delegate { return(Config.Instance.AvatarsInGame); }; AvatarsInGame.SetValue += delegate(bool value) { Config.Instance.AvatarsInGame = value; }; var NetworkQuality = settingsMenu.AddInt("Network Quality", "Higher number, smoother avatar. Note that this effects how you appear to others. ", 0, 5, 1); NetworkQuality.GetValue += delegate { return(Config.Instance.NetworkQuality); }; NetworkQuality.SetValue += delegate(int value) { Config.Instance.NetworkQuality = value; if (Controllers.PlayerController.Instance.isBroadcasting) { Controllers.PlayerController.Instance.StopBroadcasting(); Controllers.PlayerController.Instance.StartBroadcasting(); } }; var NetworkScaling = settingsMenu.AddBool("Network Scaling", "Scales your network traffic based on the size of your lobby."); NetworkScaling.GetValue += delegate { return(Config.Instance.NetworkScaling); }; NetworkScaling.SetValue += delegate(bool value) { Config.Instance.NetworkScaling = value; }; }
public void OnP2PSessionRequest(P2PSessionRequest_t pCallback) { try { Logger.Debug($"{pCallback.m_steamIDRemote} requested a P2P session"); int numMembers = SteamMatchmaking.GetNumLobbyMembers(SteamAPI.getLobbyID()); for (int i = 0; i < numMembers; i++) { var member = SteamMatchmaking.GetLobbyMemberByIndex(SteamAPI.getLobbyID(), i); if (member.m_SteamID == pCallback.m_steamIDRemote.m_SteamID) { Logger.Debug($"{pCallback.m_steamIDRemote} is in our lobby, lets accept their P2P session"); bool ret = SteamNetworking.AcceptP2PSessionWithUser(pCallback.m_steamIDRemote); } } } catch (Exception e) { Logger.Error(e); } }
private void CreateSettingsMenu() { var settingsMenu = SettingsUI.CreateSubMenu(Plugin.instance.Name); var AutoStartLobby = settingsMenu.AddList("Auto-Start Lobby", new float[3] { 0, 1, 2 }); AutoStartLobby.GetValue += delegate { return(_autoStart); }; AutoStartLobby.SetValue += delegate(float value) { _autoStart = value; switch (value) { default: case 0: Config.Instance.AutoStartLobby = false; break; case 1: Config.Instance.AutoStartLobby = true; Config.Instance.IsPublic = false; break; case 2: Config.Instance.AutoStartLobby = true; Config.Instance.IsPublic = true; break; } }; AutoStartLobby.FormatValue += delegate(float value) { switch (value) { default: case 0: return("Disabled"); case 1: return("Private Lobby"); case 2: return("Public Lobby"); } }; var MaxLobbySite = settingsMenu.AddInt("Lobby Size", "Configure the amount of users you want to be able to join your lobby.", 2, 15, 1); MaxLobbySite.GetValue += delegate { return(Config.Instance.MaxLobbySize); }; MaxLobbySite.SetValue += delegate(int value) { SteamMatchmaking.SetLobbyMemberLimit(SteamAPI.getLobbyID(), value); Config.Instance.MaxLobbySize = value; }; var Volume = settingsMenu.AddInt("Voice Volume", "Higher numbers are louder", 1, 20, 1); Volume.GetValue += delegate { return((int)Config.Instance.Volume); }; Volume.SetValue += delegate(int value) { Config.Instance.Volume = (float)value; AudioMixerGroup g = Utils.Assets.AudioGroup; g.audioMixer.SetFloat("MasterVolume", (float)value); }; var Avatar = settingsMenu.AddList("Enable Avatars", new float[4] { 0, 1, 2, 3 }); Avatar.GetValue += delegate { return(_avatarState); }; Avatar.SetValue += delegate(float value) { _avatarState = value; switch (value) { default: case 0: Config.Instance.AvatarsInLobby = false; Config.Instance.AvatarsInGame = false; break; case 1: Config.Instance.AvatarsInLobby = true; Config.Instance.AvatarsInGame = false; break; case 2: Config.Instance.AvatarsInLobby = false; Config.Instance.AvatarsInGame = true; break; case 3: Config.Instance.AvatarsInLobby = true; Config.Instance.AvatarsInGame = true; break; } }; Avatar.FormatValue += delegate(float value) { switch (value) { default: case 0: return("Disabled"); case 1: return("Lobby Only"); case 2: return("InGame Only"); case 3: return("Enabled"); } }; var NetworkQuality = settingsMenu.AddInt("Network Quality", "Higher number, smoother avatar. Note that this effects how you appear to others. ", 0, 5, 1); NetworkQuality.GetValue += delegate { return(Config.Instance.NetworkQuality); }; NetworkQuality.SetValue += delegate(int value) { Config.Instance.NetworkQuality = value; if (Controllers.PlayerController.Instance.isBroadcasting) { Controllers.PlayerController.Instance.StopBroadcasting(); Controllers.PlayerController.Instance.StartBroadcasting(); } }; }
public void OnLobbyDataUpdate(LobbyDataUpdate_t pCallback) { if (pCallback.m_ulSteamIDLobby == pCallback.m_ulSteamIDMember) { LobbyInfo info = new LobbyInfo(SteamMatchmaking.GetLobbyData(new CSteamID(pCallback.m_ulSteamIDLobby), "LOBBY_INFO")); if (pCallback.m_ulSteamIDLobby == 0) { return; } Logger.Debug($"Received: {info.ToString()}"); if (pCallback.m_ulSteamIDLobby == SteamAPI.getLobbyID().m_SteamID) { SteamAPI.UpdateLobbyInfo(info); if (DidScreenChange(info.Screen, LobbyInfo.SCREEN_TYPE.WAITING)) { currentScreen = info.Screen; Logger.Debug($"Song has been selected, going to the waiting screen"); WaitingMenu.Instance.Present(); } else if (DidScreenChange(info.Screen, LobbyInfo.SCREEN_TYPE.MENU)) { currentScreen = info.Screen; Logger.Debug($"Song has finished, updating state to menu"); GameController.Instance.SongFinished(null, null, null, null); } else if (DidScreenChange(info.Screen, LobbyInfo.SCREEN_TYPE.PLAY_SONG)) { currentScreen = info.Screen; Logger.Debug($"Host requested to play the current song {info.CurrentSongId}"); LevelSO song = SongListUtils.GetInstalledSong(); if (SteamAPI.IsHost()) { SteamAPI.setLobbyStatus("Playing " + song.songName + " by " + song.songAuthorName); } SteamAPI.ClearPlayerReady(new CSteamID(SteamAPI.GetUserID()), true); SongListUtils.StartSong(song, SteamAPI.GetSongDifficulty(), info.GameplayModifiers); } } else { SteamAPI.SetOtherLobbyData(pCallback.m_ulSteamIDLobby, info); } } else { string status = SteamMatchmaking.GetLobbyMemberData(new CSteamID(pCallback.m_ulSteamIDLobby), new CSteamID(pCallback.m_ulSteamIDMember), "STATUS"); if (status == "DISCONNECTED") { SteamAPI.DisconnectPlayer(pCallback.m_ulSteamIDMember); } else if (status.StartsWith("KICKED")) { ulong playerId = Convert.ToUInt64(status.Substring(7)); if (playerId != 0 && playerId == SteamAPI.GetUserID()) { SteamAPI.Disconnect(); } } } }