void MessageManager::saveUsers() { SimpleXML xml; xml.addTag("Ignored"); xml.stepIn(); xml.addTag("Users"); xml.stepIn(); //TODO: cache this information? { RLock l(Ignorecs); for (const auto& u : ignoredUsers) { xml.addTag("User"); xml.addChildAttrib("CID", u->getCID().toBase32()); auto ou = ClientManager::getInstance()->findOnlineUser(u->getCID(), ""); if (ou) { xml.addChildAttrib("Nick", ou->getIdentity().getNick()); xml.addChildAttrib("Hub", ou->getHubUrl()); xml.addChildAttrib("LastSeen", GET_TIME()); } else { auto ofu = ClientManager::getInstance()->getOfflineUser(u->getCID()); xml.addChildAttrib("Nick", ofu ? ofu->getNick() : ""); xml.addChildAttrib("Hub", ofu ? ofu->getUrl() : ""); xml.addChildAttrib("LastSeen", ofu ? ofu->getLastSeen() : GET_TIME()); } } } xml.stepOut(); xml.stepOut(); SettingsManager::saveSettingFile(xml, CONFIG_DIR, CONFIG_NAME); }
void CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD) { for (auto &hContact : Contacts()) { char *proto = GetContactProto(hContact); if (proto && (db_get_b(hContact, proto, "ChatRoom", 0) == 0) && (CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) && isContactGoneFor(hContact, options.iAbsencePeriod2) && (db_get_b(hContact, MODULENAME, "StillAbsentNotified", 0) == 0)) { db_set_b(hContact, MODULENAME, "StillAbsentNotified", 1); Skin_PlaySound("buddyExpectatorStillAbsent"); wchar_t* message = TranslateT("has not returned after a long absence."); time_t tmpTime; wchar_t tmpBuf[251] = { 0 }; tmpTime = getLastSeen(hContact); if (tmpTime != -1) { wcsftime(tmpBuf, 250, TranslateT("has not returned after being absent since %#x"), gmtime(&tmpTime)); message = tmpBuf; } else { tmpTime = getLastInputMsg(hContact); if (tmpTime != -1) { wcsftime(tmpBuf, 250, TranslateT("has not returned after being absent since %#x"), gmtime(&tmpTime)); message = tmpBuf; } } GoneNotify(hContact, message); } } }
/** * Checks - whether user has been gone for specified number of days */ bool isContactGoneFor(MCONTACT hContact, int days) { time_t lastSeen = getLastSeen(hContact); time_t lastInputMsg = getLastInputMsg(hContact); time_t currentTime = time(0); int daysSinceOnline = -1; if (lastSeen != -1) daysSinceOnline = (int)((currentTime - lastSeen) / (60 * 60 * 24)); int daysSinceMessage = -1; if (lastInputMsg != -1) daysSinceMessage = (int)((currentTime - lastInputMsg) / (60 * 60 * 24)); if (options.hideInactive) if (daysSinceMessage >= options.iSilencePeriod) if (!db_get_b(hContact, "CList", "Hidden", 0) && !db_get_b(hContact, MODULENAME, "NeverHide", 0)) { POPUPDATAT_V2 ppd = { 0 }; ppd.cbSize = sizeof(ppd); ppd.lchContact = hContact; ppd.lchIcon = IcoLib_GetIcon("enabled_icon"); mir_snwprintf(ppd.lptzContactName, TranslateT("Hiding %s (%S)"), Clist_GetContactDisplayName(hContact), GetContactProto(hContact)); mir_snwprintf(ppd.lptzText, TranslateT("%d days since last message"), daysSinceMessage); if (!options.iUsePopupColors) { ppd.colorBack = options.iPopupColorBack; ppd.colorText = options.iPopupColorFore; } ppd.PluginWindowProc = HidePopupDlgProc; ppd.iSeconds = -1; hideactions[0].flags = hideactions[1].flags = PAF_ENABLED; ppd.lpActions = hideactions; ppd.actionCount = 2; CallService(MS_POPUP_ADDPOPUPT, (WPARAM)&ppd, APF_NEWDATA); Skin_PlaySound("buddyExpectatorHide"); } return (daysSinceOnline >= days && (daysSinceMessage == -1 || daysSinceMessage >= days)); }
MoveInfo getLastSeenMove() { if (auto lastSeen = getLastSeen()) { double lastSeenTimeout = 20; if (!lastSeen->pos.isSameLevel(creature->getPosition()) || lastSeen->time < creature->getGlobalTime() - lastSeenTimeout || lastSeen->pos == creature->getPosition()) { lastSeen = none; return NoMove; } if (chase && lastSeen->type == LastSeen::ATTACK) if (auto action = creature->moveTowards(lastSeen->pos)) { return {0.5, action.append([=](Creature* creature) { creature->setInCombat(); })}; } if (lastSeen->type == LastSeen::PANIC && lastSeen->pos.dist8(creature->getPosition()) < 4) if (auto action = creature->moveAway(lastSeen->pos, chase)) return {0.5, action.append([=](Creature* creature) { creature->setInCombat(); })}; } return NoMove; }
/** * ContactSettingChanged callback */ int SettingChanged(WPARAM hContact, LPARAM lParam) { DBCONTACTWRITESETTING *inf = (DBCONTACTWRITESETTING*)lParam; if (hContact == NULL || inf->value.type == DBVT_DELETED || strcmp(inf->szSetting, "Status") != 0) return 0; if (db_get_b(hContact, "CList", "NotOnList", 0) == 1) return 0; char *proto = GetContactProto(hContact); if (proto == nullptr || (db_get_b(hContact, proto, "ChatRoom", 0) == 1) || !(CallProtoService(proto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND)) return 0; int currentStatus = inf->value.wVal; int prevStatus = db_get_w(hContact, "UserOnline", "OldStatus", ID_STATUS_OFFLINE); if (currentStatus == prevStatus) return 0; // Last status db_set_dw(hContact, MODULENAME, "LastStatus", prevStatus); if (prevStatus == ID_STATUS_OFFLINE) { if (db_get_b(hContact, MODULENAME, "MissYou", 0)) { // Display Popup POPUPDATAT_V2 ppd = { 0 }; ppd.cbSize = sizeof(ppd); ppd.lchContact = hContact; ppd.lchIcon = IcoLib_GetIcon("enabled_icon"); wcsncpy(ppd.lptzContactName, Clist_GetContactDisplayName(hContact), MAX_CONTACTNAME); wcsncpy(ppd.lptzText, TranslateT("You awaited this contact!"), MAX_SECONDLINE); if (!options.iUsePopupColors) { ppd.colorBack = options.iPopupColorBack; ppd.colorText = options.iPopupColorFore; } ppd.PluginWindowProc = MissYouPopupDlgProc; ppd.PluginData = nullptr; ppd.iSeconds = -1; missyouactions[0].flags = PAF_ENABLED; ppd.lpActions = missyouactions; ppd.actionCount = 1; CallService(MS_POPUP_ADDPOPUPT, (WPARAM)&ppd, APF_NEWDATA); Skin_PlaySound("buddyExpectatorMissYou"); } } if (currentStatus == ID_STATUS_OFFLINE) { setLastSeen(hContact); return 0; } if (db_get_dw(hContact, MODULENAME, "LastSeen", (DWORD)-1) == (DWORD)-1 && options.notifyFirstOnline) { ReturnNotify(hContact, TranslateT("has gone online for the first time.")); setLastSeen(hContact); } unsigned int AbsencePeriod = db_get_dw(hContact, MODULENAME, "iAbsencePeriod", options.iAbsencePeriod); if (isContactGoneFor(hContact, AbsencePeriod)) { wchar_t* message = TranslateT("has returned after a long absence."); wchar_t tmpBuf[251] = { 0 }; time_t tmpTime = getLastSeen(hContact); if (tmpTime != -1) { wcsftime(tmpBuf, 250, TranslateT("has returned after being absent since %#x"), gmtime(&tmpTime)); message = tmpBuf; } else { tmpTime = getLastInputMsg(hContact); if (tmpTime != -1) { wcsftime(tmpBuf, 250, TranslateT("has returned after being absent since %#x"), gmtime(&tmpTime)); message = tmpBuf; } } ReturnNotify(hContact, message); if ((options.iShowMessageWindow == 0 && options.iShowUDetails == 0) || (options.iShowEvent == 0 && options.iShowPopup == 0)) setLastSeen(hContact); } else setLastSeen(hContact); return 0; }