int CSteamProto::SetStatus(int new_status) { mir_cslock lock(set_status_lock); // Routing statuses not supported by Steam switch (new_status) { case ID_STATUS_OFFLINE: case ID_STATUS_AWAY: case ID_STATUS_NA: break; case ID_STATUS_DND: case ID_STATUS_OCCUPIED: case ID_STATUS_ONTHEPHONE: case ID_STATUS_OUTTOLUNCH: new_status = ID_STATUS_NA; break; default: new_status = ID_STATUS_ONLINE; break; } if (new_status == m_iDesiredStatus) return 0; debugLog(_T("CSteamProto::SetStatus: changing status from %i to %i"), m_iStatus, new_status); int old_status = m_iStatus; m_iDesiredStatus = new_status; if (new_status == ID_STATUS_OFFLINE) { m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); ptrA token(getStringA("TokenSecret")); ptrA umqid(getStringA("UMQID")); SendRequest(new LogoffRequest(token, umqid)); requestQueue->Stop(); if (!Miranda_Terminated()) SetAllContactsStatus(ID_STATUS_OFFLINE); } else if (old_status == ID_STATUS_OFFLINE) { m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); requestQueue->Start(); ptrA token(getStringA("TokenSecret")); if (mir_strlen(token) > 0) { PushRequest( new LogonRequest(token), &CSteamProto::OnLoggedOn); } else { ptrA username(mir_urlEncode(ptrA(mir_utf8encodeT(getTStringA("Username"))))); if (username == NULL || username[0] == '\0') { m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); return 0; } PushRequest( new GetRsaKeyRequest(username), &CSteamProto::OnGotRsaKey); } } else { m_iStatus = new_status; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); } return 0; }
int CSkypeProto::SetStatus(int iNewStatus) { if (iNewStatus == m_iDesiredStatus) return 0; switch (iNewStatus) { case ID_STATUS_FREECHAT: case ID_STATUS_ONTHEPHONE: iNewStatus = ID_STATUS_ONLINE; break; case ID_STATUS_NA: case ID_STATUS_OUTTOLUNCH: iNewStatus = ID_STATUS_AWAY; break; case ID_STATUS_OCCUPIED: iNewStatus = ID_STATUS_DND; break; } //mir_cslock lck(m_StatusLock); debugLogA(__FUNCTION__ ": changing status from %i to %i", m_iStatus, iNewStatus); int old_status = m_iStatus; m_iDesiredStatus = iNewStatus; if (iNewStatus == ID_STATUS_OFFLINE) { if (m_iStatus > ID_STATUS_CONNECTING + 1) { SendRequest(new DeleteEndpointRequest(li)); delSetting("registrationRoken"); delSetting("endpointId"); delSetting("expires"); } m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; // logout requestQueue->Stop(); ShutdownConnections(); CloseDialogs(); ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, ID_STATUS_OFFLINE); if (!Miranda_Terminated()) SetAllContactsStatus(ID_STATUS_OFFLINE); return 0; } else { if (old_status == ID_STATUS_CONNECTING) return 0; if (old_status == ID_STATUS_OFFLINE && m_iStatus == ID_STATUS_OFFLINE) { Login(); } else { SendRequest(new SetStatusRequest(MirandaToSkypeStatus(m_iDesiredStatus), li), &CSkypeProto::OnStatusChanged); } } ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus); return 0; }
CSteamProto::CSteamProto(const char* protoName, const TCHAR* userName) : PROTO<CSteamProto>(protoName, userName), hAuthProcess(1), hMessageProcess(1) { CreateProtoService(PS_CREATEACCMGRUI, &CSteamProto::OnAccountManagerInit); m_idleTS = 0; isTerminated = false; m_hQueueThread = NULL; m_pollingConnection = NULL; m_hPollingThread = NULL; // icons wchar_t filePath[MAX_PATH]; GetModuleFileName(g_hInstance, filePath, MAX_PATH); wchar_t sectionName[100]; mir_sntprintf(sectionName, _T("%s/%s"), LPGENT("Protocols"), LPGENT(MODULE)); char settingName[100]; mir_snprintf(settingName, "%s_%s", MODULE, "main"); SKINICONDESC sid = { 0 }; sid.flags = SIDF_ALL_TCHAR; sid.defaultFile.t = filePath; sid.pszName = settingName; sid.section.t = sectionName; sid.description.t = LPGENT("Protocol icon"); sid.iDefaultIndex = -IDI_STEAM; IcoLib_AddIcon(&sid); mir_snprintf(settingName, "%s_%s", MODULE, "gaming"); sid.description.t = LPGENT("Gaming icon"); sid.iDefaultIndex = -IDI_GAMING; IcoLib_AddIcon(&sid); // temporary DB settings db_set_resident(m_szModuleName, "XStatusId"); db_set_resident(m_szModuleName, "XStatusName"); db_set_resident(m_szModuleName, "XStatusMsg"); db_set_resident(m_szModuleName, "IdleTS"); db_set_resident(m_szModuleName, "GameID"); db_set_resident(m_szModuleName, "ServerIP"); db_set_resident(m_szModuleName, "ServerID"); SetAllContactsStatus(ID_STATUS_OFFLINE); // services CreateServiceFunction(MODULE"/MenuChoose", CSteamProto::MenuChooseService); // avatar API CreateProtoService(PS_GETAVATARINFO, &CSteamProto::GetAvatarInfo); CreateProtoService(PS_GETAVATARCAPS, &CSteamProto::GetAvatarCaps); CreateProtoService(PS_GETMYAVATAR, &CSteamProto::GetMyAvatar); // custom status API CreateProtoService(PS_GETCUSTOMSTATUSEX, &CSteamProto::OnGetXStatusEx); CreateProtoService(PS_GETCUSTOMSTATUSICON, &CSteamProto::OnGetXStatusIcon); CreateProtoService(PS_GETADVANCEDSTATUSICON, &CSteamProto::OnRequestAdvStatusIconIdx); // netlib support TCHAR name[128]; mir_sntprintf(name, TranslateT("%s connection"), m_tszUserName); NETLIBUSER nlu = { sizeof(nlu) }; nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR; nlu.ptszDescriptiveName = name; nlu.szSettingsModule = m_szModuleName; m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); requestQueue = new RequestQueue(m_hNetlibUser); }