-
-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for multi account login. #1200
base: main
Are you sure you want to change the base?
Conversation
internal void SetItems(string[] items) | ||
{ | ||
_items = items; | ||
if (_items.Length > 0 && _arrow == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for null reference here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
src/Configuration/AccountManager.cs
Outdated
{ | ||
public static List<Account> Accounts; | ||
|
||
public static string[] GetAccountNames(string serverName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this include port number? I'm thinking this is probably overkill but i suppose it is possible that a given server may have different servers running on the same IP and point to different ports.
|
||
private static string PathToAccountFile() | ||
{ | ||
string path = FileSystemHelper.CreateFolderIfNotExists(CUOEnviroment.ExecutablePath, "Data", "Profiles"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will need to adjust if the profile directory becomes custom according to: https://github.com/andreakarasho/ClassicUO/pull/1180
if(CurrentLoginStep == LoginSteps.VerifyingAccount) | ||
{ | ||
AccountManager.SaveAccount(Settings.GlobalSettings.IP, Settings.GlobalSettings.Username, Settings.GlobalSettings.Password, Settings.GlobalSettings.SaveAccount); | ||
if (!Settings.GlobalSettings.SaveAccount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is questionable as it appears to move away from the current behavior. I am just not sure if the current functionality to keep these fields populated if the user does not have the "Save Account" checkbox enabled and then go back to the login screen is desired. It seems like a potential current bug, but this may be original functionality. Could be easily removed.
src/Game/UI/Gumps/Login/LoginGump.cs
Outdated
{ | ||
X = offsetX, | ||
Y = offsetY, | ||
Width = 190, | ||
Height = 25, | ||
}); | ||
|
||
_textboxAccount.OnOptionSelected += (sender, e) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking for a place to unhook this but I couldn't find a good spot. It would probably be a good idea for memory management.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the anonymous function and make it named function. Overrode disposed, and unhooked it there.
string item = items[i]; | ||
|
||
if (item == null) | ||
item = string.Empty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap one-liners with curly braces, whenever you stumble upon them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh, this was a copy pasta from ComboBox, normally VS would pick it up for me but i turned it off because i normally use tabs and i kept ending up with tabs everywhere. will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
private void Label_MouseUp(object sender, MouseEventArgs e) | ||
{ | ||
if (e.Button == MouseButtonType.Left) | ||
_setIndex((int)((Label)sender).Tag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well... see one-liners comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/Configuration/AccountManager.cs
Outdated
var accounts = LoadAccountsFromFile(); | ||
Accounts = accounts.Where(x => x.Server == serverName).ToList(); | ||
Load(serverName); | ||
return Accounts?.Where(x => x.Server == serverName).Select(x => x.UserName).ToArray() ?? new string[] { }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this a lot as well, x
instead of a proper name for what x might be. Why not account
? And in case the line gets "too long", you can break the line before .Select
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad habits die hard :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed.
_contextMenu.OnItemSelected -= ItemSelectedHandler; | ||
UIManager.GetGump<ComboboxContextMenu>()?.Dispose(); | ||
_contextMenu = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be pulled out into a CleanupContextMenu()
?
get => _selectedIndex; | ||
set | ||
{ | ||
_selectedIndex = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
if (_selectedIndex == value || value < 0)
{
return;
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually. This was also some copy pasta from the ComboBox
and now that i look at it... None of this logic should really reside in this setter. This is probably better handled in the event handler for the OnItemSelected
event that i added to the ComboboxContextMenu
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the auto property and moved all the relevant functionality to the event handler.
_arrow.Hue = 0; | ||
TextboxComboContextMenu contextMenu = new TextboxComboContextMenu(_items, Width, 100, _font, selectedIndex => SelectedIndex = selectedIndex) | ||
_arrow.Graphic = ARROW_UP; | ||
if (x > _arrow.X && x < _arrow.X + _arrow.Width && y > _arrow.Y && y < _arrow.Y + _arrow.Height) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm hmm hmm, I've seen this quite a bit, Maybe Gump
should have a public method bool Contains(Point point)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually considered this. This is a pretty standard function for game development. I peeked in the Utilities
folder to see if i could find anything, but no luck. I definitely agree on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon further investigation the GumpPic has its own event for mouse down and mouse up. Instead of doing the hitbox check i just subbed to the events on the GumpPic control itself and then the hitbox test is no longer needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
subbed to the mouse events and moved the logic there. no more need for hitbox detection.
src/Game/UI/Gumps/Login/LoginGump.cs
Outdated
// var savedAccounts = ProfileManager.GetAccounts(World.ServerName); | ||
var savedAccounts = new string[] { "Hello World", "hello", "hello", "hello", "hello", "hello", "hello", "hello" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two lines look bogus ;) Probably remains from testing.
I really should start merging my unit-test-branch. Then this can be covered by unit tests as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
src/Game/UI/Gumps/Login/LoginGump.cs
Outdated
// var savedPassword = ProfileManager.GetSavedPassword(World.ServerName, _textboxAccount.Text); | ||
var savedPassword = "HelloWorld"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also probably remains from testing around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed.
don't forget to pull updates from latest dev |
public event EventHandler<int> OnOptionSelected; | ||
public event EventHandler OnBeforeContextMenu; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties should go below the constructor.
{ | ||
_arrow.MouseDown -= ArrowMouseDownHandler; | ||
_arrow.MouseUp -= ArrowMouseUpHandler; | ||
_arrow = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_arrow.Dispose();
should be enough.
{ | ||
_contextMenu.OnItemSelected -= ItemSelectedHandler; | ||
UIManager.GetGump<ComboboxContextMenu>()?.Dispose(); | ||
_contextMenu = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_contextMenu.Dispose();
should be enough here too
src/Game/UI/Controls/Combobox.cs
Outdated
//Cleanup Context Menu | ||
_contextMenu.OnItemSelected -= ItemSelectedHandler; | ||
UIManager.GetGump<ComboboxContextMenu>()?.Dispose(); | ||
_contextMenu = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_contextMenu.Dispose();
should be enough
src/Configuration/Accounts.cs
Outdated
{ | ||
public Account() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being picky regarding formatting. Can you please remove the empty line here?
(SonarLint/Cube/StyleCop will cry about it, if we decide to add it :D)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (existingRecord != null && !saveAccount) | ||
{ | ||
_accounts.Remove(existingRecord); | ||
} | ||
//There is an existing record and they have updated their password. save the udpated password. | ||
else if (existingRecord != null && existingRecord.Password != password) | ||
{ | ||
existingRecord.UpdatePassword(password); | ||
} | ||
//Otherwise if there is no existing record, the user has opted to save the account, and that account has a username save the record. | ||
else if (existingRecord == null && saveAccount && !string.IsNullOrWhiteSpace(userName)) | ||
{ | ||
_accounts.Add(new Account(serverName, userName, password)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm hmm what about a switch block with pattern matching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor changes I believe.
No description provided.