Skip to content

Commit

Permalink
0.3.7 with admin check
Browse files Browse the repository at this point in the history
  • Loading branch information
Immueggpain authored and Immueggpain committed Dec 5, 2019
1 parent 30e8737 commit 41fd42e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.immueggpain</groupId>
<artifactId>bettermultiplayer</artifactId>
<version>0.2.0</version>
<version>0.3.7</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import com.sun.jna.platform.win32.Advapi32Util;

import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
Expand All @@ -30,9 +31,21 @@ public class BMPPeer implements Callable<Void> {

@Override
public Void call() throws Exception {
// check admin privilege
boolean isAdmin = isWinAdmin();
System.out.println("is admin? " + isAdmin);

// check tap device
if (!hasTapAdapter()) {
// make sure tap driver/adapter is installed!

// check if we have admin rights
if (!isAdmin) {
System.err.println("can't install tap adapter driver!");
System.err.println("please re-run with admin privilege!");
return null;
}

System.out.println("Please intall tap adapter");
Process process = new ProcessBuilder("ovpn\\tap-windows.exe").inheritIO().start();
int exitCode = process.waitFor();
Expand All @@ -45,18 +58,19 @@ public Void call() throws Exception {
}
// wait a sec
Thread.sleep(1000);
}

// setup udp redirect
Thread recvOvpnThread = Util.execAsync("recv_ovpn_thread", () -> recv_ovpn_thread(Launcher.LOCAL_PORT));
Thread recvServerThread = Util.execAsync("recv_server_thread",
() -> recv_server_thread(Launcher.LOCAL_OVPN_PORT));
// setup udp redirect
Thread recvOvpnThread = Util.execAsync("recv_ovpn_thread", () -> recv_ovpn_thread(Launcher.LOCAL_PORT));
Thread recvServerThread = Util.execAsync("recv_server_thread",
() -> recv_server_thread(Launcher.LOCAL_OVPN_PORT));

// start ovpn
startOvpnProcess(Launcher.LOCAL_PORT);
// start ovpn
startOvpnProcess(Launcher.LOCAL_PORT);

recvOvpnThread.join();
recvServerThread.join();

recvOvpnThread.join();
recvServerThread.join();
}
return null;
}

Expand Down Expand Up @@ -127,4 +141,14 @@ private static boolean hasTapAdapter() throws IOException, InterruptedException
return m.find();
}

public static boolean isWinAdmin() throws IOException, InterruptedException {
Advapi32Util.Account[] groups = Advapi32Util.getCurrentUserGroups();
for (Advapi32Util.Account group : groups) {
if ("S-1-16-12288".equals(group.sidString)) {
return true;
}
}
return false;
}

}

0 comments on commit 41fd42e

Please sign in to comment.