summaryrefslogtreecommitdiff
path: root/protocols/Steam/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Steam/src')
-rw-r--r--protocols/Steam/src/main.cpp6
-rw-r--r--protocols/Steam/src/proto.h1
-rw-r--r--protocols/Steam/src/steam_login.cpp17
-rw-r--r--protocols/Steam/src/steam_proto.h3
-rw-r--r--protocols/Steam/src/steam_ws.cpp28
5 files changed, 33 insertions, 22 deletions
diff --git a/protocols/Steam/src/main.cpp b/protocols/Steam/src/main.cpp
index d39201d870..efb35cb945 100644
--- a/protocols/Steam/src/main.cpp
+++ b/protocols/Steam/src/main.cpp
@@ -34,7 +34,7 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOC
void CMPlugin::InitSteamServices()
{
- // message handlers
+ // message descriptors map
messages[EMsg::Multi] = &cmsg_multi__descriptor;
messages[EMsg::ClientHeartBeat] = &cmsg_client_heart_beat__descriptor;
messages[EMsg::ClientHello] = &cmsg_client_hello__descriptor;
@@ -137,6 +137,10 @@ void CMPlugin::InitSteamServices()
// messages[EMsg::ClientDeauthorizeDevice] = &cmsg_Client_DeauthorizeDevice;
// messages[EMsg::ClientUseLocalDeviceAuthorizations] = &cmsg_Client_UseLocalDeviceAuthorizations;
+ // message handlers
+ messageHandlers[EMsg::ClientLoggedOff] = ServiceResponseHandler(&CSteamProto::OnClientLogoff);
+ messageHandlers[EMsg::ClientLogOnResponse] = ServiceResponseHandler(&CSteamProto::OnClientLogon);
+
// services from steammessages_auth.steamclient.proto
services["Authentication"] = &authentication__descriptor;
services["AuthenticationSupport"] = &authentication_support__descriptor;
diff --git a/protocols/Steam/src/proto.h b/protocols/Steam/src/proto.h
index fdb120452d..c7f917a4e8 100644
--- a/protocols/Steam/src/proto.h
+++ b/protocols/Steam/src/proto.h
@@ -2142,5 +2142,4 @@ namespace proto
PROTOBUF_PTR(MsgMulti, cmsg_multi__descriptor);
PROTOBUF_PTR(MsgProtoBufHeader, cmsg_proto_buf_header__descriptor);
- PROTOBUF_PTR(MsgClientLogonResponse, cmsg_client_logon_response__descriptor);
};
diff --git a/protocols/Steam/src/steam_login.cpp b/protocols/Steam/src/steam_login.cpp
index 13c6b9f371..30b773b7db 100644
--- a/protocols/Steam/src/steam_login.cpp
+++ b/protocols/Steam/src/steam_login.cpp
@@ -253,18 +253,15 @@ void CSteamProto::OnPollSession(const CAuthenticationPollAuthSessionStatusRespon
WSSend(EMsg::ClientLogon, request);
}
-void CSteamProto::OnClientLogon(const uint8_t *buf, size_t cbLen)
+void CSteamProto::OnClientLogon(const CMsgClientLogonResponse &reply, const CMsgProtoBufHeader &hdr)
{
- proto::MsgClientLogonResponse reply(buf, cbLen);
- if (reply == nullptr || !reply->has_eresult || reply->eresult != (int)EResult::OK) {
+ if (hdr.failed()) {
Logout();
return;
}
- debugLogA("client logged in\n%s", protobuf_c_text_to_string(*reply).c_str());
-
- if (reply->has_heartbeat_seconds)
- m_impl.m_heartBeat.Start(reply->heartbeat_seconds * 1000);
+ if (reply.has_heartbeat_seconds)
+ m_impl.m_heartBeat.Start(reply.heartbeat_seconds * 1000);
// go to online now
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus);
@@ -272,3 +269,9 @@ void CSteamProto::OnClientLogon(const uint8_t *buf, size_t cbLen)
// load contact list
SendRequest(new GetFriendListRequest(m_szAccessToken, m_iSteamId, "friend,ignoredfriend,requestrecipient"), &CSteamProto::OnGotFriendList);
}
+
+void CSteamProto::OnClientLogoff(const CMsgClientLoggedOff &reply, const CMsgProtoBufHeader&)
+{
+ debugLogA("received logout request with error code %d", reply.has_eresult ? reply.eresult : 0);
+ Logout();
+}
diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h
index 57f87b6b77..5453485a95 100644
--- a/protocols/Steam/src/steam_proto.h
+++ b/protocols/Steam/src/steam_proto.h
@@ -162,7 +162,8 @@ class CSteamProto : public PROTO<CSteamProto>
static INT_PTR CALLBACK EnterEmailCode(void *param);
void OnBeginSession(const CAuthenticationBeginAuthSessionViaCredentialsResponse &pResponse, const CMsgProtoBufHeader &hdr);
- void OnClientLogon(const uint8_t *buf, size_t cbLen);
+ void OnClientLogon(const CMsgClientLogonResponse &pResponse, const CMsgProtoBufHeader &hdr);
+ void OnClientLogoff(const CMsgClientLoggedOff &pResponse, const CMsgProtoBufHeader &hdr);
void OnGotRsaKey(const CAuthenticationGetPasswordRSAPublicKeyResponse &pResponse, const CMsgProtoBufHeader &hdr);
void OnGotConfirmationCode(const CAuthenticationUpdateAuthSessionWithSteamGuardCodeResponse &pResponse, const CMsgProtoBufHeader &hdr);
void OnPollSession(const CAuthenticationPollAuthSessionStatusResponse &pResponse, const CMsgProtoBufHeader &hdr);
diff --git a/protocols/Steam/src/steam_ws.cpp b/protocols/Steam/src/steam_ws.cpp
index f7a1112add..ceca7636a7 100644
--- a/protocols/Steam/src/steam_ws.cpp
+++ b/protocols/Steam/src/steam_ws.cpp
@@ -137,7 +137,7 @@ void CSteamProto::ProcessMessage(const uint8_t *buf, size_t cbLen)
}
if (!bIsProto) {
- debugLogA("Got unknown packet, exiting");
+ debugLogA("Got unknown packet of type %d, exiting", msgType);
Netlib_Dump(HNETLIBCONN(m_ws->getConn()), buf, cbLen, false, 0);
return;
}
@@ -156,22 +156,26 @@ void CSteamProto::ProcessMessage(const uint8_t *buf, size_t cbLen)
// persistent callbacks
switch (msgType) {
- case EMsg::ClientLogOnResponse:
- OnClientLogon(buf, cbLen);
- break;
-
case EMsg::ServiceMethodResponse:
ProcessServiceResponse(buf, cbLen, *hdr);
break;
- case EMsg::ClientLoggedOff:
- debugLogA("received logout request");
- Logout();
- break;
-
default:
- debugLogA("Received message of type %d", msgType);
- Netlib_Dump(HNETLIBCONN(m_ws->getConn()), buf, cbLen, false, 0);
+ // find message descriptor first, if succeeded, try to find a message handler then
+ auto md = g_plugin.messages.find(msgType);
+ if (md == g_plugin.messages.end()) {
+ debugLogA("Received message of type %d", msgType);
+ Netlib_Dump(HNETLIBCONN(m_ws->getConn()), buf, cbLen, false, 0);
+ }
+ else if (auto *pMessage = protobuf_c_message_unpack(md->second, 0, cbLen, buf)) {
+ debugLogA("Received known message:\n%s", protobuf_c_text_to_string(*pMessage).c_str());
+
+ auto mh = g_plugin.messageHandlers.find(msgType);
+ if (mh != g_plugin.messageHandlers.end())
+ (this->*(mh->second))(*pMessage, *hdr);
+
+ protobuf_c_message_free_unpacked(pMessage, 0);
+ }
}
}