void CMsnProto::MSN_Promoteuser(GCHOOK *gch, const char *pszRole) { GCThreadData *thread = MSN_GetThreadByChatId(gch->pDest->ptszID); msnNsThread->sendPacketPayload("PUT", "MSGR\\THREAD", "<thread><id>%d:%s</id><members><member><mri>%s</mri><role>%s</role></member></members></thread>", thread->netId, thread->szEmail, _T2A(gch->ptszUID), pszRole); }
void CMsnProto::MSN_Kickuser(GCHOOK *gch) { GCThreadData *thread = MSN_GetThreadByChatId(gch->pDest->ptszID); msnNsThread->sendPacketPayload("DEL", "MSGR\\THREAD", "<thread><id>%d:%s</id><members><member><mri>%s</mri></member></members></thread>", thread->netId, thread->szEmail, _T2A(gch->ptszUID)); }
int CMsnProto::MSN_GCMenuHook(WPARAM, LPARAM lParam) { GCMENUITEMS *gcmi = (GCMENUITEMS*)lParam; if (gcmi == NULL || _stricmp(gcmi->pszModule, m_szModuleName)) return 0; if (gcmi->Type == MENU_ON_LOG) { static const struct gc_item Items[] = { { LPGENT("&Invite user..."), 10, MENU_ITEM, FALSE }, { LPGENT("&Leave chat session"), 20, MENU_ITEM, FALSE } }; gcmi->nItems = _countof(Items); gcmi->Item = (gc_item*)Items; } else if (gcmi->Type == MENU_ON_NICKLIST) { char *email = mir_t2a(gcmi->pszUID); if (!_stricmp(GetMyUsername(NETID_SKYPE), email)) { static const struct gc_item Items[] = { { LPGENT("User &details"), 10, MENU_ITEM, FALSE }, { LPGENT("User &history"), 20, MENU_ITEM, FALSE }, { _T(""), 100, MENU_SEPARATOR, FALSE }, { LPGENT("&Leave chat session"), 110, MENU_ITEM, FALSE } }; gcmi->nItems = _countof(Items); gcmi->Item = (gc_item*)Items; } else { static struct gc_item Items[] = { { LPGENT("User &details"), 10, MENU_ITEM, FALSE }, { LPGENT("User &history"), 20, MENU_ITEM, FALSE }, { LPGENT("&Kick user") , 30, MENU_ITEM, FALSE }, { LPGENT("&Op user") , 40, MENU_ITEM, FALSE } }; GCThreadData* thread = MSN_GetThreadByChatId(gcmi->pszID); if (thread && thread->mMe && mir_tstrcmpi(thread->mMe->role, _T("admin"))) { Items[2].bDisabled = TRUE; Items[3].bDisabled = TRUE; } else { const TCHAR *pszRole = MSN_GCGetRole(thread, email); if (pszRole && !mir_tstrcmpi(pszRole, _T("admin"))) Items[3].pszDesc = LPGENT("&Deop user"); } gcmi->nItems = _countof(Items); gcmi->Item = (gc_item*)Items; } mir_free(email); } return 0; }
void CMsnProto::MSN_ChatStart(ezxml_t xmli) { if (!mir_strcmp(xmli->txt, "thread")) return; // If Chat ID already exists, don'T create a new one const char *pszID = ezxml_txt(ezxml_child(xmli, "id")); GCThreadData* info = MSN_GetThreadByChatId(_A2T(pszID)); if (info == NULL) { info = new GCThreadData; { mir_cslock lck(m_csThreads); m_arGCThreads.insert(info); } MSN_ChatInit(info, pszID, ezxml_txt(ezxml_get(xmli, "properties", 0, "topic", -1))); MSN_StartStopTyping(info, false); } else { GCDEST gcd = { m_szModuleName, info->mChatID, GC_EVENT_CONTROL }; GCEVENT gce = { sizeof(gce), &gcd }; CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); } const char *pszCreator = ezxml_txt(ezxml_get(xmli, "properties", 0, "creator", -1)); for (ezxml_t memb = ezxml_get(xmli, "members", 0, "member", -1); memb != NULL; memb = ezxml_next(memb)) { const char *mri = ezxml_txt(ezxml_child(memb, "mri")); const char *role = ezxml_txt(ezxml_child(memb, "role")); GCUserItem *gcu = NULL; for (int j = 0; j < info->mJoinedContacts.getCount(); j++) { if (!mir_strcmp(info->mJoinedContacts[j]->WLID, mri)) { gcu = info->mJoinedContacts[j]; break; } } if (!gcu) { gcu = new GCUserItem; info->mJoinedContacts.insert(gcu); strncpy(gcu->WLID, mri, sizeof(gcu->WLID)); } mir_tstrcpy(gcu->role, _A2T(role)); if (pszCreator && !mir_strcmp(mri, pszCreator)) info->mCreator = gcu; char* szEmail, *szNet; parseWLID(NEWSTR_ALLOCA(mri), &szNet, &szEmail, NULL); if (!mir_strcmpi(szEmail, GetMyUsername(atoi(szNet)))) info->mMe = gcu; gcu->btag = 1; } // Remove contacts not on list (not tagged) for (int j = 0; j < info->mJoinedContacts.getCount(); j++) { if (!info->mJoinedContacts[j]->btag) { info->mJoinedContacts.remove(j); j--; } else info->mJoinedContacts[j]->btag = 0; } }
int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam) { GCHOOK *gch = (GCHOOK*)lParam; if (!gch) return 1; if (_stricmp(gch->pDest->pszModule, m_szModuleName)) return 0; switch (gch->pDest->iType) { case GC_SESSION_TERMINATE: { GCThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); if (thread != NULL) { m_arGCThreads.remove(thread); for (int i = 0; i < thread->mJoinedContacts.getCount(); i++) delete thread->mJoinedContacts[i]; delete thread; } } break; case GC_USER_MESSAGE: if (gch->ptszText && gch->ptszText[0]) { GCThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); if (thread) { TCHAR* pszMsg = UnEscapeChatTags(NEWTSTR_ALLOCA(gch->ptszText)); rtrimt(pszMsg); // remove the ending linebreak msnNsThread->sendMessage('N', thread->szEmail, thread->netId, UTF8(pszMsg), 0); DBVARIANT dbv; int bError = getTString("Nick", &dbv); GCDEST gcd = { m_szModuleName, gch->pDest->ptszID, GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; gce.ptszNick = bError ? _T("") : dbv.ptszVal; gce.ptszUID = mir_a2t(MyOptions.szEmail); gce.time = time(NULL); gce.ptszText = gch->ptszText; gce.bIsMe = TRUE; CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); mir_free((void*)gce.ptszUID); if (!bError) db_free(&dbv); } } break; case GC_USER_CHANMGR: DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this))); break; case GC_USER_PRIVMESS: { char *email = mir_t2a(gch->ptszUID); MCONTACT hContact = MSN_HContactFromEmail(email); CallService(MS_MSG_SENDMESSAGE, hContact, 0); mir_free(email); } break; case GC_USER_LOGMENU: switch (gch->dwData) { case 10: DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this))); break; case 20: MSN_KillChatSession(gch->pDest->ptszID); break; } break; case GC_USER_NICKLISTMENU: MCONTACT hContact = MSN_HContactFromEmail(_T2A(gch->ptszUID)); switch (gch->dwData) { case 10: CallService(MS_USERINFO_SHOWDIALOG, hContact, 0); break; case 20: CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact, 0); break; case 30: MSN_Kickuser(gch); break; case 110: MSN_KillChatSession(gch->pDest->ptszID); break; case 40: const TCHAR *pszRole = MSN_GCGetRole(MSN_GetThreadByChatId(gch->pDest->ptszID), _T2A(gch->ptszUID)); MSN_Promoteuser(gch, (pszRole && !mir_tstrcmp(pszRole, _T("admin"))) ? "user" : "admin"); break; } break; } return 0; }
void CMsnProto::MSN_GCProcessThreadActivity(ezxml_t xmli, const TCHAR *mChatID) { if (!mir_strcmp(xmli->name, "topicupdate")) { ezxml_t initiator = ezxml_child(xmli, "initiator"); GCDEST gcd = { m_szModuleName, mChatID, GC_EVENT_TOPIC}; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; gce.time = MsnTSToUnixtime(ezxml_txt(ezxml_child(xmli, "eventtime"))); gce.ptszUID = initiator?mir_a2t(initiator->txt):NULL; MCONTACT hContInitiator = MSN_HContactFromEmail(initiator->txt); gce.ptszNick = GetContactNameT(hContInitiator); gce.ptszText = mir_a2t(ezxml_txt(ezxml_child(xmli, "value"))); CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); mir_free((TCHAR*)gce.ptszUID); mir_free((TCHAR*)gce.ptszText); } else if (ezxml_t target = ezxml_child(xmli, "target")) { MCONTACT hContInitiator = NULL; GCDEST gcd = { m_szModuleName, mChatID, 0}; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; if (!mir_strcmp(xmli->name, "deletemember")) { gcd.iType = GC_EVENT_PART; if (ezxml_t initiator = ezxml_child(xmli, "initiator")) { if (mir_strcmp(initiator->txt, target->txt)) { hContInitiator = MSN_HContactFromEmail(initiator->txt); gce.ptszStatus = GetContactNameT(hContInitiator); gcd.iType = GC_EVENT_KICK; } } } else if (!mir_strcmp(xmli->name, "addmember")) { gcd.iType = GC_EVENT_JOIN; } else if (!mir_strcmp(xmli->name, "roleupdate")) { gcd.iType = GC_EVENT_ADDSTATUS; if (ezxml_t initiator = ezxml_child(xmli, "initiator")) { hContInitiator = MSN_HContactFromEmail(initiator->txt); gce.ptszText= GetContactNameT(hContInitiator); } gce.ptszStatus = _T("admin"); } if (gcd.iType) { gce.time = MsnTSToUnixtime(ezxml_txt(ezxml_child(xmli, "eventtime"))); const char *pszTarget = NULL; while (target) { switch (gcd.iType) { case GC_EVENT_JOIN: gce.ptszStatus = MSN_GCGetRole(MSN_GetThreadByChatId(mChatID), target->txt); // ..fall through.. // case GC_EVENT_KICK: case GC_EVENT_PART: pszTarget = target->txt; break; case GC_EVENT_ADDSTATUS: case GC_EVENT_REMOVESTATUS: gcd.iType = mir_strcmp(ezxml_txt(ezxml_child(target, "role")), "admin") == 0 ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS; pszTarget = ezxml_txt(ezxml_child(target, "id")); break; } char *szEmail, *szNet; parseWLID(NEWSTR_ALLOCA(pszTarget), &szNet, &szEmail, NULL); gce.bIsMe = !mir_strcmpi(szEmail, GetMyUsername(atoi(szNet))); gce.ptszUID = mir_a2t(pszTarget); MCONTACT hContTarget = MSN_HContactFromEmail(pszTarget); gce.ptszNick = GetContactNameT(hContTarget); CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); mir_free((TCHAR*)gce.ptszUID); if ((gcd.iType == GC_EVENT_PART || gcd.iType == GC_EVENT_KICK) && gce.bIsMe) { GCDEST gcd2 = { m_szModuleName, mChatID, GC_EVENT_CONTROL }; GCEVENT gce2 = { sizeof(gce2), &gcd2 }; CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, (LPARAM)&gce2); break; } target = ezxml_next(target); } } } }
int CMsnProto::MSN_GCEventHook(WPARAM, LPARAM lParam) { GCHOOK *gch = (GCHOOK*) lParam; if (!gch) return 1; if (_stricmp(gch->pDest->pszModule, m_szModuleName)) return 0; switch (gch->pDest->iType) { case GC_SESSION_TERMINATE: { ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); if (thread != NULL) thread->sendTerminate(); break; } case GC_USER_MESSAGE: if (gch->ptszText && gch->ptszText[0]) { ThreadData* thread = MSN_GetThreadByChatId(gch->pDest->ptszID); if (thread) { rtrim(gch->ptszText); // remove the ending linebreak TCHAR* pszMsg = UnEscapeChatTags(NEWTSTR_ALLOCA(gch->ptszText)); thread->sendMessage('N', NULL, NETID_MSN, UTF8(pszMsg), 0); DBVARIANT dbv; int bError = getTString("Nick", &dbv); GCDEST gcd = { m_szModuleName, { NULL }, GC_EVENT_MESSAGE }; gcd.ptszID = gch->pDest->ptszID; GCEVENT gce = {0}; gce.cbSize = sizeof(GCEVENT); gce.dwFlags = GC_TCHAR | GCEF_ADDTOLOG; gce.pDest = &gcd; gce.ptszNick = bError ? _T("") : dbv.ptszVal; gce.ptszUID = mir_a2t(MyOptions.szEmail); gce.time = time(NULL); gce.ptszText = gch->ptszText; gce.bIsMe = TRUE; CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); mir_free((void*)gce.ptszUID); if (!bError) MSN_FreeVariant(&dbv); } } break; case GC_USER_CHANMGR: DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this))); break; case GC_USER_PRIVMESS: { char *email = mir_t2a(gch->ptszUID); HANDLE hContact = MSN_HContactFromEmail(email); MSN_CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0); mir_free(email); break; } case GC_USER_LOGMENU: switch(gch->dwData) { case 10: DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, DlgInviteToChat, LPARAM(new InviteChatParam(gch->pDest->ptszID, NULL, this))); break; case 20: MSN_KillChatSession(gch->pDest->ptszID); break; } break; case GC_USER_NICKLISTMENU: { char *email = mir_t2a(gch->ptszUID); HANDLE hContact = MSN_HContactFromEmail(email); mir_free(email); switch(gch->dwData) { case 10: MSN_CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0); break; case 20: MSN_CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)hContact, 0); break; case 110: MSN_KillChatSession(gch->pDest->ptszID); break; } break; } /* haven't implemented in chat.dll case GC_USER_TYPNOTIFY: { int chatID = atoi(p); ThreadData* thread = MSN_GetThreadByContact((HANDLE)-chatID); for (int j=0; j < thread->mJoinedCount; j++) { if ((long)thread->mJoinedContacts[j] > 0) CallService(MS_PROTO_SELFISTYPING, (WPARAM) thread->mJoinedContacts[j], (LPARAM) PROTOTYPE_SELFTYPING_ON); } break; } */ } return 0; }