-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathEventSocket.cs
64 lines (61 loc) · 2.61 KB
/
EventSocket.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Linq;
using System.Windows;
using System.Xml;
using System.Xml.Serialization;
namespace FSClient {
[XmlRoot("settingsEventSocket")]
public class SettingsEventSocket {
public SettingsField[] fields { get; set; }
public EventSocket GetEventSocket() {
EventSocket socket = new EventSocket();
foreach (SettingsField field in fields) {
FieldValue val = FieldValue.GetByName(socket.values, field.name);
if (val != null)
val.value = field.value;
}
return socket;
}
public SettingsEventSocket() {
}
public SettingsEventSocket(EventSocket socket) {
fields = (from fv in socket.values select new SettingsField(fv)).ToArray();
}
}
public class EventSocket{
public static Field[] fields = {
new Field(Field.FIELD_TYPE.String, "Listen IP","listen-ip","listen-ip","127.0.0.1",""),
new Field(Field.FIELD_TYPE.Int,"Listen Port","listen-port","listen-port","8022",""),
new Field(Field.FIELD_TYPE.String,"Password","password","password","ClueCon",""),
new Field(Field.FIELD_TYPE.String,"Inbound ACL","apply-inbound-acl","apply-inbound-acl","",""),
new Field(Field.FIELD_TYPE.Bool,"Nat Map","nat-map","nat-map","false",""),
new Field(Field.FIELD_TYPE.Combo,"Debug Mode","debug","debug","0","",new Field.FieldOption{display_value="true", value="1"},new Field.FieldOption{display_value="false", value="0"}),
};
private static string[] AllowedEmptyFields = new[] { "password", "listen-ip" };
public FieldValue[] values = FieldValue.FieldValues(fields);
public void gen_config(XmlNode config_node){
XmlNode settings = XmlUtils.AddNodeNode(config_node, "settings");
foreach (FieldValue value in values) {
if (String.IsNullOrEmpty(value.field.xml_name))
continue;
if (String.IsNullOrWhiteSpace(value.value) && !AllowedEmptyFields.Contains(value.field.name))
continue;
Utils.add_xml_param(settings, value.field.xml_name, value.value);
}
}
public void reload_config(){
Utils.bgapi_exec("reload", "mod_event_socket");
}
public void edit() {
GenericEditor editor = new GenericEditor();
editor.Init("Editing Event Socket Settings", values);
editor.ShowDialog();
if (editor.DialogResult == true){
MessageBoxResult mres = MessageBox.Show("Do you want to reload the event socket settings now, doing so will drop anyone connected to the event socket?", "Reload Module Warning", MessageBoxButton.YesNo);
if (mres != MessageBoxResult.Yes)
return;
reload_config();
}
}
}
}