/// <summary> /// Updates a player's saved statistics /// </summary> /// <param name="player"></param> /// <returns></returns> public bool savePlayer(TrPlayer player) { player.lastLogin = DateTime.UtcNow.ToString("G"); return _db.Query("UPDATE TimeBasedRanking SET Time = @0, LastLogin = @1," + " Experience = @2 WHERE Name = @3", player.time, player.lastLogin, player.points, player.name) != 0; }
/// <summary> /// Handles login events. Syncs the player's stored stats if they have them /// </summary> /// <param name="e"></param> private void PostLogin(TShockAPI.Hooks.PlayerPostLoginEventArgs e) { if (config.AutoStartUsers && e.Player.Group.Name == config.StartGroup) TShock.Users.SetUserGroup( TShock.Users.GetUserByName(e.Player.UserAccountName), config.Groups.Keys.ToList()[0]); if (Tools.GetPlayerByName(e.Player.UserAccountName) != null) { var player = Tools.GetPlayerByName(e.Player.UserAccountName); player.index = e.Player.Index; player.online = true; } else { if (Tools.GetPlayerByName("~^" + e.Player.Name) != null) { var player = Tools.GetPlayerByName("~^" + e.Player.Name); player.name = e.Player.UserAccountName; if (player.index != e.Player.Index) player.index = e.Player.Index; player.online = true; if (!dbManager.insertPlayer(player)) Log.ConsoleError("[TimeRanks] Failed to create storage for {0}.", player.name); else Log.ConsoleInfo("[TimeRanks] Created storage for {0}.", player.name); } else { var player = new TrPlayer(e.Player.UserAccountName, 0, DateTime.UtcNow.ToString("G"), DateTime.UtcNow.ToString("G"), 0) {index = e.Player.Index, online = true}; Tools.Players.Add(player); if (!dbManager.insertPlayer(player)) Log.ConsoleError("[TimeRanks] Failed to create storage for {0}.", player.name); else Log.ConsoleInfo("[TimeRanks] Created storage for {0}.", player.name); } } }
/// <summary> /// Inserts a player into the database. Is only called for players that do not exist already. /// </summary> /// <param name="player">Player to insert</param> public bool insertPlayer(TrPlayer player) { return _db.Query("INSERT INTO TimeBasedRanking (Name, Time, FirstLogin, LastLogin, Experience)" + " VALUES (@0, @1, @2, @3, @4)", player.name, player.time, player.firstLogin, player.lastLogin, player.points) != 0; }
/// <summary> /// Handles greet events. /// </summary> /// <param name="args"></param> private void OnGreet(GreetPlayerEventArgs args) { if (!TShock.Config.DisableUUIDLogin) { if (TShock.Players[args.Who].IsLoggedIn) PostLogin(new TShockAPI.Hooks.PlayerPostLoginEventArgs(TShock.Players[args.Who])); else { var player = new TrPlayer("~^" + TShock.Players[args.Who].Name, 0, DateTime.UtcNow.ToString("G"), DateTime.UtcNow.ToString("G"), 0) {index = args.Who, online = true}; Tools.Players.Add(player); } } else { var player = new TrPlayer("~^" + TShock.Players[args.Who].Name, 0, DateTime.UtcNow.ToString("G"), DateTime.UtcNow.ToString("G"), 0) {index = args.Who, online = true}; Tools.Players.Add(player); } }