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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
|
#include "stdafx.h"
void CSteamProto::SetContactStatus(MCONTACT hContact, WORD status)
{
WORD oldStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE);
if (oldStatus != status)
{
setWord(hContact, "Status", status);
// Special handling of some statuses
switch (status)
{
case ID_STATUS_FREECHAT:
{
// Contact is looking to play, save it to as status message
if (hContact)
db_set_ts(hContact, "CList", "StatusMsg", TranslateT("Looking to play"));
}
break;
case ID_STATUS_OUTTOLUNCH:
{
// Contact is looking to trade, save it to as status message
if (hContact)
db_set_ts(hContact, "CList", "StatusMsg", TranslateT("Looking to trade"));
}
break;
case ID_STATUS_OFFLINE:
{
// If contact is offline, clear also xstatus
delSetting(hContact, "XStatusId");
delSetting(hContact, "XStatusName");
delSetting(hContact, "XStatusMsg");
if (hContact)
SetContactExtraIcon(hContact, NULL);
}
// no break intentionally
default:
{
if (hContact)
db_unset(hContact, "CList", "StatusMsg");
}
break;
}
}
}
void CSteamProto::SetAllContactsStatus(WORD status)
{
for (MCONTACT hContact = db_find_first(this->m_szModuleName); hContact; hContact = db_find_next(hContact, this->m_szModuleName))
{
if (this->isChatRoom(hContact))
continue;
SetContactStatus(hContact, status);
}
}
MCONTACT CSteamProto::GetContactFromAuthEvent(MEVENT hEvent)
{
DWORD body[3];
DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
dbei.cbBlob = sizeof(DWORD)* 2;
dbei.pBlob = (PBYTE)&body;
if (db_event_get(hEvent, &dbei))
return INVALID_CONTACT_ID;
if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
return INVALID_CONTACT_ID;
if (strcmp(dbei.szModule, m_szModuleName) != 0)
return INVALID_CONTACT_ID;
return DbGetAuthEventContact(&dbei);
}
MCONTACT CSteamProto::FindContact(const char *steamId)
{
MCONTACT hContact = NULL;
mir_cslock lck(this->contact_search_lock);
for (hContact = db_find_first(this->m_szModuleName); hContact; hContact = db_find_next(hContact, this->m_szModuleName))
{
ptrA cSteamId(db_get_sa(hContact, this->m_szModuleName, "SteamID"));
if (!lstrcmpA(cSteamId, steamId))
break;
}
return hContact;
}
void CSteamProto::UpdateContact(MCONTACT hContact, JSONNODE *data)
{
JSONNODE *node = NULL;
// set common data
node = json_get(data, "personaname");
setTString(hContact, "Nick", ptrT(json_as_string(node)));
node = json_get(data, "profileurl");
setString(hContact, "Homepage", _T2A(ptrT(json_as_string(node))));
node = json_get(data, "primaryclanid");
setString(hContact, "PrimaryClanID", _T2A(ptrT(json_as_string(node))));
// set name
node = json_get(data, "realname");
if (node != NULL)
{
std::wstring realname = ptrT(json_as_string(node));
if (!realname.empty())
{
size_t pos = realname.find(L' ', 1);
if (pos != std::wstring::npos)
{
setWString(hContact, "FirstName", realname.substr(0, pos).c_str());
setWString(hContact, "LastName", realname.substr(pos + 1).c_str());
}
else
{
setWString(hContact, "FirstName", realname.c_str());
delSetting(hContact, "LastName");
}
}
}
else
{
delSetting(hContact, "FirstName");
delSetting(hContact, "LastName");
}
// avatar
bool biggerAvatars = getBool("UseBigAvatars", false);
node = json_get(data, biggerAvatars ? "avatarfull" : "avatarmedium");
std::string avatarUrl = _T2A(ptrT(json_as_string(node)));
CheckAvatarChange(hContact, avatarUrl);
// set country
node = json_get(data, "loccountrycode");
if (node != NULL)
{
const char *iso = ptrA(mir_u2a(ptrT(json_as_string(node))));
char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)iso, 0);
setString(hContact, "Country", country);
}
else
delSetting(hContact, "Country");
// state code
node = json_get(data, "locstatecode");
if (node)
setDword(hContact, "StateCode", json_as_int(node));
else
delSetting(hContact, "StateCode");
// city id
node = json_get(data, "loccityid");
if (node)
setDword(hContact, "CityID", json_as_int(node));
else
delSetting(hContact, "CityID");
// account created
node = json_get(data, "timecreated");
setDword(hContact, "MemberTS", json_as_int(node));
// last logout time
node = json_get(data, "lastlogoff");
setDword(hContact, "LogoffTS", json_as_int(node));
// status
// NOTE: this here is wrong info, probably depending on publicity of steam profile, but we don't need this at all, we get status updates by polling
/*node = json_get(data, "personastate");
status = SteamToMirandaStatus(json_as_int(node));
SetContactStatus(hContact, status);
*/
// client
node = json_get(data, "personastateflags");
int stateflags = node ? json_as_int(node) : -1;
switch (stateflags)
{
case 0:
{
// nothing special, either standard client or in different status (only online, I want to play, I want to trade statuses support this flags)
WORD status = getWord(hContact, "Status", ID_STATUS_OFFLINE);
if (status == ID_STATUS_ONLINE || status == ID_STATUS_OUTTOLUNCH || status == ID_STATUS_FREECHAT)
setTString(hContact, "MirVer", _T("Steam"));
}
break;
case 256:
// on website
setTString(hContact, "MirVer", _T("Steam (website)"));
break;
case 512:
// on mobile
setTString(hContact, "MirVer", _T("Steam (mobile)"));
break;
case 1024:
// big picture mode
setTString(hContact, "MirVer", _T("Steam (Big Picture)"));
break;
default:
// none/unknown (e.g. when contact is offline)
delSetting(hContact, "MirVer");
break;
}
// playing game
node = json_get(data, "gameid");
DWORD gameId = node ? atol(_T2A(ptrT(json_as_string(node)))) : 0;
node = json_get(data, "gameextrainfo");
ptrT gameInfo(json_as_string(node));
if (gameId > 0 || gameInfo[0] != '\0')
{
node = json_get(data, "gameserverip");
ptrT serverIP(json_as_string(node));
node = json_get(data, "gameserversteamid");
ptrT serverID (json_as_string(node));
setDword(hContact, "GameID", gameId);
setString(hContact, "ServerIP", _T2A(serverIP));
setString(hContact, "ServerID", _T2A(serverID));
CMString message(gameInfo);
if (!gameId)
message.Append(TranslateT(" (Non-Steam)"));
if (serverIP[0] != '\0')
message.AppendFormat(TranslateT(" on server %s"), serverIP);
setDword(hContact, "XStatusId", gameId);
setTString(hContact, "XStatusName", TranslateT("Playing"));
setTString(hContact, "XStatusMsg", message);
SetContactExtraIcon(hContact, gameId);
}
else
{
delSetting(hContact, "GameID");
delSetting(hContact, "ServerIP");
delSetting(hContact, "ServerID");
delSetting(hContact, "XStatusId");
delSetting(hContact, "XStatusName");
delSetting(hContact, "XStatusMsg");
SetContactExtraIcon(hContact, NULL);
}
}
void CSteamProto::ContactIsRemoved(MCONTACT hContact)
{
if (!getDword(hContact, "DeletedTS", 0) && getByte(hContact, "Auth", 0) == 0)
{
setByte(hContact, "Auth", 1);
setDword(hContact, "DeletedTS", ::time(NULL));
SetContactStatus(hContact, ID_STATUS_OFFLINE);
ptrT nick(getTStringA(hContact, "Nick"));
TCHAR message[MAX_PATH];
mir_sntprintf(message, MAX_PATH, TranslateT("%s has been removed from your contact list"), nick);
ShowNotification(_T("Steam"), message);
}
}
void CSteamProto::ContactIsFriend(MCONTACT hContact)
{
if (getDword(hContact, "DeletedTS", 0) || getByte(hContact, "Auth", 0) != 0)
{
delSetting(hContact, "Auth");
delSetting(hContact, "DeletedTS");
delSetting(hContact, "Grant");
ptrT nick(getTStringA(hContact, "Nick"));
TCHAR message[MAX_PATH];
mir_sntprintf(message, MAX_PATH, TranslateT("%s is back in your contact list"), nick);
ShowNotification(_T("Steam"), message);
}
}
void CSteamProto::ContactIsIgnored(MCONTACT hContact)
{
// todo
setByte(hContact, "Block", 1);
}
MCONTACT CSteamProto::AddContact(const char *steamId, bool isTemporary)
{
MCONTACT hContact = this->FindContact(steamId);
if (!hContact)
{
// create contact
hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM)this->m_szModuleName);
setString(hContact, "SteamID", steamId);
// update info
//UpdateContact(hContact, contact);
if (isTemporary)
{
setByte(hContact, "Auth", 1);
//setByte(hContact, "Grant", 1);
db_set_b(hContact, "CList", "NotOnList", 1);
}
// move to default group
DBVARIANT dbv;
if (!getWString("DefaultGroup", &dbv))
{
db_set_ts(hContact, "CList", "Group", dbv.ptszVal);
db_free(&dbv);
}
}
return hContact;
}
void CSteamProto::ProcessContact(std::map<std::string, JSONNODE*>::iterator *it, MCONTACT hContact)
{
std::string steamId = (*it)->first;
JSONNODE *child = (*it)->second;
if (!hContact)
hContact = AddContact(steamId.c_str());
JSONNODE *node = json_get(child, "friend_since");
if (node)
db_set_dw(hContact, "UserInfo", "ContactAddTime", json_as_int(node));
node = json_get(child, "relationship");
if (node == NULL)
return;
ptrA relationship(mir_u2a(ptrT(json_as_string(node))));
if (!lstrcmpiA(relationship, "friend"))
{
ContactIsFriend(hContact);
}
else if (!lstrcmpiA(relationship, "ignoredfriend"))
{
ContactIsIgnored(hContact);
}
else if (!lstrcmpiA(relationship, "requestrecipient"))
{
// todo
//RaiseAuthRequestThread((void*)hContact);
}
}
void CSteamProto::OnGotFriendList(const NETLIBHTTPREQUEST *response, void *)
{
if (response == NULL)
return;
JSONROOT root(response->pData);
if (root == NULL)
return;
std::string steamIds = ptrA(getStringA("SteamID"));
std::map<std::string, JSONNODE*> friends;
// Remember contacts on server
JSONNODE *node = json_get(root, "friends");
JSONNODE *nroot = json_as_array(node);
if (nroot != NULL)
{
for (size_t i = 0; i < json_size(nroot); i++)
{
JSONNODE *child = json_at(nroot, i);
if (child == NULL)
break;
node = json_get(child, "steamid");
if (node == NULL)
continue;
std::string steamId = _T2A(ptrT(json_as_string(node)));
friends.insert(std::make_pair(steamId, child));
}
}
// Check and update contacts in database
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
{
if (isChatRoom(hContact))
continue;
ptrA id(getStringA(hContact, "SteamID"));
if (id == NULL)
continue;
std::map<std::string, JSONNODE*>::iterator it = friends.find(std::string(id));
if (it != friends.end())
{
// Contact is on server-list, update (and eventually notify) it
ProcessContact(&it, hContact);
steamIds.append(",").append(it->first);
friends.erase(it);
}
else
{
// Contact was removed from server-list, notify it
ContactIsRemoved(hContact);
}
}
// Check remaining contacts in map and add them to contact list
for (std::map<std::string, JSONNODE*>::iterator it = friends.begin(); it != friends.end();)
{
// Contact is on server-list, but not in database, add (but not notify) it
ProcessContact(&it, NULL);
steamIds.append(",").append(it->first);
it = friends.erase(it);
}
friends.clear();
// We need to delete nroot here at the end, because we had references to JSONNODE objects stored in friends map
json_delete(nroot);
if (!steamIds.empty())
{
//steamIds.pop_back();
ptrA token(getStringA("TokenSecret"));
PushRequest(
new SteamWebApi::GetUserSummariesRequest(token, steamIds.c_str()),
&CSteamProto::OnGotUserSummaries);
}
}
void CSteamProto::OnGotBlockList(const NETLIBHTTPREQUEST *response, void *)
{
if (response == NULL)
return;
JSONROOT root(response->pData);
if (root == NULL)
return;
//std::string steamIds;
JSONNODE *node = json_get(root, "friends");
JSONNODE *nroot = json_as_array(node);
if (nroot != NULL)
{
for (size_t i = 0; i < json_size(nroot); i++)
{
JSONNODE *child = json_at(nroot, i);
if (child == NULL)
break;
node = json_get(child, "steamid");
ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
/*MCONTACT hContact = FindContact(steamId);
if (!hContact)
{
hContact = AddContact(steamId);
steamIds.append(steamId).append(",");
}*/
node = json_get(child, "relationship");
ptrA relationship(mir_u2a(ptrT(json_as_string(node))));
if (!lstrcmpiA(relationship, "ignoredfriend"))
{
// todo: open block list
}
else continue;
}
json_delete(nroot);
}
}
void CSteamProto::OnGotUserSummaries(const NETLIBHTTPREQUEST *response, void *)
{
if (response == NULL)
return;
JSONROOT root(response->pData);
if (root == NULL)
return;
JSONNODE *node = json_get(root, "players");
JSONNODE *nroot = json_as_array(node);
if (nroot != NULL)
{
for (size_t i = 0; i < json_size(nroot); i++)
{
JSONNODE *item = json_at(nroot, i);
if (item == NULL)
break;
node = json_get(item, "steamid");
ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
MCONTACT hContact = NULL;
if (!IsMe(steamId)) {
hContact = FindContact(steamId);
if (!hContact)
hContact = AddContact(steamId);
}
UpdateContact(hContact, item);
}
json_delete(nroot);
}
}
void CSteamProto::OnGotAvatar(const NETLIBHTTPREQUEST *response, void *arg)
{
PROTO_AVATAR_INFORMATIONW pai = { sizeof(pai) };
pai.hContact = (MCONTACT)arg;
GetDbAvatarInfo(pai);
if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
ptrA steamId(getStringA(pai.hContact, "SteamID"));
debugLogA("CSteamProto::OnGotAvatar: failed to get avatar %s", steamId);
if (pai.hContact)
ProtoBroadcastAck(pai.hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, (HANDLE)&pai, 0);
return;
}
FILE *fp = _tfopen(pai.filename, _T("wb"));
if (fp)
{
fwrite(response->pData, sizeof(char), response->dataLength, fp);
fclose(fp);
if (pai.hContact)
ProtoBroadcastAck(pai.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&pai, 0);
else
CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0);
}
}
void CSteamProto::OnFriendAdded(const NETLIBHTTPREQUEST *response, void *arg)
{
SendAuthParam *param = (SendAuthParam*)arg;
if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true"))
{
ptrA steamId(getStringA(param->hContact, "SteamID"));
debugLogA("CSteamProto::OnFriendAdded: failed to add friend %s", steamId);
ProtoBroadcastAck(param->hContact, ACKTYPE_AUTHREQ, ACKRESULT_FAILED, param->hAuth, 0);
return;
}
delSetting(param->hContact, "Auth");
delSetting(param->hContact, "Grant");
db_unset(param->hContact, "CList", "NotOnList");
ProtoBroadcastAck(param->hContact, ACKTYPE_AUTHREQ, ACKRESULT_SUCCESS, param->hAuth, 0);
}
void CSteamProto::OnFriendBlocked(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true"))
{
debugLogA("CSteamProto::OnFriendIgnored: failed to ignore friend %s", (char*)arg);
return;
}
}
void CSteamProto::OnFriendRemoved(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL || response->resultCode != HTTP_STATUS_OK || lstrcmpiA(response->pData, "true"))
{
MCONTACT hContact = (MCONTACT)arg;
ptrA who(getStringA(hContact, "SteamID"));
debugLogA("CSteamProto::OnFriendRemoved: failed to remove friend %s", who);
return;
}
}
void CSteamProto::OnAuthRequested(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
debugLogA("CSteamProto::OnAuthRequested: failed to request info for %s", (char*)arg);
return;
}
JSONROOT root(response->pData);
if (root == NULL)
return;
JSONNODE *node = json_get(root, "players");
JSONNODE *nodes = json_as_array(node);
JSONNODE *nroot = json_at(nodes, 0);
if (nroot != NULL)
{
node = json_get(nroot, "steamid");
ptrA steamId(mir_u2a(ptrT(json_as_string(node))));
MCONTACT hContact = FindContact(steamId);
if (!hContact)
hContact = AddContact(steamId);
UpdateContact(hContact, nroot);
ptrA nickName(getStringA(hContact, "Nick"));
ptrA firstName(getStringA(hContact, "FirstName"));
if (firstName == NULL)
firstName = mir_strdup("");
ptrA lastName(getStringA(hContact, "LastName"));
if (lastName == NULL)
lastName = mir_strdup("");
char reason[MAX_PATH];
mir_snprintf(reason, SIZEOF(reason), Translate("%s has added you to his or her Friend List"), nickName);
// blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), sid(ASCIIZ), reason(ASCIIZ)
DWORD cbBlob = (DWORD)(sizeof(DWORD)* 2 + lstrlenA(nickName) + lstrlenA(firstName) + lstrlenA(lastName) + lstrlenA(steamId) + lstrlenA(reason) + 5);
PBYTE pBlob, pCurBlob;
pCurBlob = pBlob = (PBYTE)mir_alloc(cbBlob);
*((PDWORD)pCurBlob) = 0;
pCurBlob += sizeof(DWORD);
*((PDWORD)pCurBlob) = (DWORD)hContact;
pCurBlob += sizeof(DWORD);
strcpy((char*)pCurBlob, nickName);
pCurBlob += lstrlenA(nickName) + 1;
strcpy((char*)pCurBlob, firstName);
pCurBlob += lstrlenA(firstName) + 1;
strcpy((char*)pCurBlob, lastName);
pCurBlob += lstrlenA(lastName) + 1;
strcpy((char*)pCurBlob, steamId);
pCurBlob += lstrlenA(steamId) + 1;
strcpy((char*)pCurBlob, reason);
AddDBEvent(hContact, EVENTTYPE_AUTHREQUEST, time(NULL), DBEF_UTF, cbBlob, pBlob);
}
json_delete(nodes);
}
void CSteamProto::OnPendingApproved(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s", (char*)arg);
return;
}
JSONROOT root(response->pData);
if (root == NULL)
return;
JSONNODE *node = json_get(root, "success");
if (json_as_int(node) == 0)
{
node = json_get(root, "error_text");
debugLogA("CSteamProto::OnPendingApproved: failed to approve pending from %s (%s)", (char*)arg, ptrA(mir_utf8encodeW(ptrT(json_as_string(node)))));
}
}
void CSteamProto::OnPendingIgnoreded(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s", (char*)arg);
return;
}
JSONROOT root(response->pData);
if (root == NULL)
return;
JSONNODE *node = json_get(root, "success");
if (json_as_int(node) == 0)
{
node = json_get(root, "error_text");
debugLogA("CSteamProto::OnPendingApproved: failed to ignore pending from %s (%s)", (char*)arg, ptrA(mir_utf8encodeW(ptrT(json_as_string(node)))));
}
}
void CSteamProto::OnSearchByIdEnded(const NETLIBHTTPREQUEST *response, void *arg)
{
if (response == NULL || response->resultCode != HTTP_STATUS_OK)
{
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYID, 0);
debugLogA("CSteamProto::OnSearchByIdEnded: failed to get summaries for %s", (char*)arg);
return;
}
JSONROOT root(response->pData);
if (root == NULL)
return;
JSONNODE *node = json_get(root, "players");
JSONNODE *nodes = json_as_array(node);
JSONNODE *nroot = json_at(nodes, 0);
if (nroot != NULL)
{
STEAM_SEARCH_RESULT ssr = { 0 };
ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT);
ssr.hdr.flags = PSR_TCHAR;
ssr.hdr.id = (TCHAR*)arg;
node = json_get(nroot, "personaname");
ssr.hdr.nick = mir_wstrdup(ptrT(json_as_string(node)));
node = json_get(nroot, "realname");
if (node != NULL)
{
std::wstring realname = ptrT(json_as_string(node));
if (!realname.empty())
{
size_t pos = realname.find(' ', 1);
if (pos != std::string::npos)
{
ssr.hdr.firstName = mir_wstrdup(realname.substr(0, pos).c_str());
ssr.hdr.lastName = mir_wstrdup(realname.substr(pos + 1).c_str());
}
else
ssr.hdr.firstName = mir_wstrdup(realname.c_str());
}
}
//ssr.contact = contact;
ssr.data = json_copy(nroot);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)STEAM_SEARCH_BYID, (LPARAM)&ssr);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)STEAM_SEARCH_BYID, 0);
}
json_delete(nodes);
}
void CSteamProto::OnSearchByNameStarted(const NETLIBHTTPREQUEST *, void *)
{
}
//void CSteamProto::SearchByNameThread(void* arg)
//{
// ptrW keywordsW((wchar_t*)arg);
// ptrA keywords(mir_utf8encodeW(keywordsW));
//
// ptrA token(getStringA("TokenSecret"));
//
// SteamWebApi::SearchApi::SearchResult searchResult;
// debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::SearchApi::Search");
// SteamWebApi::SearchApi::Search(m_hNetlibUser, token, keywords, &searchResult);
//
// if (!searchResult.IsSuccess())
// {
// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYNAME, 0);
// return;
// }
//
// CMStringA steamIds;
// for (int i = 0; i < searchResult.GetItemCount(); i++)
// {
// const SteamWebApi::SearchApi::SearchItem *item = searchResult.GetAt(i);
// if (steamIds.IsEmpty())
// steamIds.Append(item->GetSteamId());
// else
// steamIds.AppendFormat(",%s", item->GetSteamId());
// }
//
// SteamWebApi::FriendApi::Summaries summarues;
// debugLogA("CSteamProto::SearchByNameThread: call SteamWebApi::FriendApi::LoadSummaries");
// SteamWebApi::FriendApi::LoadSummaries(m_hNetlibUser, token, steamIds, &summarues);
//
// if (!summarues.IsSuccess())
// {
// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)STEAM_SEARCH_BYNAME, 0);
// return;
// }
//
// for (size_t i = 0; i < summarues.GetItemCount(); i++)
// {
// const SteamWebApi::FriendApi::Summary *contact = summarues.GetAt(i);
//
// STEAM_SEARCH_RESULT ssr = { 0 };
// ssr.hdr.cbSize = sizeof(STEAM_SEARCH_RESULT);
// ssr.hdr.flags = PSR_TCHAR;
//
// ssr.hdr.id = mir_a2u(contact->GetSteamId());
// ssr.hdr.nick = mir_wstrdup(contact->GetNickName());
// ssr.hdr.firstName = mir_wstrdup(contact->GetFirstName());
// ssr.hdr.lastName = mir_wstrdup(contact->GetLastName());
//
// ssr.contact = contact;
//
// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)STEAM_SEARCH_BYNAME, (LPARAM)&ssr);
// }
//
// ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)STEAM_SEARCH_BYNAME, 0);
//}
|