View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.utils;
2   
3   import cz.cuni.amis.pogamut.base.utils.Pogamut;
4   import cz.cuni.amis.utils.exception.PogamutIOException;
5   import java.io.File;
6   import java.io.IOException;
7   import java.net.InetAddress;
8   import java.net.URI;
9   import java.util.Arrays;
10  import java.util.List;
11  
12  /**
13   * Wrapper of the UT2004 instance. Can be used for launching the game in spectate mode.
14   * @author ik
15   */
16  public class UT2004Wrapper {
17  
18      public static void launchSpectate(URI serverUri) throws IOException {
19          String utHomeProp = Pogamut.getPlatform().getProperty(PogamutUT2004Property.POGAMUT_UNREAL_HOME.getKey());
20          if(utHomeProp == null) throw new PogamutIOException(
21                  "Property " + PogamutUT2004Property.POGAMUT_UNREAL_HOME.getKey() + " not set. Set it to point to the UT2004 home directory. You can do this in environments variables.", null);
22          String path = utHomeProp + File.separator + "System" + File.separator;
23          
24          List<String> cmds = null;
25          if (!System.getProperty("os.name").contains("Windows")) {
26              // TODO how to start in UNIX?
27          } else {
28              path += "UT2004.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 \"UT2004 Spectate\" /low \"" + path + "\" " + adr.getHostAddress());
35          }
36  
37          ProcessBuilder builder = new ProcessBuilder(cmds);
38          Process ut = builder.start();
39      }
40  }