Skip to content
This repository was archived by the owner on Nov 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions AutoRegister/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Terraria;
using Terraria.Localization;
Expand All @@ -27,7 +25,7 @@ public class Plugin : TerrariaPlugin
/// <summary>
/// The version of the plugin in its current state.
/// </summary>
public override Version Version => new Version(1, 0, 1);
public override Version Version => new Version(1, 1, 0);

/// <summary>
/// The author(s) of the plugin.
Expand Down Expand Up @@ -78,12 +76,17 @@ void OnGreetPlayer(GreetPlayerEventArgs args)
{
try
{
player.SendSuccessMessage($"New server-side character created successfully! Your password is \"{newPass}\".");
player.SendSuccessMessage($"Contact an admin if you lose access to this account, or forget your password.");
player.SendSuccessMessage($"Account \"{player.Name}\" has been registered.");
player.SendSuccessMessage("Your password is " + newPass);
}
catch { }
tmpPasswords.Remove(player.Name + player.UUID + player.IP);
}
else if (!player.IsLoggedIn)
{
player.SendErrorMessage("Sorry, " + player.Name + " was already taken by another person.");
player.SendErrorMessage("Please try a different username.");
}
}

/// <summary>
Expand All @@ -96,15 +99,12 @@ void OnServerJoin(JoinEventArgs args)
{
var player = TShock.Players[args.Who];

// Get the user using a combo of their UUID/name, as this is what's required for uuid login to function it seems
var users = TShock.Users.GetUsers().Where(u => u.UUID == player.UUID && u.Name == player.Name);
if (users.Count() == 0)
if (TShock.UserAccounts.GetUserAccountByName(player.Name) == null && player.Name != TSServerPlayer.AccountName)
{
Log($"Creating new user for {player.Name}...");

// If the user didn't exist, generate a password for them then create a new user based on their uuid/username
tmpPasswords[player.Name + player.UUID + player.IP] = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 10);
TShock.Users.AddUser(new User(
tmpPasswords[player.Name + player.UUID + player.IP] =
Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 10).Replace('l', 'L')
.Replace('1', '7').Replace('I', 'i').Replace('O', 'o').Replace('0', 'o');
TShock.UserAccounts.AddUserAccount(new UserAccount(
player.Name,
BCrypt.Net.BCrypt.HashPassword(tmpPasswords[player.Name + player.UUID + player.IP].Trim()),
player.UUID,
Expand All @@ -113,7 +113,7 @@ void OnServerJoin(JoinEventArgs args)
DateTime.UtcNow.ToString("s"),
""));

Log("Success!");
TShock.Log.ConsoleInfo(player.Name + $" registered an account: \"{player.Name}\"");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions AutoRegister/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Mod Info
AutoRegister is a TShock plugin created to automatically register new users on SSC enabled servers.

# How it works
When a new user joins a server AutoRegister checks to see if there is already a user present with their name/uuid. If there isn't, a new user is automatically created for them. The password which is generated is then posted in chat for them to either save, or change.
## Overview
### How it works
When a new user joins a server, AutoRegister checks to see if there is an existing user with their name/UUID in the database. If there isn't, a new user account is automatically created for the new player. The randomly generated password is then posted in the chat for them to save or change.

### Features
- Enables seamless onboarding of new players on SSC-enabled servers. No more players getting confused and bombarding the host with "Why am I stoned/frozen/webbed/stuck?" questions.
- Automatically register a new account with a randomly generated password if an account by the player's name does not exist in the database.
- Users will be notified in the chat of their newly AutoRegistered account and randomly generated password, which they can change later.
- If an account by the same name as the new player already exist in the database, he/she will be notified in the chat to try a different username.
- Automatic registration success or failure is present in the same way as TShock for improved clarity and cohesion.
- Writes to server console and logs if a new user was successfully registered.
- Compatible with PC TShock 4.3.26 (Zombie/Mintaka) and Mobile TShock 4.3.26 (Bellatrix)

## Installation Guide
1. Copy and paste AutoRegister.dll into your ServerPlugins folder. That's it.
2. If the server is running, restart it. Otherwise start the server.

## Source
[AutoRegister](https://tshock.co/xf/index.php?resources/autoregister.234/)