Пример #1
0
 public static void Disconnect()
 {
     try
     {
         Logger.Debug($"Disconnect from current lobby");
         SteamMatchmaking.SetLobbyMemberData(_lobbyInfo.LobbyID, "STATUS", "DISCONNECTED");
         Controllers.PlayerController.Instance.StopBroadcasting();
         _lobbyInfo.HostName = "";
         SendLobbyPacket(true);
         Connection = ConnectionState.DISCONNECTED;
         SteamMatchmaking.LeaveLobby(_lobbyInfo.LobbyID);
         Controllers.PlayerController.Instance.DestroyAvatars();
         WaitingMenu.firstInit  = true;
         WaitingMenu.queuedSong = null;
         _lobbyInfo             = new LobbyPacket();
         UpdateUserInfo();
         VoiceChatWorker.VoipEnabled = false;
         Scoreboard.Instance.RemoveAll();
         SongListUtils.InSong = false;
         Controllers.PlayerController.Instance._playerInfo = new PlayerPacket(GetUserName(), GetUserID());
         LobbyData.Clear();
     } catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Пример #2
0
        public static void Init()
        {
            UpdateUserInfo();
            OnLobbyMatchListCallResult = CallResult <LobbyMatchList_t> .Create(OnLobbyMatchList);

            OnLobbyCreatedCallResult = CallResult <LobbyCreated_t> .Create(OnLobbyCreated);

            callbacks  = new SteamCallbacks();
            _lobbyInfo = new LobbyPacket();


            string[] args  = System.Environment.GetCommandLineArgs();
            string   input = "";

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "+connect_lobby" && args.Length > i + 1)
                {
                    input = args[i + 1];
                }
            }

            if (!string.IsNullOrEmpty(input))
            {
                ulong lobbyId = Convert.ToUInt64(input);

                if (lobbyId > 0)
                {
                    Logger.Debug($"Game was started with +connect_lobby, lets join it @ {lobbyId}");
                    JoinLobby(new CSteamID(lobbyId));
                }
            }
        }
Пример #3
0
        public static void OnLobbyMatchList(LobbyMatchList_t pCallback, bool bIOFailure)
        {
            if (!SteamManager.Initialized)
            {
                Logger.Error("CONNECTION FAILED");
                return;
            }
            uint numLobbies = pCallback.m_nLobbiesMatching;

            Logger.Debug($"Found {numLobbies} total lobbies");
            try
            {
                for (int i = 0; i < numLobbies; i++)
                {
                    CSteamID lobbyId = SteamMatchmaking.GetLobbyByIndex(i);
                    if (lobbyId.m_SteamID == _lobbyInfo.LobbyID.m_SteamID)
                    {
                        continue;
                    }
                    LobbyPacket info = new LobbyPacket(SteamMatchmaking.GetLobbyData(lobbyId, "LOBBY_INFO"));

                    SetOtherLobbyData(lobbyId.m_SteamID, info, false);
                    Logger.Info($"{info.HostName} has {info.UsedSlots} users in it and is currently {info.Status}");
                }
            } catch (Exception e)
            {
                Logger.Error(e);
            }

            MultiplayerListing.refreshLobbyList();
        }
Пример #4
0
        public static void SetOtherLobbyData(ulong lobbyId, LobbyPacket info, bool refresh = true)
        {
            string version = SteamMatchmaking.GetLobbyData(new CSteamID(lobbyId), "version");

            info.UsedSlots = SteamMatchmaking.GetNumLobbyMembers(new CSteamID(lobbyId));
            if (info.UsedSlots > 0 && info.HostName != "" && version == PACKET_VERSION)
            {
                LobbyData.Add(lobbyId, info);

                MultiplayerListing.refreshLobbyList();
            }
        }
Пример #5
0
        public static void OnLobbyEnter(LobbyEnter_t pCallback)
        {
            Logger.Debug($"You have entered lobby {pCallback.m_ulSteamIDLobby}");
            Controllers.PlayerController.Instance.StartBroadcasting();
            SteamAPI.SetConnectionState(SteamAPI.ConnectionState.CONNECTED);
            SteamAPI.SendPlayerPacket(Controllers.PlayerController.Instance._playerInfo);
            LobbyPacket info = new LobbyPacket(SteamMatchmaking.GetLobbyData(new CSteamID(pCallback.m_ulSteamIDLobby), "LOBBY_INFO"));

            SteamAPI.UpdateLobbyPacket(info);
            if (info.Screen == LobbyPacket.SCREEN_TYPE.IN_GAME && info.CurrentSongOffset > 0f)
            {
                WaitingMenu.autoReady             = true;
                WaitingMenu.timeRequestedToLaunch = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
                WaitingMenu.Instance.Present();
            }
        }
Пример #6
0
        public void OnLobbyDataUpdate(LobbyDataUpdate_t pCallback)
        {
            if (pCallback.m_ulSteamIDLobby == pCallback.m_ulSteamIDMember)
            {
                if (pCallback.m_ulSteamIDLobby == 0)
                {
                    return;
                }
                LobbyPacket info = new LobbyPacket(SteamMatchmaking.GetLobbyData(new CSteamID(pCallback.m_ulSteamIDLobby), "LOBBY_INFO"));

                Logger.Debug($"Received: {info.ToString()}");
                if (pCallback.m_ulSteamIDLobby == SteamAPI.getLobbyID().m_SteamID)
                {
                    SteamAPI.UpdateLobbyPacket(info);
                    if (DidScreenChange(info.Screen, LobbyPacket.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, LobbyPacket.SCREEN_TYPE.MENU))
                    {
                        currentScreen = info.Screen;
                        Logger.Debug($"Song has finished, updating state to menu");
                        MultiplayerLobby.UpdateJoinButton();
                        GameController.Instance.SongFinished(null, null, null, null);
                    }
                    else if (DidScreenChange(info.Screen, LobbyPacket.SCREEN_TYPE.PLAY_SONG))
                    {
                        currentScreen = info.Screen;
                        Logger.Debug($"Host requested to play the current song {info.CurrentSongId}");
                        IBeatmapLevel song = SongListUtils.GetInstalledSong();
                        if (SteamAPI.IsHost())
                        {
                            SteamAPI.setLobbyStatus("Playing " + song.songName + " by " + song.songAuthorName);
                        }
                        try
                        {
                            SteamAPI.ClearPlayerReady(new CSteamID(SteamAPI.GetUserID()), true);
                            SongListUtils.StartSong(song, SteamAPI.GetSongDifficulty(), info.GameplayModifiers, null);
                        } catch (Exception e)
                        {
                            Logger.Error(e);
                        }
                    }
                    else if (DidScreenChange(info.Screen, LobbyPacket.SCREEN_TYPE.IN_GAME))
                    {
                        MultiplayerLobby.UpdateJoinButton();
                    }
                }
                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();
                    }
                }
            }
        }
Пример #7
0
 public static void UpdateLobbyPacket(LobbyPacket info)
 {
     _lobbyInfo = info;
 }