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
|
#include "stdafx.h"
static int64_t getRandomInt()
{
int64_t ret;
Utils_GetRandom(&ret, sizeof(ret));
return (ret >= 0) ? ret : -ret;
}
void CSteamProto::WSSend(EMsg msgType, const ProtobufCppMessage &msg)
{
CMsgProtoBufHeader hdr;
hdr.has_client_sessionid = hdr.has_steamid = hdr.has_jobid_source = hdr.has_jobid_target = true;
switch (msgType) {
case EMsg::ClientHello:
hdr.jobid_source = -1;
break;
default:
hdr.jobid_source = getRandomInt();
break;
}
hdr.jobid_target = -1;
WSSendHeader(msgType, hdr, msg);
}
void CSteamProto::WSSendHeader(EMsg msgType, const CMsgProtoBufHeader &hdr, const ProtobufCppMessage &msg)
{
uint32_t hdrLen = (uint32_t)protobuf_c_message_get_packed_size(&hdr);
MBinBuffer hdrbuf(hdrLen);
protobuf_c_message_pack(&hdr, (uint8_t *)hdrbuf.data());
hdrbuf.appendBefore(&hdrLen, sizeof(hdrLen));
uint32_t type = (uint32_t)msgType;
type |= STEAM_PROTOCOL_MASK;
hdrbuf.appendBefore(&type, sizeof(type));
MBinBuffer body(protobuf_c_message_get_packed_size(&msg));
protobuf_c_message_pack(&msg, body.data());
hdrbuf.append(body);
m_ws->sendBinary(hdrbuf.data(), hdrbuf.length());
}
void CSteamProto::WSSendService(const char *pszServiceName, const ProtobufCppMessage &msg, MsgCallback pCallback)
{
CMsgProtoBufHeader hdr;
hdr.has_client_sessionid = hdr.has_steamid = hdr.has_jobid_source = hdr.has_jobid_target = true;
hdr.jobid_source = getRandomInt();
hdr.jobid_target = -1;
hdr.target_job_name = (char*)pszServiceName;
hdr.realm = 1; hdr.has_realm = true;
if (pCallback) {
mir_cslock lck(m_csRequests);
m_arRequests.insert(new ProtoRequest(hdr.jobid_source, pCallback));
}
WSSendHeader(EMsg::ServiceMethodCallFromClientNonAuthed, hdr, msg);
}
/////////////////////////////////////////////////////////////////////////////////////////
int64_t CSteamProto::GetId(MCONTACT hContact, const char *pszSetting)
{
return _atoi64(getMStringA(hContact, pszSetting));
}
void CSteamProto::SetId(MCONTACT hContact, const char *pszSetting, int64_t id)
{
char szId[100];
_i64toa(id, szId, 10);
setString(hContact, pszSetting, szId);
}
/////////////////////////////////////////////////////////////////////////////////////////
int64_t CSteamProto::GetId(const char *pszSetting)
{
return _atoi64(getMStringA(pszSetting));
}
void CSteamProto::SetId(const char *pszSetting, int64_t id)
{
char szId[100];
_i64toa(id, szId, 10);
setString(pszSetting, szId);
}
/////////////////////////////////////////////////////////////////////////////////////////
uint16_t CSteamProto::SteamToMirandaStatus(PersonaState state)
{
switch (state) {
case PersonaState::Offline:
return ID_STATUS_OFFLINE;
case PersonaState::Online:
return ID_STATUS_ONLINE;
case PersonaState::Busy:
return ID_STATUS_DND;
case PersonaState::Away:
return ID_STATUS_AWAY;
case PersonaState::Snooze:
return ID_STATUS_NA;
case PersonaState::LookingToPlay:
case PersonaState::LookingToTrade:
return ID_STATUS_FREECHAT;
case PersonaState::Invisible:
return ID_STATUS_INVISIBLE;
default:
return ID_STATUS_ONLINE;
}
}
PersonaState CSteamProto::MirandaToSteamState(int status)
{
switch (status) {
case ID_STATUS_OFFLINE:
return PersonaState::Offline;
case ID_STATUS_ONLINE:
return PersonaState::Online;
case ID_STATUS_DND:
return PersonaState::Busy;
case ID_STATUS_AWAY:
return PersonaState::Away;
case ID_STATUS_NA:
return PersonaState::Snooze;
case ID_STATUS_FREECHAT:
return PersonaState::LookingToPlay;
case ID_STATUS_INVISIBLE:
return PersonaState::Invisible;
default:
return PersonaState::Online;
}
}
void CSteamProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags, MCONTACT hContact)
{
if (Miranda_IsTerminated())
return;
if (Popup_Enabled()) {
POPUPDATAW ppd;
ppd.lchContact = hContact;
wcsncpy(ppd.lpwzContactName, caption, MAX_CONTACTNAME);
wcsncpy(ppd.lpwzText, message, MAX_SECONDLINE);
ppd.lchIcon = IcoLib_GetIcon(MODULE"_main");
if (!PUAddPopupW(&ppd))
return;
}
MessageBox(nullptr, message, caption, MB_OK | flags);
}
void CSteamProto::ShowNotification(const wchar_t *message, int flags, MCONTACT hContact)
{
ShowNotification(_A2W(MODULE), message, flags, hContact);
}
INT_PTR CSteamProto::OnGetEventTextChatStates(WPARAM pEvent, LPARAM datatype)
{
// Retrieves a chat state description from an event
DBEVENTINFO *dbei = (DBEVENTINFO *)pEvent;
if (dbei->cbBlob > 0 && dbei->pBlob[0] == STEAM_DB_EVENT_CHATSTATES_GONE)
return (datatype == DBVT_WCHAR)
? (INT_PTR)mir_wstrdup(TranslateT("closed chat session"))
: (INT_PTR)mir_strdup(Translate("closed chat session"));
return NULL;
}
|