Merge branch 'general-devel' of github.com:NyxStudios/TShock into general-devel
This commit is contained in:
commit
c36738e2ba
6 changed files with 128 additions and 109 deletions
|
|
@ -787,7 +787,7 @@ namespace TShockAPI
|
|||
(usingUUID && user.UUID == args.Player.UUID && !TShock.Config.DisableUUIDLogin &&
|
||||
!String.IsNullOrWhiteSpace(args.Player.UUID)))
|
||||
{
|
||||
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, TShock.Users.GetUserID(user.Name));
|
||||
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, user.ID);
|
||||
|
||||
var group = TShock.Utils.GetGroup(user.Group);
|
||||
|
||||
|
|
@ -4137,8 +4137,8 @@ namespace TShockAPI
|
|||
User user = TShock.Users.GetUserByID(userId);
|
||||
if (user != null)
|
||||
return user.Name;
|
||||
else
|
||||
return string.Concat("{ID: ", userId, "}");
|
||||
|
||||
return string.Concat("{ID: ", userId, "}");
|
||||
});
|
||||
List<string> extraLines = PaginationTools.BuildLinesFromTerms(sharedUsersSelector.Distinct());
|
||||
extraLines[0] = "Shared with: " + extraLines[0];
|
||||
|
|
@ -4201,10 +4201,8 @@ namespace TShockAPI
|
|||
if ((boundaryPoint.X + boundaryPoint.Y & 1) == 0)
|
||||
args.Player.SendTileSquare(boundaryPoint.X, boundaryPoint.Y, 1);
|
||||
|
||||
// ReSharper disable AccessToModifiedClosure
|
||||
Debug.Assert(boundaryHideTimer != null);
|
||||
boundaryHideTimer.Dispose();
|
||||
// ReSharper restore AccessToModifiedClosure
|
||||
},
|
||||
null, 5000, Timeout.Infinite
|
||||
);
|
||||
|
|
|
|||
|
|
@ -143,6 +143,11 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts player data to the tsCharacter database table
|
||||
/// </summary>
|
||||
/// <param name="player">player to take data from</param>
|
||||
/// <returns>true if inserted successfully</returns>
|
||||
public bool InsertPlayerData(TSPlayer player)
|
||||
{
|
||||
PlayerData playerData = player.PlayerData;
|
||||
|
|
@ -151,13 +156,13 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
|
||||
|
||||
if (!GetPlayerData(player, player.UserID).exists)
|
||||
if (!GetPlayerData(player, player.User.ID).exists)
|
||||
{
|
||||
try
|
||||
{
|
||||
database.Query(
|
||||
"INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals, skinColor, eyeColor, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18);",
|
||||
player.UserID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor),TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBitsByte(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor),TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished);
|
||||
player.User.ID, playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor),TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBitsByte(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor),TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -171,7 +176,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
database.Query(
|
||||
"UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15, skinColor = @16, eyeColor = @17, questsCompleted = @18 WHERE Account = @5;",
|
||||
playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.UserID, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBitsByte(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor), TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished);
|
||||
playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.User.ID, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBitsByte(player.TPlayer.hideVisual), TShock.Utils.EncodeColor(player.TPlayer.skinColor), TShock.Utils.EncodeColor(player.TPlayer.eyeColor), player.TPlayer.anglerQuestsFinished);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -182,6 +187,11 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a player's data from the tsCharacter database table
|
||||
/// </summary>
|
||||
/// <param name="userid">User ID of the player</param>
|
||||
/// <returns>true if removed successfully</returns>
|
||||
public bool RemovePlayer(int userid)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -334,6 +334,12 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an allowed user from a region
|
||||
/// </summary>
|
||||
/// <param name="regionName">Name of the region to modify</param>
|
||||
/// <param name="userName">Username to remove</param>
|
||||
/// <returns>true if removed successfully</returns>
|
||||
public bool RemoveUser(string regionName, string userName)
|
||||
{
|
||||
Region r = GetRegionByName(regionName);
|
||||
|
|
@ -349,6 +355,12 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a user to a region's allowed user list
|
||||
/// </summary>
|
||||
/// <param name="regionName">Name of the region to modify</param>
|
||||
/// <param name="userName">Username to add</param>
|
||||
/// <returns>true if added successfully</returns>
|
||||
public bool AddNewUser(string regionName, string userName)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.CodeDom.Compiler;
|
||||
using System.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -33,14 +32,14 @@ namespace TShockAPI.DB
|
|||
public class UserManager
|
||||
{
|
||||
/// <summary>database - The database object to use for connections.</summary>
|
||||
private IDbConnection database;
|
||||
private IDbConnection _database;
|
||||
|
||||
/// <summary>UserManager - Creates a UserManager object. During instantiation, this method will verify the table structure against the format below.</summary>
|
||||
/// <param name="db">db - The database to connect to.</param>
|
||||
/// <summary>Creates a UserManager object. During instantiation, this method will verify the table structure against the format below.</summary>
|
||||
/// <param name="db">The database to connect to.</param>
|
||||
/// <returns>A UserManager object.</returns>
|
||||
public UserManager(IDbConnection db)
|
||||
{
|
||||
database = db;
|
||||
_database = db;
|
||||
|
||||
var table = new SqlTable("Users",
|
||||
new SqlColumn("ID", MySqlDbType.Int32) {Primary = true, AutoIncrement = true},
|
||||
|
|
@ -71,7 +70,7 @@ namespace TShockAPI.DB
|
|||
int ret;
|
||||
try
|
||||
{
|
||||
ret = database.Query("INSERT INTO Users (Username, Password, UUID, UserGroup, Registered) VALUES (@0, @1, @2, @3, @4);", user.Name,
|
||||
ret = _database.Query("INSERT INTO Users (Username, Password, UUID, UserGroup, Registered) VALUES (@0, @1, @2, @3, @4);", user.Name,
|
||||
user.Password, user.UUID, user.Group, DateTime.UtcNow.ToString("s"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -97,7 +96,7 @@ namespace TShockAPI.DB
|
|||
try
|
||||
{
|
||||
var tempuser = GetUser(user);
|
||||
int affected = database.Query("DELETE FROM Users WHERE Username=@0", user.Name);
|
||||
int affected = _database.Query("DELETE FROM Users WHERE Username=@0", user.Name);
|
||||
|
||||
if (affected < 1)
|
||||
throw new UserNotExistException(user.Name);
|
||||
|
|
@ -120,7 +119,7 @@ namespace TShockAPI.DB
|
|||
try
|
||||
{
|
||||
if (
|
||||
database.Query("UPDATE Users SET Password = @0 WHERE Username = @1;", user.Password,
|
||||
_database.Query("UPDATE Users SET Password = @0 WHERE Username = @1;", user.Password,
|
||||
user.Name) == 0)
|
||||
throw new UserNotExistException(user.Name);
|
||||
}
|
||||
|
|
@ -140,7 +139,7 @@ namespace TShockAPI.DB
|
|||
try
|
||||
{
|
||||
if (
|
||||
database.Query("UPDATE Users SET UUID = @0 WHERE Username = @1;", uuid,
|
||||
_database.Query("UPDATE Users SET UUID = @0 WHERE Username = @1;", uuid,
|
||||
user.Name) == 0)
|
||||
throw new UserNotExistException(user.Name);
|
||||
}
|
||||
|
|
@ -163,7 +162,7 @@ namespace TShockAPI.DB
|
|||
if (null == grp)
|
||||
throw new GroupNotExistsException(group);
|
||||
|
||||
if (database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0)
|
||||
if (_database.Query("UPDATE Users SET UserGroup = @0 WHERE Username = @1;", group, user.Name) == 0)
|
||||
throw new UserNotExistException(user.Name);
|
||||
|
||||
// Update player group reference for any logged in player
|
||||
|
|
@ -178,13 +177,13 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>UpdateLogin - Updates the last accessed time for a database user to the current time.</summary>
|
||||
/// <param name="user">user - The user object to modify.</param>
|
||||
/// <summary>Updates the last accessed time for a database user to the current time.</summary>
|
||||
/// <param name="user">The user object to modify.</param>
|
||||
public void UpdateLogin(User user)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (database.Query("UPDATE Users SET LastAccessed = @0, KnownIps = @1 WHERE Username = @2;", DateTime.UtcNow.ToString("s"), user.KnownIps, user.Name) == 0)
|
||||
if (_database.Query("UPDATE Users SET LastAccessed = @0, KnownIps = @1 WHERE Username = @2;", DateTime.UtcNow.ToString("s"), user.KnownIps, user.Name) == 0)
|
||||
throw new UserNotExistException(user.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -193,14 +192,14 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>GetUserID - Gets the database ID of a given user object from the database.</summary>
|
||||
/// <param name="username">username - The username of the user to query for.</param>
|
||||
/// <returns>int - The user's ID</returns>
|
||||
/// <summary>Gets the database ID of a given user object from the database.</summary>
|
||||
/// <param name="username">The username of the user to query for.</param>
|
||||
/// <returns>The user's ID</returns>
|
||||
public int GetUserID(string username)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var reader = database.QueryReader("SELECT * FROM Users WHERE Username=@0", username))
|
||||
using (var reader = _database.QueryReader("SELECT * FROM Users WHERE Username=@0", username))
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
|
|
@ -215,9 +214,9 @@ namespace TShockAPI.DB
|
|||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>GetUserByName - Gets a user object by name.</summary>
|
||||
/// <param name="name">name - The user's name.</param>
|
||||
/// <returns>User - The user object returned from the search.</returns>
|
||||
/// <summary>Gets a user object by name.</summary>
|
||||
/// <param name="name">The user's name.</param>
|
||||
/// <returns>The user object returned from the search.</returns>
|
||||
public User GetUserByName(string name)
|
||||
{
|
||||
try
|
||||
|
|
@ -230,9 +229,9 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>GetUserByID - Gets a user object by their user ID.</summary>
|
||||
/// <param name="id">id - The user's ID.</param>
|
||||
/// <returns>User - The user object returned from the search.</returns>
|
||||
/// <summary>Gets a user object by their user ID.</summary>
|
||||
/// <param name="id">The user's ID.</param>
|
||||
/// <returns>The user object returned from the search.</returns>
|
||||
public User GetUserByID(int id)
|
||||
{
|
||||
try
|
||||
|
|
@ -245,9 +244,9 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>GetUser - Gets a user object by a user object.</summary>
|
||||
/// <param name="user">user - The user object to search by.</param>
|
||||
/// <returns>User - The user object that is returned from the search.</returns>
|
||||
/// <summary>Gets a user object by a user object.</summary>
|
||||
/// <param name="user">The user object to search by.</param>
|
||||
/// <returns>The user object that is returned from the search.</returns>
|
||||
public User GetUser(User user)
|
||||
{
|
||||
bool multiple = false;
|
||||
|
|
@ -269,7 +268,7 @@ namespace TShockAPI.DB
|
|||
|
||||
try
|
||||
{
|
||||
using (var result = database.QueryReader(query, arg))
|
||||
using (var result = _database.QueryReader(query, arg))
|
||||
{
|
||||
if (result.Read())
|
||||
{
|
||||
|
|
@ -291,14 +290,14 @@ namespace TShockAPI.DB
|
|||
throw new UserNotExistException(user.Name);
|
||||
}
|
||||
|
||||
/// <summary>GetUsers - Gets all users from the database.</summary>
|
||||
/// <returns>List - The users from the database.</returns>
|
||||
/// <summary>Gets all users from the database.</summary>
|
||||
/// <returns>The users from the database.</returns>
|
||||
public List<User> GetUsers()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<User> users = new List<User>();
|
||||
using (var reader = database.QueryReader("SELECT * FROM Users"))
|
||||
using (var reader = _database.QueryReader("SELECT * FROM Users"))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
|
|
@ -315,18 +314,18 @@ namespace TShockAPI.DB
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetUsersByName - Gets all users from the database with a username that starts with or contains <see cref="username"/>
|
||||
/// Gets all users from the database with a username that starts with or contains <see cref="username"/>
|
||||
/// </summary>
|
||||
/// <param name="username">String - Rough username search. "n" will match "n", "na", "nam", "name", etc</param>
|
||||
/// <param name="notAtStart">Boolean - If <see cref="username"/> is not the first part of the username. If true then "name" would match "name", "username", "wordsnamewords", etc</param>
|
||||
/// <returns>List or null - Matching users or null if exception is thrown</returns>
|
||||
/// <param name="username">Rough username search. "n" will match "n", "na", "nam", "name", etc</param>
|
||||
/// <param name="notAtStart">If <see cref="username"/> is not the first part of the username. If true then "name" would match "name", "username", "wordsnamewords", etc</param>
|
||||
/// <returns>Matching users or null if exception is thrown</returns>
|
||||
public List<User> GetUsersByName(string username, bool notAtStart = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<User> users = new List<User>();
|
||||
string search = notAtStart ? string.Format("%{0}%", username) : string.Format("{0}%", username);
|
||||
using (var reader = database.QueryReader("SELECT * FROM Users WHERE Username LIKE @0",
|
||||
using (var reader = _database.QueryReader("SELECT * FROM Users WHERE Username LIKE @0",
|
||||
search))
|
||||
{
|
||||
while (reader.Read())
|
||||
|
|
@ -343,10 +342,10 @@ namespace TShockAPI.DB
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>LoadUserFromResult - Fills out the fields of a User object with the results from a QueryResult object.</summary>
|
||||
/// <param name="user">user - The user to add data to.</param>
|
||||
/// <param name="result">result - The QueryResult object to add data from.</param>
|
||||
/// <returns>User - The 'filled out' user object.</returns>
|
||||
/// <summary>Fills out the fields of a User object with the results from a QueryResult object.</summary>
|
||||
/// <param name="user">The user to add data to.</param>
|
||||
/// <param name="result">The QueryResult object to add data from.</param>
|
||||
/// <returns>The 'filled out' user object.</returns>
|
||||
private User LoadUserFromResult(User user, QueryResult result)
|
||||
{
|
||||
user.ID = result.Get<int>("ID");
|
||||
|
|
@ -361,41 +360,41 @@ namespace TShockAPI.DB
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>User - A database user.</summary>
|
||||
/// <summary>A database user.</summary>
|
||||
public class User
|
||||
{
|
||||
/// <summary>ID - The database ID of the user.</summary>
|
||||
/// <summary>The database ID of the user.</summary>
|
||||
public int ID { get; set; }
|
||||
|
||||
/// <summary>Name - The user's name.</summary>
|
||||
/// <summary>The user's name.</summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>Password - The hashed password for the user.</summary>
|
||||
/// <summary>The hashed password for the user.</summary>
|
||||
public string Password { get; internal set; }
|
||||
|
||||
/// <summary>UUID - The user's saved Univerally Unique Identifier token.</summary>
|
||||
/// <summary>The user's saved Univerally Unique Identifier token.</summary>
|
||||
public string UUID { get; set; }
|
||||
|
||||
/// <summary>Group - The group object that the user is a part of.</summary>
|
||||
/// <summary>The group object that the user is a part of.</summary>
|
||||
public string Group { get; set; }
|
||||
|
||||
/// <summary>Registered - The unix epoch corresponding to the registration date of the user.</summary>
|
||||
/// <summary>The unix epoch corresponding to the registration date of the user.</summary>
|
||||
public string Registered { get; set; }
|
||||
|
||||
/// <summary>LastAccessed - The unix epoch corresponding to the last access date of the user.</summary>
|
||||
/// <summary>The unix epoch corresponding to the last access date of the user.</summary>
|
||||
public string LastAccessed { get; set; }
|
||||
|
||||
/// <summary>KnownIps - A JSON serialized list of known IP addresses for a user.</summary>
|
||||
/// <summary>A JSON serialized list of known IP addresses for a user.</summary>
|
||||
public string KnownIps { get; set; }
|
||||
|
||||
/// <summary>User - Constructor for the user object, assuming you define everything yourself.</summary>
|
||||
/// <param name="name">name - The user's name.</param>
|
||||
/// <param name="pass">pass - The user's password hash.</param>
|
||||
/// <param name="uuid">uuid - The user's UUID.</param>
|
||||
/// <param name="group">group - The user's group name.</param>
|
||||
/// <param name="registered">registered - The unix epoch for the registration date.</param>
|
||||
/// <param name="last">last - The unix epoch for the last access date.</param>
|
||||
/// <param name="known">known - The known IPs for the user, serialized as a JSON object</param>
|
||||
/// <summary>Constructor for the user object, assuming you define everything yourself.</summary>
|
||||
/// <param name="name">The user's name.</param>
|
||||
/// <param name="pass">The user's password hash.</param>
|
||||
/// <param name="uuid">The user's UUID.</param>
|
||||
/// <param name="group">The user's group name.</param>
|
||||
/// <param name="registered">The unix epoch for the registration date.</param>
|
||||
/// <param name="last">The unix epoch for the last access date.</param>
|
||||
/// <param name="known">The known IPs for the user, serialized as a JSON object</param>
|
||||
/// <returns>A completed user object.</returns>
|
||||
public User(string name, string pass, string uuid, string group, string registered, string last, string known)
|
||||
{
|
||||
|
|
@ -408,7 +407,7 @@ namespace TShockAPI.DB
|
|||
KnownIps = known;
|
||||
}
|
||||
|
||||
/// <summary>User - Default constructor for a user object; holds no data.</summary>
|
||||
/// <summary>Default constructor for a user object; holds no data.</summary>
|
||||
/// <returns>A user object.</returns>
|
||||
public User()
|
||||
{
|
||||
|
|
@ -427,13 +426,13 @@ namespace TShockAPI.DB
|
|||
/// If the password is stored using BCrypt, it will be re-saved if the work factor in the config
|
||||
/// is greater than the existing work factor with the new work factor.
|
||||
/// </summary>
|
||||
/// <param name="password">string password - The password to check against the user object.</param>
|
||||
/// <param name="password">The password to check against the user object.</param>
|
||||
/// <returns>bool true, if the password matched, or false, if it didn't.</returns>
|
||||
public bool VerifyPassword(string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (BCrypt.Net.BCrypt.Verify(password, this.Password))
|
||||
if (BCrypt.Net.BCrypt.Verify(password, Password))
|
||||
{
|
||||
// If necessary, perform an upgrade to the highest work factor.
|
||||
UpgradePasswordWorkFactor(password);
|
||||
|
|
@ -442,10 +441,10 @@ namespace TShockAPI.DB
|
|||
}
|
||||
catch (SaltParseException)
|
||||
{
|
||||
if (HashPassword(password).ToUpper() == this.Password.ToUpper())
|
||||
if (HashPassword(password).ToUpper() == Password.ToUpper())
|
||||
{
|
||||
// Return true to keep blank passwords working but don't convert them to bcrypt.
|
||||
if (this.Password == "non-existant password") {
|
||||
if (Password == "non-existant password") {
|
||||
return true;
|
||||
}
|
||||
// The password is not stored using BCrypt; upgrade it to BCrypt immediately
|
||||
|
|
@ -458,43 +457,43 @@ namespace TShockAPI.DB
|
|||
}
|
||||
|
||||
/// <summary>Upgrades a password to BCrypt, from an insecure hashing algorithm.</summary>
|
||||
/// <param name="password">string password - the raw user password (unhashed) to upgrade</param>
|
||||
/// <param name="password">The raw user password (unhashed) to upgrade</param>
|
||||
protected void UpgradePasswordToBCrypt(string password)
|
||||
{
|
||||
// Save the old password, in the event that we have to revert changes.
|
||||
string oldpassword = this.Password;
|
||||
string oldpassword = Password;
|
||||
|
||||
// Convert the password to BCrypt, and save it.
|
||||
try
|
||||
{
|
||||
this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.BCryptWorkFactor);
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.BCryptWorkFactor);
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
TShock.Log.ConsoleError("Invalid BCrypt work factor in config file! Upgrading user password to BCrypt using default work factor.");
|
||||
this.Password = BCrypt.Net.BCrypt.HashPassword(password);
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(password);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TShock.Users.SetUserPassword(this, this.Password);
|
||||
TShock.Users.SetUserPassword(this, Password);
|
||||
}
|
||||
catch (UserManagerException e)
|
||||
{
|
||||
TShock.Log.ConsoleError(e.ToString());
|
||||
this.Password = oldpassword; // Revert changes
|
||||
Password = oldpassword; // Revert changes
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Upgrades a password to the highest work factor available in the config.</summary>
|
||||
/// <param name="password">string password - the raw user password (unhashed) to upgrade</param>
|
||||
/// <param name="password">The raw user password (unhashed) to upgrade</param>
|
||||
protected void UpgradePasswordWorkFactor(string password)
|
||||
{
|
||||
// If the destination work factor is not greater, we won't upgrade it or re-hash it
|
||||
int currentWorkFactor = 0;
|
||||
int currentWorkFactor;
|
||||
try
|
||||
{
|
||||
currentWorkFactor = Int32.Parse((this.Password.Split('$')[2]));
|
||||
currentWorkFactor = Int32.Parse((Password.Split('$')[2]));
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
|
|
@ -506,7 +505,7 @@ namespace TShockAPI.DB
|
|||
{
|
||||
try
|
||||
{
|
||||
this.Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.BCryptWorkFactor);
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(password, TShock.Config.BCryptWorkFactor);
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
|
|
@ -515,7 +514,7 @@ namespace TShockAPI.DB
|
|||
|
||||
try
|
||||
{
|
||||
TShock.Users.SetUserPassword(this, this.Password);
|
||||
TShock.Users.SetUserPassword(this, Password);
|
||||
}
|
||||
catch (UserManagerException e)
|
||||
{
|
||||
|
|
@ -525,7 +524,7 @@ namespace TShockAPI.DB
|
|||
}
|
||||
|
||||
/// <summary>Creates a BCrypt hash for a user and stores it in this object.</summary>
|
||||
/// <param name="password">string password - the plain text password to hash</param>
|
||||
/// <param name="password">The plain text password to hash</param>
|
||||
public void CreateBCryptHash(string password)
|
||||
{
|
||||
if (password.Trim().Length < Math.Max(4, TShock.Config.MinimumPasswordLength))
|
||||
|
|
@ -534,25 +533,25 @@ namespace TShockAPI.DB
|
|||
}
|
||||
try
|
||||
{
|
||||
this.Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), TShock.Config.BCryptWorkFactor);
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), TShock.Config.BCryptWorkFactor);
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
TShock.Log.ConsoleError("Invalid BCrypt work factor in config file! Creating new hash using default work factor.");
|
||||
this.Password = BCrypt.Net.BCrypt.HashPassword(password.Trim());
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Creates a BCrypt hash for a user and stores it in this object.</summary>
|
||||
/// <param name="password">string password - the plain text password to hash</param>
|
||||
/// <param name="workFactor">int workFactor - the work factor to use in generating the password hash</param>
|
||||
/// <param name="password">The plain text password to hash</param>
|
||||
/// <param name="workFactor">The work factor to use in generating the password hash</param>
|
||||
public void CreateBCryptHash(string password, int workFactor)
|
||||
{
|
||||
if (password.Trim().Length < Math.Max(4, TShock.Config.MinimumPasswordLength))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("password", "Password must be > " + TShock.Config.MinimumPasswordLength + " characters.");
|
||||
}
|
||||
this.Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), workFactor);
|
||||
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), workFactor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -595,7 +594,7 @@ namespace TShockAPI.DB
|
|||
/// <returns>string hash</returns>
|
||||
protected string HashPassword(string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password) && this.Password == "non-existant password")
|
||||
if (string.IsNullOrEmpty(password) && Password == "non-existant password")
|
||||
return "non-existant password";
|
||||
return HashPassword(Encoding.UTF8.GetBytes(password));
|
||||
}
|
||||
|
|
@ -606,57 +605,57 @@ namespace TShockAPI.DB
|
|||
[Serializable]
|
||||
public class UserManagerException : Exception
|
||||
{
|
||||
/// <summary>UserManagerException - Creates a new UserManagerException object.</summary>
|
||||
/// <param name="message">message - The message for the object.</param>
|
||||
/// <returns>public - a new UserManagerException object.</returns>
|
||||
/// <summary>Creates a new UserManagerException object.</summary>
|
||||
/// <param name="message">The message for the object.</param>
|
||||
/// <returns>A new UserManagerException object.</returns>
|
||||
public UserManagerException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>UserManagerException - Creates a new UserManagerObject with an internal exception.</summary>
|
||||
/// <param name="message">message - The message for the object.</param>
|
||||
/// <param name="inner">inner - The inner exception for the object.</param>
|
||||
/// <returns>public - a nwe UserManagerException with a defined inner exception.</returns>
|
||||
/// <summary>Creates a new UserManagerObject with an internal exception.</summary>
|
||||
/// <param name="message">The message for the object.</param>
|
||||
/// <param name="inner">The inner exception for the object.</param>
|
||||
/// <returns>A new UserManagerException with a defined inner exception.</returns>
|
||||
public UserManagerException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>UserExistsException - A UserExistsException object, used when a user already exists when attempting to create a new one.</summary>
|
||||
/// <summary>A UserExistsException object, used when a user already exists when attempting to create a new one.</summary>
|
||||
[Serializable]
|
||||
public class UserExistsException : UserManagerException
|
||||
{
|
||||
/// <summary>UserExistsException - Creates a new UserExistsException object.</summary>
|
||||
/// <param name="name">name - The name of the user that already exists.</param>
|
||||
/// <returns>public - a UserExistsException object with the user's name passed in the message.</returns>
|
||||
/// <summary>Creates a new UserExistsException object.</summary>
|
||||
/// <param name="name">The name of the user that already exists.</param>
|
||||
/// <returns>A UserExistsException object with the user's name passed in the message.</returns>
|
||||
public UserExistsException(string name)
|
||||
: base("User '" + name + "' already exists")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>UserNotExistException - A UserNotExistException, used when a user does not exist and a query failed as a result of it.</summary>
|
||||
/// <summary>A UserNotExistException, used when a user does not exist and a query failed as a result of it.</summary>
|
||||
[Serializable]
|
||||
public class UserNotExistException : UserManagerException
|
||||
{
|
||||
/// <summary>UserNotExistException - Creates a new UserNotExistException object, with the user's name in the message.</summary>
|
||||
/// <param name="name">name - The user's name to be pasesd in the message.</param>
|
||||
/// <returns>public - a new UserNotExistException object with a message containing the user's name that does not exist.</returns>
|
||||
/// <summary>Creates a new UserNotExistException object, with the user's name in the message.</summary>
|
||||
/// <param name="name">The user's name to be pasesd in the message.</param>
|
||||
/// <returns>A new UserNotExistException object with a message containing the user's name that does not exist.</returns>
|
||||
public UserNotExistException(string name)
|
||||
: base("User '" + name + "' does not exist")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>GroupNotExistsException - A GroupNotExistsException, used when a group does not exist.</summary>
|
||||
/// <summary>A GroupNotExistsException, used when a group does not exist.</summary>
|
||||
[Serializable]
|
||||
public class GroupNotExistsException : UserManagerException
|
||||
{
|
||||
/// <summary>GroupNotExistsException - Creates a new GroupNotExistsException object with the group's name in the message.</summary>
|
||||
/// <param name="group">group - The group name.</param>
|
||||
/// <returns>public - a new GroupNotExistsException with the group that does not exist's name in the message.</returns>
|
||||
/// <summary>Creates a new GroupNotExistsException object with the group's name in the message.</summary>
|
||||
/// <param name="group">The group name.</param>
|
||||
/// <returns>A new GroupNotExistsException with the group that does not exist's name in the message.</returns>
|
||||
public GroupNotExistsException(string group)
|
||||
: base("Group '" + group + "' does not exist")
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1438,7 +1438,7 @@ namespace TShockAPI
|
|||
{
|
||||
if(user.UUID == args.Player.UUID)
|
||||
{
|
||||
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, TShock.Users.GetUserID(args.Player.Name));
|
||||
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, user.ID);
|
||||
|
||||
if (args.Player.State == 1)
|
||||
args.Player.State = 2;
|
||||
|
|
@ -1514,7 +1514,7 @@ namespace TShockAPI
|
|||
if (user.VerifyPassword(password))
|
||||
{
|
||||
args.Player.RequiresPassword = false;
|
||||
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, TShock.Users.GetUserID(args.Player.Name));
|
||||
args.Player.PlayerData = TShock.CharacterDB.GetPlayerData(args.Player, user.ID);
|
||||
|
||||
if (args.Player.State == 1)
|
||||
args.Player.State = 2;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ namespace TShockAPI
|
|||
{
|
||||
if (includeIDs)
|
||||
{
|
||||
players.Add(ply.Name + " (IX: " + ply.Index + ", ID: " + ply.UserID + ")");
|
||||
players.Add(ply.Name + " (IX: " + ply.Index + ", ID: " + ply.User.ID + ")");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue