-
Notifications
You must be signed in to change notification settings - Fork 5
/
commands.hpp
122 lines (115 loc) · 3.47 KB
/
commands.hpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
command_result remote_cmd(color_ostream &out, std::vector <std::string> & args)
{
if (args.size())
{
std::string &cmd = args[0];
if (cmd == "on" || cmd == "1" || cmd == "start")
{
remote_start();
save_config();
}
else if (cmd == "off" || cmd == "0" || cmd == "stop")
{
remote_stop();
save_config();
}
else if (cmd == "publish" && args.size() == 2)
{
remote_publish(args[1]);
save_config();
}
else if (cmd == "unpublish")
{
remote_unpublish();
save_config();
}
else if (cmd == "connect")
{
#define HAS_FLAG(f) (std::find(args.begin()+1, args.end(), f) != args.end())
bool debug = HAS_FLAG("-debug");
bool no_external = HAS_FLAG("-no-external");
bool no_publish = HAS_FLAG("-no-publish");
bool randomize = HAS_FLAG("-randomize");
bool firewall = HAS_FLAG("-firewall");
remote_connect(out, debug, no_external, no_publish, randomize, firewall);
save_config();
}
else if (cmd == "password" || cmd == "pwd" || cmd == "pass")
{
if (args.size() == 2)
{
remote_setpwd(args[1]);
save_config();
}
else if (args.size() == 1)
{
DFHack::CommandHistory hist;
std::string ret;
int rv = Core::getInstance().getConsole().lineedit("Enter new password (Ctrl-C to cancel, blank to disable password): ", ret, hist);
if (rv != -1)
{
remote_setpwd(ret);
save_config();
}
}
else
return CR_WRONG_USAGE;
}
else if (cmd == "port" && args.size() == 2)
{
if (remote_on)
{
out << "Stop using `remote off` first." << std::endl;
return CR_OK;
}
int newport;
if (parse_int(args[1], newport))
enet_port = newport;
else
return CR_WRONG_USAGE;
save_config();
}
else if (cmd == "debug" && args.size() == 2)
{
string &arg1 = args[1];
if (arg1 == "on" || arg1 == "1")
debug = true;
else
debug = false;
}
else if (cmd == "reload")
{
remote_unload_lua();
}
else if (cmd == "v" || cmd == "ver" || cmd == "version")
{
remote_print_version();
}
else if (cmd == "advflags")
{
if (args.size() == 3)
{
int bit, val;
if (parse_int(args[1], bit) && parse_int(args[2], val) && bit >= 0 && bit <= 15)
{
if (val)
advflags |= (1<<bit);
else
advflags &= ~(1<<bit);
}
}
for (int i = 15; i >= 0; i--)
*out2 << (advflags&(1<<i) ? 1 : 0);
*out2 << "=" << advflags << std::endl;
save_config();
}
else if (cmd == "noop")
{
}
else
return CR_WRONG_USAGE;
}
else
return CR_WRONG_USAGE;
return CR_OK;
}