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

Change server list in dev client #124

Merged
Merged
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
4 changes: 2 additions & 2 deletions illaclient/src/main/java/illarion/client/IllaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public final class IllaClient implements EventTopicSubscriber<ConfigChangedEvent
static {
String server = System.getProperty("illarion.server", "realserver");
switch ((server == null) ? "" : server) {
case "testserver":
DEFAULT_SERVER = Servers.Testserver;
case "localserver":
DEFAULT_SERVER = Servers.Localserver;
break;
case "devserver":
DEFAULT_SERVER = Servers.Devserver;
Expand Down
151 changes: 112 additions & 39 deletions illaclient/src/main/java/illarion/client/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,12 @@ public boolean login() {
}

int clientVersion;
if (getServer() == Servers.Customserver) {
if (IllaClient.getCfg().getBoolean("clientVersionOverwrite")) {
clientVersion = IllaClient.getCfg().getInteger("clientVersion");
} else {
clientVersion = getServer().getClientVersion();
}
Servers server = getServer();
if ((server == Servers.Customserver || server == Servers.Localserver)
&& IllaClient.getCfg().getBoolean("clientVersionOverwrite")) {
clientVersion = IllaClient.getCfg().getInteger("clientVersion");
} else {
clientVersion = getServer().getClientVersion();
clientVersion = server.getClientVersion();
}
World.getNet().sendCommand(new LoginCmd(loginChar, getPassword(), clientVersion));

Expand Down Expand Up @@ -178,7 +176,16 @@ public String getPassword() {

@Contract(pure = true)
public boolean isCharacterListRequired() {
return (getServer() != Servers.Customserver) || IllaClient.getCfg().getBoolean("serverAccountLogin");
Servers server = getServer();

switch (server) {
case Localserver:
return false;
case Customserver:
return IllaClient.getCfg().getBoolean("serverAccountLogin");
default:
return true;
}
}

/**
Expand Down Expand Up @@ -292,39 +299,73 @@ public void restoreLoginData() {
* login field on the login window.
*/
private void restoreLogin() {
if (getServer() == Servers.Customserver) {
loginName = IllaClient.getCfg().getString("customLastLogin");
} else {
loginName = IllaClient.getCfg().getString("lastLogin");
Servers server = getServer();

switch (server) {
case Localserver:
restoreLogin("localLastLogin");
break;
case Customserver:
restoreLogin("customLastLogin");
break;
default:
restoreLogin("lastLogin");
break;
}
}

private void restoreLogin(String lastLogin) {
loginName = IllaClient.getCfg().getString(lastLogin);
}

/**
* Load the saved password from the configuration file and insert it to the
* password field on the login window.
*/
private void restorePassword() {
String encoded;
if (getServer() == Servers.Customserver) {
encoded = IllaClient.getCfg().getString("customFingerprint");
} else {
encoded = IllaClient.getCfg().getString("fingerprint");
Servers server = getServer();

switch (server) {
case Localserver:
restorePassword("localFingerprint");
break;
case Customserver:
restorePassword("customFingerprint");
break;
default:
restorePassword("fingerprint");
break;
}
}

private void restorePassword(String fingerprint) {
String encoded = IllaClient.getCfg().getString(fingerprint);
password = (encoded != null) ? shufflePassword(encoded, true) : "";
}

/**
* Load the saved decision for whether to save the password
*/
private void restoreStorePassword() {
if (getServer() == Servers.Customserver) {
storePassword = IllaClient.getCfg().getBoolean("customSavePassword");
} else {
storePassword = IllaClient.getCfg().getBoolean("savePassword");
Servers server = getServer();

switch (server) {
case Localserver:
restoreStorePassword("localSavePassword");
break;
case Customserver:
restoreStorePassword("customSavePassword");
break;
default:
restoreStorePassword("savePassword");
break;
}
}

private void restoreStorePassword(String savePassword) {
storePassword = IllaClient.getCfg().getBoolean(savePassword);
}

/**
* Shuffle the letters of the password around a bit.
*
Expand Down Expand Up @@ -412,12 +453,17 @@ public void storeData(boolean storePassword) {
IllaClient.getInstance().setUsedServer(getServer());
}

if (getServer() == Servers.Customserver) {
IllaClient.getCfg().set("customLastLogin", getLoginName());
IllaClient.getCfg().set("customSavePassword", storePassword);
} else {
IllaClient.getCfg().set("lastLogin", getLoginName());
IllaClient.getCfg().set("savePassword", storePassword);
Servers server = getServer();
switch (server) {
case Localserver:
storeLoginStorePasswordData("localLastLogin", "localSavePassword");
break;
case Customserver:
storeLoginStorePasswordData("customLastLogin", "customSavePassword");
break;
default:
storeLoginStorePasswordData("lastLogin", "savePassword");
break;
}

if (storePassword) {
Expand All @@ -429,6 +475,11 @@ public void storeData(boolean storePassword) {
IllaClient.getCfg().save();
}

private void storeLoginStorePasswordData(String lastLogin, String savePassword) {
IllaClient.getCfg().set(lastLogin, getLoginName());
IllaClient.getCfg().set(savePassword, storePassword);
}

@Nonnull
public String getLoginName() {
if (loginName == null) {
Expand All @@ -443,28 +494,50 @@ public String getLoginName() {
* @param pw the password that stall be stored to the configuration file
*/
private void storePassword(@Nonnull String pw) {
if (getServer() == Servers.Customserver) {
IllaClient.getCfg().set("customSavePassword", true);
IllaClient.getCfg().set("customFingerprint", shufflePassword(pw, false));
} else {
IllaClient.getCfg().set("savePassword", true);
IllaClient.getCfg().set("fingerprint", shufflePassword(pw, false));
Servers server = getServer();

switch (server) {
case Localserver:
storePassword("localSavePassword", "localFingerprint", pw);
break;
case Customserver:
storePassword("customSavePassword", "customFingerprint", pw);
break;
default:
storePassword("savePassword", "fingerprint", pw);
break;
}
}

private void storePassword(String savePassword, String fingerprint, String password) {
IllaClient.getCfg().set(savePassword, true);
IllaClient.getCfg().set(fingerprint, shufflePassword(password, false));
}

/**
* Remove the stored password.
*/
private void deleteStoredPassword() {
if (getServer() == Servers.Customserver) {
IllaClient.getCfg().set("customSavePassword", false);
IllaClient.getCfg().remove("customFingerprint");
} else {
IllaClient.getCfg().set("savePassword", false);
IllaClient.getCfg().remove("fingerprint");
Servers server = getServer();

switch (server) {
case Localserver:
deleteStorePassword("localSavePassword", "localFingerprint");
break;
case Customserver:
deleteStorePassword("customSavePassword", "customFingerprint");
break;
default:
deleteStorePassword("savePassword", "fingerprint");
break;
}
}

private void deleteStorePassword(String savePassword, String fingerprint) {
IllaClient.getCfg().set(savePassword, false);
IllaClient.getCfg().remove(fingerprint);
}

@FunctionalInterface
public interface RequestCharListCallback {
void finishedRequest(int errorCode);
Expand Down
2 changes: 1 addition & 1 deletion illaclient/src/main/java/illarion/client/Servers.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum Servers {
/**
* The Testserver of Illarion. Testers and developers need a client that is allowed to connect to this server.
*/
Testserver(1, "testserver", Illarionserver.serverHostName, 3011, 20),
Localserver(1, "localserver", "localhost", 13000, 20),

/**
* The development server of Illarion. Developers need a client that is allowed to connect to this server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void bind(@Nonnull Nifty nifty, @Nonnull Screen screen) {
server = screen.findNiftyControl("server", DropDown.class);
if (server != null) {
server.addItem("${login-bundle.server.develop}");
server.addItem("${login-bundle.server.test}");
server.addItem("${login-bundle.server.local}");
server.addItem("${login-bundle.server.game}");
server.addItem("${login-bundle.server.custom}");
server.selectItemByIndex(IllaClient.getCfg().getInteger("server"));
Expand Down
5 changes: 2 additions & 3 deletions illaclient/src/main/resources/login_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ password=Passwort:
savePassword=Passwort merken
server=Server:
server.develop=Entwicklungsserver
server.test=Testserver
server.game=Spielserver
server.custom=Benutzerdefiniert
server.local=Lokaler Testserver
server.local=Lokaler Server
login=Einloggen
options=Optionen
exit=Beenden
credits=Credits
receivingCharacters=Charaktere werden vom Server empfangen.
receivingCharacters=Charaktere werden vom Server empfangen.
5 changes: 2 additions & 3 deletions illaclient/src/main/resources/login_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ password=Password:
savePassword=Save password
server=Server:
server.develop=development server
server.test=test server
server.game=game server
server.custom=user defined
server.local=local testserver
server.local=local server
login=Login
options=Options
exit=Exit
credits=Credits
receivingCharacters=Characters are being received from the server.
receivingCharacters=Characters are being received from the server.