Skip to content

Commit

Permalink
Initial Account Security and Password Recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Suli committed Nov 23, 2020
1 parent f88a6a2 commit ae1911d
Show file tree
Hide file tree
Showing 8 changed files with 1,590 additions and 56 deletions.
482 changes: 461 additions & 21 deletions src/Client/JClassPatcher.java

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions src/Client/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package Client;

import Game.Replay;
import Game.ReplayQueue;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
Expand All @@ -32,6 +30,8 @@
import java.util.Locale;
import java.util.zip.CRC32;
import java.util.zip.GZIPInputStream;
import Game.Replay;
import Game.ReplayQueue;

/** A miscellaneous utility class */
public class Util {
Expand Down Expand Up @@ -415,4 +415,17 @@ public static void int_put(byte[] buffer, int offset, int num) {
buffer[offset + 2] = (byte) (num >> 8);
buffer[offset + 3] = (byte) num;
}

/** RSC175 - format a string to only have letters and numbers, with maxlength */
public static String formatString(String s, int maxLen) {
String lowerString = s.toLowerCase();
String res = "";
for (int i = 0; i < lowerString.length() && i < maxLen; ++i) {
char ch = lowerString.charAt(i);
if (ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9') {
res = String.valueOf(res) + ch;
}
}
return res;
}
}
829 changes: 821 additions & 8 deletions src/Game/AccountManagement.java

Large diffs are not rendered by default.

138 changes: 126 additions & 12 deletions src/Game/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@
package Game;

import static Replay.game.constants.Game.itemActionMap;

import Client.JClassPatcher;
import Client.JConfig;
import Client.KeybindSet;
import Client.Launcher;
import Client.Logger;
import Client.NotificationsHandler;
import Client.NotificationsHandler.NotifType;
import Client.Settings;
import Client.Speedrun;
import Client.TwitchIRC;
import Replay.game.constants.Game.ItemAction;
import java.applet.Applet;
import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand All @@ -52,6 +40,17 @@
import java.util.List;
import java.util.Map;
import javax.swing.JOptionPane;
import Client.JClassPatcher;
import Client.JConfig;
import Client.KeybindSet;
import Client.Launcher;
import Client.Logger;
import Client.NotificationsHandler;
import Client.NotificationsHandler.NotifType;
import Client.Settings;
import Client.Speedrun;
import Client.TwitchIRC;
import Replay.game.constants.Game.ItemAction;

/**
* This class prepares the client for login, handles chat messages, and performs player related
Expand Down Expand Up @@ -185,6 +184,8 @@ public class Client {
public static String pm_text;
public static String pm_enteredText;
public static String lastpm_username = null;
public static String modal_text;
public static String modal_enteredText;

public static String mouseText = "";

Expand Down Expand Up @@ -310,12 +311,18 @@ public class Client {
public static int login_delay;
public static String server_address;
public static int serverjag_port;
public static int session_id;
public static boolean failedRecovery = false;

public static Object panelWelcome;
public static Object panelLogin;
public static Object panelRegister;
public static Object panelRecovery;
public static Object panelRecoveryQuestions;
public static Object panelContactDetails;
public static int loginUserInput;
public static int loginPassInput;
public static int loginLostPasswordButton;
public static int registerButton;
public static int controlRegister;
public static int chooseUserInput;
Expand All @@ -324,6 +331,30 @@ public class Client {
public static int acceptTermsCheckbox;
public static int chooseSubmitRegisterButton;
public static int chooseCancelRegisterButton;
public static int controlRecovery1;
public static int controlRecovery2;
public static int controlRecoveryQuestion[] = new int[5];
public static int controlRecoveryInput[] = new int[5];
public static int recoverOldPassInput;
public static int recoverNewPassInput;
public static int recoverConfirmPassInput;
public static int chooseSubmitRecoveryButton;
public static int chooseCancelRecoveryButton;
public static int controlRecoveryQuestions;
public static String controlRecoveryText[] = new String[5];
public static int controlRecoveryIns[] = new int[5];
public static int controlAnswerInput[] = new int[5];
public static int controlQuestion[] = new int[5];
public static int controlCustomQuestion[] = new int[5];
public static int chooseFinishSetRecoveryButton;
public static int controlContactDetails;
public static int fullNameInput;
public static int zipCodeInput;
public static int countryInput;
public static int emailInput;
public static int chooseSubmitContactDetailsButton;
public static boolean showRecoveryQuestions;
public static boolean showContactDetails;

/**
* Iterates through {@link #strings} array and checks if various conditions are met. Used for
Expand Down Expand Up @@ -516,6 +547,16 @@ public static boolean skipToLogin() {
return skipToLogin || Settings.START_LOGINSCREEN.get(Settings.currentProfile);
}

/**
* Reference for JClassPatcher and any other required. Indicates if should show account and
* security settings
*
* @return
*/
public static boolean showSecuritySettings() {
return Settings.SHOW_ACCOUNT_SECURITY_SETTINGS.get(Settings.currentProfile);
}

/**
* Method that gets called when starting game, normally would go to Welcome screen but if no world
* configured (using RSC+ for replay mode) skip directly to login for replays
Expand Down Expand Up @@ -895,6 +936,55 @@ public static void isLoadingHook(boolean isLoading) {
}
}
}

/**
* General extra check for new received opcodes
* Send false if has finished processing
* @param opcode - Packet opcode
* @param psize - Packet size
* @return false to indicate no more processing is needed
*/
public static boolean newOpcodeReceivedHook(int opcode, int psize) {
boolean couldNotProcess = true;

if (AccountManagement.processPacket(opcode, psize)) {
couldNotProcess = false;
}

return couldNotProcess;
}

/**
* General in game input hook for new added elements
* return false to indicate continue checking conditions in the original gameInput() method
*/
public static boolean gameInputHook(int n1, int mouseY, int n3, int mouseX) {
boolean continueFlow = true;

if (Client.showRecoveryQuestions) {
AccountManagement.recovery_questions_input(n1, mouseY, n3, mouseX);
continueFlow = false;
} else if (Client.showContactDetails) {
AccountManagement.contact_details_input(n1, mouseY, n3, mouseX);
continueFlow = false;
}

return continueFlow;
}

public static void loginOtherButtonCheckHook() {
AccountManagement.processForgotPassword();
}

public static boolean drawGameHook() {
boolean continueFlow = true;

if (AccountManagement.pending_render()) {
continueFlow = false;
}

return continueFlow;
}

public static void resetLoginMessage() {
setLoginMessage("Please enter your username and password", "");
Expand Down Expand Up @@ -1373,6 +1463,24 @@ public static void clearScreen() {
} catch (Exception e) {
}
}

public static void setInterlace(boolean value) {
if (Reflection.interlace == null) return;

try {
Reflection.interlace.set(Renderer.instance, value);
} catch (Exception e) {
}
}

public static void drawGraphics() {
if (Reflection.drawGraphics == null) return;

try {
Reflection.drawGraphics.invoke(Renderer.instance, Renderer.graphicsInstance, 0, 256, 0);
} catch (Exception e) {
}
}

public static void preGameDisplay() {
if (Reflection.preGameDisplay == null) return;
Expand Down Expand Up @@ -1479,6 +1587,12 @@ public static void retroFPSHook(Object surfaceInstance) {
}
}
}

public static void initCreateExtraPanelsHook() {
AccountManagement.create_account_recovery();
AccountManagement.create_recovery_questions();
AccountManagement.create_contact_details();
}

public static int attack_menu_hook(int cmpVar) {
if (Settings.ATTACK_ALWAYS_LEFT_CLICK.get(Settings.currentProfile)
Expand Down
15 changes: 13 additions & 2 deletions src/Game/Panel.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public class Panel {
public static int control_text_size;
public static boolean control_use_alt_color;
public static String control_text;

public static Object createPanel(int maxElements) {
if (Reflection.panel == null) return null;

Object result = null;
try {
result = Reflection.panel.newInstance(Renderer.instance, maxElements);
} catch (Exception e) {
}

return result;
}

public static void drawPanel(Object panelSource) {
if (Reflection.drawPanel == null) return;
Expand Down Expand Up @@ -173,7 +185,6 @@ public static int addButtonTo(Object panelSource, int xPos, int yPos, int width,

public static int addInputTo(
Object panelSource,
int n,
int xPos,
int yPos,
int width,
Expand All @@ -190,7 +201,7 @@ public static int addInputTo(
(int)
Reflection.addInput.invoke(
panelSource,
n - 3845,
0,
capacity,
width,
isBackground,
Expand Down
Loading

0 comments on commit ae1911d

Please sign in to comment.