Пример #1
0
HANDLE CMsnProto::AddToListByEmail(const char *email, const char *nick, DWORD flags)
{
	HANDLE hContact = MSN_HContactFromEmail(email, nick, true, flags & PALF_TEMPORARY);

	if (flags & PALF_TEMPORARY) 
	{
		if (DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) == 1) 
			DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
	}
	else 
	{
		DBDeleteContactSetting(hContact, "CList", "Hidden");
		if (msnLoggedIn) 
		{
//			int netId = Lists_GetNetId(email);
//			if (netId == NETID_UNKNOWN)
			int netId = strncmp(email, "tel:", 4) ? NETID_MSN : NETID_MOB;
			if (MSN_AddUser(hContact, email, netId, LIST_FL))
			{
				MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
				MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
				MSN_AddUser(hContact, email, netId, LIST_AL);
				DBDeleteContactSetting(hContact, "CList", "Hidden");
			}
			MSN_SetContactDb(hContact, email);

			if (MSN_IsMeByContact(hContact)) displayEmailCount(hContact);
		}
		else hContact = NULL;
	}
	return hContact;
}
Пример #2
0
int CMsnProto::OnPrebuildContactMenu(WPARAM hContact, LPARAM)
{
	if (!MSN_IsMyContact(hContact))
		return 0;

	char szEmail[MSN_MAX_EMAIL_LEN];
	bool isMe = MSN_IsMeByContact(hContact, szEmail);
	if (szEmail[0]) {
		int listId = Lists_GetMask(szEmail);
		bool noChat = !(listId & LIST_FL) || isMe || isChatRoom(hContact);

		Menu_ModifyItem(hBlockMenuItem, (listId & LIST_BL) ? LPGENT("&Unblock") : LPGENT("&Block"));
		Menu_ShowItem(hBlockMenuItem, !noChat);

		Menu_ModifyItem(hOpenInboxMenuItem, isMe ? LPGENT("Open &Hotmail Inbox") : LPGENT("Send &Hotmail E-mail"));
		Menu_ShowItem(hOpenInboxMenuItem, emailEnabled);

#ifdef OBSOLETE
		Menu_ShowItem(hNetmeetingMenuItem, !noChat);
#endif
		Menu_ShowItem(hChatInviteMenuItem, !noChat);
	}

	return 0;
}
Пример #3
0
int __cdecl CMsnProto::AuthRequest(HANDLE hContact, const TCHAR* szMessage)
{	
	if (msnLoggedIn) 
	{
		char email[MSN_MAX_EMAIL_LEN];
		if (getStaticString(hContact, "e-mail", email, sizeof(email))) 
			return 1;

		char* szMsg = mir_utf8encodeT(szMessage);

//			int netId = Lists_GetNetId(email);
//			if (netId == NETID_UNKNOWN)
		int netId = strncmp(email, "tel:", 4) == 0 ? NETID_MOB : NETID_MSN;
		if (MSN_AddUser(hContact, email, netId, LIST_FL, szMsg))
		{
			MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_AL);
		}
		MSN_SetContactDb(hContact, email);
		mir_free(szMsg);

		if (MSN_IsMeByContact(hContact)) displayEmailCount(hContact);
		return 0;
	}
	return 1;
}
Пример #4
0
int CMsnProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
{
	const HANDLE hContact = (HANDLE)wParam;
	char szEmail[MSN_MAX_EMAIL_LEN];

	CLISTMENUITEM mi = {0};
	mi.cbSize = sizeof(mi);

	if (!MSN_IsMyContact(hContact)) return 0;

	bool isMe = MSN_IsMeByContact(hContact, szEmail);
	if (szEmail[0]) 
	{
		int listId = Lists_GetMask(szEmail);
		
		bool noChat = !(listId & LIST_FL) || isMe || getByte(hContact, "ChatRoom", 0);

		mi.flags = CMIM_NAME | CMIM_FLAGS | CMIF_ICONFROMICOLIB;
		if (noChat) mi.flags |= CMIF_HIDDEN;
		mi.pszName = (char*)((listId & LIST_BL) ? "&Unblock" : "&Block");
		MSN_CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hBlockMenuItem, (LPARAM)&mi);

		mi.flags = CMIM_NAME | CMIM_FLAGS | CMIF_ICONFROMICOLIB;
		if (!emailEnabled) mi.flags |= CMIF_HIDDEN;
		mi.pszName = isMe ? LPGEN("Open &Hotmail Inbox") : LPGEN("Send &Hotmail E-mail");
		MSN_CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hOpenInboxMenuItem, (LPARAM)&mi);

		mi.flags = CMIM_FLAGS | CMIF_ICONFROMICOLIB | CMIF_NOTOFFLINE;
		if (noChat) mi.flags |= CMIF_HIDDEN;
		MSN_CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hNetmeetingMenuItem, (LPARAM)&mi);
		MSN_CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hChatInviteMenuItem, (LPARAM)&mi);
	}

	return 0;
}
Пример #5
0
INT_PTR CMsnProto::MsnSendNetMeeting(WPARAM wParam, LPARAM)
{
	if (!msnLoggedIn) return 0;

	MCONTACT hContact = MCONTACT(wParam);

	char szEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, szEmail)) return 0;

	ThreadData* thread = MSN_GetThreadByContact(szEmail);

	if (thread == NULL) {
		MessageBox(NULL, TranslateT("You must be talking to start Netmeeting"), TranslateT("MSN Protocol"), MB_OK | MB_ICONERROR);
		return 0;
	}

	char msg[1024];

	mir_snprintf(msg, _countof(msg),
		"Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n"
		"Application-Name: NetMeeting\r\n"
		"Application-GUID: {44BBA842-CC51-11CF-AAFA-00AA00B6015C}\r\n"
		"Session-Protocol: SM1\r\n"
		"Invitation-Command: INVITE\r\n"
		"Invitation-Cookie: %i\r\n"
		"Session-ID: {1A879604-D1B8-11D7-9066-0003FF431510}\r\n\r\n",
		MSN_GenRandom());

	thread->sendMessage('N', NULL, 1, msg, MSG_DISABLE_HDR);
	return 0;
}
Пример #6
0
// MsnAddToList - adds contact to the server list
MCONTACT CMsnProto::AddToListByEmail(const char *email, const char *nick, DWORD flags)
{
	MCONTACT hContact = MSN_HContactFromEmail(email, nick, true, flags & PALF_TEMPORARY);

	if (flags & PALF_TEMPORARY) {
		if (db_get_b(hContact, "CList", "NotOnList", 0) == 1)
			db_set_b(hContact, "CList", "Hidden", 1);
	}
	else {
		db_unset(hContact, "CList", "Hidden");
		if (msnLoggedIn) {
			int netId = strncmp(email, "tel:", 4) ? NETID_MSN : NETID_MOB;
			if (MSN_AddUser(hContact, email, netId, LIST_FL)) {
				MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
				MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
				MSN_AddUser(hContact, email, netId, LIST_AL);
				db_unset(hContact, "CList", "Hidden");
			}
			MSN_SetContactDb(hContact, email);

			if (MSN_IsMeByContact(hContact)) displayEmailCount(hContact);
		}
		else hContact = NULL;
	}
	return hContact;
}
Пример #7
0
int CMsnProto::OnWindowEvent(WPARAM, LPARAM lParam)
{
	MessageWindowEventData* msgEvData = (MessageWindowEventData*)lParam;

	if (msgEvData->uType == MSG_WINDOW_EVT_OPENING) {
		if (m_iStatus == ID_STATUS_OFFLINE || m_iStatus == ID_STATUS_INVISIBLE)
			return 0;

		if (!MSN_IsMyContact(msgEvData->hContact)) return 0;

		char tEmail[MSN_MAX_EMAIL_LEN];
		if (MSN_IsMeByContact(msgEvData->hContact, tEmail)) return 0;

		int netId = Lists_GetNetId(tEmail);
		if (netId != NETID_MSN && netId != NETID_LCS) return 0;

		if (Lists_IsInList(LIST_BL, tEmail)) return 0;

		bool isOffline;
		ThreadData* thread = MSN_StartSB(tEmail, isOffline);

		if (thread == NULL && !isOffline)
			MsgQueue_Add(tEmail, 'X', NULL, 0);
	}
	return 0;
}
Пример #8
0
int CMsnProto::OnContactDoubleClicked(WPARAM hContact, LPARAM)
{
	if (emailEnabled && MSN_IsMeByContact(hContact)) {
		MsnSendHotmail(hContact, 0);
		return 1;
	}
	return 0;
}
Пример #9
0
INT_PTR CMsnProto::MsnSendHotmail(WPARAM hContact, LPARAM)
{
	char szEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, szEmail))
		MsnGotoInbox(0, 0);
	else if (msnLoggedIn)
		MsnInvokeMyURL(true, CMStringA().Format("http://mail.live.com?rru=compose?to=%s", ptrA(mir_urlEncode(szEmail))));

	return 0;
}
Пример #10
0
int CMsnProto::OnContactDoubleClicked(WPARAM wParam, LPARAM)
{
	const HANDLE hContact = (HANDLE)wParam;

	if (emailEnabled && MSN_IsMeByContact(hContact)) 
	{
		MsnSendHotmail(wParam, 0);
		return 1;
	}
	return 0;
}
Пример #11
0
int CMsnProto::OnDbSettingChanged(WPARAM hContact, LPARAM lParam)
{
	DBCONTACTWRITESETTING* cws = (DBCONTACTWRITESETTING*)lParam;

	if (!msnLoggedIn || MyOptions.netId != NETID_MSN)
		return 0;

	if (hContact == NULL) {
		if (MyOptions.SlowSend && strcmp(cws->szSetting, "MessageTimeout") == 0 &&
			(strcmp(cws->szModule, "SRMM") == 0 || strcmp(cws->szModule, "SRMsg") == 0)) {
			if (cws->value.dVal < 60000)
				MessageBox(NULL, TranslateT("MSN requires message send timeout in your Message window plugin to be not less then 60 sec. Please correct the timeout value."),
				TranslateT("MSN Protocol"), MB_OK | MB_ICONINFORMATION);
		}
		return 0;
	}

	if (!strcmp(cws->szSetting, "ApparentMode")) {
		char tEmail[MSN_MAX_EMAIL_LEN];
		if (!db_get_static(hContact, m_szModuleName, "wlid", tEmail, sizeof(tEmail)) ||
			!db_get_static(hContact, m_szModuleName, "e-mail", tEmail, sizeof(tEmail))) {
			bool isBlocked = Lists_IsInList(LIST_BL, tEmail);

			if (isBlocked && (cws->value.type == DBVT_DELETED || cws->value.wVal == 0)) {
				MSN_AddUser(hContact, tEmail, 0, LIST_BL + LIST_REMOVE);
				MSN_AddUser(hContact, tEmail, 0, LIST_AL);
			}
			else if (!isBlocked && cws->value.wVal == ID_STATUS_OFFLINE) {
				MSN_AddUser(hContact, tEmail, 0, LIST_AL + LIST_REMOVE);
				MSN_AddUser(hContact, tEmail, 0, LIST_BL);
			}
		}
	}

	if (!strcmp(cws->szSetting, "MyHandle") && !strcmp(cws->szModule, "CList")) {
		bool isMe = MSN_IsMeByContact(hContact);
		if (!isMe || !nickChg) {
			char szContactID[100];
			if (!db_get_static(hContact, m_szModuleName, "ID", szContactID, sizeof(szContactID))) {
				if (cws->value.type != DBVT_DELETED) {
					if (cws->value.type == DBVT_UTF8)
						MSN_ABUpdateNick(cws->value.pszVal, szContactID);
					else
						MSN_ABUpdateNick(UTF8(cws->value.pszVal), szContactID);
				}
				else MSN_ABUpdateNick(NULL, szContactID);
			}

			if (isMe)
				displayEmailCount(hContact);
		}
	}
	return 0;
}
Пример #12
0
INT_PTR CMsnProto::SendNudge(WPARAM hContact, LPARAM)
{
	if (!msnLoggedIn) return 0;

	char tEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, tEmail)) return 0;

	int netId = Lists_GetNetId(tEmail);

#ifdef OBSOLETE
	static const char nudgemsg[] =
		"Content-Type: text/x-msnmsgr-datacast\r\n\r\n"
		"ID: 1\r\n\r\n";

	switch (netId) {
	case NETID_UNKNOWN:
		hContact = MSN_GetChatInernalHandle(hContact);

	case NETID_MSN:
	case NETID_LCS:
	{
		bool isOffline;
		ThreadData* thread = MSN_StartSB(tEmail, isOffline);
		if (thread == NULL) {
			if (isOffline) return 0;
			MsgQueue_Add(tEmail, 'N', nudgemsg, -1);
		}
		else {
			int tNnetId = netId == NETID_UNKNOWN ? NETID_MSN : netId;
			thread->sendMessage('N', tEmail, tNnetId, nudgemsg, MSG_DISABLE_HDR);
		}
	}
	break;

	case NETID_YAHOO:
		msnNsThread->sendMessage('3', tEmail, netId, nudgemsg, MSG_DISABLE_HDR);
		break;

	default:
		break;
	}
#else
	msnNsThread->sendMessage('3', tEmail, netId, "", MSG_NUDGE);
#endif
	return 0;
}
Пример #13
0
INT_PTR CMsnProto::MsnSendHotmail(WPARAM wParam, LPARAM)
{
	const HANDLE hContact = (HANDLE)wParam;
	char szEmail[MSN_MAX_EMAIL_LEN];

	if (MSN_IsMeByContact(hContact, szEmail))
		MsnGotoInbox(0, 0);
	else if (msnLoggedIn)
	{
		char szEmailEnc[MSN_MAX_EMAIL_LEN*3], szUrl[256];

		UrlEncode(szEmail, szEmailEnc, sizeof(szEmailEnc));
		mir_snprintf(szUrl, sizeof(szUrl), "http://mail.live.com?rru=compose?to=%s", szEmailEnc);
		MsnInvokeMyURL(true, szUrl);
	}

	return 0;
}
Пример #14
0
// PSS_AUTHREQUEST
int __cdecl CMsnProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage)
{
	if (msnLoggedIn) {
		char email[MSN_MAX_EMAIL_LEN];
		if (db_get_static(hContact, m_szModuleName, "wlid", email, sizeof(email)) &&
			db_get_static(hContact, m_szModuleName, "e-mail", email, sizeof(email)))
			return 1;

		int netId = strncmp(email, "tel:", 4) == 0 ? NETID_MOB : (strncmp(email, "live:", 5) == 0 ? NETID_SKYPE : NETID_MSN);
		if (MSN_AddUser(hContact, email, netId, LIST_FL, T2Utf(szMessage))) {
			MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
			MSN_AddUser(hContact, email, netId, LIST_AL);
		}
		MSN_SetContactDb(hContact, email);

		if (MSN_IsMeByContact(hContact)) displayEmailCount(hContact);
		return 0;
	}
	return 1;
}
Пример #15
0
// MsnUserIsTyping - notify another contact that we're typing a message
int __cdecl CMsnProto::UserIsTyping(MCONTACT hContact, int type)
{
	if (!msnLoggedIn) return 0;

	char tEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, tEmail)) return 0;

	bool typing = type == PROTOTYPE_SELFTYPING_ON;

	int netId = Lists_GetNetId(tEmail);
#ifdef OBSOLETE
	switch (netId) {
	case NETID_UNKNOWN:
	case NETID_MSN:
	case NETID_LCS:
		bool isOffline;
		{
			ThreadData* thread = MSN_StartSB(tEmail, isOffline);
			if (thread == NULL) {
				if (isOffline)
					return 0;
				MsgQueue_Add(tEmail, 2571, NULL, 0, NULL, typing);
			}
			else MSN_StartStopTyping(thread, typing);
		}
		break;

	case NETID_YAHOO:
		if (typing) MSN_SendTyping(msnNsThread, tEmail, netId);
		break;

	default:
		break;
	}
#endif
	if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
		MSN_SendTyping(msnNsThread, tEmail, netId, typing);

	return 0;
}
Пример #16
0
// MsnSendContacts - sends contacts to a certain user
int __cdecl CMsnProto::SendContacts(MCONTACT hContact, int, int nContacts, MCONTACT *hContactsList)
{
	if (!msnLoggedIn)
		return 0;

	char tEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, tEmail)) return 0;

	int seq = 0;
	int netId = Lists_GetNetId(tEmail);
	CMStringA msg;

	msg.Append("<contacts alt=\"[Contacts enclosed. Please upgrade to latest Skype version to receive contacts.]\">");
	for (int i = 0; i < nContacts; i++) {
		ptrA wlid(getStringA(hContactsList[i], "wlid"));
		if (wlid != NULL) msg.AppendFormat("<c t=\"s\" s=\"%s\"/>", wlid);
	}
	msg.Append("</contacts>");
	seq = msnNsThread->sendMessage('1', tEmail, netId, msg, MSG_CONTACT);
	ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this, ACKTYPE_CONTACTS));
	return seq;
}
Пример #17
0
int __cdecl CMsnProto::UserIsTyping(HANDLE hContact, int type)
{
	if (!msnLoggedIn) return 0;

	char tEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, tEmail)) return 0;

	bool typing = type == PROTOTYPE_SELFTYPING_ON;

	int netId = Lists_GetNetId(tEmail);
	switch (netId)
	{
	case NETID_UNKNOWN:
	case NETID_MSN:
	case NETID_LCS:
		{
			bool isOffline;
			ThreadData* thread = MSN_StartSB(tEmail, isOffline);

			if (thread == NULL) 
			{
				if (isOffline) return 0;
				MsgQueue_Add(tEmail, 2571, NULL, 0, NULL, typing);
			}
			else
				MSN_StartStopTyping(thread, typing);
		}
		break;

	case NETID_YAHOO:
		if (typing) MSN_SendTyping(msnNsThread, tEmail, netId);
		break;

	default:
		break;
	}

	return 0;
}
Пример #18
0
int CMsnProto::OnContactDeleted(WPARAM hContact, LPARAM)
{
	if (!msnLoggedIn)  //should never happen for MSN contacts
		return 0;

	if (isChatRoom(hContact)) {
		DBVARIANT dbv;
		if (!getTString(hContact, "ChatRoomID", &dbv)) {
			MSN_KillChatSession(dbv.ptszVal);
			db_free(&dbv);
		}
	}
	else {
		char szEmail[MSN_MAX_EMAIL_LEN];
		if (MSN_IsMeByContact(hContact, szEmail))
			pcli->pfnRemoveEvent(hContact, 1);

		if (szEmail[0]) {
			debugLogA("Deleted Handler Email");

			if (Lists_IsInList(LIST_FL, szEmail)) {
				DeleteParam param = { this, hContact };
				DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_DELETECONTACT), NULL, DlgDeleteContactUI, (LPARAM)&param);

				MsnContact *msc = Lists_Get(szEmail);
				if (msc)
					msc->hContact = NULL;
			}

			if (Lists_IsInList(LIST_LL, szEmail))
				MSN_AddUser(hContact, szEmail, 0, LIST_LL | LIST_REMOVE);
		}
	}

	return 0;
}
Пример #19
0
// MsnSendMessage - sends the message to a server
int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc)
{
	const char *errMsg = NULL;

	if (!msnLoggedIn) {
		errMsg = Translate("Protocol is offline");
		ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this));
		return 999999;
	}

	char tEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, tEmail)) {
		errMsg = Translate("You cannot send message to yourself");
		ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this));
		return 999999;
	}

	char *msg = (char*)pszSrc;
	if (msg == NULL)
		return 0;

	int rtlFlag = (flags & PREF_RTL) ? MSG_RTL : 0;

	int seq = 0;
	int netId = Lists_GetNetId(tEmail);

	switch (netId) {
	case NETID_MOB:
		if (mir_strlen(msg) > 133) {
			errMsg = Translate("Message is too long: SMS page limited to 133 UTF8 chars");
			seq = 999997;
		}
		else {
			errMsg = NULL;
			seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag);
		}
		ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
		break;

	case NETID_YAHOO:
		if (mir_strlen(msg) > 1202) {
			seq = 999996;
			errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars");
			ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
		}
		else {
			seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag);
			ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
		}
		break;

	default:
		if (mir_strlen(msg) > 1202) {
			seq = 999996;
			errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars");
			ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
		}
		else {
#ifdef OBSOLETE
			const char msgType = MyOptions.SlowSend ? 'A' : 'N';
			bool isOffline;
			ThreadData *thread = MSN_StartSB(tEmail, isOffline);
#else
			/* MSNP24 doesn't have a switchboard anymore */
			bool isOffline = true;
			ThreadData *thread = NULL;
#endif

			if (thread == NULL) {
				if (isOffline) {
					if (netId != NETID_LCS) {
						seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag | MSG_OFFLINE);
						ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
					}
					else {
						seq = 999993;
						errMsg = Translate("Offline messaging is not allowed for LCS contacts");
						ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
					}
				}
#ifdef OBSOLETE
				else
					seq = MsgQueue_Add(tEmail, msgType, msg, 0, 0, rtlFlag);
			}
			else {
				seq = thread->sendMessage(msgType, tEmail, netId, msg, rtlFlag);
				if (!MyOptions.SlowSend)
					ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
#endif
			}
		}
		break;
	}

	return seq;
}
Пример #20
0
int __cdecl CMsnProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc)
{
	const char *errMsg = NULL;

	if (!msnLoggedIn)
	{
		errMsg = MSN_Translate("Protocol is offline");
		ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this));
		return 999999;
	}

	char tEmail[MSN_MAX_EMAIL_LEN];
	if (MSN_IsMeByContact(hContact, tEmail)) 
	{
		errMsg = MSN_Translate("You cannot send message to yourself");
		ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this));
		return 999999;
	}

	char *msg = (char*)pszSrc;
	if (msg == NULL) return 0;

	if (flags & PREF_UNICODE)
	{
		char* p = strchr(msg, '\0');
		if (p != msg)
		{
			while (*(++p) == '\0') {}
			msg = mir_utf8encodeW((wchar_t*)p);
		}
		else
			msg = mir_strdup(msg);
	}
	else
		msg = (flags & PREF_UTF) ? mir_strdup(msg) : mir_utf8encode(msg);

	int rtlFlag = (flags & PREF_RTL) ? MSG_RTL : 0;

	int seq = 0;
	int netId  = Lists_GetNetId(tEmail);

	switch (netId)
	{
	case NETID_MOB:
		if (strlen(msg) > 133)
		{
			errMsg = MSN_Translate("Message is too long: SMS page limited to 133 UTF8 chars");
			seq = 999997;
		}
		else
		{
			errMsg = NULL;
			seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag);
		}
		ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
		break;

	case NETID_YAHOO:
		if (strlen(msg) > 1202) 
		{
			seq = 999996;
			errMsg = MSN_Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars");
			ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
		}
		else
		{
			seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag);
			ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
		}
		break;

	default:
		if (strlen(msg) > 1202) 
		{
			seq = 999996;
			errMsg = MSN_Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars");
			ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
		}
		else
		{
			const char msgType = MyOptions.SlowSend ? 'A' : 'N';
			bool isOffline;
			ThreadData* thread = MSN_StartSB(tEmail, isOffline);
			if (thread == NULL)
			{
				if (isOffline) 
				{
					if (netId != NETID_LCS)
					{
						seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag | MSG_OFFLINE);
						ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
					}
					else
					{
						seq = 999993;
						errMsg = MSN_Translate("Offline messaging is not allowed for LCS contacts");
						ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
					}
				}
				else
					seq = MsgQueue_Add(tEmail, msgType, msg, 0, 0, rtlFlag);
			}
			else
			{
				seq = thread->sendMessage(msgType, tEmail, netId, msg, rtlFlag);
				if (!MyOptions.SlowSend)
					ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
			}
		}
		break;
	}

	mir_free(msg);
	return seq;
}