Skip to content
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

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from

Conversation

wiscow
Copy link

@wiscow wiscow commented Aug 29, 2020

No description provided.

internal void SetItems(string[] items)
{
_items = items;
if (_items.Length > 0 && _arrow == null)
Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

{
public static List<Account> Accounts;

public static string[] GetAccountNames(string serverName)
Copy link
Author

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");
Copy link
Author

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)
Copy link
Author

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.

{
X = offsetX,
Y = offsetY,
Width = 190,
Height = 25,
});

_textboxAccount.OnOptionSelected += (sender, e) =>
Copy link
Author

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.

Copy link
Author

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;
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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);
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix.

Copy link
Author

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 Show resolved Hide resolved
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[] { };
Copy link
Contributor

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 ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad habits die hard :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

src/Configuration/AccountManager.cs Outdated Show resolved Hide resolved
src/Configuration/AccountManager.cs Outdated Show resolved Hide resolved
src/Configuration/AccountManager.cs Outdated Show resolved Hide resolved
Comment on lines 73 to 75
_contextMenu.OnItemSelected -= ItemSelectedHandler;
UIManager.GetGump<ComboboxContextMenu>()?.Dispose();
_contextMenu = null;
Copy link
Contributor

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;
Copy link
Contributor

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;
}
...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed.

Copy link
Author

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.

Copy link
Author

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)
Copy link
Contributor

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).

Copy link
Author

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.

Copy link
Author

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.

Copy link
Author

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.

Comment on lines 229 to 230
// var savedAccounts = ProfileManager.GetAccounts(World.ServerName);
var savedAccounts = new string[] { "Hello World", "hello", "hello", "hello", "hello", "hello", "hello", "hello" };
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

Comment on lines 241 to 242
// var savedPassword = ProfileManager.GetSavedPassword(World.ServerName, _textboxAccount.Text);
var savedPassword = "HelloWorld";
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@andreakarasho
Copy link
Collaborator

don't forget to pull updates from latest dev

Comment on lines 124 to 125
public event EventHandler<int> OnOptionSelected;
public event EventHandler OnBeforeContextMenu;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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

//Cleanup Context Menu
_contextMenu.OnItemSelected -= ItemSelectedHandler;
UIManager.GetGump<ComboboxContextMenu>()?.Dispose();
_contextMenu = null;
Copy link
Contributor

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

{
public Account()
{

Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +37 to +50
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));
}
Copy link
Contributor

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?

Copy link
Contributor

@deccer deccer left a 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.

@andreakarasho andreakarasho changed the base branch from dev to main November 7, 2022 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants