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); } }
public void Awake() { if (Instance != this) { Instance = this; DontDestroyOnLoad(gameObject); _playerInfo = new PlayerInfo(SteamAPI.GetUserName(), SteamAPI.GetUserID()); _currentScene = SceneManager.GetActiveScene().name; } }
public static void SendToAllInLobby(byte[] bytes) { int numMembers = SteamMatchmaking.GetNumLobbyMembers(_lobbyInfo.LobbyID); for (int i = 0; i < numMembers; i++) { CSteamID member = SteamMatchmaking.GetLobbyMemberByIndex(_lobbyInfo.LobbyID, i); if (member.m_SteamID != SteamAPI.GetUserID()) { SteamNetworking.SendP2PPacket(member, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable); } } }
public void UpdatePlayerInfo() { _playerInfo.avatarHash = ModelSaberAPI.cachedAvatars.FirstOrDefault(x => x.Value == CustomAvatar.Plugin.Instance.PlayerAvatarManager.GetCurrentAvatar()).Key; if (_playerInfo.avatarHash == null) { _playerInfo.avatarHash = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; } _playerInfo.playerName = SteamAPI.GetUserName(); _playerInfo.playerId = SteamAPI.GetUserID(); WorldController.CharacterPosition pos = WorldController.GetCharacterInfo(); _playerInfo.headPos = pos.headPos; _playerInfo.headRot = pos.headRot; _playerInfo.leftHandPos = pos.leftHandPos; _playerInfo.leftHandRot = pos.leftHandRot; _playerInfo.rightHandPos = pos.rightHandPos; _playerInfo.rightHandRot = pos.rightHandRot; }
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(); } } } }