-
Notifications
You must be signed in to change notification settings - Fork 1
/
originalFeatures.cpp
390 lines (345 loc) · 9.29 KB
/
originalFeatures.cpp
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*******************************************
A Docile Sloth 2016 ([email protected])
*******************************************/
extern "C"
{
#include "ts3plugin.h"
};
#include <sstream>
#include <vector>
#include "slothSock.hpp"
#include "utility.hpp"
std::wstring Communicate(int cont, slothSock &obs, std::vector<std::string> &schandlerid)
{
blog(LOG_INFO, "TS3: Communicate");
std::wstring poop = L"poop"; //failure return
bool iResult;
//char *notify = "clientnotifyregister schandlerid=1 event=notifyclientnamefromuid\n";
const char *notify;
std::string snotify;
std::wstringstream wnewname;
char reci2[256];
char reci3[256];
char reci4[256];
std::string space = "\\s";
std::wstring wspace = L"\\s";
std::wstring temp;
bool multiChange;
std::string sendschandlerid;
std::string tmp;
const char* recname;
//get cluid and recording prefix
std::wstring cluid = s2ws(getCluid());
std::wstring rec = s2ws(getPrefix());
if(rec.length() > 10)
{
rec = rec.substr(0, 10);
}
wReplaceAll(rec, L" ", wspace); //replace spaces with \s
int modcount = wcountSubstring(rec, wspace); //number of \s
multiChange = getAllServers();
//set up the getname call
std::wstring wtempgetname = L"clientgetnamefromuid cluid=";
wtempgetname.append(cluid);
wtempgetname.append(L"\n");
std::string tempgetname(wtempgetname.begin(), wtempgetname.end());
const char *getname = tempgetname.c_str();
//return string
std::wstring rname;
int numServer;
if(multiChange)
{
numServer = schandlerid.size();
}
else
{
numServer = 1;
}
for(int i = 0; i < numServer; i++)
{
wnewname << L"clientupdate client_nickname=";
snotify = "clientnotifyregister " + schandlerid[i] + " event=notifyclientnamefromuid\n";
notify = snotify.c_str();
sendschandlerid = "use " + schandlerid[i] + "\n";
//set server to notify on
iResult = obs.sendAll(sendschandlerid.c_str(), sendschandlerid.size(), 0); //use schandlerid=i
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: useschandlerid=i Send Failure");
return poop;
}
iResult = obs.recvAll(reci2, 256, 0, "msg="); //recieve result: error id=0...
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: useschandlerid=i Recieve Failure");
return poop;
}
memset(reci2, 0, 256);
//notifyregister
iResult = obs.sendAll(notify, (int)strlen(notify), 0); //request notifyregister...
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: notifyregister Send Failure");
return poop;
}
iResult = obs.recvAll(reci2, 256, 0, "msg="); //recieve result: error id=0...
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: notifyregister Recieve Failure");
return poop;
}
//clientnamefromuid
iResult = obs.sendAll(getname, (int)strlen(getname), 0); //request clientnamefromuid...
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: clientnamefromuid Send Failure");
return poop;
}
iResult = obs.recvAll(reci3, 256, 0, "msg="); //recieve name
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: clientnamefromuid Recieve Failure");
return poop;
}
//get name
std::wstring identstart = L"name=";
std::wstring identend = L"\n";
std::string name = reci3;
std::wstring wname = s2ws(name);
size_t startpos = wname.find(identstart); //start of name
if(startpos == -1)
{
blog(LOG_WARNING, "TS3: Communicate: startpos == -1");
blog(LOG_WARNING, name.c_str());
//goto endofif;
return poop;
}
size_t endpos = wname.find(identend);
if(endpos < startpos)
{
blog(LOG_WARNING, "TS3: Communicate: endpos < startpos");
blog(LOG_WARNING, name.c_str());
//goto endofif;
return poop;
}
wname = wname.substr(startpos+5, endpos-startpos-5);
int count = wcountSubstring(wname, wspace); //number of \s
//wname = wname.substr(startpos+5 , 30 + count);
//get name end
bool bprefix = getSuffix();
if(bprefix) //if using suffix
{
size_t spc = wname.find(L"\n");
wname = wname.substr(0, spc);
int nstrt = wname.length();
nstrt = nstrt - rec.length();
if(nstrt < 0)
{
nstrt = 0;
}
int nlen = wname.length() - count;
if(cont == 1) //adding modifier
{
if(wname.substr(nstrt) != rec)
{
if(nlen > 30)
{
wname = wname.substr(0, 30 + count - rec.length());
}
wnewname << wname
<< rec << L"\n"; //finish name set string
}
}
else if(cont == 0) //removing modifier
{
if(wname.substr(nstrt) == rec)
{
wname = wname.substr(0, nlen + count - rec.length());
}
wnewname << wname << L"\n"; //finish name set string
}
rname = wname;
if(!rec.empty())
{
rname.append(rec);
}
}
else //if using prefix
{
if(cont == 1) //adding modifier
{
if(wname.substr(0, rec.length()) != rec)
{
wname = wname.substr(0, 30 + count - rec.length());
wnewname << rec; //finish name set string
}
}
else if(cont == 0) //removing modifier
{
if(wname.substr(0, rec.length()) == rec)
{
wname = wname.substr(rec.length(), 30 + count - modcount - rec.length());
}
}
wnewname << wname << L"\n"; //finish name set string
if(!rec.empty())
{
rname = rec;
rname.append(wname);
}
else
{
rname = wname;
}
}
//no need to send new name if name is not updated
if(rec.empty())
{
blog(LOG_WARNING, "TS3: Communicate: rec is empty");
//goto endofif;
return poop;
}
//AppWarning(wnewname.str().c_str()); //print name being sent
tmp = ws2s(wnewname.str()); //set name to string
recname = tmp.c_str(); //set name to char* so it can be sent
//clientupdate
iResult = obs.sendAll(recname, (int)strlen(recname), 0);
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: clientupdate Send Failure");
return poop;
}
iResult = obs.recvAll(reci4, 256 ,0, "msg=");
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: clientupdate Recieve Failure");
return poop;
}
//endofif:
wnewname.str(L"");
memset(reci2, 0, 256);
memset(reci3, 0, 256);
memset(reci4, 0, 256);
}
//return to default server
sendschandlerid = "use " + schandlerid[0] + "\n";
iResult = obs.sendAll(sendschandlerid.c_str(), sendschandlerid.size(), 0); //use schandlerid=i
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: useschandlerid=0 Send Failure");
return poop;
}
iResult = obs.recvAll(reci2, 256, 0, "msg="); //recieve result: error id=0...
if (!iResult)
{
blog(LOG_WARNING, "TS3: Communicate: useschandlerid=0r Recieve Failure");
return poop;
}
/*delete[] reci2;
delete[] reci3;
delete[] reci4;
delete notify;
delete recname;
delete getname;*/
return rname;
}
bool MuteandDeafen(int state, slothSock &obs, std::vector<std::string> &schandlerid)
{
blog(LOG_INFO, "TS3: MuteandDeafen");
int mnd = getMuteAndDeafen();
if(mnd != 1 && mnd != 2 && mnd != 3) //if not set to mute or deafen
{
return true;
}
bool iResult;
std::stringstream sstate;
sstate << state << "\n";
bool multiChange = getAllServers();
int numServer;
if(multiChange)
{
numServer = schandlerid.size();
}
else
{
numServer = 1;
}
char reci3[256];
std::string sendschandlerid;
for(int i = 0; i < numServer; i++)
{
sendschandlerid = "use " + schandlerid[i] + "\n";
//set server to notify on
iResult = obs.sendAll(sendschandlerid.c_str(), sendschandlerid.size(), 0); //use schandlerid=i
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: useschandlerid=i Send Failure");
return false;
}
iResult = obs.recvAll(reci3, 256, 0, "msg="); //recieve result: error id=0...
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: useschandlerid=i Recieve Failure");
return false;
}
memset(reci3, 0, 256);
if(mnd == 1 || mnd == 3) //if set to mute
{
char reci1[256];
std::string tempmute = "clientupdate client_input_muted=";
tempmute.append(sstate.str());
const char *mute = tempmute.c_str();
iResult = obs.sendAll(mute, (int)strlen(mute), 0); //set mute
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: Mute Send Failure");
return false;
}
psleep(1000);
iResult = obs.recvAll(reci1, 256, 0, "msg="); //recieve result: error id=0...
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: Mute Recieve Failure");
return false;
}
//delete[] reci1;
}
if(mnd == 2 || mnd == 3)
{
char reci2[256];
std::string tempdeaf = "clientupdate client_output_muted=";
tempdeaf.append(sstate.str());
const char *deaf = tempdeaf.c_str();
iResult = obs.sendAll(deaf, (int)strlen(deaf), 0); //set deafen
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: Deaf Send Failure");
return false;
}
psleep(1000);
iResult = obs.recvAll(reci2, 256, 0, "msg="); //recieve result: error id=0...
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: Deaf Recieve Failure");
return false;
}
//delete[] reci2;
}
}
//return to default server
sendschandlerid = "use " + schandlerid[0] + "\n";
iResult = obs.sendAll(sendschandlerid.c_str(), sendschandlerid.size(), 0); //use schandlerid=0
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: useschandlerid=0 Send Failure");
return false;
}
iResult = obs.recvAll(reci3, 256, 0, "msg="); //recieve result: error id=0...
if (!iResult)
{
blog(LOG_WARNING, "TS3: MuteandDeafen: useschandlerid=0 Recieve Failure");
return false;
}
//delete[] reci3;
return true;
}