Auth system now checks if a superadmin exists
The 'auth-verify' command was also removed and its alias was added to 'auth', which now does both things.
This commit is contained in:
parent
1c9faa84a8
commit
b6267bbaa7
2 changed files with 56 additions and 64 deletions
|
|
@ -208,15 +208,11 @@ namespace TShockAPI
|
||||||
ChatCommands.Add(cmd);
|
ChatCommands.Add(cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
add(new Command(AuthToken, "auth")
|
add(new Command(AuthToken, "auth", "auth-verify")
|
||||||
{
|
{
|
||||||
AllowServer = false,
|
AllowServer = false,
|
||||||
HelpText = "Used to authenticate as superadmin when first setting up TShock."
|
HelpText = "Used to authenticate as superadmin when first setting up TShock."
|
||||||
});
|
});
|
||||||
add(new Command(Permissions.authverify, AuthVerify, "auth-verify")
|
|
||||||
{
|
|
||||||
HelpText = "Used to verify that you have correctly set up TShock."
|
|
||||||
});
|
|
||||||
add(new Command(Permissions.user, ManageUsers, "user")
|
add(new Command(Permissions.user, ManageUsers, "user")
|
||||||
{
|
{
|
||||||
DoLog = false,
|
DoLog = false,
|
||||||
|
|
@ -4627,56 +4623,45 @@ namespace TShockAPI
|
||||||
TShock.Log.Warn("{0} attempted to use {1}auth even though it's disabled.", args.Player.IP, Specifier);
|
TShock.Log.Warn("{0} attempted to use {1}auth even though it's disabled.", args.Player.IP, Specifier);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int givenCode = Convert.ToInt32(args.Parameters[0]);
|
|
||||||
if (givenCode == TShock.AuthToken && args.Player.Group.Name != "superadmin")
|
// If the user account is already a superadmin (permanent), disable the system
|
||||||
|
if (args.Player.IsLoggedIn && args.Player.tempGroup == null && args.Player.Group.Name == new SuperAdminGroup().Name)
|
||||||
{
|
{
|
||||||
try
|
args.Player.SendSuccessMessage("Your new account has been verified, and the {0}auth system has been turned off.", Specifier);
|
||||||
{
|
args.Player.SendSuccessMessage("You can always use the {0}user command to manage players.", Specifier);
|
||||||
args.Player.Group = TShock.Utils.GetGroup("superadmin");
|
args.Player.SendSuccessMessage("The auth system will remain disabled as long as a superadmin exists (even if you delete auth.lck).");
|
||||||
args.Player.SendInfoMessage("Superadmin has been temporarily given to you. It will be removed on logout.");
|
args.Player.SendSuccessMessage("Share your server, talk with other admins, and more on our forums -- https://tshock.co/");
|
||||||
args.Player.SendInfoMessage("Please use the following to create a permanent account for you.");
|
args.Player.SendSuccessMessage("Thank you for using TShock for Terraria!");
|
||||||
args.Player.SendInfoMessage("{0}user add <username> <password> superadmin", Specifier);
|
FileTools.CreateFile(Path.Combine(TShock.SavePath, "auth.lck"));
|
||||||
args.Player.SendInfoMessage("Creates: <username> with the password <password> as part of the superadmin group.");
|
File.Delete(Path.Combine(TShock.SavePath, "authcode.txt"));
|
||||||
args.Player.SendInfoMessage("Please use {0}login <username> <password> after this process.", Specifier);
|
TShock.AuthToken = 0;
|
||||||
args.Player.SendInfoMessage("If you understand, please {0}login <username> <password> now, and type {0}auth-verify.", Specifier);
|
|
||||||
}
|
|
||||||
catch (UserManagerException ex)
|
|
||||||
{
|
|
||||||
TShock.Log.ConsoleError(ex.ToString());
|
|
||||||
args.Player.SendErrorMessage(ex.Message);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.Player.Group.Name == "superadmin")
|
if (args.Parameters.Count == 0)
|
||||||
{
|
{
|
||||||
args.Player.SendInfoMessage("Please disable the auth system! If you need help, consult the forums. https://tshock.co/");
|
args.Player.SendErrorMessage("You must provide an auth code!");
|
||||||
args.Player.SendInfoMessage("This account is superadmin, please do the following to finish your install:");
|
|
||||||
args.Player.SendInfoMessage("Please use {0}login <username> <password> to login from now on.", Specifier);
|
|
||||||
args.Player.SendInfoMessage("If you understand, please {0}login <username> <password> now, and type {0}auth-verify.", Specifier);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Player.SendErrorMessage("Incorrect auth code. This incident has been logged.");
|
int givenCode;
|
||||||
TShock.Log.Warn(args.Player.IP + " attempted to use an incorrect auth code.");
|
if (!Int32.TryParse(args.Parameters[0], out givenCode) || givenCode != TShock.AuthToken)
|
||||||
}
|
|
||||||
|
|
||||||
private static void AuthVerify(CommandArgs args)
|
|
||||||
{
|
|
||||||
if (TShock.AuthToken == 0)
|
|
||||||
{
|
{
|
||||||
args.Player.SendWarningMessage("It appears that you have already turned off the auth token.");
|
args.Player.SendErrorMessage("Incorrect auth code. This incident has been logged.");
|
||||||
args.Player.SendWarningMessage("If this is a mistake, delete auth.lck.");
|
TShock.Log.Warn(args.Player.IP + " attempted to use an incorrect auth code.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Player.SendSuccessMessage("Your new account has been verified, and the /auth system has been turned off.");
|
if (args.Player.Group.Name != "superadmin")
|
||||||
args.Player.SendSuccessMessage("You can always use the /user command to manage players. Don't just delete the auth.lck.");
|
args.Player.tempGroup = new SuperAdminGroup();
|
||||||
args.Player.SendSuccessMessage("Share your server, talk with other admins, and more on our forums -- https://tshock.co/");
|
|
||||||
args.Player.SendSuccessMessage("Thank you for using TShock for Terraria!");
|
args.Player.SendInfoMessage("Superadmin has been temporarily given to you. It will be removed on logout.");
|
||||||
FileTools.CreateFile(Path.Combine(TShock.SavePath, "auth.lck"));
|
args.Player.SendInfoMessage("Please use the following to create a permanent account for you.");
|
||||||
File.Delete(Path.Combine(TShock.SavePath, "authcode.txt"));
|
args.Player.SendInfoMessage("{0}user add <username> <password> superadmin", Specifier);
|
||||||
TShock.AuthToken = 0;
|
args.Player.SendInfoMessage("Creates: <username> with the password <password> as part of the superadmin group.");
|
||||||
|
args.Player.SendInfoMessage("Please use {0}login <username> <password> after this process.", Specifier);
|
||||||
|
args.Player.SendInfoMessage("If you understand, please {0}login <username> <password> now, and then type {0}auth.", Specifier);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ThirdPerson(CommandArgs args)
|
private static void ThirdPerson(CommandArgs args)
|
||||||
|
|
|
||||||
|
|
@ -789,36 +789,43 @@ namespace TShockAPI
|
||||||
private void OnPostInit(EventArgs args)
|
private void OnPostInit(EventArgs args)
|
||||||
{
|
{
|
||||||
SetConsoleTitle(false);
|
SetConsoleTitle(false);
|
||||||
if (!File.Exists(Path.Combine(SavePath, "auth.lck")) && !File.Exists(Path.Combine(SavePath, "authcode.txt")))
|
|
||||||
|
// Disable the auth system if "auth.lck" is present or a superadmin exists
|
||||||
|
if (File.Exists(Path.Combine(SavePath, "auth.lck")) || Users.GetUsers().Exists(u => u.Group == new SuperAdminGroup().Name))
|
||||||
|
{
|
||||||
|
AuthToken = 0;
|
||||||
|
|
||||||
|
if (File.Exists(Path.Combine(SavePath, "authcode.txt")))
|
||||||
|
{
|
||||||
|
Log.ConsoleInfo("A superadmin account has been detected in the user database, but authcode.txt is still present.");
|
||||||
|
Log.ConsoleInfo("TShock will now disable the auth system and remove authcode.txt as it is no longer needed.");
|
||||||
|
File.Delete(Path.Combine(SavePath, "authcode.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(Path.Combine(SavePath, "auth.lck")))
|
||||||
|
{
|
||||||
|
// This avoids unnecessary database work, which can get ridiculously high on old servers as all users need to be fetched
|
||||||
|
File.Create(Path.Combine(SavePath, "auth.lck"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!File.Exists(Path.Combine(SavePath, "authcode.txt")))
|
||||||
{
|
{
|
||||||
var r = new Random((int)DateTime.Now.ToBinary());
|
var r = new Random((int)DateTime.Now.ToBinary());
|
||||||
AuthToken = r.Next(100000, 10000000);
|
AuthToken = r.Next(100000, 10000000);
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type {0}auth {1}", Commands.Specifier, AuthToken);
|
Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type {0}auth {1}", Commands.Specifier, AuthToken);
|
||||||
Console.WriteLine("This token will display until disabled by verification. ({0}auth-verify)", Commands.Specifier);
|
Console.WriteLine("This token will display until disabled by verification. ({0}auth-verify)", Commands.Specifier);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ResetColor();
|
||||||
FileTools.CreateFile(Path.Combine(SavePath, "authcode.txt"));
|
File.WriteAllText(Path.Combine(SavePath, "authcode.txt"), AuthToken.ToString());
|
||||||
using (var tw = new StreamWriter(Path.Combine(SavePath, "authcode.txt")))
|
|
||||||
{
|
|
||||||
tw.WriteLine(AuthToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (File.Exists(Path.Combine(SavePath, "authcode.txt")))
|
|
||||||
{
|
|
||||||
using (var tr = new StreamReader(Path.Combine(SavePath, "authcode.txt")))
|
|
||||||
{
|
|
||||||
AuthToken = Convert.ToInt32(tr.ReadLine());
|
|
||||||
}
|
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
||||||
Console.WriteLine(
|
|
||||||
"TShock Notice: authcode.txt is still present, and the AuthToken located in that file will be used.");
|
|
||||||
Console.WriteLine("To become superadmin, join the game and type {0}auth {1}", Commands.Specifier, AuthToken);
|
|
||||||
Console.WriteLine("This token will display until disabled by verification. ({0}auth-verify)", Commands.Specifier);
|
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AuthToken = 0;
|
AuthToken = Convert.ToInt32(File.ReadAllText(Path.Combine(SavePath, "authcode.txt")));
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine("TShock Notice: authcode.txt is still present, and the AuthToken located in that file will be used.");
|
||||||
|
Console.WriteLine("To become superadmin, join the game and type {0}auth {1}", Commands.Specifier, AuthToken);
|
||||||
|
Console.WriteLine("This token will display until disabled by verification. ({0}auth)", Commands.Specifier);
|
||||||
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
Regions.Reload();
|
Regions.Reload();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue