1 package cz.cuni.amis.pogamut.ut2004.tournament;
2
3 import java.io.File;
4 import java.io.InputStream;
5 import java.net.URISyntaxException;
6
7 import cz.cuni.amis.utils.IniFile;
8 import cz.cuni.amis.utils.exception.PogamutException;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class UT2004Ini extends IniFile {
24
25
26
27
28
29 public static final String Section_URL = "URL";
30 public static final String Section_Engine_GameReplicationInfo = "Engine.GameReplicationInfo";
31
32
33
34
35
36 public static final String Key_Port = "Port";
37
38 public static final String Key_ServerName = "ServerName";
39 public static final String Key_ShortName = "ShortName";
40
41
42
43
44 public UT2004Ini() {
45 InputStream defaults = UT2004Ini.class.getResourceAsStream("/cz/cuni/amis/pogamut/ut2004/tournament/UT2004.ini");
46 load(defaults);
47 }
48
49
50
51
52
53
54 public UT2004Ini(File source) {
55 if (!source.exists()) {
56 throw new PogamutException("File with defaults for UT2004.ini does not exist at: " + source.getAbsolutePath() + ".", this);
57 }
58 load(source);
59 }
60
61 public UT2004Ini(UT2004Ini ut2004Ini) {
62 super(ut2004Ini);
63 }
64
65
66
67
68
69 public String getServerName() {
70 return getSection(Section_Engine_GameReplicationInfo).get(Key_ServerName);
71 }
72
73
74
75
76
77 public String getServerShortName() {
78 return getSection(Section_Engine_GameReplicationInfo).get(Key_ShortName);
79 }
80
81
82
83
84
85
86 public void setServerName(String serverName, String shortName) {
87 getSection(Section_Engine_GameReplicationInfo).set(Key_ServerName, serverName);
88 getSection(Section_Engine_GameReplicationInfo).set(Key_ShortName, shortName);
89 }
90
91
92
93
94
95 public int getPort() {
96 String port = getSection(Section_URL).get(Key_Port);
97 try {
98 return Integer.parseInt(port);
99 } catch (Exception e) {
100 return 0;
101 }
102 }
103
104
105
106
107
108 public void setPort(int port) {
109 getSection(Section_URL).set(Key_Port, String.valueOf(port));
110 }
111
112 }