示例#1
0
        public static void UpdateServerTick(GalaxyID id)
        {
            try
            {
                var mm = GalaxyInstance.Matchmaking();
                int numberOfPlayers = Game1.getOnlineFarmers().Count;

                int numberOfPlayerSlots = -1;
                try
                {
                    Multiplayer mp = ModEntry.ModHelper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();
                    numberOfPlayerSlots = mp.playerLimit;
                }
                catch (Exception) { }

                int freeCabins = GetCabinsInsides().Where(x => x.owner == null || x.owner.Name.Length == 0).Count();

                mm.SetLobbyData(id, "numberOfPlayers", numberOfPlayers.ToString());
                mm.SetLobbyData(id, "numberOfPlayerSlots", numberOfPlayerSlots.ToString());
                mm.SetLobbyData(id, "freeCabins", freeCabins.ToString());
            }
            catch (Exception)
            {
                Console.WriteLine("Could not update server metadata - likely because the world is not yet initialised");
            }
        }
        public virtual string GetLobbyOwnerName(object lobbyId)
        {
            GalaxyID lobby = new GalaxyID((ulong)lobbyId);
            GalaxyID owner = GalaxyInstance.Matchmaking().GetLobbyOwner(lobby);

            return(GalaxyInstance.Friends().GetFriendPersonaName(owner));
        }
示例#3
0
 private void onGalaxyLobbyEnter(GalaxyID lobbyID, LobbyEnterResult result)
 {
     connectingLobbyID = null;
     if (result != 0)
     {
         return;
     }
     Console.WriteLine("Lobby entered: {0}", lobbyID.ToUint64());
     lobby      = lobbyID;
     lobbyOwner = GalaxyInstance.Matchmaking().GetLobbyOwner(lobbyID);
     if (Game1.chatBox != null)
     {
         string invite_code_string = "";
         if (Program.sdk.Networking != null && Program.sdk.Networking.SupportsInviteCodes())
         {
             invite_code_string = Game1.content.LoadString("Strings\\UI:Chat_LobbyJoined_InviteCode", GetInviteCode());
         }
         if (isRecreatedLobby)
         {
             Game1.chatBox.addInfoMessage(Game1.content.LoadString("Strings\\UI:Chat_LobbyRecreated", invite_code_string).Trim());
         }
         else
         {
             Game1.chatBox.addInfoMessage(Game1.content.LoadString("Strings\\UI:Chat_LobbyJoined", invite_code_string).Trim());
         }
     }
     if (lobbyOwner == selfId)
     {
         foreach (KeyValuePair <string, string> pair in lobbyData)
         {
             GalaxyInstance.Matchmaking().SetLobbyData(lobby, pair.Key, pair.Value);
         }
         updateLobbyPrivacy();
     }
 }
示例#4
0
 private void tryCreateLobby()
 {
     Console.WriteLine("Creating lobby...");
     galaxyLobbyLeftCallback = new GalaxyLobbyLeftListener(onGalaxyLobbyLeft);
     GalaxyInstance.Matchmaking().CreateLobby(privacyToLobbyType(privacy), memberLimit, joinable: true, LobbyTopologyType.LOBBY_TOPOLOGY_TYPE_STAR);
     recreateTimer = 0L;
 }
示例#5
0
        public static void InnitServer(GalaxyID id)
        {
            Console.WriteLine("Initialising server metadata");
            var mm = GalaxyInstance.Matchmaking();

            string serverBrowserVersion = ModEntry.ModHelper.ModRegistry.Get("Ilyaki.ServerBrowser").Manifest.Version.ToString();

            mm.SetLobbyData(id, "serverBrowserVersion", serverBrowserVersion);

            string serverMessage = ModEntry.Config.ServerMessage;

            mm.SetLobbyData(id, "serverMessage", serverMessage);

            StringBuilder sb = new StringBuilder();

            foreach (var modID in ModEntry.Config.RequiredMods)
            {
                sb.Append(modID);
                sb.Append(',');
            }
            mm.SetLobbyData(id, "requiredMods", sb.ToString());

            sb.Clear();
            foreach (var modID in ModEntry.ModHelper.ModRegistry.GetAll().Select(x => x.Manifest.UniqueID))
            {
                sb.Append(modID);
                sb.Append(',');
            }
            mm.SetLobbyData(id, "serverMods", sb.ToString());

            string password = ModEntry.Config.Password;

            mm.SetLobbyData(id, "password", password);
        }
示例#6
0
        public IEnumerable <GalaxyID> LobbyMembers()
        {
            if (lobby == null)
            {
                yield break;
            }
            uint lobby_members_count;

            try
            {
                lobby_members_count = GalaxyInstance.Matchmaking().GetNumLobbyMembers(lobby);
            }
            catch (Exception)
            {
                yield break;
            }
            uint i = 0u;

            while (i < lobby_members_count)
            {
                GalaxyID lobbyMember = GalaxyInstance.Matchmaking().GetLobbyMemberByIndex(lobby, i);
                if (!(lobbyMember == selfId) && !ghosts.Contains(lobbyMember.ToUint64()))
                {
                    yield return(lobbyMember);
                }
                uint num = i + 1;
                i = num;
            }
        }
示例#7
0
 private void updateLobbyPrivacy()
 {
     if (lobbyOwner != selfId)
     {
         return;
     }
     if (lobby != null)
     {
         GalaxyInstance.Matchmaking().SetLobbyType(lobby, privacyToLobbyType(privacy));
     }
     if (lobby == null)
     {
         if (steamLobby.HasValue)
         {
             SteamMatchmaking.LeaveLobby(steamLobby.Value);
         }
     }
     else if (!steamLobby.HasValue)
     {
         if (steamLobbyEnterCallback == null)
         {
             steamLobbyEnterCallback = Callback <LobbyEnter_t> .Create(onSteamLobbyEnter);
         }
         SteamMatchmaking.CreateLobby(privacyToSteamLobbyType(privacy), (int)memberLimit);
     }
     else
     {
         SteamMatchmaking.SetLobbyType(steamLobby.Value, privacyToSteamLobbyType(privacy));
         SteamMatchmaking.SetLobbyData(steamLobby.Value, "connect", getConnectionString());
     }
 }
    // Gets a lobby message
    public string GetLobbyMessage(GalaxyID lobbyID, ref GalaxyID senderID, uint messageID)
    {
        string message = null;

        GalaxyInstance.Matchmaking().GetLobbyMessage(lobbyID, messageID, ref senderID, out message);
        return(message);
    }
示例#9
0
 public void SetLobbyData(string key, string value)
 {
     lobbyData[key] = value;
     if (lobby != null)
     {
         GalaxyInstance.Matchmaking().SetLobbyData(lobby, key, value);
     }
 }
示例#10
0
        private void onRichPresenceUpdated(GalaxyID userID)
        {
            GalaxyID lobby = parseConnectionString(GalaxyInstance.Friends().GetRichPresence("connect", userID));

            if (lobby != null)
            {
                GalaxyInstance.Matchmaking().RequestLobbyData(lobby);
            }
        }
        private void LobbyCreated(GalaxyID lobbyID)
        {
            matchmaking.SetLobbyData(lobbyID, "name", matchmaking.lobbyName);
            matchmaking.SetLobbyData(lobbyID, "state", "notReady");

            matchmaking.CurrentLobbyID = lobbyID;
            matchmaking.LobbyOwnerID   = GalaxyInstance.Matchmaking().GetLobbyOwner(lobbyID);
            matchmaking.SetLobbyMemberData("state", "notReady");
            GameObject.Find("MainMenu").GetComponent <MainMenuController>().SwitchMenu(MainMenuController.MenuEnum.OnlineWait);
        }
示例#12
0
 public void JoinLobby(GalaxyID lobbyId)
 {
     try
     {
         GalaxyInstance.Matchmaking().JoinLobby(lobbyId);
     }
     catch (Exception value)
     {
         Console.WriteLine(value);
     }
 }
示例#13
0
        private void onLobbyDataUpdate(LobbyDataUpdate_t pCallback)
        {
            CSteamID steamLobby = new CSteamID(pCallback.m_ulSteamIDLobby);
            GalaxyID lobbyID    = parseConnectionString(SteamMatchmaking.GetLobbyData(steamLobby, "connect"));

            lobbyOwners[lobbyID.ToUint64()] = SteamMatchmaking.GetLobbyOwner(steamLobby);
            if (lobbyID != null)
            {
                GalaxyInstance.Matchmaking().RequestLobbyData(lobbyID);
            }
        }
 // Joins a specified lobby
 public void JoinLobby(GalaxyID lobbyID)
 {
     Debug.Log("Joining lobby " + lobbyID);
     try
     {
         GalaxyInstance.Matchmaking().JoinLobby(lobbyID);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not join lobby " + lobbyID + " for reason: " + e);
     }
 }
 /* Requests lobby data for provided lobbyID
  * Note: Must be called before getting any lobby data,
  * unless you are a member of lobby your trying to get data for (you joined said lobby) */
 public void RequestLobbyData(GalaxyID lobbyID)
 {
     Debug.Log("Requesting data for lobby " + lobbyID);
     try
     {
         GalaxyInstance.Matchmaking().RequestLobbyData(lobbyID);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not retrieve lobby " + lobbyID + " data for reason: " + e);
     }
 }
 /* Requests list of available lobbies
  * Note: Private lobbies will not be retrieved */
 public void RequestLobbyList(bool allowFull = false)
 {
     Debug.Log("Requesting lobby list");
     try
     {
         GalaxyInstance.Matchmaking().RequestLobbyList(allowFull);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not retrieve lobby list for reason: " + e);
     }
 }
 // Creates a lobby with specified parameters
 public void CreateLobby(LobbyType lobbyType, uint maxMembers, bool joinable, LobbyTopologyType lobbyTopologyType)
 {
     Debug.Log("Creating a lobby");
     try
     {
         GalaxyInstance.Matchmaking().CreateLobby(lobbyType, maxMembers, joinable, lobbyTopologyType);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not create lobby for reason: " + e);
     }
 }
示例#18
0
 // Joins a specified lobby
 public void JoinLobby(GalaxyID lobbyID)
 {
     Debug.Log("Joining lobby " + lobbyID);
     try
     {
         Debug.Assert(lobbyEnteredListenerBrowsing != null);
         GalaxyInstance.Matchmaking().JoinLobby(lobbyID, lobbyEnteredListenerBrowsing);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not join lobby " + lobbyID + " for reason: " + e);
     }
 }
 // Sets current user lobby member data 'key' to 'value' in currently entered lobby
 public void SetLobbyMemberData(string key, string value)
 {
     Debug.Log("Trying to set lobby " + currentLobbyID + " member data " + key + " to " + value);
     try
     {
         GalaxyInstance.Matchmaking().SetLobbyMemberData(currentLobbyID, key, value);
         Debug.Log("Lobby " + currentLobbyID + " member data " + key + " set to " + value);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not set lobby " + currentLobbyID + " member data " + key + " : " + value + " for reason " + e);
     }
 }
示例#20
0
 /* Requests lobby data for provided lobbyID
  * Note: Must be called before getting any lobby data,
  * unless you are a member of lobby your trying to get data for (you joined said lobby) */
 public void RequestLobbyData(GalaxyID lobbyID)
 {
     Debug.Log("Requesting data for lobby " + lobbyID);
     try
     {
         Debug.Assert(lobbyDataRetrieveListenerBrowsing != null);
         GalaxyInstance.Matchmaking().RequestLobbyData(lobbyID, lobbyDataRetrieveListenerBrowsing);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not retrieve lobby " + lobbyID + " data for reason: " + e);
     }
 }
示例#21
0
 // Leaves currently entered lobby
 public void LeaveLobby()
 {
     Debug.Log("Leaving lobby " + currentLobbyID);
     try
     {
         Debug.Assert(currentLobbyID != null);
         GalaxyInstance.Matchmaking().LeaveLobby(currentLobbyID);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not leave lobby " + currentLobbyID + " for reason: " + e);
     }
 }
    // Gets a number of lobby members currently in the lobby 'lobbyID'
    public uint GetNumLobbyMembers(GalaxyID lobbyID)
    {
        uint lobbyMembersCount = 0;

        try
        {
            lobbyMembersCount = GalaxyInstance.Matchmaking().GetNumLobbyMembers(lobbyID);
        }
        catch (GalaxyInstance.Error e)
        {
            Debug.LogWarning("Could not get lobby member count for reason " + e);
        }
        return(lobbyMembersCount);
    }
示例#23
0
 // Creates a lobby with specified parameters
 public void CreateLobby(string gameName, LobbyType lobbyType, uint maxMembers, bool joinable,
                         LobbyTopologyType lobbyTopologyType)
 {
     Debug.Log("Creating a lobby");
     try
     {
         lobbyName = gameName;
         Debug.Assert(lobbyCreatedListener != null);
         GalaxyInstance.Matchmaking().CreateLobby(lobbyType, maxMembers, joinable, lobbyTopologyType, lobbyCreatedListener);
     }
     catch (GalaxyInstance.Error e)
     {
         Debug.LogWarning("Could not create lobby for reason: " + e);
     }
 }
    // Gets lobby 'lobbyID' data 'key'
    public string GetLobbyData(GalaxyID lobbyID, string key)
    {
        string lobbyData = null;

        try
        {
            lobbyData = GalaxyInstance.Matchmaking().GetLobbyData(lobbyID, key);
            Debug.Log("Lobby " + lobbyID + " data " + key + " read " + lobbyData);
        }
        catch (GalaxyInstance.Error e)
        {
            Debug.LogWarning("Could not retrieve lobby " + lobbyID + " data " + key + " for reason: " + e);
        }
        return(lobbyData);
    }
示例#25
0
 public void JoinLobby(GalaxyID lobbyId, Action <string> onError)
 {
     try
     {
         connectingLobbyID = lobbyId;
         GalaxyInstance.Matchmaking().JoinLobby(connectingLobbyID);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         string error_message2 = Game1.content.LoadString("Strings\\UI:CoopMenu_Failed");
         error_message2 = ((!e.Message.EndsWith("already joined this lobby")) ? (error_message2 + " (" + e.Message + ")") : (error_message2 + " (already connected)"));
         onError(error_message2);
         Close();
     }
 }
    // Gets the GalaxyID of the lobby owner
    public GalaxyID GetLobbyOwner(GalaxyID lobbyID)
    {
        GalaxyID lobbyOwnerID = null;

        Debug.Log("Trying to get lobby owner id " + lobbyOwnerID);
        try
        {
            lobbyOwnerID = GalaxyInstance.Matchmaking().GetLobbyOwner(lobbyID);
            Debug.Log("Lobby onwer ID received " + lobbyOwnerID);
        }
        catch (GalaxyInstance.Error e)
        {
            Debug.LogWarning("Could not retrieve lobby " + lobbyID + " owner ID for reason: " + e);
        }
        return(lobbyOwnerID);
    }
    // Gets lobby 'lobbyID' member GalaxyID by 'index'
    public GalaxyID GetLobbyMemberByIndex(GalaxyID lobbyID, uint index)
    {
        Debug.Log("Getting lobby member " + index + " GalaxyID");
        GalaxyID memberID = null;

        try
        {
            memberID = GalaxyInstance.Matchmaking().GetLobbyMemberByIndex(lobbyID, index);
            Debug.Log("Lobby member " + index + " GalaxyID " + memberID);
        }
        catch (GalaxyInstance.Error e)
        {
            Debug.LogWarning("Could not get lobby member " + index + " GalaxyID for reason: " + e);
        }
        return(memberID);
    }
    // Gets data 'key' of specified member 'memberID' in currently entered lobby
    public string GetLobbyMemberData(GalaxyID memberID, string key)
    {
        Debug.Log("Trying to get lobby " + currentLobbyID + " member " + memberID + " data " + key);
        string memberData = "";

        try
        {
            memberData = GalaxyInstance.Matchmaking().GetLobbyMemberData(currentLobbyID, memberID, key);
            Debug.Log("Lobby " + currentLobbyID + " member " + memberID + " data " + key + " read " + memberData);
        }
        catch (GalaxyInstance.Error e)
        {
            Debug.LogWarning("Could not read lobby " + currentLobbyID + " member " + memberID + " data " + key + " for reason " + e);
        }
        return(memberData);
    }
示例#29
0
 private void onGalaxyLobbyEnter(GalaxyID lobbyID, LobbyEnterResult result)
 {
     if (result == LobbyEnterResult.LOBBY_ENTER_RESULT_SUCCESS)
     {
         Console.WriteLine("Lobby entered: {0}", lobbyID.ToUint64());
         lobby      = lobbyID;
         lobbyOwner = GalaxyInstance.Matchmaking().GetLobbyOwner(lobbyID);
         if (lobbyOwner == selfId)
         {
             foreach (KeyValuePair <string, string> pair in lobbyData)
             {
                 GalaxyInstance.Matchmaking().SetLobbyData(lobby, pair.Key, pair.Value);
             }
             updateLobbyPrivacy();
         }
     }
 }
示例#30
0
 private void LobbyListRetrieved(uint count)
 {
     Debug.Log(count + " lobbies OnLobbyList");
     if (count == 0)
     {
         GameObject.Find("OnlineBrowserScreen").GetComponent <OnlineBrowserController>().DisplayLobbyList(lobbyList);
     }
     else
     {
         for (uint i = 0; i < count; i++)
         {
             GalaxyID lobbyID = GalaxyInstance.Matchmaking().GetLobbyByIndex(i);
             lobbyList.Add(lobbyID);
             Debug.Log("Requesting lobby data for lobby " + i + " with lobbyID " + lobbyID.ToString());
             matchmaking.RequestLobbyData(lobbyID);
         }
     }
 }