-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverlayComs.cpp
More file actions
569 lines (522 loc) · 11.7 KB
/
Copy pathOverlayComs.cpp
File metadata and controls
569 lines (522 loc) · 11.7 KB
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
/*****************************
2015 <adocilesloth@gmail.com>
*****************************/
#include "TS3Plugin.h"
#include "ending.h"
#include "socketSRall.h"
#include <string>
#include <sstream>
#include <fstream>
#include <codecvt>
#include <vector>
using namespace std;
SOCKET overlay;
ending close;
//ofstream file;
void ShutdownOverlay()
{
AppWarning(TEXT("Overlay: ShutdownOverlay"));
close.now();
return;
}
void ResetOverlay()
{
AppWarning(TEXT("Overlay: ResetOverlay"));
close.nolonger();
return;
}
void RunOverlay(char* adrs)
{
std::locale loc(std::locale::classic(), new codecvt_utf8<wchar_t>);
//file.imbue(loc);
int iname;
bool bname;
bool bright;
bool btalker;
int italker;
vector<wstring> vname;
vector<int> vtime;
bool bsaid = false;
SendAll sa;
RecvAll ra;
bool iResult;
char reci1[181];
char reci2[64];
vector<char> reci3;
int reci3Size;
char reci4[256];
char* whoami = "whoami\n";
char* schandlerlist = "serverconnectionhandlerlist\n";
//string location
string identstart;
wstring widentstart;
string identend;
wstring widentend;
wstring talkstart = L"client_flag_talking=";
size_t startpos;
size_t endpos;
string tempstr;
wstring wtempstr;
//useful things
string cid;
string list;
wstring wlist;
vector<wstring> name;
int namesize;
vector<bool> talk;
bool discon = true;
bool noserv = true;
bool rename = true;
bool bCom = false;
wstring userName;
bool bMnD = false;
bool bSwt = false;
vector<string> schandlerid;
//File stuff
wstring path = OBSGetPluginDataPath().Array();
path.append(L"\\Overlay.txt");
wofstream fOverlay;
fOverlay.imbue(loc);
fOverlay.open(path); //open and close to clear file
fOverlay.close();
AppWarning(TEXT("Overlay: Started"));
//Overlay Loop
while(!close.state())
{
//connect
if(!ConnectToHost(25639, adrs, overlay))
{
if(discon) //if initial disconnection
{
AppWarning(TEXT("Overlay: Connection Failure: Check TS3 is running and ClientQuery Plugin is enabled"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
discon = false;
//force Communicate, MuteandDeafen and ChannelSwitch
bCom = false;
bMnD = false;
bSwt = false;
rename = true;
}
fOverlay.open(path); //empty client list text file if not connected
fOverlay.close();
goto skip;
}
discon = true;
iResult = ra.recv_all(overlay, reci1, 181 ,0); //get TS3 Client...
if (!iResult)
{
AppWarning(TEXT("Overlay: First Recieve Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
if(rename)
{
iResult = sa.send_all(overlay, schandlerlist, (int)strlen(schandlerlist), 0); //send serverconnectionhandlerlist
if(!iResult)
{
AppWarning(TEXT("Overlay: schandlerlist Send Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
iResult = ra.recv_all(overlay, reci4, 256, 0, "msg="); //get serverconnectionhandlerlist
if (!iResult)
{
AppWarning(TEXT("Overlay: schandlerlist Recieve Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
tempstr = reci4;
memset(reci4, 0, 256);
while(tempstr.size() > 12)
{
identstart = "sch";
startpos = tempstr.find(identstart);
if(startpos > 0 && startpos < tempstr.size())
{
schandlerid.push_back(tempstr.substr(startpos, 13));
}
else
{
break;
}
tempstr = tempstr.substr(startpos + 13, tempstr.size() - (startpos + 13));
}
if(!bCom)
{
userName = Communicate(1, overlay, schandlerid);
if(userName != L"poop")
{
wReplaceAll(userName, L"\\s", L" ");
bCom = true;
}
else
{
bCom = false;
}
}
if(!bMnD)
{
bMnD = MuteandDeafen(1, overlay, schandlerid);
}
if(!bSwt)
{
bSwt = ChannelSwitch(1, overlay);
}
if(bCom && bMnD && bSwt)
{
bCom = false;
bMnD = false;
bSwt = false;
rename = false;
}
schandlerid.clear();
}
//get cid
iResult = sa.send_all(overlay, whoami, (int)strlen(whoami), 0); //send whoami
if (!iResult)
{
AppWarning(TEXT("Overlay: whoami Send Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
iResult = ra.recv_all(overlay, reci2, 64 ,0 ,"msg="); //get whoami
if (!iResult)
{
AppWarning(TEXT("Overlay: whoami Recieve Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
tempstr = reci2;
identstart = "msg=";
startpos = tempstr.find(identstart);
if(tempstr.substr(startpos, 5) == "msg=n")
{
if(noserv) //if initial disconnection
{
AppWarning(TEXT("Overlay: Not Connected to TS3 Server"));
noserv = false;
//force Communicate, MuteandDeafen and ChannelSwitch
bCom = false;
bMnD = false;
bSwt = false;
rename = false;
}
memset(reci2, 0, 64);
fOverlay.open(path); //empty client list text file if not on server
fOverlay.close();
goto skip;
}
tempstr = "";
if(!noserv)
{
AppWarning(TEXT("Overlay: Now Connected to TS3 Server"));
rename = true;
noserv = true;
}
identstart = "cid=";
identend = "\n";
cid = reci2;
startpos = cid.find(identstart);
if(startpos == -1)
{
AppWarning(TEXT("Overlay: startpos == -1"));
goto skip;
}
endpos = cid.find(identend);
if(endpos < 0)
{
AppWarning(TEXT("Overlay: endpos < 0"));
goto skip;
}
cid = cid.substr(startpos, endpos - startpos);
//set up channelclientlist
tempstr = "channelclientlist ";
tempstr.append(cid);
tempstr.append(" -voice\n");
const char *cllist = tempstr.c_str();
//recieve setup
iname = GetNumberOfNames();
reci3Size = iname * 360;
reci3.resize(reci3Size);
//get channelclientlist
iResult = sa.send_all(overlay, cllist, (int)strlen(cllist), 0); //send channelcli...
if (!iResult)
{
AppWarning(TEXT("Overlay: channelclientlist Send Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
iResult = ra.recv_all(overlay, &reci3[0], reci3.size(), 0, "msg="); //recieve channelcli...
if (!iResult)
{
AppWarning(TEXT("Overlay: channelclientlist Recieve Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
widentstart = L"name=";
widentend = L"client_type";
list.assign(reci3.begin(), reci3.end());
wlist = s2ws(list);
//generate client list
for(int i = 0; i < iname; i++)
{
startpos = wlist.find(widentstart);
if(startpos == -1)
{
break;
}
endpos = wlist.find(widentend);
if(endpos < 0)
{
break;
}
wtempstr = wlist.substr(startpos + 5, endpos-startpos-6);
name.push_back(wtempstr);
startpos = wlist.find(talkstart);
if(startpos == -1)
{
talk.push_back(false);
break;
}
else if(wlist.substr(startpos + 20, 1) == L"0")
{
talk.push_back(false);
}
else if(wlist.substr(startpos + 20, 1) == L"1")
{
talk.push_back(true);
}
wlist = wlist.substr(startpos+25);
}
//only show talker time keeping
btalker = GetOnlyShowTalker();
if(btalker)
{
italker = GetHideNameAfter()/100;
if(static_cast<int>(vtime.size()) > 0)
{
for(int i = static_cast<int>(vtime.size()) - 1; i > -1; i--)
{
if(vtime[i] > italker)
{
vtime.erase(vtime.begin() + i);
vname.erase(vname.begin() + i);
}
else
{
vtime[i]++;
}
}
}
}
//print client list
bname = GetHideSelf();
bright = GetRightOfSymbol();
fOverlay.open(path);
//fOverlay << bname << endl; //uncomment to remove the BOOL warning which forces this true or false
namesize = name.size();
if(namesize < 1)
{
goto skip;
}
else if(namesize < iname)
{
iname = namesize;
}
//normal
if(!btalker)
{
for(int i = 0; i < iname; i++)
{
if(name[i].empty())
{
break;
}
wReplaceAll(name[i], L"\\s", L" ");
if(bname && name[i] == userName)
{
//do nothing
}
else
{
wstring wsTmp(name[i].begin(), name[i].end());
if(!bright)
{
if(talk[i])
{
fOverlay << L"\u25CF" << wsTmp << endl;
}
else
{
fOverlay << L"\u25CB" << wsTmp << endl;
}
}
else
{
if(talk[i])
{
fOverlay << wsTmp << L"\u25CF" << endl;
}
else
{
fOverlay << wsTmp << L"\u25CB" << endl;
}
}
}
}//end for(int i...
}
//Only show talkers
else
{
for(int i = 0; i < iname; i++)
{
if(name[i].empty())
{
break;
}
wReplaceAll(name[i], L"\\s", L" ");
if(bname && name[i] == userName)
{
//do nothing
}
else
{
wstring wsTmp(name[i].begin(), name[i].end());
if(talk[i])
{
bsaid = false;
if(static_cast<int>(vname.size()) > 0)
{
for(int j = 0; j < static_cast<int>(vname.size()); j++)
{
if(wsTmp == vname[j])
{
vtime[j] = 0;
bsaid = true;
break;
}
}
}
if(!bsaid)
{
vname.push_back(wsTmp);
vtime.push_back(0);
}
else
{
bsaid = false;
}
}//end if(talk[i])
}
}//end for(int i...
//Print
if(static_cast<int>(vname.size()) > 0)
{
for(int j = 0; j < static_cast<int>(vname.size()); j++)
{
fOverlay << vname[j] << endl;
}
}
}//end Only Show talkers
fOverlay.close();
//reset variables
memset(reci1, 0, 181);
memset(reci2, 0, 64);
reci3.clear();
cid.clear();
list.clear();
name.clear();
talk.clear();
identstart.clear();
identend.clear();
startpos = 0;
endpos = 0;
tempstr.clear();
skip:
CloseConnection(overlay);
Sleep(100);
}
if(!ConnectToHost(25639, adrs, overlay))
{
AppWarning(TEXT("StopStream: Connection Failure: Check TS3 is running and ClientQuery Plugin is enabled"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
return;
}
iResult = ra.recv_all(overlay, reci1, 181 ,0); //get TS3 Client...
if (!iResult)
{
AppWarning(TEXT("StopStream: First Recieve Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
}
iResult = sa.send_all(overlay, schandlerlist, (int)strlen(schandlerlist), 0); //send serverconnectionhandlerlist
if(!iResult)
{
AppWarning(TEXT("Overlay: schandlerlist Send Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
iResult = ra.recv_all(overlay, reci4, 256, 0, "msg="); //get serverconnectionhandlerlist
if (!iResult)
{
AppWarning(TEXT("Overlay: schandlerlist Recieve Failure"));
AppWarning(TEXT("SOCKET_ERROR"));
wstringstream code;
code << WSAGetLastError();
AppWarning(code.str().c_str());
goto skip;
}
tempstr = reci4;
memset(reci4, 0, 256);
while(tempstr.size() > 12)
{
identstart = "sch";
startpos = tempstr.find(identstart);
if(startpos > 0 && startpos < tempstr.size())
{
schandlerid.push_back(tempstr.substr(startpos, 13));
}
else
{
break;
}
tempstr = tempstr.substr(startpos + 13, tempstr.size() - (startpos + 13));
}
Communicate(0, overlay, schandlerid);
MuteandDeafen(0, overlay, schandlerid);
ChannelSwitch(0, overlay);
CloseConnection(overlay);
return;
}