* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand. * WIP - Rewriting packets. * Cleanup and updates README * Converts more packets * Fixes header * Converts Effects packets. * Forgot the send command * Adds the start of containers packets. * Adds message packets with caching * Extends the send methods * Starts to add Acquire methods * Converted the packets * Cleanup * Cleanup * Adds more packets * Adds more packets * Fixes clearing arrays from pool. Adds Mobile Incoming * Converts more packets. * Moves more packets * Moves more packets * Test compression * Merges * Migrating to an idiomatic syntax that also supports compression, and proxying. * Optimize the stack alloc. Changes attributes * Converted container packets * Visual Studio doesn't auto save files. I am still getting used to subpar IDEs. * Adds static packet caching. Will profile later. Converts more packets * Fixes packets and changes how compression is configured * WIP - Adds basics for Gumps. Not finished though. * Fix file * Fixes formatting * Changed SpanWriter to be more idiomatic. * Fixes Span vs RawSpan and missing stackallocs * Converts over some more gumps * WIP - Deletes 32bit support. * Drops RDRand32 support. * Fixes gump compilation * Converting gump components * Removes old huffman compression function * Revert signature for backwards compatibility * WIP - Converting more gump components * Creates ArraySet for the strings. Updates AppendTo to reference that. * Converts the maining gump components * Cleans up gump components * Cleans up directives * Cleans up ArraySet and moves it. Adds null-coalescing-assignment * Cleanup, Target Packets, and C# 8 changes. * Removed OPL Packet * World packets * Fixing packet uses * Cleans up code. Fixes packet uses in various places. * More cleanup for packets * Code cleanup * Converts more packet uses and cleans up more code * More code cleanup * Finishes fixing the packets in Item * Updates secure trade packets * Updates core and gets it to compile. * Moved packets to scripts. Fixed account handler use of packets * Code cleanup * Updates chat packets * Code cleanuo * Adds party packets, but need to implement them. * Party packets WIP * Finishes party packets * Rearrange movement namespaces and classes * Finishes plant packets * Code Formatting * Fixes moving effects * Code cleanup, eliminates equipinfo * Adds more packets. Fixes bugs with various packets. * Finishes mahjon packets * Fixes mahjong packet * Code cleanup * Finishes mahjong packets * Adds Map packets * Add multifacet maps and charts * Cleans up some packets with UTF8 * Optimizes packets * Cleans up more packets. Moves the MessageHelper * Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets. * Updates protocol extensions packet receiver * Fixes a few bugs. Fixes a few more packets. * Code cleanup and fixing more packets * Fixes packet effects * Cleaned up more code * Buff Icon cleanup * Removed unused constructors * Code Cleanup. Adds BoatHS Packets * Moves house files. Updates house foundation packets. * Deployment cleanup * Fixes: * Code cleanup * More code cleanup * More code cleanup * Cleaned up BaseHouse * Enforces styling * Converts foreach to linq where possible. * Dont need that * Goals/Readme updates * Removes 32bit support at the highest level. Turns on HRT by default. * Code cleanup. Fixes extended features packet. * Fixes various bugs * Code cleanup * Code cleanup * Code cleanup. Fixes gump X/Y assignment. * Code cleanup using |= operator * More code cleanup * Cleanup * Fixes spacing issues. Thanks Visual Studio. You suck. * Compiler error * Fixes NPE from RunUO 2.7 * Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README * Fixes more packets. Stupid trailing nulls. * Fixes various bugs. * Fixes for gumps * Fixes more gump stuff. Going to split it out later since it is getting insane * Recoded the gump writing * WIP * *Added output path of scripts project to dev branch *Activated debugging in code
401 lines
12 KiB
C#
401 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using Server.Accounting;
|
|
using Server.Engines.Help;
|
|
using Server.Network;
|
|
using Server.Regions;
|
|
|
|
namespace Server.Misc
|
|
{
|
|
public enum PasswordProtection
|
|
{
|
|
None,
|
|
Crypt,
|
|
NewCrypt
|
|
}
|
|
|
|
public class AccountHandler
|
|
{
|
|
private static int MaxAccountsPerIP = 1;
|
|
private static bool AutoAccountCreation = true;
|
|
private static bool RestrictDeletion = !TestCenter.Enabled;
|
|
private static TimeSpan DeleteDelay = TimeSpan.FromDays(7.0);
|
|
|
|
public static PasswordProtection ProtectPasswords = PasswordProtection.NewCrypt;
|
|
|
|
private static CityInfo[] StartingCities =
|
|
{
|
|
new CityInfo("New Haven", "New Haven Bank", 1150168, 3667, 2625, 0),
|
|
new CityInfo("Yew", "The Empath Abbey", 1075072, 633, 858, 0),
|
|
new CityInfo("Minoc", "The Barnacle", 1075073, 2476, 413, 15),
|
|
new CityInfo("Britain", "The Wayfarer's Inn", 1075074, 1602, 1591, 20),
|
|
new CityInfo("Moonglow", "The Scholars Inn", 1075075, 4408, 1168, 0),
|
|
new CityInfo("Trinsic", "The Traveler's Inn", 1075076, 1845, 2745, 0),
|
|
new CityInfo("Jhelom", "The Mercenary Inn", 1075078, 1374, 3826, 0),
|
|
new CityInfo("Skara Brae", "The Falconer's Inn", 1075079, 618, 2234, 0),
|
|
new CityInfo("Vesper", "The Ironwood Inn", 1075080, 2771, 976, 0)
|
|
};
|
|
|
|
/* Old Haven/Magincia Locations
|
|
new CityInfo( "Britain", "Sweet Dreams Inn", 1496, 1628, 10 );
|
|
// ..
|
|
// Trinsic
|
|
new CityInfo( "Magincia", "The Great Horns Tavern", 3734, 2222, 20 ),
|
|
// Jhelom
|
|
// ..
|
|
new CityInfo( "Haven", "Buckler's Hideaway", 3667, 2625, 0 )
|
|
|
|
if ( Core.AOS )
|
|
{
|
|
//CityInfo haven = new CityInfo( "Haven", "Uzeraan's Mansion", 3618, 2591, 0 );
|
|
CityInfo haven = new CityInfo( "Haven", "Uzeraan's Mansion", 3503, 2574, 14 );
|
|
StartingCities[StartingCities.Length - 1] = haven;
|
|
}
|
|
*/
|
|
|
|
private static bool PasswordCommandEnabled = false;
|
|
|
|
private static Dictionary<IPAddress, int> m_IPTable;
|
|
|
|
private static readonly char[] m_ForbiddenChars =
|
|
{
|
|
'<', '>', ':', '"', '/', '\\', '|', '?', '*'
|
|
};
|
|
|
|
public static AccessLevel LockdownLevel{ get; set; }
|
|
|
|
public static Dictionary<IPAddress, int> IPTable
|
|
{
|
|
get
|
|
{
|
|
if (m_IPTable == null)
|
|
{
|
|
m_IPTable = new Dictionary<IPAddress, int>();
|
|
|
|
foreach (Account a in Accounts.GetAccounts())
|
|
if (a.LoginIPs.Length > 0)
|
|
{
|
|
IPAddress ip = a.LoginIPs[0];
|
|
m_IPTable[ip] = (m_IPTable.TryGetValue(ip, out int value) ? value : 0) + 1;
|
|
}
|
|
}
|
|
|
|
return m_IPTable;
|
|
}
|
|
}
|
|
|
|
public static void Initialize()
|
|
{
|
|
EventSink.DeleteRequest += EventSink_DeleteRequest;
|
|
EventSink.AccountLogin += EventSink_AccountLogin;
|
|
EventSink.GameLogin += EventSink_GameLogin;
|
|
|
|
if (PasswordCommandEnabled)
|
|
CommandSystem.Register("Password", AccessLevel.Player, Password_OnCommand);
|
|
}
|
|
|
|
[Usage("Password <newPassword> <repeatPassword>")]
|
|
[Description(
|
|
"Changes the password of the commanding players account. Requires the same C-class IP address as the account's creator.")]
|
|
public static void Password_OnCommand(CommandEventArgs e)
|
|
{
|
|
Mobile from = e.Mobile;
|
|
|
|
if (!(from.Account is Account acct))
|
|
return;
|
|
|
|
IPAddress[] accessList = acct.LoginIPs;
|
|
|
|
if (accessList.Length == 0)
|
|
return;
|
|
|
|
NetState ns = from.NetState;
|
|
|
|
if (ns == null)
|
|
return;
|
|
|
|
if (e.Length == 0)
|
|
{
|
|
from.SendMessage("You must specify the new password.");
|
|
return;
|
|
}
|
|
|
|
if (e.Length == 1)
|
|
{
|
|
from.SendMessage("To prevent potential typing mistakes, you must type the password twice. Use the format:");
|
|
from.SendMessage("Password \"(newPassword)\" \"(repeated)\"");
|
|
return;
|
|
}
|
|
|
|
string pass = e.GetString(0);
|
|
string pass2 = e.GetString(1);
|
|
|
|
if (pass != pass2)
|
|
{
|
|
from.SendMessage("The passwords do not match.");
|
|
return;
|
|
}
|
|
|
|
bool isSafe = true;
|
|
|
|
for (int i = 0; isSafe && i < pass.Length; ++i)
|
|
isSafe = pass[i] >= 0x20 && pass[i] < 0x7F;
|
|
|
|
if (!isSafe)
|
|
{
|
|
from.SendMessage("That is not a valid password.");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
IPAddress ipAddress = ns.Address;
|
|
|
|
if (Utility.IPMatchClassC(accessList[0], ipAddress))
|
|
{
|
|
acct.SetPassword(pass);
|
|
from.SendMessage("The password to your account has changed.");
|
|
}
|
|
else
|
|
{
|
|
PageEntry entry = PageQueue.GetEntry(from);
|
|
|
|
if (entry != null)
|
|
{
|
|
if (entry.Message.StartsWith("[Automated: Change Password]"))
|
|
from.SendMessage("You already have a password change request in the help system queue.");
|
|
else
|
|
from.SendMessage("Your IP address does not match that which created this account.");
|
|
}
|
|
else if (PageQueue.CheckAllowedToPage(from))
|
|
{
|
|
from.SendMessage(
|
|
"Your IP address does not match that which created this account. A page has been entered into the help system on your behalf.");
|
|
|
|
from.SendLocalizedMessage(501234, "",
|
|
0x35); /* The next available Counselor/Game Master will respond as soon as possible.
|
|
* Please check your Journal for messages every few minutes.
|
|
*/
|
|
|
|
PageQueue.Enqueue(new PageEntry(from,
|
|
$"[Automated: Change Password]<br>Desired password: {pass}<br>Current IP address: {ipAddress}<br>Account IP address: {accessList[0]}",
|
|
PageType.Account));
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
|
|
private static void EventSink_DeleteRequest(DeleteRequestEventArgs e)
|
|
{
|
|
NetState state = e.State;
|
|
int index = e.Index;
|
|
|
|
if (!(state.Account is Account acct))
|
|
{
|
|
state.Dispose();
|
|
return;
|
|
}
|
|
|
|
DeleteResultType deleteType;
|
|
|
|
if (index < 0 || index >= acct.Length)
|
|
deleteType = DeleteResultType.BadRequest;
|
|
else
|
|
{
|
|
Mobile m = acct[index];
|
|
|
|
if (m == null)
|
|
deleteType = DeleteResultType.CharNotExist;
|
|
else if (m.NetState != null)
|
|
deleteType = DeleteResultType.CharBeingPlayed;
|
|
else if (RestrictDeletion && DateTime.UtcNow < m.CreationTime + DeleteDelay)
|
|
deleteType = DeleteResultType.CharTooYoung;
|
|
else if (m.AccessLevel == AccessLevel.Player &&
|
|
Region.Find(m.LogoutLocation, m.LogoutMap).IsPartOf<Jail>()
|
|
) //Don't need to check current location, if netstate is null, they're logged out
|
|
deleteType = DeleteResultType.BadRequest;
|
|
else
|
|
{
|
|
Console.WriteLine("Client: {0}: Deleting character {1} (0x{2:X})", state, index, m.Serial.Value);
|
|
|
|
acct.Comments.Add(new AccountComment("System", $"Character #{index + 1} {m} deleted by {state}"));
|
|
|
|
m.Delete();
|
|
Packets.SendCharacterListUpdate(state, acct);
|
|
return;
|
|
}
|
|
}
|
|
|
|
Packets.SendDeleteResult(state, deleteType);
|
|
Packets.SendCharacterListUpdate(state, acct);
|
|
}
|
|
|
|
public static bool CanCreate(IPAddress ip) => !IPTable.ContainsKey(ip) || IPTable[ip] < MaxAccountsPerIP;
|
|
|
|
private static bool IsForbiddenChar(char c) => m_ForbiddenChars.Any(t => c == t);
|
|
|
|
private static Account CreateAccount(NetState state, string un, string pw)
|
|
{
|
|
if (un.Length == 0 || pw.Length == 0)
|
|
return null;
|
|
|
|
bool isSafe = !(un.StartsWith(" ") || un.EndsWith(" ") || un.EndsWith("."));
|
|
|
|
for (int i = 0; isSafe && i < un.Length; ++i)
|
|
isSafe = un[i] >= 0x20 && un[i] < 0x7F && !IsForbiddenChar(un[i]);
|
|
|
|
for (int i = 0; isSafe && i < pw.Length; ++i)
|
|
isSafe = pw[i] >= 0x20 && pw[i] < 0x7F;
|
|
|
|
if (!isSafe)
|
|
return null;
|
|
|
|
if (!CanCreate(state.Address))
|
|
{
|
|
Console.WriteLine("Login: {0}: Account '{1}' not created, ip already has {2} account{3}.", state, un,
|
|
MaxAccountsPerIP, MaxAccountsPerIP == 1 ? "" : "s");
|
|
return null;
|
|
}
|
|
|
|
Console.WriteLine("Login: {0}: Creating new account '{1}'", state, un);
|
|
|
|
Account a = new Account(un, pw);
|
|
|
|
return a;
|
|
}
|
|
|
|
public static void EventSink_AccountLogin(AccountLoginEventArgs e)
|
|
{
|
|
if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address))
|
|
{
|
|
e.Accepted = false;
|
|
e.RejectReason = ALRReason.InUse;
|
|
|
|
Console.WriteLine("Login: {0}: Past IP limit threshold", e.State);
|
|
|
|
using (StreamWriter op = new StreamWriter("ipLimits.log", true))
|
|
{
|
|
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.UtcNow);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
string un = e.Username;
|
|
string pw = e.Password;
|
|
|
|
e.Accepted = false;
|
|
|
|
if (!(Accounts.GetAccount(un) is Account acct))
|
|
{
|
|
// To prevent someone from making an account of just '' or a bunch of meaningless spaces
|
|
if (AutoAccountCreation && un.Trim().Length > 0)
|
|
{
|
|
e.State.Account = acct = CreateAccount(e.State, un, pw);
|
|
e.Accepted = acct?.CheckAccess(e.State) ?? false;
|
|
|
|
if (!e.Accepted)
|
|
e.RejectReason = ALRReason.BadComm;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Login: {0}: Invalid username '{1}'", e.State, un);
|
|
e.RejectReason = ALRReason.Invalid;
|
|
}
|
|
}
|
|
else if (!acct.HasAccess(e.State))
|
|
{
|
|
Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un);
|
|
e.RejectReason = LockdownLevel > AccessLevel.Player ? ALRReason.BadComm : ALRReason.BadPass;
|
|
}
|
|
else if (!acct.CheckPassword(pw))
|
|
{
|
|
Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un);
|
|
e.RejectReason = ALRReason.BadPass;
|
|
}
|
|
else if (acct.Banned)
|
|
{
|
|
Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un);
|
|
e.RejectReason = ALRReason.Blocked;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Login: {0}: Valid credentials for '{1}'", e.State, un);
|
|
e.State.Account = acct;
|
|
e.Accepted = true;
|
|
|
|
acct.LogAccess(e.State);
|
|
}
|
|
|
|
if (!e.Accepted)
|
|
AccountAttackLimiter.RegisterInvalidAccess(e.State);
|
|
}
|
|
|
|
public static void EventSink_GameLogin(GameLoginEventArgs e)
|
|
{
|
|
if (!IPLimiter.SocketBlock && !IPLimiter.Verify(e.State.Address))
|
|
{
|
|
e.Accepted = false;
|
|
|
|
Console.WriteLine("Login: {0}: Past IP limit threshold", e.State);
|
|
|
|
using (StreamWriter op = new StreamWriter("ipLimits.log", true))
|
|
{
|
|
op.WriteLine("{0}\tPast IP limit threshold\t{1}", e.State, DateTime.UtcNow);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
string un = e.Username;
|
|
string pw = e.Password;
|
|
|
|
if (!(Accounts.GetAccount(un) is Account acct))
|
|
e.Accepted = false;
|
|
else if (!acct.HasAccess(e.State))
|
|
{
|
|
Console.WriteLine("Login: {0}: Access denied for '{1}'", e.State, un);
|
|
e.Accepted = false;
|
|
}
|
|
else if (!acct.CheckPassword(pw))
|
|
{
|
|
Console.WriteLine("Login: {0}: Invalid password for '{1}'", e.State, un);
|
|
e.Accepted = false;
|
|
}
|
|
else if (acct.Banned)
|
|
{
|
|
Console.WriteLine("Login: {0}: Banned account '{1}'", e.State, un);
|
|
e.Accepted = false;
|
|
}
|
|
else
|
|
{
|
|
acct.LogAccess(e.State);
|
|
|
|
Console.WriteLine("Login: {0}: Account '{1}' at character list", e.State, un);
|
|
e.State.Account = acct;
|
|
e.Accepted = true;
|
|
e.CityInfo = StartingCities;
|
|
}
|
|
|
|
if (!e.Accepted)
|
|
AccountAttackLimiter.RegisterInvalidAccess(e.State);
|
|
}
|
|
|
|
public static bool CheckAccount(Mobile mobCheck, Mobile accCheck)
|
|
{
|
|
if (accCheck?.Account is Account a)
|
|
for (int i = 0; i < a.Length; ++i)
|
|
if (a[i] == mobCheck)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|