////////////////

        private void PrepareDataForPlayer(Player player)
        {
            var    mymod = ResetModeMod.Instance;
            string uid   = null;

            try {
                uid = PlayerIdentityHelpers.GetUniqueId(player);

                this.NewData = mymod.Session.Data.Clone();
                this.NewData.PlayersValidated.Clear();
                this.NewData.PlayerPPSpendings.Clear();
            } catch (Exception e) {
                LogHelpers.Warn("Error 1: " + e.ToString());
            }

            try {
                if (mymod.Session.Data.PlayersValidated.Contains(uid))
                {
                    this.NewData.PlayersValidated.Add(uid);
                }
            } catch (Exception e) {
                LogHelpers.Warn("Error 2: " + e.ToString());
            }

            try {
                float sessVal;
                if (mymod.Session.Data.TryGetPlayerPPSpendingSync(uid, out sessVal))
                {
                    this.NewData.SetPlayerPPSpendingSync(uid, sessVal);
                }
            } catch (Exception e) {
                LogHelpers.Warn("Error 3a: " + e.ToString());
            }
        }
Example #2
0
        public override void OnEnterWorld(Player enteringPlayer)
        {
            if (enteringPlayer.whoAmI != Main.myPlayer)
            {
                return;
            }
            if (this.player.whoAmI != Main.myPlayer)
            {
                return;
            }

            var mymod = (TheLunaticMod)this.mod;

            if (mymod.Config.DebugModeInfo)
            {
                LogHelpers.Alert(enteringPlayer.name + " joined (" + PlayerIdentityHelpers.GetUniqueId(enteringPlayer) + ")");
            }

            if (Main.netMode == 0)
            {
                this.OnSingleConnect();
            }
            if (Main.netMode == 1)
            {
                this.OnClientConnect(enteringPlayer);
            }
        }
Example #3
0
        ////////////////

        protected CustomEntity(CustomEntityConstructor ctor)
        {
            var myctor = ctor as CustomEntityConstructor;

            if (this.OwnerPlayer != null)
            {
                this.OwnerPlayerWho = this.OwnerPlayer.whoAmI;
                this.OwnerPlayerUID = PlayerIdentityHelpers.GetProperUniqueId(this.OwnerPlayer);
            }
            else
            {
                this.OwnerPlayerWho = -1;
                this.OwnerPlayerUID = "";
            }

            if (myctor != null)
            {
                this.Core       = this.CreateCore(myctor);
                this.Components = this.CreateComponents(myctor);
            }
            else
            {
                this.Core       = this.CreateCoreTemplate();
                this.Components = this.CreateComponentsTemplate();
            }
        }
        ////

        private void OnFinishPlayerEnterWorldForHost(out bool isSynced)
        {
            var  mymod   = (RewardsMod)this.mod;
            var  myworld = ModContent.GetInstance <RewardsWorld>();
            bool success = false;

            string playerUid = PlayerIdentityHelpers.GetUniqueId(this.player);

            KillData plrData = myworld.Logic.GetPlayerData(this.player);

            if (plrData == null)
            {
                LogHelpers.Warn("Could not get player " + this.player.name + "'s (" + this.player.whoAmI + ") kill data.");
                isSynced = false;
                return;
            }

            success = plrData.Load(playerUid, this.player);
            if (!success)
            {
                if (KillData.CanReceiveOtherPlayerKillRewards( ))
                {
                    plrData.AddToMe(myworld.Logic.WorldData);
                }
            }

            if (mymod.SettingsConfig.DebugModeInfo || mymod.SettingsConfig.DebugModeKillInfo)
            {
                LogHelpers.Alert("who: " + this.player.whoAmI + " success: " + success + ", " + plrData.ToString());
            }

            isSynced = success;
        }
 public void PreUpdateSyncedServerForPlayer(Player player)
 {
     if (PlayerIdentityHelpers.GetUniqueId(player) != null)
     {
         this.CheckValidationOnHost(player);
     }
 }
Example #6
0
 internal SerializableCustomEntity(string typeName, CustomEntityCore core, IList <CustomEntityComponent> components, string playerUid)
     : base(null)
 {
     this.MyTypeName     = typeName;
     this.Core           = core;
     this.Components     = components;
     this.OwnerPlayerUID = playerUid;
     this.OwnerPlayerWho = PlayerIdentityHelpers.GetPlayerByProperId(playerUid)?.whoAmI ?? -1;
 }
Example #7
0
        internal void AddPlayer(Player player)
        {
            string uid = PlayerIdentityHelpers.GetUniqueId(player);

            this.Data.PlayersValidated.Add(uid);
            if (Main.netMode != 1)
            {
                this.Save();
            }
        }
Example #8
0
        public void UnloadModules()
        {
            this.Loadables.OnModsUnload();

            this.Loadables                  = null;
            this.ReflectionHelpers          = null;
            this.PacketProtocolMngr         = null;
            this.ExceptionMngr              = null;
            this.Timers                     = null;
            this.LogHelpers                 = null;
            this.ModFeaturesHelpers         = null;
            this.BuffHelpers                = null;
            this.NetHelpers                 = null;
            this.NPCAttributeHelpers        = null;
            this.ProjectileAttributeHelpers = null;
            this.BuffIdentityHelpers        = null;
            this.NPCBannerHelpers           = null;
            this.RecipeFinderHelpers        = null;
            this.RecipeGroupHelpers         = null;
            this.PlayerHooks                = null;
            this.LoadHelpers                = null;
            this.GetModInfo                 = null;
            this.GetModTags                 = null;
            this.WorldStateHelpers          = null;
            this.ModLock                    = null;
            this.EntityGroups               = null;
            this.AnimatedColors             = null;
            this.AnimatedTextures           = null;
            this.PlayerMessages             = null;
            this.Inbox                 = null;
            this.ControlPanel          = null;
            this.MenuItemMngr          = null;
            this.MenuContextMngr       = null;
            this.MusicHelpers          = null;
            this.PlayerIdentityHelpers = null;
            this.LoadHooks             = null;
            this.CustomLoadHooks       = null;
            this.DataStore             = null;
            this.CustomHotkeys         = null;
            this.XnaHelpers            = null;
            this.Server                = null;
            //this.PlayerDataMngr = null;
            this.SupportInfo          = null;
            this.RecipeHack           = null;
            this.ModListHelpers       = null;
            this.ItemAttributeHelpers = null;
            this.WorldTimeHooks       = null;

            this.ControlPanelHotkey = null;
            this.DataDumpHotkey     = null;
        }
        /// <summary>
        /// Indicates if the given player has special priviledge on a server. Currently, this is only defined by a config
        /// setting (`PrivilegedUserId`) using the user's internal unique ID (see `PlayerIdentityHelpers.GetUniqueId()`).
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        public static bool HasBasicServerPrivilege(Player player)
        {
            if (Main.netMode == 0 && !Main.dedServ)
            {
                throw new ModHelpersException("Not multiplayer.");
            }

            if (string.IsNullOrEmpty(ModHelpersMod.PrivConfig.PrivilegedUserId))
            {
                return(false);
            }

            return(ModHelpersMod.PrivConfig.PrivilegedUserId == PlayerIdentityHelpers.GetUniqueId(player));
        }
Example #10
0
        private void LoadDataSources()
        {
            DataDumper.SetDumpSource("WorldUidWithSeed", () => {
                return("  " + WorldHelpers.GetUniqueIdForCurrentWorld(true) + " (net mode: " + Main.netMode + ")");
            });

            DataDumper.SetDumpSource("PlayerUid", () => {
                if (Main.myPlayer < 0 || Main.myPlayer >= (Main.player.Length - 1))
                {
                    return("  Unobtainable");
                }

                return("  " + PlayerIdentityHelpers.GetUniqueId());
            });
        }
Example #11
0
        internal void CopyChangesFrom(CustomEntityCore core, IList <CustomEntityComponent> components, Player ownerPlr = null)
        {
            this.Core           = new CustomEntityCore(core);
            this.OwnerPlayerWho = ownerPlr != null ? ownerPlr.whoAmI : -1;
            this.OwnerPlayerUID = ownerPlr != null?PlayerIdentityHelpers.GetProperUniqueId(ownerPlr) : "";

            this.Components = components.SafeSelect(c => c.InternalClone()).ToList();
            this.ClearComponentCache();

            if (!this.IsInitialized)
            {
                //throw new HamstarException( "!ModHelpers."+this.GetType().Name+".CopyChangesFrom - Not initialized post-copy." );
                throw new HamstarException("Not initialized post-copy.");
            }
        }
Example #12
0
        ////////////////

        public void RefundRewardsSpendings(Player player)
        {
            var mymod      = ResetModeMod.Instance;
            Mod rewardsMod = ModLoader.GetMod("Rewards");

            if (rewardsMod == null)
            {
                if (mymod.Config.DebugModeInfo)
                {
                    LogHelpers.Alert("No Rewards mod.");
                }
                return;
            }

            var uid = PlayerIdentityHelpers.GetUniqueId(player);

            if (mymod.Config.ResetRewardsSpendings)
            {
                float ppSpent;
                if (mymod.Session.Data.TryGetPlayerPPSpendingSync(uid, out ppSpent))
                {
                    rewardsMod.Call("AddPoints", player, ppSpent);

                    if (mymod.Config.DebugModeInfo)
                    {
                        LogHelpers.Alert(player.name + "' PP spendings of " + ppSpent + " returned");
                    }
                }
                else
                {
                    if (mymod.Config.DebugModeInfo)
                    {
                        LogHelpers.Warn(player.name + "' PP could not be set");
                    }
                }
            }

            mymod.Session.Data.SetPlayerPPSpendingSync(uid, 0);
            if (Main.netMode != 1)
            {
                mymod.Session.Save();
            }

            if (mymod.Config.ResetRewardsKills)
            {
                rewardsMod.Call("ResetKills", player);
            }
        }
Example #13
0
        public override void OnEnterWorld(Player player)
        {
            if (player.whoAmI != Main.myPlayer)
            {
                return;
            }
            if (this.player.whoAmI != Main.myPlayer)
            {
                return;
            }

            var mymod = (ResetModeMod)this.mod;

            if (mymod.Config.DebugModeInfo)
            {
                string uid = PlayerIdentityHelpers.GetUniqueId(player);

                LogHelpers.Alert(player.name + " joined (" + uid + ")");
            }

            if (Main.netMode == 0)
            {
                this.OnSingleEnterWorld();
            }
            if (Main.netMode == 1)
            {
                this.OnCurrentClientEnterWorld();
            }

            Timers.SetTimer("ResetModeDebugSync", 10 * 60, () => {
                if (!this.HasModSettings)
                {
                    Main.NewText("Failed to sync mod settings", Color.Red);
                    LogHelpers.Warn("Failed to sync mod settings (so far?)");
                }
                if (!this.HasSessionData)
                {
                    Main.NewText("Failed to sync session data", Color.Red);
                    LogHelpers.Warn("Failed to sync session data (so far?)");
                }
                if (!this.IsSynced)
                {
                    Main.NewText("Failed to sync", Color.Red);
                    LogHelpers.Warn("Failed to sync (so far?)");
                }
                return(false);
            });
        }
        public void UnloadOuter()
        {
            this.ReflectionHelpers         = null;
            this.PacketProtocolMngr        = null;
            this.ExceptionMngr             = null;
            this.Timers                    = null;
            this.ConfigJson                = null;
            this.LogHelpers                = null;
            this.ModFeaturesHelpers        = null;
            this.BuffHelpers               = null;
            this.NetHelpers                = null;
            this.ItemIdentityHelpers       = null;
            this.NPCIdentityHelpers        = null;
            this.ProjectileIdentityHelpers = null;
            this.BuffIdentityHelpers       = null;
            this.NPCBannerHelpers          = null;
            this.RecipeIdentityHelpers     = null;
            this.RecipeGroupHelpers        = null;
            this.PlayerHooks               = null;
            this.LoadHelpers               = null;
            this.GetModInfo                = null;
            this.GetModTags                = null;
            this.WorldStateHelpers         = null;
            this.ModLock                   = null;
            this.EntityGroups              = null;
            this.AnimatedColors            = null;
            this.PlayerMessages            = null;
            this.Inbox                 = null;
            this.ControlPanel          = null;
            this.MenuItemMngr          = null;
            this.MenuContextMngr       = null;
            this.MusicHelpers          = null;
            this.PlayerIdentityHelpers = null;
            this.CustomEntMngr         = null;
            this.Promises              = null;
            this.DataStore             = null;
            this.CustomHotkeys         = null;
            this.XnaHelpers            = null;
            this.ServerInfo            = null;
            //this.PlayerDataMngr = null;
            this.SupportInfo    = null;
            this.RecipeHack     = null;
            this.ModListHelpers = null;

            this.ControlPanelHotkey = null;
            this.DataDumpHotkey     = null;
        }
Example #15
0
        private void LoadModules()
        {
            this.Loadables.OnModsLoad();

            this.ReflectionHelpers = new ReflectionHelpers();
            this.DataStore         = new DataStore();
            this.LoadHooks         = new LoadHooks();
            this.CustomLoadHooks   = new CustomLoadHooks();
            this.LoadHelpers       = new LoadHelpers();

            this.Timers             = new Timers();
            this.LogHelpers         = new LogHelpers();
            this.ModFeaturesHelpers = new ModFeaturesHelpers();
            this.PacketProtocolMngr = new PacketProtocolManager();

            this.BuffHelpers                = new BuffHelpers();
            this.NetHelpers                 = new NetPlayHelpers();
            this.NPCAttributeHelpers        = new NPCAttributeHelpers();
            this.ProjectileAttributeHelpers = new ProjectileAttributeHelpers();
            this.BuffIdentityHelpers        = new BuffAttributesHelpers();
            this.NPCBannerHelpers           = new NPCBannerHelpers();
            this.RecipeFinderHelpers        = new RecipeFinderHelpers();
            this.RecipeGroupHelpers         = new RecipeGroupHelpers();
            this.PlayerHooks                = new ExtendedPlayerHooks();
            this.WorldTimeHooks             = new WorldTimeHooks();
            this.WorldStateHelpers          = new WorldStateHelpers();
            this.ControlPanel               = new UIControlPanel();
            this.ModLock               = new ModLockService();
            this.EntityGroups          = new EntityGroups();
            this.PlayerMessages        = new PlayerMessages();
            this.Inbox                 = new InboxControl();
            this.GetModInfo            = new GetModInfo();
            this.GetModTags            = new GetModTags();
            this.MenuItemMngr          = new MenuItemManager();
            this.MenuContextMngr       = new MenuContextServiceManager();
            this.MusicHelpers          = new MusicHelpers();
            this.PlayerIdentityHelpers = new PlayerIdentityHelpers();
            this.CustomHotkeys         = new CustomHotkeys();
            this.XnaHelpers            = new XNAHelpers();
            this.Server                = new Server();
            //this.PlayerDataMngr = new PlayerDataManager();
            this.SupportInfo          = new SupportInfoDisplay();
            this.RecipeHack           = new RecipeHack();
            this.ModListHelpers       = new ModListHelpers();
            this.ItemAttributeHelpers = new ItemAttributeHelpers();
        }
        private void LoadDataSources()
        {
            DataDumper.SetDumpSource("WorldUidWithSeed", () => {
                return("  " + WorldHelpers.GetUniqueIdWithSeed() + " (net mode: " + Main.netMode + ")");
            });

            DataDumper.SetDumpSource("PlayerUid", () => {
                if (Main.myPlayer < 0 || Main.myPlayer >= (Main.player.Length - 1))
                {
                    return("  Unobtainable");
                }

                bool _;
                string oldUid = PlayerIdentityHelpers._GetUniqueId(Main.LocalPlayer, out _);

                return("  " + PlayerIdentityHelpers.GetMyProperUniqueId() + " (old uid: " + oldUid + ")");
            });
        }
Example #17
0
        ////////////////

        public KillData GetPlayerData(Player player)
        {
            string uid = PlayerIdentityHelpers.GetUniqueId(player);

            if (uid == null)
            {
                return(null);
            }

            lock (WorldLogic.MyLock) {
                if (!this.PlayerData.ContainsKey(uid))
                {
                    this.PlayerData[uid] = new KillData();
                }

                return(this.PlayerData[uid]);
            }
        }
Example #18
0
        ////////////////

        protected override void Receive(int fromWho)
        {
            Player player = Main.player[fromWho];

            if (player == null || !player.active)
            {
                throw new ModHelpersException("Could not save. Player id " + fromWho + " invalid?");
            }

            var mymod    = RewardsMod.Instance;
            var myplayer = (RewardsPlayer)TmlHelpers.SafelyGetModPlayer(player, mymod, "RewardsPlayer");

            if (PlayerIdentityHelpers.GetUniqueId(player) != this.Uid)
            {
                throw new ModHelpersException("Could not save. Player UID mismatch for " + player.name + " (" + player.whoAmI + ")");
            }

            myplayer.SaveKillData();
        }
        protected override void InitializeServerRequestReplyDataOfClient(int toWho, int fromWho)
        {
            Player plr = Main.player[toWho];

            if (plr == null /*|| !plr.active*/)
            {
                LogHelpers.Warn("Player (" + toWho + ": " + (plr == null ? "null" : plr.name) + ") not available.");
                return;
            }

            string uid = PlayerIdentityHelpers.GetUniqueId(plr);

            if (uid == null)
            {
                return;
            }

            this.PrepareDataForPlayer(plr);
        }
Example #20
0
        internal static CustomEntity CreateRaw(Type mytype, CustomEntityCore core, IList <CustomEntityComponent> components, string ownerUid = "")
        {
            var ent = (CustomEntity)Activator.CreateInstance(mytype, BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { }, null);

            ent.Core           = core;
            ent.Components     = components;
            ent.OwnerPlayerWho = -1;
            ent.OwnerPlayerUID = ownerUid;

            Player plr = PlayerIdentityHelpers.GetPlayerByProperId(ownerUid);

            if (plr != null)
            {
                ent.OwnerPlayerWho = plr.whoAmI;
            }

            ent.OnClone();

            return(ent);
        }
        ////////////////

        public void SaveKillData()
        {
            var    mymod   = (RewardsMod)this.mod;
            var    myworld = ModContent.GetInstance <RewardsWorld>();
            string uid     = PlayerIdentityHelpers.GetUniqueId(this.player);

            KillData plrData = myworld.Logic.GetPlayerData(this.player);

            if (plrData == null)
            {
                LogHelpers.Warn("Could not save player kill data; no data found.");
                return;
            }

            plrData.Save(uid);

            if (mymod.SettingsConfig.DebugModeInfo)
            {
                LogHelpers.Alert("uid: " + uid + ", data: " + plrData.ToString());
            }
        }
Example #22
0
        ////////////////

        internal void RefreshOwnerWho()
        {
            if (Main.netMode == 1)
            {
                throw new HamstarException("No client.");
            }

            if (string.IsNullOrEmpty(this.OwnerPlayerUID))
            {
                this.OwnerPlayerWho = -1;
                return;
            }

            Player ownerPlr = PlayerIdentityHelpers.GetPlayerByProperId(this.OwnerPlayerUID);

            if (ownerPlr == null)
            {
                LogHelpers.Alert("No player found with UID " + this.OwnerPlayerUID);
            }

            this.OwnerPlayerWho = ownerPlr == null ? -1 : ownerPlr.whoAmI;
        }
Example #23
0
 public static int GetHash(Player player)
 {
     return(PlayerIdentityHelpers.GetVanillaSnapshotHash(player, true, false));
 }
        ////////////////

        public override void Action(CommandCaller caller, string input, string[] args)
        {
            string uid = PlayerIdentityHelpers.GetMyProperUniqueId();

            caller.Reply("Your user ID is: " + uid, Color.Lime);
        }
Example #25
0
        ////

        protected override void InitializeClientSendData()
        {
            this.Uid = PlayerIdentityHelpers.GetUniqueId();
        }
Example #26
0
        internal bool IsPlaying(Player player)
        {
            string uid = PlayerIdentityHelpers.GetUniqueId(player);

            return(this.Data.PlayersValidated.Contains(uid));
        }
        ////////////////

        public void LogRewardsPPSpending(Player player, float pp)
        {
            string pid = PlayerIdentityHelpers.GetUniqueId(player);

            this.Data.AddPlayerPPSpendingSync(pid, pp);
        }
Example #28
0
        ////////////////

        protected override void SetClientDefaults()
        {
            this.PlayerIds[Main.myPlayer] = PlayerIdentityHelpers.GetProperUniqueId(Main.LocalPlayer);
        }