diff --git a/PulsarModLoader/MPModChecks/MPModCheckManager.cs b/PulsarModLoader/MPModChecks/MPModCheckManager.cs index 9ae81f3..3aac868 100644 --- a/PulsarModLoader/MPModChecks/MPModCheckManager.cs +++ b/PulsarModLoader/MPModChecks/MPModCheckManager.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.IO; using System.Reflection.Emit; -using System.Security.Cryptography; using System.Text; using Hashtable = ExitGames.Client.Photon.Hashtable; using Logger = PulsarModLoader.Utilities.Logger; @@ -71,7 +70,7 @@ private void RefreshData(PulsarMod mod = null) RefreshData(); } - private void UpdateLobbyModList() //Update Photon Lobby Listing with mod list + internal void UpdateLobbyModList() //Update Photon Lobby Listing with mod list { if (PhotonNetwork.isMasterClient && PhotonNetwork.inRoom && PLNetworkManager.Instance != null) { @@ -115,7 +114,7 @@ private void UpdateLobbyModList() //Update Photon Lobby Listing with mod list /// public List RequestedModLists = new List(); - private Dictionary NetworkedPeersModLists = new Dictionary(); + internal Dictionary NetworkedPeersModLists = new Dictionary(); private int HighestLevelOfMPMods = 0; @@ -142,9 +141,9 @@ public MPUserDataBlock GetNetworkedPeerMods(PhotonPlayer Photonplayer) /// /// /// Returns true if player has mod - public bool NetworkedPeerHasMod(PhotonPlayer player, string HarmonyIdentifier) + public bool NetworkedPeerHasMod(PhotonPlayer Player, string HarmonyIdentifier) { - MPUserDataBlock userData = GetNetworkedPeerMods(player); + MPUserDataBlock userData = GetNetworkedPeerMods(Player); if(userData != null) { foreach(MPModDataBlock modData in userData.ModData) @@ -182,27 +181,38 @@ public List NetworkedPeersWithMod(string HarmonyIdentifier) /// /// Adds a player's mod list to the local NetworkedPeersModLists /// - /// + /// /// - public void AddNetworkedPeerMods(PhotonPlayer Photonplayer, MPUserDataBlock modList) + public void AddNetworkedPeerMods(PhotonPlayer PhotonPlayer, MPUserDataBlock modList) { - if (NetworkedPeersModLists.ContainsKey(Photonplayer)) + if (NetworkedPeersModLists.ContainsKey(PhotonPlayer)) { - NetworkedPeersModLists[Photonplayer] = modList; + NetworkedPeersModLists[PhotonPlayer] = modList; return; } - NetworkedPeersModLists.Add(Photonplayer, modList); + NetworkedPeersModLists.Add(PhotonPlayer, modList); } /// /// Clears player from NetworkedPeersModLists /// - /// - public void RemoveNetworkedPeerMods(PhotonPlayer Photonplayer) + /// + public void RemoveNetworkedPeerMods(PhotonPlayer PhotonPlayer) + { + NetworkedPeersModLists.Remove(PhotonPlayer); + } + + /// + /// Checks NetworkedPeersModLists + /// + /// + /// + public bool GetNetworkedPeerModlistExists(PhotonPlayer PhotonPlayer) { - NetworkedPeersModLists.Remove(Photonplayer); + return NetworkedPeersModLists.ContainsKey(PhotonPlayer); } + private List GetMPModList() { HighestLevelOfMPMods = 0; @@ -228,9 +238,9 @@ private void UpdateMyModList() stopwatch.Start(); List UnprocessedMods = GetMPModList(); MPModDataBlock[] ProcessedMods = new MPModDataBlock[UnprocessedMods.Count]; - for (int i = 0; i < UnprocessedMods.Count; i++) - { - PulsarMod currentMod = UnprocessedMods[i]; + for (int i = 0; i < UnprocessedMods.Count; i++) + { + PulsarMod currentMod = UnprocessedMods[i]; ProcessedMods[i] = new MPModDataBlock(currentMod.HarmonyIdentifier(), currentMod.Name, currentMod.Version, (MPRequirement)currentMod.MPRequirements, currentMod.VersionLink, currentMod.ModHash); } MyModList = ProcessedMods; @@ -723,16 +733,10 @@ class AddPlayerPatch { static void Postfix(PhotonPlayer photonPlayer) { - if(PhotonNetwork.isMasterClient) + ModMessageHelper.Instance.photonView.RPC("ClientRecieveModList", photonPlayer, new object[] { - ModMessageHelper.Instance.photonView.RPC("ClientRecieveModList", photonPlayer, new object[] - { - Instance.SerializeHashlessUserData() - }); - return; - } - Instance.RequestedModLists.Add(photonPlayer); - ModMessageHelper.Instance.photonView.RPC("ClientRequestModList", photonPlayer, new object[] { }); + Instance.SerializeHashlessUserData() + }); } } } diff --git a/PulsarModLoader/ModMessage/ModMessageHelper.cs b/PulsarModLoader/ModMessage/ModMessageHelper.cs index 2075986..01eb15a 100644 --- a/PulsarModLoader/ModMessage/ModMessageHelper.cs +++ b/PulsarModLoader/ModMessage/ModMessageHelper.cs @@ -106,13 +106,17 @@ public void ReceiveMessage(string modID, object[] arguments, PhotonMessageInfo p } /// - /// RPC activated message popup, used for client faiures to join. + /// RPC activated message popup, used for client failures to join. /// /// + /// [PunRPC] - public void RecieveErrorMessage(string message) + public void RecieveErrorMessage(string message, PhotonMessageInfo pmi) { - PLNetworkManager.Instance.MainMenu.AddActiveMenu(new PLErrorMessageMenu(message)); + if (pmi.sender.IsMasterClient) + { + PLNetworkManager.Instance.MainMenu.AddActiveMenu(new PLErrorMessageMenu(message)); + } } /// @@ -128,15 +132,8 @@ public void ServerRecieveModList(byte[] recievedData, PhotonMessageInfo pmi) MPModCheckManager.Instance.AddNetworkedPeerMods(pmi.sender, userDataBlock); } - /*[PunRPC] - public void ClientRecieveModListFromServer(PhotonPlayer player, byte[] recievedData, PhotonMessageInfo pmi) - { - MPUserDataBlock userDataBlock = MPModCheckManager.DeserializeHashfullMPUserData(recievedData); - MPModCheckManager.Instance.AddNetworkedPeerMods(player, userDataBlock); - }*/ - /// - /// Recieves mod list from connecting client. Use ClientRequest mod list to make a request to the host. + /// Recieves mod list from connecting client. /// /// /// @@ -145,31 +142,26 @@ public void ClientRecieveModList(byte[] recievedData, PhotonMessageInfo pmi) { MPUserDataBlock userDataBlock = MPModCheckManager.DeserializeHashlessMPUserData(recievedData); Logger.Info($"recieved modlist from user with the following info:\nPMLVersion: {userDataBlock.PMLVersion}\nModlist:{MPModCheckManager.GetModListAsString(userDataBlock.ModData)}"); - MPModCheckManager.Instance.AddNetworkedPeerMods(pmi.sender, userDataBlock); + + //Check if client modlist already exists, then update or add modlist. + if (MPModCheckManager.Instance.GetNetworkedPeerModlistExists(pmi.sender)) + { + MPModCheckManager.Instance.NetworkedPeersModLists[pmi.sender] = userDataBlock; + } + else + { + MPModCheckManager.Instance.AddNetworkedPeerMods(pmi.sender, userDataBlock); + } } /// - /// Client sends request to the host for modlist of a client + /// Client sends request to the host for modlist of a client. Deprecated /// /// [PunRPC] public void ClientRequestModList(PhotonMessageInfo pmi) { - if(!PhotonNetwork.isMasterClient) //stop if not host. - { - return; - } - PhotonPlayer sender = pmi.sender; - photonView.RPC("ClientRecieveModList", sender, new object[] - { - MPModCheckManager.Instance.SerializeHashlessUserData() - }); - - if (MPModCheckManager.Instance.GetNetworkedPeerMods(sender) == null && !MPModCheckManager.Instance.RequestedModLists.Contains(sender)) - { - MPModCheckManager.Instance.RequestedModLists.Add(sender); - photonView.RPC("ClientRequestModList", sender, new object[] {}); - } + Logger.Info("ModMessageHelper recieved modlist request. This is a deprecated RPC and is only called by older modloader versions"); } } } diff --git a/PulsarModLoader/PulsarModLoader.csproj b/PulsarModLoader/PulsarModLoader.csproj index 55238b5..4ac3234 100644 --- a/PulsarModLoader/PulsarModLoader.csproj +++ b/PulsarModLoader/PulsarModLoader.csproj @@ -250,7 +250,7 @@ - +