5
5
import com .superzanti .serversync .gui .GUI_Client_Mock ;
6
6
import com .superzanti .serversync .server .ServerSetup ;
7
7
import com .superzanti .serversync .util .Logger ;
8
- import com .superzanti .serversync .util .ProgramArguments ;
9
8
import com .superzanti .serversync .util .enums .EServerMode ;
9
+ import picocli .CommandLine ;
10
+ import picocli .CommandLine .*;
10
11
11
12
import java .util .Locale ;
12
13
import java .util .MissingResourceException ;
13
14
import java .util .ResourceBundle ;
15
+ import java .util .concurrent .Callable ;
14
16
15
- public class ServerSync {
17
+ @ Command (name = "ServerSync" , mixinStandardHelpOptions = true , version = "3.6.0" , description = "A utility for synchronizing a server<->client style game." )
18
+ public class ServerSync implements Callable <Integer > {
16
19
17
20
/* AWT EVENT DISPATCHER THREAD */
18
21
@@ -21,23 +24,45 @@ public class ServerSync {
21
24
public static EServerMode MODE ;
22
25
23
26
public static GUI_Client clientGUI ;
24
-
25
27
public static ResourceBundle strings ;
26
28
27
- public static ProgramArguments arguments ;
29
+ @ Option (names = {"-o" , "--progress" , "progress-only" }, description = "Only show progress indication. Ignored if '-s', '--server' is specified." )
30
+ private boolean modeProgressOnly = false ;
31
+ @ Option (names = {"-q" , "--quiet" , "silent" }, description = "Remove all GUI interaction. Ignored if '-s', '--server' is specified." )
32
+ private boolean modeQuiet = false ;
33
+ @ Option (names = {"-s" , "--server" , "server" }, description = "Run the program in server mode." )
34
+ private boolean modeServer = false ;
35
+ @ Option (names = {"-a" , "--address" }, description = "The address of the server you wish to connect to." )
36
+ private String serverAddress ;
37
+ @ Option (names = {"-p" , "--port" }, description = "The port the server is running on." )
38
+ private int serverPort = -1 ;
28
39
29
40
public static void main (String [] args ) {
30
- arguments = new ProgramArguments (args );
41
+ int exitCode = new CommandLine (new ServerSync ()).execute (args );
42
+ if (exitCode != 0 ) {
43
+ System .exit (exitCode );
44
+ }
45
+ }
31
46
32
- if (arguments .isServer ) {
47
+ @ Override
48
+ public Integer call () {
49
+ if (modeServer ) {
33
50
runInServerMode ();
34
51
} else {
35
52
runInClientMode ();
36
53
}
54
+ return 0 ;
37
55
}
38
56
39
- private static void commonInit () {
57
+ private void commonInit () {
40
58
Locale locale = SyncConfig .getConfig ().LOCALE ;
59
+ if (serverAddress != null ) {
60
+ SyncConfig .getConfig ().SERVER_IP = serverAddress ;
61
+ }
62
+ if (serverPort > 0 ) {
63
+ SyncConfig .getConfig ().SERVER_PORT = serverPort ;
64
+ }
65
+
41
66
try {
42
67
Logger .log ("Loading language file: " + locale );
43
68
strings = ResourceBundle .getBundle ("assets.serversync.lang.MessagesBundle" , locale );
@@ -47,7 +72,7 @@ private static void commonInit() {
47
72
}
48
73
}
49
74
50
- private static void runInServerMode () {
75
+ private void runInServerMode () {
51
76
ServerSync .MODE = EServerMode .SERVER ;
52
77
new Logger ("server" );
53
78
Logger .setSystemOutput (true );
@@ -58,17 +83,17 @@ private static void runInServerMode() {
58
83
serverThread .start ();
59
84
}
60
85
61
- private static void runInClientMode () {
86
+ private void runInClientMode () {
62
87
ServerSync .MODE = EServerMode .CLIENT ;
63
88
new Logger ("client" );
64
89
SyncConfig config = SyncConfig .getConfig ();
65
90
commonInit ();
66
91
67
92
Thread clientThread ;
68
- if (arguments . syncSilent ) {
93
+ if (modeQuiet ) {
69
94
clientGUI = new GUI_Client_Mock ();
70
95
new Thread (new ClientWorker ()).start ();
71
- } else if (arguments . syncProgressOnly ) {
96
+ } else if (modeProgressOnly ) {
72
97
// TODO setup a progress only version of the GUI
73
98
clientGUI = new GUI_Client ();
74
99
clientGUI .setIPAddress (config .SERVER_IP );
0 commit comments