Skip to content

Commit 5fc7ed1

Browse files
authored
Merge pull request #179 from runejs/refactor/move-game-init-to-game
Move game specific login to Game from Gameshell
2 parents 1751986 + 5208ed8 commit 5fc7ed1

File tree

2 files changed

+78
-58
lines changed

2 files changed

+78
-58
lines changed

src/main/java/org/runejs/client/Game.java

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public class Game {
5252

5353
/**
5454
* The codec currently in use to encode and decode packets.
55-
*
55+
*
5656
* TODO (Jameskmonger) add a clear way to use different codecs
5757
*/
5858
public static final MessagePacketCodec packetCodec = new RuneJS435PacketCodec();
59-
59+
6060
/**
6161
* The registry that holds all the InboundMessage handlers.
6262
*/
@@ -695,6 +695,78 @@ public static void setConfigToDefaults() {
695695
aBoolean519 = true;
696696
}
697697

698+
public Game(String[] args) {
699+
Configuration.read();
700+
Native.username = Configuration.getUsername();
701+
Native.password = Configuration.getPassword();
702+
String[] params = new String[]{"1", "live", "live", "highmem", "members"};
703+
if (args.length != 0) {
704+
params = args;
705+
}
706+
if (params.length != 5) {
707+
Game.printHelp();
708+
}
709+
710+
Player.worldId = Integer.parseInt(params[0]);
711+
712+
// Location argument (to set server IP based on JMod location?)
713+
switch (params[1]) {
714+
case "live":
715+
Game.modewhere = 0;
716+
break;
717+
case "office":
718+
Game.modewhere = 1;
719+
break;
720+
case "local":
721+
Game.modewhere = 2;
722+
break;
723+
default:
724+
Game.printHelp();
725+
break;
726+
}
727+
728+
switch (params[2]) {
729+
case "live":
730+
Game.modewhat = 0;
731+
break;
732+
case "rc":
733+
Game.modewhat = 1;
734+
break;
735+
case "wip":
736+
Game.modewhat = 2;
737+
break;
738+
default:
739+
Game.printHelp();
740+
break;
741+
}
742+
// Memory argument
743+
switch (params[3]) {
744+
case "lowmem":
745+
Game.setLowMemory();
746+
break;
747+
case "highmem":
748+
MovedStatics.setHighMemory();
749+
break;
750+
default:
751+
Game.printHelp();
752+
break;
753+
}
754+
755+
// Memory argument
756+
switch (params[4]) {
757+
case "free":
758+
MovedStatics.membersWorld = false;
759+
break;
760+
case "members":
761+
MovedStatics.membersWorld = true;
762+
763+
break;
764+
default:
765+
Game.printHelp();
766+
break;
767+
}
768+
}
769+
698770
public static void method353() {
699771
MovedStatics.anInt2628++;
700772
renderPlayers(0, true);
@@ -1616,7 +1688,7 @@ public static void handleLoginScreenActions() {
16161688

16171689
// TODO (Jameskmonger) this allows the OutgoingPackets to access the ISAAC cipher. This is a hack and should be fixed.
16181690
OutgoingPackets.init(OutgoingPackets.buffer.outCipher);
1619-
1691+
16201692
for (int i = 0; i < 4; i++) {
16211693
seeds[i] += 50;
16221694
}

src/main/java/org/runejs/client/GameShell.java

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,63 +41,11 @@ public GameShell(Game game) {
4141
}
4242

4343
public static void main(String[] args) {
44-
Configuration.read();
45-
Native.username = Configuration.getUsername();
46-
Native.password = Configuration.getPassword();
47-
String[] params = new String[]{"1", "live", "live", "highmem", "members"};
48-
if(args.length != 0) {
49-
params = args;
50-
}
44+
Game game = new Game(args);
45+
GameShell shell = new GameShell(game);
46+
game.setErrorHandler(shell);
5147
try {
52-
if (params.length != 5)
53-
Game.printHelp();
54-
55-
Player.worldId = Integer.parseInt(params[0]);
56-
57-
// Location argument (to set server IP based on JMod location?)
58-
if (params[1].equals("live")) {
59-
Game.modewhere = 0;
60-
} else if (params[1].equals("office")) {
61-
Game.modewhere = 1;
62-
} else if (params[1].equals("local")) {
63-
Game.modewhere = 2;
64-
} else {
65-
Game.printHelp();
66-
}
67-
68-
if (params[2].equals("live"))
69-
Game.modewhat = 0;
70-
else if (!params[2].equals("rc")) {
71-
if (params[2].equals("wip"))
72-
Game.modewhat = 2;
73-
else
74-
Game.printHelp();
75-
} else
76-
Game.modewhat = 1;
77-
78-
// Memory argument
79-
if (params[3].equals("lowmem")) {
80-
Game.setLowMemory();
81-
} else if (params[3].equals("highmem")) {
82-
MovedStatics.setHighMemory();
83-
} else {
84-
Game.printHelp();
85-
}
86-
87-
// Player membership argument
88-
if (params[4].equals("free")) {
89-
MovedStatics.membersWorld = false;
90-
} else if (params[4].equals("members")) {
91-
MovedStatics.membersWorld = true;
92-
} else {
93-
Game.printHelp();
94-
}
95-
96-
Game game = new Game();
97-
GameShell shell = new GameShell(game);
98-
game.setErrorHandler(shell);
9948
shell.openClientApplet("client435", 13, 32 + Game.modewhat, InetAddress.getByName(Configuration.SERVER_ADDRESS), 435);
100-
10149
} catch (Exception exception) {
10250
exception.printStackTrace();
10351
}

0 commit comments

Comments
 (0)