View Javadoc

1   package cz.cuni.amis.pogamut.udk.utils;
2   
3   import cz.cuni.amis.pogamut.base.utils.Pogamut;
4   import cz.cuni.amis.pogamut.base.utils.PogamutProperty;
5   import cz.cuni.amis.utils.exception.PogamutIOException;
6   import java.io.File;
7   import java.io.IOException;
8   import java.net.InetAddress;
9   import java.net.URI;
10  import java.util.Arrays;
11  import java.util.List;
12  
13  /**
14   * Wrapper of the UDK instance. Can be used for launching the game in spectate mode.
15   * @author ik
16   */
17  public class UDKWrapper {
18  
19      public static void launchSpectate(URI serverUri) throws IOException {
20          String udkHomeProp = Pogamut.getPlatform().getProperty(PogamutUDKProperty.POGAMUT_UNREAL_HOME.getKey());
21          if(udkHomeProp == null) throw new PogamutIOException(
22                  "Property " + PogamutUDKProperty.POGAMUT_UNREAL_HOME.getKey() + " not set. Set it to point to the UDK home directory. You can do this in environments variables.", null);
23          String path = udkHomeProp + File.separator + "System" + File.separator;
24          List<String> cmds = null;
25          if (!System.getProperty("os.name").contains("Windows")) {
26              // TODO how to start in UNIX?
27          } else {
28              path += "UDK.exe";
29              // TODO deal with multiple uccs on one host
30              // get IP
31              InetAddress adr = InetAddress.getByName(serverUri.getHost());
32              cmds = Arrays.asList("cmd.exe",
33                      "/c",
34                      "start \"UDK Spectate\" /low \"" + path + "\" " + adr.getHostAddress());
35          }
36  
37          ProcessBuilder builder = new ProcessBuilder(cmds);
38          Process ut = builder.start();
39      }
40  }