corrade-vassal – Blame information for rev 22

Subversion Repositories:
Rev:
Rev Author Line No. Line
7 zed 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. //
5 ///////////////////////////////////////////////////////////////////////////
6  
7 using System;
2 zed 8 using System.Collections.Generic;
9 using System.ComponentModel;
10 using System.IO;
11 using System.Text;
12 using System.Xml.Serialization;
13  
14 namespace Vassal
15 {
16 /// <summary>
17 /// Possible input and output filters.
18 /// </summary>
19 public enum Filter : uint
20 {
13 eva 21 [XmlEnum(Name = "none")] [Description("none")] NONE = 0,
22 [XmlEnum(Name = "RFC1738")] [Description("RFC1738")] RFC1738,
23 [XmlEnum(Name = "RFC3986")] [Description("RFC3986")] RFC3986,
24 [XmlEnum(Name = "ENIGMA")] [Description("ENIGMA")] ENIGMA,
25 [XmlEnum(Name = "VIGENERE")] [Description("VIGENERE")] VIGENERE,
26 [XmlEnum(Name = "ATBASH")] [Description("ATBASH")] ATBASH,
27 [XmlEnum(Name = "BASE64")] [Description("BASE64")] BASE64
2 zed 28 }
29  
30 /// <summary>
31 /// ENIGMA machine settings.
32 /// </summary>
33 public struct ENIGMA
34 {
35 public char[] plugs;
36 public char reflector;
37 public char[] rotors;
38 }
13 eva 39  
2 zed 40 [Serializable]
41 public class VassalConfiguration
42 {
43 private static readonly object VassalConfigurationLock = new object();
44  
45 private ENIGMA _enigma = new ENIGMA
46 {
13 eva 47 rotors = new[] {'3', 'g', '1'},
48 plugs = new[] {'z', 'p', 'q'},
2 zed 49 reflector = 'b'
50 };
13 eva 51  
52 private string _group = string.Empty;
53 private string _HTTPServerURL = @"http://127.0.0.1:8080/";
2 zed 54 private List<Filter> _inputFilters = new List<Filter>();
55 private List<Filter> _outputFilters = new List<Filter>();
13 eva 56 private string _password = string.Empty;
57 private uint _regionRestartDelay = 120;
22 office 58 private uint _servicesTimeout = 60000;
13 eva 59 private uint _teleportTimeout = 30000;
2 zed 60 private string _vigenereSecret = string.Empty;
61  
62 public string Group
63 {
64 get
65 {
66 lock (VassalConfigurationLock)
67 {
68 return _group;
69 }
70 }
71 set
72 {
73 lock (VassalConfigurationLock)
74 {
75 _group = value;
76 }
77 }
78 }
79  
80 public string Password
81 {
82 get
83 {
84 lock (VassalConfigurationLock)
85 {
86 return _password;
87 }
88 }
89 set
90 {
91 lock (VassalConfigurationLock)
92 {
93 _password = value;
94 }
95 }
96 }
97  
98 public ENIGMA ENIGMA
99 {
100 get
101 {
102 lock (VassalConfigurationLock)
103 {
104 return _enigma;
105 }
106 }
107 set
108 {
109 lock (VassalConfigurationLock)
110 {
111 _enigma = value;
112 }
113 }
114 }
115  
116 public string VIGENERESecret
117 {
118 get
119 {
120 lock (VassalConfigurationLock)
121 {
122 return _vigenereSecret;
123 }
124 }
125 set
126 {
127 lock (VassalConfigurationLock)
128 {
129 _vigenereSecret = value;
130 }
131 }
132 }
133  
134 public List<Filter> InputFilters
135 {
136 get
137 {
138 lock (VassalConfigurationLock)
139 {
21 office 140 return _inputFilters;
2 zed 141 }
142 }
143 set
144 {
145 lock (VassalConfigurationLock)
146 {
147 _inputFilters = value;
148 }
149 }
150 }
151  
152 public List<Filter> OutputFilters
153 {
154 get
155 {
156 lock (VassalConfigurationLock)
157 {
21 office 158 return _outputFilters;
2 zed 159 }
160 }
161 set
162 {
163 lock (VassalConfigurationLock)
164 {
165 _outputFilters = value;
166 }
167 }
168 }
169  
170 public string HTTPServerURL
171 {
172 get
173 {
174 lock (VassalConfigurationLock)
175 {
176 return _HTTPServerURL;
177 }
178 }
179 set
180 {
181 lock (VassalConfigurationLock)
182 {
183 _HTTPServerURL = value;
184 }
185 }
186 }
187  
188 public uint TeleportTimeout
189 {
190 get
191 {
192 lock (VassalConfigurationLock)
193 {
194 return _teleportTimeout;
195 }
196 }
197 set
198 {
199 lock (VassalConfigurationLock)
200 {
201 _teleportTimeout = value;
202 }
203 }
204 }
205  
16 eva 206 public uint ServicesTimeout
2 zed 207 {
208 get
209 {
210 lock (VassalConfigurationLock)
211 {
16 eva 212 return _servicesTimeout;
2 zed 213 }
214 }
215 set
216 {
217 lock (VassalConfigurationLock)
218 {
16 eva 219 _servicesTimeout = value;
2 zed 220 }
221 }
222 }
223  
5 eva 224 public uint RegionRestartDelay
225 {
226 get
227 {
228 lock (VassalConfigurationLock)
229 {
230 return _regionRestartDelay;
231 }
232 }
233 set
234 {
235 lock (VassalConfigurationLock)
236 {
237 _regionRestartDelay = value;
238 }
239 }
240 }
241  
2 zed 242 public static void Save(string file, ref VassalConfiguration configuration)
243 {
244 lock (VassalConfigurationLock)
245 {
22 office 246 using (var writer = new StreamWriter(file, false, Encoding.UTF8))
2 zed 247 {
22 office 248 var serializer = new XmlSerializer(typeof(VassalConfiguration));
2 zed 249 serializer.Serialize(writer, configuration);
250 //writer.Flush();
251 }
252 }
253 }
254  
255 public static void Load(string file, ref VassalConfiguration configuration)
256 {
257 lock (VassalConfigurationLock)
258 {
22 office 259 using (var stream = new StreamReader(file, Encoding.UTF8))
2 zed 260 {
22 office 261 var serializer =
262 new XmlSerializer(typeof(VassalConfiguration));
13 eva 263 configuration = (VassalConfiguration) serializer.Deserialize(stream);
2 zed 264 }
265 }
266 }
267 }
13 eva 268 }