adding special port rotation for boot peers
[SauerbratenRemote.git] / P2PMud-sauerbraten / src / Props.groovy
blobbb75ece1228c8ae85a331c26fa7cce56871a6045
1 class Props {
2 def properties = [:] as Properties
3 def profile = ""
4 def profiles = [] as Set
5 def last_profile = ""
6 def file
7 def static defaultProps = [
8 sauer_port: '12345',
9 name: 'bubba-' + System.currentTimeMillis(),
10 guild: '',
11 pastry_port_start: '3993',
12 pastry_port_end: '3999',
13 pastry_port_rotate: '',
14 pastry_boot_host: 'plubble.com',
15 pastry_boot_start: '3993',
16 pastry_boot_end: '3994',
17 external_ip: '',
18 external_port: '3993',
19 headless: '0',
20 upnp: '1',
21 sauer_mode: 'launch',
22 past_storage:'/tmp/storage-9090'
23 ] as Properties
26 def initProps() {
27 println "going to initprops()"
28 for (e in defaultProps) {
29 if (!this[e.key]) this[e.key] = e.value
31 if (!this['sauer_cmd']) {
32 if (System.getProperty('os.name').equalsIgnoreCase('linux')) {
33 this.sauer_cmd = 'packages/plexus/dist/sauerbraten_plexus_linux -t'
34 } else {
35 this.sauer_cmd = 'packages/plexus/dist/sauerbraten_plexus_windows.exe -t'
40 def setProfile(prof) {
41 profile = prof ? "$prof-" : ""
42 initProps()
44 def getAt(String key) {
45 properties["$profile$key" as String]
47 def putAt(String key, value) {
48 key = "$profile$key" as String
49 def old = properties[key]
51 properties[key] = value as String
52 old
54 def propertyMissing(String name) {
55 getAt(name)
57 def propertyMissing(String name, value) {
58 putAt(name, value)
60 def store() {
61 def output = file.newOutputStream()
63 properties.store(output, "Plexus Properties")
64 output.close()
66 def load() {
67 def dir = new File('').getAbsoluteFile()
68 def plexusdir = new File(dir, 'packages/plexus')
69 this.file = new File(plexusdir, 'plexus.properties')
71 properties = [:] as Properties
72 if (file.exists()) {
73 def input = new FileInputStream(file)
75 properties.load(input)
76 input.close()
77 profiles = [*(properties?.profiles ? properties.profiles.split(',') : [])] as Set
78 if (properties.last_profile == null) properties.last_profile = ""
79 last_profile = properties.last_profile
81 initProps()
83 def setLastProfile(prof) {
84 if (prof != last_profile) {
85 last_profile = properties.last_profile = prof
88 def containsProfile(prof) {
89 return profiles.contains(prof);
91 def addProfile(prof) {
92 if (!profiles.contains(prof)) {
93 profiles.add prof
94 properties.profiles = profiles.join(',')
95 store()
96 return true
97 } else {
98 return false
101 def removeProfile() {
102 if (profile) {
103 def k = []
105 k.addAll(properties.keySet())
106 k.each {
107 if (it ==~ "$profile.*") {
108 properties.remove(it)
111 profiles.remove(profile.substring(0, profile.length() - 1))
112 properties.profiles = profiles.join(',')
113 store()