Example #1
0
        public static void OnPlayerPropertyModification(object[] playerAndUpdatedProps)
        {
            PhotonPlayer player = playerAndUpdatedProps[0] as PhotonPlayer;

            ExitGames.Client.Photon.Hashtable properties = playerAndUpdatedProps[1] as ExitGames.Client.Photon.Hashtable;

            // Remove invalid properties
            if (player.isLocal && properties.ContainsKey("sender") && properties["sender"] is PhotonPlayer)
            {
                PhotonPlayer sender = (PhotonPlayer)properties["sender"];
                if (!sender.isLocal)
                {
                    properties.StripKeysWithNullValues();
                    List <object> keys = properties.Keys.ToList();
                    PropertyWhitelist.ForEach(k => keys.Remove(k));

                    if (keys.Count > 0)
                    {
                        Mod.Logger.Error($"#{sender.Id} applied foreign properties to you.");
                        string propertiesModified = string.Join(", ", keys.Select(k => $"{{{k}={properties[k]}}}").ToArray());
                        Mod.Logger.Error($"Properties: {propertiesModified}");

                        ExitGames.Client.Photon.Hashtable nullified = new ExitGames.Client.Photon.Hashtable();
                        keys.ForEach(v => nullified.Add(v, null));
                        PhotonNetwork.player.SetCustomProperties(nullified);

                        if (!FengGameManagerMKII.IgnoreList.Contains(sender.Id))
                        {
                            FengGameManagerMKII.IgnoreList.Add(sender.Id);
                        }
                    }
                }
            }
        }
Example #2
0
        public static void OnRoomPropertyModification(ExitGames.Client.Photon.Hashtable propertiesThatChanged)
        {
            // Remove invalid properties
            if (PhotonNetwork.isMasterClient)
            {
                if (propertiesThatChanged.ContainsKey("sender") && propertiesThatChanged["sender"] is PhotonPlayer)
                {
                    PhotonPlayer sender = (PhotonPlayer)propertiesThatChanged["sender"];
                    if (!sender.isLocal && !sender.isMasterClient)
                    {
                        propertiesThatChanged.StripKeysWithNullValues();
                        List <object> keys = propertiesThatChanged.Keys.ToList();
                        RoomPropertyWhitelist.ForEach(k => keys.Remove(k));

                        if (keys.Count > 0)
                        {
                            Mod.Logger.Error($"#{sender.Id} applied foreign properties to the room.");
                            string propertiesModified = string.Join(", ", keys.Select(k => $"{{{k}={propertiesThatChanged[k]}}}").ToArray());
                            Mod.Logger.Error($"Properties: {propertiesModified}");

                            ExitGames.Client.Photon.Hashtable nullified = new ExitGames.Client.Photon.Hashtable();
                            keys.ForEach(v => nullified.Add(v, null));
                            PhotonNetwork.room.SetCustomProperties(nullified);
                        }

                        // Restore Joinability
                        if (PhotonNetwork.room.expectedJoinability != PhotonNetwork.room.open)
                        {
                            PhotonNetwork.room.open = PhotonNetwork.room.expectedJoinability;
                        }

                        // Restore Visibility
                        if (PhotonNetwork.room.expectedVisibility != PhotonNetwork.room.visible)
                        {
                            PhotonNetwork.room.visible = PhotonNetwork.room.expectedVisibility;
                        }

                        // Restore MaxPlayers
                        if (PhotonNetwork.room.expectedMaxPlayers != PhotonNetwork.room.maxPlayers)
                        {
                            PhotonNetwork.room.maxPlayers = PhotonNetwork.room.expectedMaxPlayers;
                        }
                    }
                }
            }
        }