22
33import com .neovisionaries .ws .client .WebSocketException ;
44import com .yeetor .androidcontrol .RemoteClient ;
5- import com .yeetor .minicap .MinicapInstallException ;
65import com .yeetor .androidcontrol .LocalServer ;
6+ import com .yeetor .androidcontrol .RemoteServer ;
77
88import java .io .IOException ;
99import java .security .InvalidParameterException ;
@@ -18,54 +18,70 @@ public class Main {
1818 * [client ip port serialNumber]
1919 * [client ip port]
2020 */
21- public static void main (String [] args ) throws MinicapInstallException {
21+ public static void main (String [] args ) {
2222
2323 try {
2424 Config config = new Config (args );
25- if (config .isLocal ) {
26- new LocalServer (config .port ).start ();
25+
26+ if (config .isClient ) {
27+ new RemoteClient (config .ip , config .port , config .key , config .serialNumber );
2728 } else {
28- new RemoteClient (config .ip , config .port , config .serialNumber );
29+ if (config .isLocal ) {
30+ new LocalServer (config .port ).start ();
31+ } else {
32+ new RemoteServer (config .port ).start ();
33+ }
2934 }
3035 } catch (InvalidParameterException ex ) {
31- System .out .println ("localserver <port>: 启动本地服务器(p2p)\n client < ip> <port> [serialNumber] 启动客户端" );
36+ System .out .println ("localserver <port>: 启动本地服务器(p2p)\n remoteserver <port> 启动服务器 \n remoteclient < ip> <port> <key > [serialNumber] 启动客户端" );
3237 System .exit (0 );
3338 } catch (WebSocketException |InterruptedException e ) {
3439 System .out .println ("启动服务器失败: " + e .getMessage ());
3540 System .exit (0 );
36- } catch (IOException e ) {
41+ } catch (Exception e ) {
3742 e .printStackTrace ();
3843 System .exit (0 );
3944 }
4045 }
4146
4247 static class Config {
4348 boolean isLocal = true ;
49+ boolean isClient = false ;
4450 String ip = "" ;
4551 int port = 6655 ;
4652 String serialNumber = "" ;
53+ String key = "" ;
4754
4855 Config (String [] args ) throws InvalidParameterException {
4956 if (args .length > 0 ) {
50- if ("remoteserver" .equals (args [0 ])) {
57+ if ("localserver" .equals (args [0 ])) {
58+ isLocal = true ;
59+ isClient = false ;
60+ } else if ("remoteserver" .equals (args [0 ])) {
5161 isLocal = false ;
62+ isClient = false ;
63+ } else {
64+ isLocal = true ;
65+ isClient = true ;
5266 }
5367 }
5468
55- if (isLocal ) {
56- if (args .length == 2 ) {
57- port = Integer .parseInt (args [1 ]);
58- } else {
59- throw new InvalidParameterException ("参数不正确" );
60- }
61- } else {
62- if (args .length == 3 ) {
69+ if (isClient ) {
70+ if (args .length == 4 ) {
6371 ip = args [1 ];
6472 port = Integer .parseInt (args [2 ]);
65- } else if (args .length == 4 ) {
73+ key = args [3 ];
74+ } else if (args .length == 5 ) {
6675 ip = args [1 ];
6776 port = Integer .parseInt (args [2 ]);
68- serialNumber = args [3 ];
77+ key = args [3 ];
78+ serialNumber = args [4 ];
79+ } else {
80+ throw new InvalidParameterException ("参数不正确" );
81+ }
82+ } else {
83+ if (args .length == 2 ) {
84+ port = Integer .parseInt (args [1 ]);
6985 } else {
7086 throw new InvalidParameterException ("参数不正确" );
7187 }
0 commit comments