Beispiel #1
0
        private static void PostLogin(PlayerPostLoginEventArgs args)
        {
            if (args.Player == null)
            {
                return;
            }
            if (args.Player.Name != args.Player.UserAccountName) //returns if player logs in as different name
            {
                return;
            }

            var player = Players.GetByUsername(args.Player.UserAccountName);

            if (player != null)
            {
                player.tsPlayer = args.Player;
            }
            else
            {
                player = new TrPlayer(args.Player.UserAccountName, 0, DateTime.UtcNow.ToString("G"),
                                      DateTime.UtcNow.ToString("G"), 0)
                {
                    tsPlayer = args.Player
                };
                Players.Add(player);

                if (!dbManager.InsertPlayer(player))
                {
                    TShock.Log.ConsoleError("[TimeRanks] Failed to create storage for {0}.", player.name);
                }
                else
                {
                    TShock.Log.ConsoleInfo("[TimeRanks] Created storage for {0}.", player.name);
                }
            }

            if (args.Player.Group.Name == config.StartGroup && config.Groups.Count > 1)                                             //starting rank/new player
            {
                TShock.Users.SetUserGroup(TShock.Users.GetUserByName(args.Player.UserAccountName), config.Groups.Keys.ToList()[0]); //AutoStarts the player to the config's first rank.
            }
            if (player.LastOnline.TotalSeconds > player.RankInfo.derankCost && player.RankInfo.derankCost > 0)                      //if not a new/starting player and passes inactivity limit. 0 = no limit
            {
                var groupIndex = TimeRanks.config.Groups.Keys.ToList().IndexOf(player.Group) - 1;
                if (groupIndex < 0)
                {
                    return;
                }
                player.time = 0; //resets player's activeness time back to 0, excluding first rank

                var user = TShock.Users.GetUserByName(player.name);

                TShock.Users.SetUserGroup(user, TimeRanks.config.Groups.Keys.ElementAt(groupIndex));
                args.Player.SendInfoMessage("You have been demoted to " + player.Group + " due to inactivity!");
                TShock.Log.ConsoleInfo(user.Name + " has been dropped a rank due to inactivity");
            }
        }
Beispiel #2
0
 public void Add(TrPlayer player)
 {
     _players.Add(player);
 }
Beispiel #3
0
 public bool SavePlayer(TrPlayer player)
 {
     player.lastlogin = DateTime.UtcNow.ToString("G");
     return(_db.Query("UPDATE TimeRanks SET Time = @0, LastLogin = @1, TotalTime = @2 WHERE Name = @3",
                      player.time, player.lastlogin, player.totaltime, player.name) != 0);
 }
Beispiel #4
0
 public bool InsertPlayer(TrPlayer player)
 {
     return(_db.Query("INSERT INTO TimeRanks (Name, Time, FirstLogin, Lastlogin, TotalTime)" + "VALUES (@0, @1, @2, @3, @4)", player.name, player.time, player.firstlogin, player.lastlogin, player.totaltime) != 0);
 }