-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathsteam_friends.cpp
1531 lines (1300 loc) · 53.8 KB
/
steam_friends.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
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
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2019 Mr Goldberg
This file is part of the Goldberg Emulator
The Goldberg Emulator is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
The Goldberg Emulator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the Goldberg Emulator; if not, see
<http://www.gnu.org/licenses/>. */
#include "dll/steam_friends.h"
#define SEND_FRIEND_RATE 4.0
Friend* Steam_Friends::find_friend(CSteamID id)
{
auto f = std::find_if(friends.begin(), friends.end(), [&id](Friend const& item) { return item.id() == id.ConvertToUint64(); });
if (friends.end() == f)
return NULL;
return &(*f);
}
void Steam_Friends::persona_change(CSteamID id, EPersonaChange flags)
{
PersonaStateChange_t data;
data.m_ulSteamID = id.ConvertToUint64();
data.m_nChangeFlags = flags;
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
}
void Steam_Friends::rich_presence_updated(CSteamID id, AppId_t appid)
{
FriendRichPresenceUpdate_t data;
data.m_steamIDFriend = id;
data.m_nAppID = appid;
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
}
bool Steam_Friends::is_appid_compatible(Friend *f)
{
if (settings->is_lobby_connect) return true;
if (f == &us) return true;
return settings->get_local_game_id().AppID() == f->appid();
}
struct Avatar_Numbers Steam_Friends::add_friend_avatars(CSteamID id)
{
uint64 steam_id = id.ConvertToUint64();
auto avatar_ids = avatars.find(steam_id);
if (avatar_ids != avatars.end()) {
return avatar_ids->second;
}
struct Avatar_Numbers avatar_numbers{};
std::string small_avatar(32 * 32 * 4, 0);
std::string medium_avatar(64 * 64 * 4, 0);
std::string large_avatar(184 * 184 * 4, 0);
static const std::initializer_list<std::string> avatar_icons = {
"account_avatar.png",
"account_avatar.jpg",
"account_avatar.jpeg",
};
if (!settings->disable_account_avatar && (id == settings->get_local_steam_id())) {
std::string file_path{};
unsigned long long file_size{};
// try local location first, then try global location
for (const auto &settings_path : { Local_Storage::get_game_settings_path(), local_storage->get_global_settings_path() }) {
for (const auto &file_name : avatar_icons) {
file_path = settings_path + file_name;
file_size = file_size_(file_path);
if (file_size) break;
}
if (file_size) break;
}
// no else statement here for default otherwise this breaks default images for friends
if (file_size) {
small_avatar = Local_Storage::load_image_resized(file_path, "", 32);
medium_avatar = Local_Storage::load_image_resized(file_path, "", 64);
large_avatar = Local_Storage::load_image_resized(file_path, "", 184);
}
} else if (!settings->disable_account_avatar) {
Friend *f = find_friend(id);
if (f && (large_avatar.compare(f->avatar()) != 0)) {
large_avatar = f->avatar();
medium_avatar = Local_Storage::load_image_resized("", f->avatar(), 64);
small_avatar = Local_Storage::load_image_resized("", f->avatar(), 32);
} else {
std::string file_path{};
unsigned long long file_size{};
// try local location first, then try global location
for (const auto &settings_path : { Local_Storage::get_game_settings_path(), local_storage->get_global_settings_path() }) {
for (const auto &file_name : avatar_icons) {
file_path = settings_path + file_name;
file_size = file_size_(file_path);
if (file_size) break;
}
if (file_size) break;
}
if (file_size) {
small_avatar = Local_Storage::load_image_resized(file_path, "", 32);
medium_avatar = Local_Storage::load_image_resized(file_path, "", 64);
large_avatar = Local_Storage::load_image_resized(file_path, "", 184);
}
}
}
avatar_numbers.smallest = settings->add_image(small_avatar, 32, 32);
avatar_numbers.medium = settings->add_image(medium_avatar, 64, 64);
avatar_numbers.large = settings->add_image(large_avatar, 184, 184);
avatars[steam_id] = avatar_numbers;
return avatar_numbers;
}
void Steam_Friends::steam_friends_callback(void *object, Common_Message *msg)
{
// PRINT_DEBUG_ENTRY();
Steam_Friends *steam_friends = (Steam_Friends *)object;
steam_friends->Callback(msg);
}
void Steam_Friends::steam_friends_run_every_runcb(void *object)
{
// PRINT_DEBUG_ENTRY();
Steam_Friends *steam_friends = (Steam_Friends *)object;
steam_friends->RunCallbacks();
}
void Steam_Friends::resend_friend_data()
{
modified = true;
}
bool Steam_Friends::ok_friend_flags(int iFriendFlags)
{
if (iFriendFlags & k_EFriendFlagImmediate) return true;
return false;
}
Steam_Friends::Steam_Friends(Settings* settings, class Local_Storage* local_storage, Networking* network, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Steam_Overlay* overlay):
settings(settings),
local_storage(local_storage),
network(network),
callbacks(callbacks),
callback_results(callback_results),
run_every_runcb(run_every_runcb),
overlay(overlay)
{
modified = false;
this->network->setCallback(CALLBACK_ID_FRIEND, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this);
this->network->setCallback(CALLBACK_ID_FRIEND_MESSAGES, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this);
this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this);
this->run_every_runcb->add(&Steam_Friends::steam_friends_run_every_runcb, this);
}
Steam_Friends::~Steam_Friends()
{
this->network->rmCallback(CALLBACK_ID_FRIEND, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this);
this->network->rmCallback(CALLBACK_ID_FRIEND_MESSAGES, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this);
this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this);
this->run_every_runcb->remove(&Steam_Friends::steam_friends_run_every_runcb, this);
}
// returns the local players name - guaranteed to not be NULL.
// this is the same name as on the users community profile page
// this is stored in UTF-8 format
// like all the other interface functions that return a char *, it's important that this pointer is not saved
// off; it will eventually be free'd or re-allocated
const char* Steam_Friends::GetPersonaName()
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
const char *local_name = settings->get_local_name();
return local_name;
}
// Sets the player name, stores it on the server and publishes the changes to all friends who are online.
// Changes take place locally immediately, and a PersonaStateChange_t is posted, presuming success.
//
// The final results are available through the return value SteamAPICall_t, using SetPersonaNameResponse_t.
//
// If the name change fails to happen on the server, then an additional global PersonaStateChange_t will be posted
// to change the name back, in addition to the SetPersonaNameResponse_t callback.
STEAM_CALL_RESULT( SetPersonaNameResponse_t )
SteamAPICall_t Steam_Friends::SetPersonaName( const char *pchPersonaName )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
// send PersonaStateChange_t callbacks
persona_change(settings->get_local_steam_id(), EPersonaChange::k_EPersonaChangeName);
SetPersonaNameResponse_t data{};
data.m_bSuccess = true;
data.m_bLocalSuccess = false;
data.m_result = k_EResultOK;
auto ret = callback_results->addCallResult(data.k_iCallback, &data, sizeof(data));
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
return ret;
}
void Steam_Friends::SetPersonaName_old( const char *pchPersonaName )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
SetPersonaName(pchPersonaName);
}
// gets the status of the current user
EPersonaState Steam_Friends::GetPersonaState()
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_EPersonaStateOnline;
}
void Steam_Friends::SetPersonaState(EPersonaState ePersonaState)
{
PRINT_DEBUG_TODO();
}
bool Steam_Friends::AddFriend(CSteamID steamIDFriend)
{
PRINT_DEBUG_TODO();
if (steamIDFriend == k_steamIDNil)
return false;
// TODO
return true;
}
bool Steam_Friends::RemoveFriend(CSteamID steamIDFriend)
{
PRINT_DEBUG_TODO();
if (steamIDFriend == k_steamIDNil)
return false;
// TODO
return true;
}
bool Steam_Friends::HasFriend(CSteamID steamIDFriend)
{
PRINT_DEBUG("sdk 0.99u");
return HasFriend(steamIDFriend, (int)k_EFriendFlagImmediate);
}
// friend iteration
// takes a set of k_EFriendFlags, and returns the number of users the client knows about who meet that criteria
// then GetFriendByIndex() can then be used to return the id's of each of those users
int Steam_Friends::GetFriendCount( int iFriendFlags )
{
PRINT_DEBUG("%i", iFriendFlags);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
int count = 0;
if (ok_friend_flags(iFriendFlags)) count = static_cast<int>(friends.size());
PRINT_DEBUG("count %i", count);
return count;
}
int Steam_Friends::GetFriendCount( EFriendFlags eFriendFlags )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return GetFriendCount((int)eFriendFlags);
}
// returns the steamID of a user
// iFriend is a index of range [0, GetFriendCount())
// iFriendsFlags must be the same value as used in GetFriendCount()
// the returned CSteamID can then be used by all the functions below to access details about the user
CSteamID Steam_Friends::GetFriendByIndex( int iFriend, int iFriendFlags )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
CSteamID id = k_steamIDNil;
if (ok_friend_flags(iFriendFlags)) {
if (iFriend >= 0 && static_cast<size_t>(iFriend) < friends.size()) {
id = CSteamID((uint64)friends[iFriend].id());
}
}
return id;
}
void Steam_Friends::GetFriendByIndex(CSteamID& res, int iFriend, int iFriendFlags )
{
PRINT_DEBUG_GNU_WIN();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
res = GetFriendByIndex(iFriend, iFriendFlags );
}
CSteamID Steam_Friends::GetFriendByIndex( int iFriend, EFriendFlags eFriendFlags )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return GetFriendByIndex(iFriend, (int)eFriendFlags );
}
void Steam_Friends::GetFriendByIndex(CSteamID& result, int iFriend, EFriendFlags eFriendFlags)
{
PRINT_DEBUG_GNU_WIN();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
result = GetFriendByIndex(iFriend, eFriendFlags );
}
// returns a relationship to a user
EFriendRelationship Steam_Friends::GetFriendRelationship( CSteamID steamIDFriend )
{
PRINT_DEBUG("%llu", steamIDFriend.ConvertToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (steamIDFriend == settings->get_local_steam_id()) return k_EFriendRelationshipNone; //Real steam behavior
if (find_friend(steamIDFriend)) return k_EFriendRelationshipFriend;
return k_EFriendRelationshipNone;
}
// returns the current status of the specified user
// this will only be known by the local user if steamIDFriend is in their friends list; on the same game server; in a chat room or lobby; or in a small group with the local user
EPersonaState Steam_Friends::GetFriendPersonaState( CSteamID steamIDFriend )
{
PRINT_DEBUG("%llu", steamIDFriend.ConvertToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
EPersonaState state = k_EPersonaStateOffline;
if (steamIDFriend == settings->get_local_steam_id() || find_friend(steamIDFriend)) {
state = k_EPersonaStateOnline;
}
//works because all of those who could be in a lobby are our friends
return state;
}
bool Steam_Friends::Deprecated_GetFriendGamePlayed(CSteamID steamIDFriend, int32 *pnGameID, uint32 *punGameIP, uint16 *pusGamePort)
{
PRINT_DEBUG_ENTRY();
// TODO: real steam seems not to fill memory pointed by pnGameID
return GetFriendGamePlayed(steamIDFriend, NULL, punGameIP, pusGamePort, NULL);
}
// returns the name another user - guaranteed to not be NULL.
// same rules as GetFriendPersonaState() apply as to whether or not the user knowns the name of the other user
// note that on first joining a lobby, chat room or game server the local user will not known the name of the other users automatically; that information will arrive asyncronously
//
const char* Steam_Friends::GetFriendPersonaName( CSteamID steamIDFriend )
{
PRINT_DEBUG("%llu", steamIDFriend.ConvertToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
const char *name = "Unknown User";
if (steamIDFriend == settings->get_local_steam_id()) {
name = settings->get_local_name();
} else {
Friend *f = find_friend(steamIDFriend);
if (f) name = f->name().c_str();
}
PRINT_DEBUG("returned '%s'", name);
return name;
}
int32 Steam_Friends::AddFriendByName(const char *pchEmailOrAccountName)
{
PRINT_DEBUG_TODO();
return 0;
}
int Steam_Friends::GetFriendCount()
{
PRINT_DEBUG("sdk 0.99u");
return GetFriendCount((int)k_EFriendFlagImmediate);
}
CSteamID Steam_Friends::GetFriendByIndex(int iFriend)
{
PRINT_DEBUG("sdk 0.99u");
return GetFriendByIndex(iFriend, (int)k_EFriendFlagImmediate);
}
void Steam_Friends::SendMsgToFriend(CSteamID steamIDFriend, EChatEntryType eChatEntryType, const char *pchMsgBody)
{
PRINT_DEBUG_TODO();
}
void Steam_Friends::SetFriendRegValue(CSteamID steamIDFriend, const char *pchKey, const char *pchValue)
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!pchValue)
return; // real steam crashes though
if (!pchKey || !pchKey[0]) // tested on real steam
{
reg.clear();
reg_nullptr = std::string(pchValue);
}
else
{
reg[std::string(pchKey)] = std::string(pchValue);
// TODO: save it to disk, because real steam can get the string when app restarts
}
}
const char *Steam_Friends::GetFriendRegValue(CSteamID steamIDFriend, const char *pchKey)
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
// TODO: load data from disk, because real steam can get the string when app restarts
if (!pchKey || !pchKey[0])
{
return reg_nullptr.c_str();
}
else
{
auto it = reg.find(std::string(pchKey));
if (it == reg.end())
return "";
return it->second.c_str();
}
}
int Steam_Friends::GetChatMessage(CSteamID steamIDFriend, int iChatID, void *pvData, int cubData, EChatEntryType *peChatEntryType)
{
PRINT_DEBUG_TODO();
if (peChatEntryType)
*peChatEntryType = k_EChatEntryTypeInvalid;
return 0;
}
bool Steam_Friends::SendMsgToFriend(CSteamID steamIDFriend, EChatEntryType eChatEntryType, const void *pvMsgBody, int cubMsgBody)
{
PRINT_DEBUG_TODO();
return true;
}
int Steam_Friends::GetChatIDOfChatHistoryStart(CSteamID steamIDFriend)
{
PRINT_DEBUG_TODO();
return 0;
}
void Steam_Friends::SetChatHistoryStart(CSteamID steamIDFriend, int iChatID)
{
PRINT_DEBUG_TODO();
}
void Steam_Friends::ClearChatHistory(CSteamID steamIDFriend)
{
PRINT_DEBUG_TODO();
}
bool Steam_Friends::InviteFriendByEmail(const char *pchEmailAccount)
{
PRINT_DEBUG_TODO();
return false;
}
int Steam_Friends::GetBlockedFriendCount()
{
PRINT_DEBUG_ENTRY();
return GetFriendCount((int)k_EFriendFlagBlocked);
}
bool Steam_Friends::GetFriendGamePlayed(CSteamID steamIDFriend, uint64 *pulGameID, uint32 *punGameIP, uint16 *pusGamePort)
{
PRINT_DEBUG("sdk 0.99u");
return GetFriendGamePlayed(steamIDFriend, pulGameID, punGameIP, pusGamePort, NULL);
}
bool Steam_Friends::GetFriendGamePlayed2(CSteamID steamIDFriend, uint64 *pulGameID, uint32 *punGameIP, uint16 *pusGamePort, uint16 *pusQueryPort)
{
PRINT_DEBUG_ENTRY();
return GetFriendGamePlayed(steamIDFriend, pulGameID, punGameIP, pusGamePort, pusQueryPort);
}
// returns true if the friend is actually in a game, and fills in pFriendGameInfo with an extra details
bool Steam_Friends::GetFriendGamePlayed( CSteamID steamIDFriend, STEAM_OUT_STRUCT() FriendGameInfo_t *pFriendGameInfo )
{
PRINT_DEBUG("%llu %p", steamIDFriend.ConvertToUint64(), pFriendGameInfo);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
bool ret = false;
if (steamIDFriend == settings->get_local_steam_id()) {
PRINT_DEBUG("found myself! %llu %llu", settings->get_local_game_id().ToUint64(), settings->get_lobby().ConvertToUint64());
if (pFriendGameInfo) {
pFriendGameInfo->m_gameID = settings->get_local_game_id();
pFriendGameInfo->m_unGameIP = 0;
pFriendGameInfo->m_usGamePort = 0;
pFriendGameInfo->m_usQueryPort = 0;
pFriendGameInfo->m_steamIDLobby = settings->get_lobby();
}
ret = true;
} else {
Friend *f = find_friend(steamIDFriend);
if (f) {
PRINT_DEBUG("found someone %u " "%" PRIu64 "", f->appid(), f->lobby_id());
if (pFriendGameInfo) {
pFriendGameInfo->m_gameID = CGameID(f->appid());
pFriendGameInfo->m_unGameIP = 0;
pFriendGameInfo->m_usGamePort = 0;
pFriendGameInfo->m_usQueryPort = 0;
pFriendGameInfo->m_steamIDLobby = CSteamID((uint64)f->lobby_id());
}
ret = true;
}
}
return ret;
}
bool Steam_Friends::GetFriendGamePlayed( CSteamID steamIDFriend, uint64 *pulGameID, uint32 *punGameIP, uint16 *pusGamePort, uint16 *pusQueryPort )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
FriendGameInfo_t info;
bool ret = GetFriendGamePlayed(steamIDFriend, &info);
if (ret) {
if (pulGameID) *pulGameID = info.m_gameID.ToUint64();
if (punGameIP) *punGameIP = info.m_unGameIP;
if (pusGamePort) *pusGamePort = info.m_usGamePort;
if (pusQueryPort) *pusQueryPort = info.m_usQueryPort;
}
return ret;
}
// accesses old friends names - returns an empty string when their are no more items in the history
const char* Steam_Friends::GetFriendPersonaNameHistory( CSteamID steamIDFriend, int iPersonaName )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
const char *ret = "";
if (iPersonaName == 0) ret = GetFriendPersonaName(steamIDFriend);
else if (iPersonaName == 1) ret = "Some Old Name";
return ret;
}
// friends steam level
int Steam_Friends::GetFriendSteamLevel( CSteamID steamIDFriend )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return 100;
}
// Returns nickname the current user has set for the specified player. Returns NULL if the no nickname has been set for that player.
const char* Steam_Friends::GetPlayerNickname( CSteamID steamIDPlayer )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return NULL;
}
// friend grouping (tag) apis
// returns the number of friends groups
int Steam_Friends::GetFriendsGroupCount()
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return 0;
}
// returns the friends group ID for the given index (invalid indices return k_FriendsGroupID_Invalid)
FriendsGroupID_t Steam_Friends::GetFriendsGroupIDByIndex( int iFG )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_FriendsGroupID_Invalid;
}
// returns the name for the given friends group (NULL in the case of invalid friends group IDs)
const char* Steam_Friends::GetFriendsGroupName( FriendsGroupID_t friendsGroupID )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return NULL;
}
// returns the number of members in a given friends group
int Steam_Friends::GetFriendsGroupMembersCount( FriendsGroupID_t friendsGroupID )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return 0;
}
// gets up to nMembersCount members of the given friends group, if fewer exist than requested those positions' SteamIDs will be invalid
void Steam_Friends::GetFriendsGroupMembersList( FriendsGroupID_t friendsGroupID, STEAM_OUT_ARRAY_CALL(nMembersCount, GetFriendsGroupMembersCount, friendsGroupID ) CSteamID *pOutSteamIDMembers, int nMembersCount )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
}
// returns true if the specified user meets any of the criteria specified in iFriendFlags
// iFriendFlags can be the union (binary or, |) of one or more k_EFriendFlags values
bool Steam_Friends::HasFriend( CSteamID steamIDFriend, int iFriendFlags )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
bool ret = false;
if (ok_friend_flags(iFriendFlags)) if (find_friend(steamIDFriend)) ret = true;
return ret;
}
bool Steam_Friends::HasFriend( CSteamID steamIDFriend, EFriendFlags eFriendFlags )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return HasFriend(steamIDFriend, (int)eFriendFlags );
}
// clan (group) iteration and access functions
int Steam_Friends::GetClanCount()
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
int counter = 0;
for (auto &c : settings->subscribed_groups_clans) counter++;
return counter;
}
CSteamID Steam_Friends::GetClanByIndex( int iClan )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
int counter = 0;
for (auto &c : settings->subscribed_groups_clans) {
if (counter == iClan) return c.id;
counter++;
}
return k_steamIDNil;
}
void Steam_Friends::GetClanByIndex( CSteamID& result, int iClan )
{
PRINT_DEBUG_GNU_WIN();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
result = GetClanByIndex(iClan);
}
const char* Steam_Friends::GetClanName( CSteamID steamIDClan )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
for (auto &c : settings->subscribed_groups_clans) {
if (c.id.ConvertToUint64() == steamIDClan.ConvertToUint64()) return c.name.c_str();
}
return "";
}
bool Steam_Friends::InviteFriendToClan(CSteamID steamIDFriend, CSteamID steamIDClan)
{
PRINT_DEBUG_TODO();
return false;
}
bool Steam_Friends::AcknowledgeInviteToClan(CSteamID steamIDClan, bool bAcceptOrDenyClanInvite)
{
PRINT_DEBUG_TODO();
return false;
}
const char* Steam_Friends::GetClanTag( CSteamID steamIDClan )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
for (auto &c : settings->subscribed_groups_clans) {
if (c.id.ConvertToUint64() == steamIDClan.ConvertToUint64()) return c.tag.c_str();
}
return "";
}
// returns the most recent information we have about what's happening in a clan
bool Steam_Friends::GetClanActivityCounts( CSteamID steamIDClan, int *pnOnline, int *pnInGame, int *pnChatting )
{
PRINT_DEBUG("TODO %llu", steamIDClan.ConvertToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return false;
}
// for clans a user is a member of, they will have reasonably up-to-date information, but for others you'll have to download the info to have the latest
SteamAPICall_t Steam_Friends::DownloadClanActivityCounts( STEAM_ARRAY_COUNT(cClansToRequest) CSteamID *psteamIDClans, int cClansToRequest )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return 0;
}
// iterators for getting users in a chat room, lobby, game server or clan
// note that large clans that cannot be iterated by the local user
// note that the current user must be in a lobby to retrieve CSteamIDs of other users in that lobby
// steamIDSource can be the steamID of a group, game server, lobby or chat room
int Steam_Friends::GetFriendCountFromSource( CSteamID steamIDSource )
{
PRINT_DEBUG("TODO %llu", steamIDSource.ConvertToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
//TODO
return 0;
}
CSteamID Steam_Friends::GetFriendFromSourceByIndex( CSteamID steamIDSource, int iFriend )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_steamIDNil;
}
void Steam_Friends::GetFriendFromSourceByIndex( CSteamID& res, CSteamID steamIDSource, int iFriend )
{
PRINT_DEBUG_GNU_WIN();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
res = GetFriendFromSourceByIndex( steamIDSource, iFriend );
}
// returns true if the local user can see that steamIDUser is a member or in steamIDSource
bool Steam_Friends::IsUserInSource( CSteamID steamIDUser, CSteamID steamIDSource )
{
PRINT_DEBUG("%llu %llu", steamIDUser.ConvertToUint64(), steamIDSource.ConvertToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (steamIDUser == settings->get_local_steam_id()) {
if (settings->get_lobby() == steamIDSource) {
return true;
}
if (settings->subscribed_groups.find(steamIDSource.ConvertToUint64()) != settings->subscribed_groups.end()) {
return true;
}
} else {
Friend *f = find_friend(steamIDUser);
if (!f) return false;
if (f->lobby_id() == steamIDSource.ConvertToUint64()) return true;
}
//TODO
return false;
}
// User is in a game pressing the talk button (will suppress the microphone for all voice comms from the Steam friends UI)
void Steam_Friends::SetInGameVoiceSpeaking( CSteamID steamIDUser, bool bSpeaking )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
}
// activates the game overlay, with an optional dialog to open
// valid options are "Friends", "Community", "Players", "Settings", "OfficialGameGroup", "Stats", "Achievements"
void Steam_Friends::ActivateGameOverlay( const char *pchDialog )
{
PRINT_DEBUG("%s", pchDialog);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
overlay->OpenOverlay(pchDialog);
}
// activates game overlay to a specific place
// valid options are
// "steamid" - opens the overlay web browser to the specified user or groups profile
// "chat" - opens a chat window to the specified user, or joins the group chat
// "jointrade" - opens a window to a Steam Trading session that was started with the ISteamEconomy/StartTrade Web API
// "stats" - opens the overlay web browser to the specified user's stats
// "achievements" - opens the overlay web browser to the specified user's achievements
// "friendadd" - opens the overlay in minimal mode prompting the user to add the target user as a friend
// "friendremove" - opens the overlay in minimal mode prompting the user to remove the target friend
// "friendrequestaccept" - opens the overlay in minimal mode prompting the user to accept an incoming friend invite
// "friendrequestignore" - opens the overlay in minimal mode prompting the user to ignore an incoming friend invite
void Steam_Friends::ActivateGameOverlayToUser( const char *pchDialog, CSteamID steamID )
{
PRINT_DEBUG("TODO %s %llu", pchDialog, steamID.ConvertToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
}
// activates game overlay web browser directly to the specified URL
// full address with protocol type is required, e.g. http://www.steamgames.com/
void Steam_Friends::ActivateGameOverlayToWebPage( const char *pchURL, EActivateGameOverlayToWebPageMode eMode )
{
PRINT_DEBUG("TODO %s %u", pchURL, eMode);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
overlay->OpenOverlayWebpage(pchURL);
}
void Steam_Friends::ActivateGameOverlayToWebPage( const char *pchURL )
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
ActivateGameOverlayToWebPage( pchURL, k_EActivateGameOverlayToWebPageMode_Default );
}
// activates game overlay to store page for app
void Steam_Friends::ActivateGameOverlayToStore( AppId_t nAppID, EOverlayToStoreFlag eFlag )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
}
void Steam_Friends::ActivateGameOverlayToStore( AppId_t nAppID)
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
}
// Mark a target user as 'played with'. This is a client-side only feature that requires that the calling user is
// in game
void Steam_Friends::SetPlayedWith( CSteamID steamIDUserPlayedWith )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
}
// activates game overlay to open the invite dialog. Invitations will be sent for the provided lobby.
void Steam_Friends::ActivateGameOverlayInviteDialog( CSteamID steamIDLobby )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
overlay->OpenOverlayInvite(steamIDLobby);
}
// gets the small (32x32) avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set
int Steam_Friends::GetSmallFriendAvatar( CSteamID steamIDFriend )
{
PRINT_DEBUG_ENTRY();
//IMPORTANT NOTE: don't change friend avatar numbers for the same friend or else some games endlessly allocate stuff.
std::lock_guard<std::recursive_mutex> lock(global_mutex);
struct Avatar_Numbers numbers = add_friend_avatars(steamIDFriend);
return numbers.smallest;
}
// gets the medium (64x64) avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set
int Steam_Friends::GetMediumFriendAvatar( CSteamID steamIDFriend )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
struct Avatar_Numbers numbers = add_friend_avatars(steamIDFriend);
return numbers.medium;
}
// gets the large (184x184) avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set
// returns -1 if this image has yet to be loaded, in this case wait for a AvatarImageLoaded_t callback and then call this again
int Steam_Friends::GetLargeFriendAvatar( CSteamID steamIDFriend )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
struct Avatar_Numbers numbers = add_friend_avatars(steamIDFriend);
return numbers.large;
}
int Steam_Friends::GetFriendAvatar( CSteamID steamIDFriend, int eAvatarSize )
{
PRINT_DEBUG_ENTRY();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (eAvatarSize == k_EAvatarSize32x32) {
return GetSmallFriendAvatar(steamIDFriend);
} else if (eAvatarSize == k_EAvatarSize64x64) {
return GetMediumFriendAvatar(steamIDFriend);
} else if (eAvatarSize == k_EAvatarSize184x184) {
return GetLargeFriendAvatar(steamIDFriend);
} else {
return 0;
}
}
int Steam_Friends::GetFriendAvatar(CSteamID steamIDFriend)
{
PRINT_DEBUG("old");
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return GetFriendAvatar(steamIDFriend, k_EAvatarSize32x32);
}
// requests information about a user - persona name & avatar
// if bRequireNameOnly is set, then the avatar of a user isn't downloaded
// - it's a lot slower to download avatars and churns the local cache, so if you don't need avatars, don't request them
// if returns true, it means that data is being requested, and a PersonaStateChanged_t callback will be posted when it's retrieved
// if returns false, it means that we already have all the details about that user, and functions can be called immediately
bool Steam_Friends::RequestUserInformation( CSteamID steamIDUser, bool bRequireNameOnly )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
//persona_change(steamIDUser, k_EPersonaChangeName);
//We already know everything
return false;
}
// requests information about a clan officer list
// when complete, data is returned in ClanOfficerListResponse_t call result
// this makes available the calls below
// you can only ask about clans that a user is a member of
// note that this won't download avatars automatically; if you get an officer,
// and no avatar image is available, call RequestUserInformation( steamID, false ) to download the avatar
STEAM_CALL_RESULT( ClanOfficerListResponse_t )
SteamAPICall_t Steam_Friends::RequestClanOfficerList( CSteamID steamIDClan )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return 0;
}
// iteration of clan officers - can only be done when a RequestClanOfficerList() call has completed
// returns the steamID of the clan owner
CSteamID Steam_Friends::GetClanOwner( CSteamID steamIDClan )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_steamIDNil;
}
void Steam_Friends::GetClanOwner(CSteamID& res, CSteamID steamIDClan )
{
PRINT_DEBUG_GNU_WIN();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
res = GetClanOwner( steamIDClan );
}
// returns the number of officers in a clan (including the owner)
int Steam_Friends::GetClanOfficerCount( CSteamID steamIDClan )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return 0;
}
// returns the steamID of a clan officer, by index, of range [0,GetClanOfficerCount)
CSteamID Steam_Friends::GetClanOfficerByIndex( CSteamID steamIDClan, int iOfficer )
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_steamIDNil;
}
void Steam_Friends::GetClanOfficerByIndex(CSteamID& res, CSteamID steamIDClan, int iOfficer )
{
PRINT_DEBUG_GNU_WIN();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
res = GetClanOfficerByIndex( steamIDClan, iOfficer );
}
// if current user is chat restricted, he can't send or receive any text/voice chat messages.
// the user can't see custom avatars. But the user can be online and send/recv game invites.
// a chat restricted user can't add friends or join any groups.
uint32 Steam_Friends::GetUserRestrictions()
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_nUserRestrictionNone;
}
EUserRestriction Steam_Friends::GetUserRestrictions_old()
{
PRINT_DEBUG_TODO();
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return k_nUserRestrictionNone;
}
// Rich Presence data is automatically shared between friends who are in the same game
// Each user has a set of Key/Value pairs
// Note the following limits: k_cchMaxRichPresenceKeys, k_cchMaxRichPresenceKeyLength, k_cchMaxRichPresenceValueLength
// There are two magic keys:
// "status" - a UTF-8 string that will show up in the 'view game info' dialog in the Steam friends list