BOOL ContactEnabled(HANDLE hContact, char *setting, int def) { if (hContact == NULL) return FALSE; char *proto = (char *) CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM) hContact, 0); if (!ProtocolEnabled(proto)) return FALSE; BYTE globpref = db_byte_get(NULL, MODULE_NAME, setting, def); BYTE userpref = db_byte_get(hContact, MODULE_NAME, setting, BST_INDETERMINATE); return (globpref && userpref == BST_INDETERMINATE) || userpref == BST_CHECKED; }
void TwitterProto::MessageLoop(void*) { LOG("***** Entering Twitter::MessageLoop"); since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_SINCEID,0); dm_since_id_ = db_pod_get<twitter_id>(0,m_szModuleName,TWITTER_KEY_DMSINCEID,0); bool new_account = db_byte_get(0,m_szModuleName,TWITTER_KEY_NEW,1) != 0; bool popups = db_byte_get(0,m_szModuleName,TWITTER_KEY_POPUP_SIGNON,1) != 0; int poll_rate = db_dword_get(0,m_szModuleName,TWITTER_KEY_POLLRATE,80); for(unsigned int i=0;;i++) { if(m_iStatus != ID_STATUS_ONLINE) goto exit; if(i%4 == 0) UpdateFriends(); if(m_iStatus != ID_STATUS_ONLINE) goto exit; UpdateStatuses(new_account,popups); if(m_iStatus != ID_STATUS_ONLINE) goto exit; UpdateMessages(new_account); if(new_account) // Not anymore! { new_account = false; DBWriteContactSettingByte(0,m_szModuleName,TWITTER_KEY_NEW,0); } if(m_iStatus != ID_STATUS_ONLINE) goto exit; LOG("***** TwitterProto::MessageLoop going to sleep..."); if(SleepEx(poll_rate*1000,true) == WAIT_IO_COMPLETION) goto exit; LOG("***** TwitterProto::MessageLoop waking up..."); popups = true; } exit: { ScopedLock s(twitter_lock_); twit_.set_credentials("","",false); } LOG("***** Exiting TwitterProto::MessageLoop"); }
void TwitterProto::SignOn(void*) { LOG("***** Beginning SignOn process"); WaitForSingleObject(&signon_lock_,INFINITE); // Kill the old thread if it's still around if(hMsgLoop_) { LOG("***** Requesting MessageLoop to exit"); QueueUserAPC(APC_callback,hMsgLoop_,(ULONG_PTR)this); LOG("***** Waiting for old MessageLoop to exit"); WaitForSingleObject(hMsgLoop_,INFINITE); CloseHandle(hMsgLoop_); } if(NegotiateConnection()) // Could this be? The legendary Go Time?? { if(!in_chat_ && db_byte_get(0,m_szModuleName,TWITTER_KEY_CHATFEED,0)) OnJoinChat(0,true); SetAllContactStatuses(ID_STATUS_ONLINE); hMsgLoop_ = ForkThreadEx(&TwitterProto::MessageLoop,this); } ReleaseMutex(signon_lock_); LOG("***** SignOn complete"); }
void userlist_connected(vqp_link_t vqpLink) { DWORD timeout = 1000 * db_byte_get(NULL, VQCHAT_PROTO, "UserlistTimeout", VQCHAT_DEF_REFRESH_TIMEOUT); s_vqpLink = vqpLink; userlist_flush(); /* start userlist refresh timers */ ASSERT_RETURNIFFAIL(!s_userlistTimer); s_userlistTimer = SetTimer(NULL, 0, timeout, userlist_remove_unreplied_cb); }
void userlist_name_change(const char * user_name, const char * new_user_name) { struct userlist_entry * entry; ASSERT_RETURNIFFAIL(VALIDPTR(user_name) && VALIDPTR(new_user_name)); ASSERT_RETURNIFFAIL(VALIDPTR(s_userlistHash)); ASSERT_RETURNIFFAIL(strcmp(user_name, new_user_name)); /* bail out if we have the new user name in the userlist already */ if(userlist_entry_by_name(new_user_name) ) return; entry = userlist_entry_by_name(user_name); if(entry) { HANDLE hContact; /* remove entry from hash table and reinsert with different nickname */ hashtable_remove(s_userlistHash, (void*)user_name, 0); hashtable_insert(s_userlistHash, strdup(new_user_name), entry); entry->alive = 1; /* update contact nickname and status */ hContact = contacts_find_contact(user_name); if(hContact) { if(db_byte_get(hContact, VQCHAT_PROTO, "LockNick", 0)) { contacts_set_contact_status(hContact, ID_STATUS_OFFLINE); } else { HANDLE hAnotherContact = contacts_find_contact(new_user_name); if(hAnotherContact) { /* there is another contact with destination name: * set hContact to offline, and get hAnotherContact alive */ contacts_set_contact_status(hContact, ID_STATUS_OFFLINE); contacts_set_contact_status( hAnotherContact, user_status_by_vqp_status(entry->vqp_status) ); contacts_set_contact_addr(hContact, entry->addr); } else { /* change nickname for the contact */ contacts_set_contact_nickname(hContact, new_user_name); } } } else { /* the specified contact does not exist, * try to find the contact with `new_user_name' nickname */ hContact = contacts_find_contact(new_user_name); if(hContact) { contacts_set_contact_status( hContact, user_status_by_vqp_status(entry->vqp_status) ); contacts_set_contact_addr(hContact, entry->addr); } } /* update chatrooms */ chatroom_channel_user_name_change(user_name, new_user_name, 1); } }