void CMsnProto::MsnInitMainMenu(void) { CMenuItem mi; mi.root = Menu_GetProtocolRoot(this); #ifdef OBSOLETE mi.pszService = MS_SET_NICKNAME_UI; CreateProtoService(mi.pszService, &CMsnProto::SetNicknameUI); mi.position = 201001; mi.hIcolibItem = GetIconHandle(IDI_MSN); mi.name.a = LPGEN("Set &Nickname"); menuItemsMain[0] = Menu_AddProtoMenuItem(&mi, m_szModuleName); #endif mi.pszService = MSN_INVITE; CreateProtoService(mi.pszService, &CMsnProto::MsnInviteCommand); mi.position = 201002; mi.hIcolibItem = GetIconHandle(IDI_INVITE); mi.name.a = LPGEN("Create &Chat"); menuItemsMain[0] = Menu_AddProtoMenuItem(&mi, m_szModuleName); mi.pszService = MS_GOTO_INBOX; CreateProtoService(mi.pszService, &CMsnProto::MsnGotoInbox); mi.position = 201003; mi.hIcolibItem = GetIconHandle(IDI_INBOX); mi.name.a = LPGEN("Display &Hotmail Inbox"); menuItemsMain[1] = Menu_AddProtoMenuItem(&mi, m_szModuleName); mi.pszService = MS_EDIT_PROFILE; CreateProtoService(mi.pszService, &CMsnProto::MsnEditProfile); mi.position = 201004; mi.hIcolibItem = GetIconHandle(IDI_PROFILE); mi.name.a = LPGEN("View &Profile"); menuItemsMain[2] = Menu_AddProtoMenuItem(&mi, m_szModuleName); mi.pszService = MS_EDIT_ALERTS; CreateProtoService(mi.pszService, &CMsnProto::MsnSetupAlerts); mi.position = 201004; mi.hIcolibItem = GetIconHandle(IDI_PROFILE); mi.name.a = LPGEN("Setup Live &Alerts"); menuItemsMain[3] = Menu_AddProtoMenuItem(&mi, m_szModuleName); MSN_EnableMenuItems(m_iStatus >= ID_STATUS_ONLINE); }
void CMsnProto::MSN_GoOffline(void) { if (m_iStatus == ID_STATUS_OFFLINE) return; msnLoggedIn = false; if (mStatusMsgTS) ForkThread(&CMsnProto::msn_storeProfileThread, NULL); mir_free(msnPreviousUUX); msnPreviousUUX = NULL; msnSearchId = NULL; if (!Miranda_Terminated()) MSN_EnableMenuItems(false); MSN_FreeGroups(); MsgQueue_Clear(); clearCachedMsg(); if (!Miranda_Terminated()) { int msnOldStatus = m_iStatus; m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)msnOldStatus, ID_STATUS_OFFLINE); isIdle = false; int count = -1; for (;;) { MsnContact *msc = Lists_GetNext(count); if (msc == NULL) break; if (ID_STATUS_OFFLINE != getWord(msc->hContact, "Status", ID_STATUS_OFFLINE)) { setWord(msc->hContact, "Status", ID_STATUS_OFFLINE); setDword(msc->hContact, "IdleTS", 0); } } } }
void CMsnProto::MsnInitMainMenu(void) { char servicefunction[100]; strcpy(servicefunction, m_szModuleName); char* tDest = servicefunction + strlen(servicefunction); CLISTMENUITEM mi = {0}; mi.cbSize = sizeof(mi); HGENMENU hRoot = MO_GetProtoRootMenu(m_szModuleName); if (hRoot == NULL) { mi.popupPosition = 500085000; mi.hParentMenu = HGENMENU_ROOT; mi.flags = CMIF_ICONFROMICOLIB | CMIF_ROOTPOPUP | CMIF_TCHAR | CMIF_KEEPUNTRANSLATED; mi.icolibItem = GetIconHandle(IDI_MSN); mi.ptszName = m_tszUserName; hRoot = mainMenuRoot = (HGENMENU)MSN_CallService(MS_CLIST_ADDPROTOMENUITEM, (WPARAM)0, (LPARAM)&mi); } else { MsnRemoveMainMenus(); mainMenuRoot = NULL; } mi.flags = CMIF_ICONFROMICOLIB | CMIF_CHILDPOPUP; mi.hParentMenu = hRoot; mi.pszService = servicefunction; strcpy(tDest, MS_SET_NICKNAME_UI); CreateProtoService(MS_SET_NICKNAME_UI, &CMsnProto::SetNicknameUI); mi.position = 201001; mi.icolibItem = GetIconHandle(IDI_MSN); mi.pszName = LPGEN("Set &Nickname"); menuItemsMain[0] = (HGENMENU)MSN_CallService(MS_CLIST_ADDPROTOMENUITEM, 0, (LPARAM)&mi); strcpy(tDest, MSN_INVITE); CreateProtoService(MSN_INVITE, &CMsnProto::MsnInviteCommand); mi.position = 201002; mi.icolibItem = GetIconHandle(IDI_INVITE); mi.pszName = LPGEN("Create &Chat"); menuItemsMain[0] = (HGENMENU)MSN_CallService(MS_CLIST_ADDPROTOMENUITEM, 0, (LPARAM)&mi); strcpy(tDest, MS_GOTO_INBOX); CreateProtoService(MS_GOTO_INBOX, &CMsnProto::MsnGotoInbox); mi.position = 201003; mi.icolibItem = GetIconHandle(IDI_INBOX); mi.pszName = LPGEN("Display &Hotmail Inbox"); menuItemsMain[1] = (HGENMENU)MSN_CallService(MS_CLIST_ADDPROTOMENUITEM, 0, (LPARAM)&mi); strcpy(tDest, MS_EDIT_PROFILE); CreateProtoService(MS_EDIT_PROFILE, &CMsnProto::MsnEditProfile); mi.position = 201004; mi.icolibItem = GetIconHandle(IDI_PROFILE); mi.pszName = LPGEN("View &Profile"); menuItemsMain[2] = (HGENMENU)MSN_CallService(MS_CLIST_ADDPROTOMENUITEM, 0, (LPARAM)&mi); strcpy(tDest, MS_EDIT_ALERTS); CreateProtoService(MS_EDIT_ALERTS, &CMsnProto::MsnSetupAlerts); mi.position = 201004; mi.icolibItem = GetIconHandle(IDI_PROFILE); mi.pszName = LPGEN("Setup Live &Alerts"); menuItemsMain[3] = (HGENMENU)MSN_CallService(MS_CLIST_ADDPROTOMENUITEM, 0, (LPARAM)&mi); MSN_EnableMenuItems(m_iStatus >= ID_STATUS_ONLINE); }
void __cdecl MSNServerThread( ThreadData* info ) { if ( !sttRedirectorWasChecked ) { sttRedirectorWasChecked = true; MSN_StartThread(( pThreadFunc )msn_RedirectorThread, NULL ); } NETLIBOPENCONNECTION tConn = { 0 }; tConn.cbSize = sizeof( tConn ); tConn.flags = NLOCF_V2; char* tPortDelim = strrchr( info->mServer, ':' ); if ( tPortDelim != NULL ) *tPortDelim = '\0'; if ( MyOptions.UseGateway && !MyOptions.UseProxy ) { tConn.szHost = MSN_DEFAULT_GATEWAY; tConn.wPort = 80; } else { tConn.szHost = info->mServer; tConn.wPort = MSN_DEFAULT_PORT; if ( tPortDelim != NULL ) { int tPortNumber; if ( sscanf( tPortDelim+1, "%d", &tPortNumber ) == 1 ) tConn.wPort = ( WORD )tPortNumber; } } MSN_DebugLog( "Thread started: server='%s', type=%d", tConn.szHost, info->mType ); info->s = ( HANDLE )MSN_CallService( MS_NETLIB_OPENCONNECTION, ( WPARAM )hNetlibUser, ( LPARAM )&tConn ); if ( info->s == NULL ) { MSN_DebugLog( "Connection Failed (%d)", WSAGetLastError() ); switch ( info->mType ) { case SERVER_NOTIFICATION: case SERVER_DISPATCH: MSN_SendBroadcast( NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_NOSERVER ); MSN_GoOffline(); break; } return; } if ( MyOptions.UseGateway ) MSN_CallService( MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM( info->s ), 2 ); MSN_DebugLog( "Connected with handle=%08X", info->s ); if ( info->mType == SERVER_DISPATCH || info->mType == SERVER_NOTIFICATION ) { if ( MyOptions.UseMSNP11 ) info->sendPacket( "VER", "MSNP11 MSNP10 CVR0" ); else info->sendPacket( "VER", "MSNP10 MSNP9 CVR0" ); } else if ( info->mType == SERVER_SWITCHBOARD ) { char tEmail[ MSN_MAX_EMAIL_LEN ]; MSN_GetStaticString( "e-mail", NULL, tEmail, sizeof( tEmail )); info->sendPacket( info->mCaller ? "USR" : "ANS", "%s %s", tEmail, info->mCookie ); } else if ( info->mType == SERVER_FILETRANS && info->mCaller == 0 ) { info->send( "VER MSNFTP\r\n", 12 ); } if ( info->mIsMainThread ) { MSN_EnableMenuItems( TRUE ); msnPingTimeout = msnPingTimeoutCurrent; msnNsThread = info; if (hKeepAliveThreadEvt == NULL) { hKeepAliveThreadEvt = ::CreateEvent( NULL, TRUE, FALSE, NULL ); MSN_StartThread(( pThreadFunc )msn_keepAliveThread, NULL ); } } MSN_DebugLog( "Entering main recv loop" ); info->mBytesInData = 0; while ( TRUE ) { int handlerResult; int recvResult = info->recv( info->mData + info->mBytesInData, sizeof( info->mData ) - info->mBytesInData ); if ( recvResult == SOCKET_ERROR ) { MSN_DebugLog( "Connection %08p [%d] was abortively closed", info->s, GetCurrentThreadId()); break; } if ( !recvResult ) { MSN_DebugLog( "Connection %08p [%d] was gracefully closed", info->s, GetCurrentThreadId()); break; } info->mBytesInData += recvResult; if ( info->mCaller == 1 && info->mType == SERVER_FILETRANS ) { handlerResult = MSN_HandleMSNFTP( info, info->mData ); if ( handlerResult ) break; } else { while( TRUE ) { char* peol = strchr(info->mData,'\r'); if ( peol == NULL ) break; if ( info->mBytesInData < peol-info->mData+2 ) break; //wait for full line end char msg[ sizeof(info->mData) ]; memcpy( msg, info->mData, peol-info->mData ); msg[ peol-info->mData ] = 0; if ( *++peol != '\n' ) MSN_DebugLog( "Dodgy line ending to command: ignoring" ); else peol++; info->mBytesInData -= peol - info->mData; memmove( info->mData, peol, info->mBytesInData ); MSN_DebugLog( "RECV:%s", msg ); if ( !isalnum( msg[0] ) || !isalnum(msg[1]) || !isalnum(msg[2]) || (msg[3] && msg[3]!=' ')) { MSN_DebugLog( "Invalid command name" ); continue; } if ( info->mType != SERVER_FILETRANS ) { if ( isdigit(msg[0]) && isdigit(msg[1]) && isdigit(msg[2])) //all error messages handlerResult = MSN_HandleErrors( info, msg ); else handlerResult = MSN_HandleCommands( info, msg ); } else handlerResult = MSN_HandleMSNFTP( info, msg ); if ( handlerResult ) goto LBL_Exit; } } if ( info->mBytesInData == sizeof( info->mData )) { MSN_DebugLog( "sizeof(data) is too small: the longest line won't fit" ); break; } } LBL_Exit: if ( info->mIsMainThread ) { MSN_GoOffline(); msnNsThread = NULL; if ( hKeepAliveThreadEvt ) SetEvent( hKeepAliveThreadEvt ); } MSN_DebugLog( "Thread [%d] ending now", GetCurrentThreadId() ); }