Beispiel #1
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);
            }
        }
        ////

        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;
        }
        ////////////////

        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());
            }
        }
 public void PreUpdateSyncedServerForPlayer(Player player)
 {
     if (PlayerIdentityHelpers.GetUniqueId(player) != null)
     {
         this.CheckValidationOnHost(player);
     }
 }
Beispiel #5
0
        internal void AddPlayer(Player player)
        {
            string uid = PlayerIdentityHelpers.GetUniqueId(player);

            this.Data.PlayersValidated.Add(uid);
            if (Main.netMode != 1)
            {
                this.Save();
            }
        }
        /// <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));
        }
Beispiel #7
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());
            });
        }
Beispiel #8
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);
            });
        }
Beispiel #9
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);
            }
        }
Beispiel #10
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]);
            }
        }
Beispiel #11
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);
        }
        ////////////////

        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());
            }
        }
        ////////////////

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

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

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

            this.Data.AddPlayerPPSpendingSync(pid, pp);
        }
Beispiel #16
0
        ////

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

            return(this.Data.PlayersValidated.Contains(uid));
        }
Beispiel #18
0
        ////////////////

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