forked from florian-sander/gseen.mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slang_gseen_commands.c
237 lines (201 loc) · 5.29 KB
/
slang_gseen_commands.c
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include <stddef.h>
static void slang_send_botnick()
{
strncat(slang_text_buf, botname, sizeof(slang_text_buf));
}
static void slang_send_query()
{
if (glob_query)
strncat(slang_text_buf, glob_query, sizeof(slang_text_buf));
}
static void slang_send_laston()
{
if (glob_laston)
strncat(slang_text_buf, glob_laston, sizeof(slang_text_buf));
}
static void slang_send_otherchan()
{
if (glob_otherchan)
strncat(slang_text_buf, glob_otherchan, sizeof(slang_text_buf));
}
static void slang_send_othernick()
{
if (glob_othernick)
strncat(slang_text_buf, glob_othernick, sizeof(slang_text_buf));
}
static void slang_send_remotebot()
{
if (glob_remotebot)
strncat(slang_text_buf, glob_remotebot, sizeof(slang_text_buf));
}
static void slang_send_snick()
{
if (glob_seendat)
strncat(slang_text_buf, glob_seendat->nick, sizeof(slang_text_buf));
}
static void slang_send_shost()
{
if (glob_seendat)
strncat(slang_text_buf, glob_seendat->host, sizeof(slang_text_buf));
}
static void slang_send_schan()
{
if (glob_seendat)
strncat(slang_text_buf, glob_seendat->chan, sizeof(slang_text_buf));
}
static void slang_send_swhen()
{
char *dur;
if (glob_seendat) {
dur = gseen_duration(now - glob_seendat->when);
strncat(slang_text_buf, dur, sizeof(slang_text_buf));
}
}
static void slang_send_stime()
{
time_t tt;
char t[20];
if (glob_seendat) {
tt = glob_seendat->when;
strftime(t, sizeof(t), "%d.%m.%Y %H:%M", localtime(&tt));
strncat(slang_text_buf, t, sizeof(slang_text_buf));
}
}
static void slang_send_spent()
{
char *dur;
if (glob_seendat) {
dur = gseen_duration(glob_seendat->spent);
strncat(slang_text_buf, dur, sizeof(slang_text_buf));
}
}
static void slang_send_smsg()
{
if (glob_seendat)
strncat(slang_text_buf, glob_seendat->msg, sizeof(slang_text_buf));
}
static void slang_send_numresults()
{
char buf[7];
snprintf(buf, sizeof(buf), "%d", numresults);
strncat(slang_text_buf, buf, sizeof(slang_text_buf));
}
static void slang_send_punisher()
{
char *reason;
ptrdiff_t len;
if (glob_seendat) {
reason = strchr(glob_seendat->msg, ' ');
if (!reason)
strncat(slang_text_buf, glob_seendat->msg, sizeof(slang_text_buf));
else {
len = reason - glob_seendat->msg;
strncat(slang_text_buf, glob_seendat->msg, (sizeof(slang_text_buf) < len) ? sizeof(slang_text_buf) : len);
}
}
}
static void slang_send_kickreason()
{
char *reason;
if (glob_seendat) {
reason = strchr(glob_seendat->msg, ' ');
if (reason)
strncat(slang_text_buf, reason, sizeof(slang_text_buf));
}
}
static void slang_send_rnick()
{
if (glob_seenrequest) {
Assert(glob_seenrequest->by);
Assert(glob_seenrequest->by->who);
strncat(slang_text_buf, glob_seenrequest->by->who, sizeof(slang_text_buf));
}
}
static void slang_send_rchan()
{
if (glob_seenrequest) {
Assert(glob_seenrequest->by);
Assert(glob_seenrequest->by->chan);
strncat(slang_text_buf, glob_seenrequest->by->chan, sizeof(slang_text_buf));
}
}
static void slang_send_rhost()
{
if (glob_seenrequest) {
Assert(glob_seenrequest->by);
Assert(glob_seenrequest->by->host);
strncat(slang_text_buf, glob_seenrequest->by->host, sizeof(slang_text_buf));
}
}
static void slang_send_rtime()
{
time_t tt;
char t[20];
if (glob_seenrequest) {
Assert(glob_seenrequest->by);
tt = glob_seenrequest->by->when;
strftime(t, sizeof(t), "%d.%m.%Y %H:%M", localtime(&tt));
strncat(slang_text_buf, t, sizeof(slang_text_buf));
}
}
static void slang_send_rwhen()
{
if (glob_seenrequest) {
Assert(glob_seenrequest->by);
strncat(slang_text_buf, gseen_duration(now - glob_seenrequest->by->when), sizeof(slang_text_buf));
}
}
static void slang_send_requests()
{
char buf[7];
snprintf(buf, sizeof(buf), "%d", glob_seenrequests);
strncat(slang_text_buf, buf, sizeof(slang_text_buf));
}
static void slang_send_totalnicks()
{
char buf[7];
snprintf(buf, sizeof(buf), "%d", glob_totalnicks);
strncat(slang_text_buf, buf, sizeof(slang_text_buf));
}
static void slang_send_totalbytes()
{
char buf[20];
snprintf(buf, sizeof(buf), "%d", glob_totalbytes);
strncat(slang_text_buf, buf, sizeof(slang_text_buf));
}
static void slang_send_nick()
{
if (glob_nick)
strncat(slang_text_buf, glob_nick, sizeof(slang_text_buf));
}
struct slang_text_commands slang_text_gseen_command_table[] =
{
{"botnick", slang_send_botnick},
{"query", slang_send_query},
{"laston", slang_send_laston},
{"otherchan", slang_send_otherchan},
{"othernick", slang_send_othernick},
{"remotebot", slang_send_remotebot},
{"snick", slang_send_snick},
{"swhen", slang_send_swhen},
{"stime", slang_send_stime},
{"shost", slang_send_shost},
{"schan", slang_send_schan},
{"spent", slang_send_spent},
{"smsg", slang_send_smsg},
{"numresults", slang_send_numresults},
{"snick2", slang_send_smsg},
{"bnbot", slang_send_smsg},
{"punisher", slang_send_punisher},
{"kickreason", slang_send_kickreason},
{"rnick", slang_send_rnick},
{"rchan", slang_send_rchan},
{"rhost", slang_send_rhost},
{"rtime", slang_send_rtime},
{"rwhen", slang_send_rwhen},
{"requests", slang_send_requests},
{"totalnicks", slang_send_totalnicks},
{"totalbytes", slang_send_totalbytes},
{"nick", slang_send_nick},
{0, 0}
};