Exemple #1
0
        public static bool IsFavourited(uint ip, int port)
        {
            if (!SteamService.IsInitialized)
            {
                return(false);
            }

            int count = SteamMatchmaking.GetFavoriteGameCount();

            for (int i = 0; i < count; ++i)
            {
                Steamworks.AppId_t appid;
                uint   pnIP;
                ushort pnConnPort;
                ushort pnQueryPort;
                uint   punFlags;
                uint   pRTime32LastPlayedOnServer;

                if (Steamworks.SteamMatchmaking.GetFavoriteGame(i, out appid, out pnIP, out pnConnPort, out pnQueryPort, out punFlags, out pRTime32LastPlayedOnServer) == false)
                {
                    continue;
                }

                if (appid != SteamService.SteamAppid)
                {
                    continue;
                }

                if ((((int)punFlags) & Steamworks.Constants.k_unFavoriteFlagFavorite) != Steamworks.Constants.k_unFavoriteFlagFavorite)
                {
                    continue;
                }

                if (pnIP != ip)
                {
                    continue;
                }

                if (pnConnPort != port)
                {
                    continue;
                }

                return(true);
            }

            return(false);
        }
        public void LobbyEntered(LobbyEnter_t enterLobby)
        {
            connectedPlayers.Clear();
            otherPlayers.Clear();
            ResetManagers();

            lobbyID = (CSteamID)enterLobby.m_ulSteamIDLobby;
            int playerCount = SteamMatchmaking.GetNumLobbyMembers(lobbyID);

            MultiplayerChat.AddChat("Entered Lobby!");


            //Send packets to all players, to establish P2P connections with them
            if (playerCount > 1)
            {
                for (int i = 0; i < playerCount; i++)
                {
                    CSteamID lobbyMember = SteamMatchmaking.GetLobbyMemberByIndex(lobbyID, i);
                    SteamNetworking.SendP2PPacket(lobbyMember, new byte[] { 255 }, 1, EP2PSend.k_EP2PSendReliable, 0);
                    SteamNetworking.SendP2PPacket(lobbyMember, new byte[] { 255 }, 1, EP2PSend.k_EP2PSendReliable, 1);
                    SteamNetworking.SendP2PPacket(lobbyMember, new byte[] { 255 }, 1, EP2PSend.k_EP2PSendReliable, 2);
                    if (!connectedPlayers.Contains(lobbyMember.m_SteamID))
                    {
                        connectedPlayers.Add(lobbyMember.m_SteamID);
                        PlayerJoinedManagers(lobbyMember.m_SteamID);
                    }
                    if (lobbyMember != SteamUser.GetSteamID())
                    {
                        otherPlayers.Add(lobbyMember.m_SteamID);
                    }
                }
            }

            //Set up network data
            NetworkGameManager.managerID = ulong.Parse(SteamMatchmaking.GetLobbyData(lobbyID, MANAGER_ID));
            NetworkGameManager.playerID  = SteamUser.GetSteamID().m_SteamID;

            if (!connectedPlayers.Contains(SteamUser.GetSteamID().m_SteamID))
            {
                connectedPlayers.Add(SteamUser.GetSteamID().m_SteamID);
                PlayerJoinedManagers(SteamUser.GetSteamID().m_SteamID);
            }


            MultiplayerChat.AddChat("This game's manager is " + SteamFriends.GetFriendPersonaName((CSteamID)NetworkGameManager.managerID));
            isInGame = true;
            Log("Entered Lobby! \nThis game's manager is " + SteamFriends.GetFriendPersonaName((CSteamID)NetworkGameManager.managerID));
        }
Exemple #3
0
        public void Update()
        {
            if (!Patches.patch_SteamManager.Initialized)
            {
                return;
            }

            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                timer = 5f;

                int newMembers = SteamMatchmaking.GetNumLobbyMembers(lobbyID);
                DiscordManager.instance.SetPartyNumber(newMembers);
            }
        }
Exemple #4
0
        private void OnLobbyEntered(LobbyEnter_t callback)
        {
            if (NetworkServer.active)
            {
                return;
            }

            string hostAddress = SteamMatchmaking.GetLobbyData(
                new CSteamID(callback.m_ulSteamIDLobby),
                HostAddressKey);

            networkManager.networkAddress = hostAddress;
            networkManager.StartClient();

            buttons.SetActive(false);
        }
 public void CreateLobby()
 {
     if (lobbyType == 0)
     {
         SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypePublic, lobbyMax);
     }
     else if (lobbyType == 1)
     {
         SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypeFriendsOnly, lobbyMax);
     }
     else
     {
         SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypePrivate, lobbyMax);
     }
     joining = true;
 }
 public void LobbyJoinRequested(GameLobbyJoinRequested_t request)  //Shift-Tab Menu
 {
     {
         patch_ProcessManager patchPM = ((patch_ProcessManager)Patches.patch_Rainworld.mainRW.processManager);
         if (patchPM.currentMainLoop is SteamMultiplayerMenu)
         {
             if (lobbyID.m_SteamID != 0)
             {
                 LeaveLobby();
             }
         }
         patchPM.ImmediateSwitchCustom(new SteamMultiplayerMenu(patchPM));
     }
     joining = true;
     SteamMatchmaking.JoinLobby(request.m_steamIDLobby);
 }
    public void setGameServerSettings(CSteamID m_Lobby, string gameServerIP, string port)
    {
        uint  gameServerIPuint = SteamAntiCheat.ToUInt(gameServerIP);
        Int32 portNum;

        if (Int32.TryParse(port, out portNum))
        {
            SteamMatchmaking.SetLobbyGameServer(m_Lobby, gameServerIPuint, (ushort)portNum, CSteamID.NonSteamGS); //127.0.0.1
            //SteamMatchmaking.SetLobbyGameServer(m_Lobby, 2130706433, 1337, CSteamID.NonSteamGS); //127.0.0.1
            Console.WriteLine("SteamMatchmaking.SetLobbyGameServer(" + m_Lobby + " " + gameServerIPuint + " " + (ushort)portNum + ", CSteamID.NonSteamGS)");
            bool reasult = SteamMatchmaking.SetLobbyJoinable(m_Lobby, true);
            Console.WriteLine("SteamMatchmaking.SetLobbyJoinable(" + m_Lobby + ", true) : " + reasult);
            bool reasult2 = SteamMatchmaking.SetLobbyType(m_Lobby, ELobbyType.k_ELobbyTypePublic);
            //SteamMatchmaking.JoinLobby(m_Lobby);
        }
    }
Exemple #8
0
        private GalaxyID GalaxyIDFromSteamID(CSteamID steamID)
        {
            var connectOutput = SteamMatchmaking.GetLobbyData(steamID, "connect");

            ulong galaxyIDLong = 0;

            for (int i = 0; i < connectOutput.Length; i++)
            {
                if (ulong.TryParse(connectOutput.Substring(i), out galaxyIDLong))
                {
                    break;
                }
            }

            return(new GalaxyID(galaxyIDLong));
        }
Exemple #9
0
            private void SearchForLobby()
            {
                SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypeFriendsOnly, 10);

                Callback <LobbyCreated_t> .Create(cb =>
                {
                    Console.WriteLine("ciaone");
                });

                SteamMatchmaking.RequestLobbyList();

                Callback <LobbyMatchList_t> .Create(x =>
                {
                    Console.WriteLine(x.m_nLobbiesMatching);
                });
            }
Exemple #10
0
    void ReceiveChatMessage(LobbyChatMsg_t cb)
    {
        CSteamID user;

        byte[]         data = new byte[4096];
        EChatEntryType chatType;
        int            dataLenght = SteamMatchmaking.GetLobbyChatEntry((CSteamID)cb.m_ulSteamIDLobby, (int)cb.m_iChatID, out user, data, data.Length, out chatType);

        string name = SteamFriends.GetFriendPersonaName(user);

        if (chatType == EChatEntryType.k_EChatEntryTypeChatMsg)
        {
            string message = Encoding.UTF8.GetString(data, 0, dataLenght);
            Text.text += "\n" + name + " : " + message;
        }
    }
Exemple #11
0
        public async Task <IEnumerable <LobbyInfo> > GetLobbies()
        {
            if (!SteamManager.Initialized)
            {
                return(Enumerable.Empty <LobbyInfo>());
            }
            var lobbyList = await SteamMatchmaking.RequestLobbyList().ToTask <LobbyMatchList_t>();

            lobbies.Clear();
            for (var i = 0; i < lobbyList.m_nLobbiesMatching; i++)
            {
                var id = SteamMatchmaking.GetLobbyByIndex(i);
                lobbies.Add(CreateLobbyInfo(id));
            }
            return(lobbies);
        }
Exemple #12
0
 public unsafe static bool InviteUser(User userVal, Lobby lobbyVal)
 {
     if (!_initialized)
     {
         return(false);
     }
     if (lobbyVal == null)
     {
         lobbyVal = lobby;
         if (lobbyVal == null)
         {
             return(false);
         }
     }
     return(userVal != null && SteamMatchmaking.InviteUserToLobby(new CSteamID(lobbyVal.id), new CSteamID(userVal.id)));
 }
Exemple #13
0
 public unsafe static void SearchForLobby(User who)
 {
     if (!_initialized)
     {
         return;
     }
     lobbySearchResult   = null;
     lobbySearchComplete = false;
     lobbiesFound        = 0;
     if (who != null)
     {
         // TODO: What does the original Steam.dll do? Filter by user?
         // This isn't critical, but only used when Duck Game's Program.testServer == true and superjoebob is your steam friend.
     }
     SetCallResult <LobbyMatchList_t>(SteamMatchmaking.RequestLobbyList());
 }
Exemple #14
0
 public void CreatePremadeTeamLobby()
 {
     if (C.LOG_INVITE)
     {
         Debug.LogWarning("Creating premade team lobby");
     }
     if (teambuilderLobbyId == CSteamID.Nil)
     {
         CreatingPremadeTeamLobby = true;
         SteamMatchmaking.CreateLobby(ELobbyType.k_ELobbyTypeInvisible, C.MAX_PLAYERS / 2);
     }
     else
     {
         _steamManager.UNETServerController.InviteFriendsToLobby(teambuilderLobbyId);
     }
 }
Exemple #15
0
    /// <summary>
    /// Used to make lobby persist.
    /// Lobby shuts down if no data sent within it for a while
    /// </summary>
    IEnumerator PingChat()
    {
        var msg    = System.Text.Encoding.ASCII.GetBytes("ping");
        var length = System.Text.Encoding.ASCII.GetByteCount("ping");

        while (teambuilderLobbyId != null)
        {
            var ret = SteamMatchmaking.SendLobbyChatMsg(teambuilderLobbyId, msg, length);
            if (C.LOG_INVITE)
            {
                Debug.Log("Sending teambuilder ping success: " + ret);
            }
            yield return(new WaitForSeconds(5f));
        }
        yield break;
    }
    private void OnLobbyCreated(LobbyCreated_t callback)
    {
        if (callback.m_eResult != EResult.k_EResultOK)
        {
            buttons.SetActive(true);
            return;
        }

        networkManager.StartHost();

        SteamMatchmaking.SetLobbyData(
            new CSteamID(callback.m_ulSteamIDLobby),
            HostAddressKey,
            SteamUser.GetSteamID().ToString()
            );
    }
Exemple #17
0
    private void OnLobbyCreated(LobbyCreated_t callback)
    {
        if (callback.m_eResult != EResult.k_EResultOK)
        {
            Debug.Log("Lobby could not be created.");
            connectionUI.SetActive(true);
            return;
        }

        networkManager.StartHost();
        SteamMatchmaking.SetLobbyData(
            new CSteamID(callback.m_ulSteamIDLobby),
            HostAddressKey,
            SteamUser.GetSteamID().ToString()
            );
    }
    void OnLobbyEnter(LobbyEnter_t pCallback, bool bIOFailure)
    {
        if (bIOFailure == false)
        {
            Debug.Log("[" + LobbyEnter_t.k_iCallback + " - LobbyEnter] - " + pCallback.m_ulSteamIDLobby + " -- " + pCallback.m_rgfChatPermissions + " -- " + pCallback.m_bLocked + " -- " + pCallback.m_EChatRoomEnterResponse);

            LobbyValue _lobby = new LobbyValue();
            _lobby.name  = SteamMatchmaking.GetLobbyData((CSteamID)pCallback.m_ulSteamIDLobby, "name");
            _lobby.lobby = (CSteamID)pCallback.m_ulSteamIDLobby;
            currentLobby = _lobby;
        }
        else
        {
            Debug.LogError("Unable to Join Lobby");
        }
    }
    public void GetLobbyByIndex(int index)
    {
        CSteamID m_LobbyValue = SteamMatchmaking.GetLobbyByIndex(index);

        if (DebugTextOn)
        {
            Debug.Log("SteamMatchmaking.SteamMatchmaking.GetLobbyByIndex(0) : " + m_LobbyValue);
        }

        Lobby _lobby = new Lobby();

        _lobby.name       = SteamMatchmaking.GetLobbyData(m_LobbyValue, "name");
        _lobby.lobbyIndex = index;
        _lobby.lobby      = m_LobbyValue;
        m_LobbyList.Add(_lobby);
    }
Exemple #20
0
    private void OnLobbyEntered(LobbyEnter_t callback)
    {
        if (NetworkServer.active)
        {
            return;
        }

        string hostAddress = SteamMatchmaking.GetLobbyData(
            new CSteamID(callback.m_ulSteamIDLobby),
            "HostAddress");

        NetworkManager.singleton.networkAddress = hostAddress;
        NetworkManager.singleton.StartClient();

        landingPagePanel.SetActive(false);
    }
Exemple #21
0
 //------------    When entering lobby (as host or user)    ------------
 private void OnLobbyEntered(LobbyEnter_t entrance)
 {
     _globals.LobbyId = (CSteamID)entrance.m_ulSteamIDLobby;
     if (_globals.PlayingAsHost)
     {
         GD.Print($"OK: Entered into a lobby with ID: {_globals.LobbyId} as host, changing scene.");
         OnLobbyEnteredFinished();
     }
     else
     {
         _globals.HostId = SteamMatchmaking.GetLobbyOwner((CSteamID)entrance.m_ulSteamIDLobby);
         _globals.OwnId  = SteamUser.GetSteamID();
         GD.Print($"OK: Entered into a lobby with ID: {_globals.LobbyId} as user.");
         SendRequestToFillPlayerIds();
     }
 }
Exemple #22
0
    public void FindMatch()
    {
        if (!SteamManager.Initialized)
        {
            lobbyConnectionState = SessionConnectionState.FAILED;
            return;
        }

        lobbyConnectionState = SessionConnectionState.CONNECTING;

        //Note: call SteamMatchmaking.AddRequestLobbyList* before RequestLobbyList to filter results by some criteria
        SteamMatchmaking.AddRequestLobbyListStringFilter("game", GAME_ID, ELobbyComparison.k_ELobbyComparisonEqual);
        var call = SteamMatchmaking.RequestLobbyList();

        m_LobbyMatchList.Set(call, OnLobbyMatchList);
    }
        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();
            }
        }
    private void OnLobbyEntered(LobbyEnter_t callback)
    {
        if (NetworkServer.active)
        {
            return;
        }

        string hostAdress = SteamMatchmaking.GetLobbyData(
            new CSteamID(callback.m_ulSteamIDLobby),
            HostAdressKey);

        networkManager.networkAddress = hostAdress;

        networkManager.StartClient();
        menuManager.NavigateToMenu("Lobby");
    }
        public void LeaveLobby()
        {
            if (lobbyID.m_SteamID != 0)
            {
                SteamMatchmaking.LeaveLobby(lobbyID);
            }
            foreach (ulong player in otherPlayers)
            {
                SteamNetworking.CloseP2PSessionWithUser((CSteamID)player);
            }
            connectedPlayers.Clear();
            otherPlayers.Clear();

            lobbyID  = new CSteamID(0);
            isInGame = false;
        }
    private void OnLobbyEnter(LobbyEnter_t callback)
    {
        if (!SteamManager.Initialized)
        {
            return;
        }
        if (this.m_LobbyId != (CSteamID)callback.m_ulSteamIDLobby)
        {
            this.m_LobbyId = new CSteamID(callback.m_ulSteamIDLobby);
        }
        CSteamID lobbyOwner = SteamMatchmaking.GetLobbyOwner(this.m_LobbyId);

        this.m_LobbyOwner = lobbyOwner;
        CSteamID steamID = SteamUser.GetSteamID();

        if (lobbyOwner.m_SteamID == steamID.m_SteamID)
        {
            if (P2PLogFilter.logInfo)
            {
                Debug.Log("[TransportLayerSteam] Connected to Steam lobby as owner");
            }
            SteamMatchmaking.SetLobbyData(this.m_LobbyId, "game_ver", GreenHellGame.s_GameVersion.ToString());
            SteamMatchmaking.SetLobbyData(this.m_LobbyId, "name", SteamFriends.GetPersonaName());
            SteamMatchmaking.SetLobbyMemberData(this.m_LobbyId, "member_name", SteamFriends.GetPersonaName());
            SteamMatchmaking.SetLobbyData(this.m_LobbyId, "lobby_type", EnumUtils <P2PGameVisibility> .GetName(this.GetGameVisibility()));
            P2PTransportLayer.OnLobbyEnter(true);
            return;
        }
        if (callback.m_EChatRoomEnterResponse == 1u)
        {
            if (P2PLogFilter.logInfo)
            {
                Debug.Log(string.Format("[TransportLayerSteam] Connected to Steam lobby {0} as member", this.m_LobbyId));
            }
            this.m_JoiningDelayed = this.RequestP2PConnectionWithHost();
            SteamMatchmaking.SetLobbyMemberData(this.m_LobbyId, "member_name", SteamFriends.GetPersonaName());
            P2PTransportLayer.OnLobbyEnter(false);
            return;
        }
        if (P2PLogFilter.logWarn)
        {
            string str = "[TransportLayerSteam] Lobby enter failure: ";
            EChatRoomEnterResponse echatRoomEnterResponse = (EChatRoomEnterResponse)callback.m_EChatRoomEnterResponse;
            Debug.LogWarning(str + echatRoomEnterResponse.ToString());
        }
        this.Shutdown();
    }
Exemple #27
0
    private void OnLobbyCreated(LobbyCreated_t callback)
    {
        if (callback.m_eResult != EResult.k_EResultOK) // if lobby not created successfully
        {
            landingPagePanel.SetActive(true);
            return;
        }

        // if lobby created successfully

        NetworkManager.singleton.StartHost();

        SteamMatchmaking.SetLobbyData(
            new CSteamID(callback.m_ulSteamIDLobby),
            "HostAddress",
            SteamUser.GetSteamID().ToString());
    }
Exemple #28
0
        private GalaxyID GalaxyIDFromSteamID(CSteamID steamID)
        {
            GalaxyID parseConnectionString(string connectionString)
            {
                if (connectionString.StartsWith("-connect-lobby-"))
                {
                    return(new GalaxyID(Convert.ToUInt64(connectionString.Substring("-connect-lobby-".Length))));
                }
                if (connectionString.StartsWith("+connect_lobby "))
                {
                    return(new GalaxyID(Convert.ToUInt64(connectionString.Substring("+connect_lobby".Length + 1))));
                }
                return(null);
            }

            return(parseConnectionString(SteamMatchmaking.GetLobbyData(steamID, "connect")));
        }
    private void OnLobbyEntered(LobbyEnter_t callback)
    {
        if (NetworkServer.active)
        {
            Debug.Log("Is host doesnt need extra data on join");
            StartCoroutine(ShowingLevelCam());
            return;
        }
        string hostAddress = SteamMatchmaking.GetLobbyData(new CSteamID(callback.m_ulSteamIDLobby), hostAddressKey);

        networkManager.networkAddress = hostAddress;
        NetworkClient.Connect(hostAddress);
        networkManager.StartClient();
        //Load level, make sure its same as lobby level
        SceneManager.LoadScene("PreBuiltLevel1", LoadSceneMode.Single);
        StartCoroutine(ShowingLevelCam());
    }
Exemple #30
0
 private void OnLobbyCreated(LobbyCreated_t result, bool failure)
 {
     if (State == LobbyState.Creating)
     {
         if (failure)
         {
             State = LobbyState.Inactive;
         }
         else
         {
             State = LobbyState.Active;
         }
         Id    = new CSteamID(result.m_ulSteamIDLobby);
         Owner = SteamMatchmaking.GetLobbyOwner(Id);
         _lobbyCreatedExternalCallback(result, failure);
     }
 }