Skip to content

Commit

Permalink
Modlists should now be sent to joining clients.
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonFire47 committed Dec 2, 2023
1 parent 84391da commit 00dad83
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 54 deletions.
54 changes: 29 additions & 25 deletions PulsarModLoader/MPModChecks/MPModCheckManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -115,7 +114,7 @@ private void RefreshData(PulsarMod mod = null)
/// </summary>
public List<PhotonPlayer> RequestedModLists = new List<PhotonPlayer>();

private Dictionary<PhotonPlayer, MPUserDataBlock> NetworkedPeersModLists = new Dictionary<PhotonPlayer, MPUserDataBlock>();
internal Dictionary<PhotonPlayer, MPUserDataBlock> NetworkedPeersModLists = new Dictionary<PhotonPlayer, MPUserDataBlock>();

private int HighestLevelOfMPMods = 0;

Expand All @@ -142,9 +141,9 @@ public MPUserDataBlock GetNetworkedPeerMods(PhotonPlayer Photonplayer)
/// <param name="player"></param>
/// <param name="HarmonyIdentifier"></param>
/// <returns>Returns true if player has mod</returns>
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)
Expand Down Expand Up @@ -182,27 +181,38 @@ public List<PhotonPlayer> NetworkedPeersWithMod(string HarmonyIdentifier)
/// <summary>
/// Adds a player's mod list to the local NetworkedPeersModLists
/// </summary>
/// <param name="Photonplayer"></param>
/// <param name="PhotonPlayer"></param>
/// <param name="modList"></param>
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);
}

/// <summary>
/// Clears player from NetworkedPeersModLists
/// </summary>
/// <param name="Photonplayer"></param>
public void RemoveNetworkedPeerMods(PhotonPlayer Photonplayer)
/// <param name="PhotonPlayer"></param>
public void RemoveNetworkedPeerMods(PhotonPlayer PhotonPlayer)
{
NetworkedPeersModLists.Remove(PhotonPlayer);
}

/// <summary>
/// Checks NetworkedPeersModLists
/// </summary>
/// <param name="PhotonPlayer"></param>
/// <returns></returns>
public bool GetNetworkedPeerModlistExists(PhotonPlayer PhotonPlayer)
{
NetworkedPeersModLists.Remove(Photonplayer);
return NetworkedPeersModLists.ContainsKey(PhotonPlayer);
}


private List<PulsarMod> GetMPModList()
{
HighestLevelOfMPMods = 0;
Expand All @@ -228,9 +238,9 @@ private void UpdateMyModList()
stopwatch.Start();
List<PulsarMod> 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;
Expand Down Expand Up @@ -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()
});
}
}
}
Expand Down
48 changes: 20 additions & 28 deletions PulsarModLoader/ModMessage/ModMessageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ public void ReceiveMessage(string modID, object[] arguments, PhotonMessageInfo p
}

/// <summary>
/// RPC activated message popup, used for client faiures to join.
/// RPC activated message popup, used for client failures to join.
/// </summary>
/// <param name="message"></param>
/// <param name="pmi"></param>
[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));
}
}

/// <summary>
Expand All @@ -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);
}*/

/// <summary>
/// Recieves mod list from connecting client. Use ClientRequest mod list to make a request to the host.
/// Recieves mod list from connecting client.
/// </summary>
/// <param name="recievedData"></param>
/// <param name="pmi"></param>
Expand All @@ -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);
}
}

/// <summary>
/// Client sends request to the host for modlist of a client
/// Client sends request to the host for modlist of a client. Deprecated
/// </summary>
/// <param name="pmi"></param>
[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");
}
}
}
2 changes: 1 addition & 1 deletion PulsarModLoader/PulsarModLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
<Compile Include="Keybinds\KeybindManager.cs" />
<Compile Include="Keybinds\LoadFromXmlPatch.cs" />
<Compile Include="Keybinds\PMLKeybind.cs" />
<Compile Include="ModMessage\AllowPMLRPCPatch.cs" />
<Compile Include="Patches\AllowPMLRPCPatch.cs" />
<Compile Include="ModMessage\ModMessage.cs" />
<Compile Include="ModMessage\ModMessageHelper.cs" />
<Compile Include="MPModChecks\MPModCheckManager.cs" />
Expand Down

0 comments on commit 00dad83

Please sign in to comment.