| | 366 | unsigned long CICQDaemon::icqSendContactList(const char *szId, |
| | 367 | UserStringList &users, bool online, unsigned short nLevel, |
| | 368 | bool bMultipleRecipients, CICQColor *pColor) |
| | 369 | { |
| | 370 | if (gUserManager.FindOwner(szId, LICQ_PPID) != NULL) return 0; |
| | 371 | |
| | 372 | char *m = new char[3 + users.size() * 80]; |
| | 373 | int p = sprintf(m, "%d%c", users.size(), char(0xFE)); |
| | 374 | ContactList vc; |
| | 375 | |
| | 376 | ICQUser *u = NULL; |
| | 377 | UserStringList::iterator iter; |
| | 378 | for (iter = users.begin(); iter != users.end(); iter++) |
| | 379 | { |
| | 380 | u = gUserManager.FetchUser(*iter, LICQ_PPID, LOCK_R); |
| | 381 | p += sprintf(&m[p], "%s%c%s%c", *iter, char(0xFE), |
| | 382 | u == NULL ? "" : u->GetAlias(), char(0xFE)); |
| | 383 | vc.push_back(new CContact(*iter, LICQ_PPID, u == NULL ? "" : u->GetAlias())); |
| | 384 | gUserManager.DropUser(u); |
| | 385 | } |
| | 386 | |
| | 387 | if (!online && p > MAX_MESSAGE_SIZE) |
| | 388 | { |
| | 389 | gLog.Warn("%sContact list too large to send through server.\n", L_WARNxSTR); |
| | 390 | delete []m; |
| | 391 | return 0; |
| | 392 | } |
| | 393 | |
| | 394 | CEventContactList *e = NULL; |
| | 395 | ICQEvent *result = NULL; |
| | 396 | |
| | 397 | unsigned long f = INT_VERSION; |
| | 398 | if (online) f |= E_DIRECT; |
| | 399 | if (nLevel == ICQ_TCPxMSG_URGENT) f |= E_URGENT; |
| | 400 | if (bMultipleRecipients) f |= E_MULTIxREC; |
| | 401 | |
| | 402 | if (!online) // send offline |
| | 403 | { |
| | 404 | e = new CEventContactList(vc, false, ICQ_CMDxSND_THRUxSERVER, TIME_NOW, f); |
| | 405 | result = icqSendThroughServer(szId, |
| | 406 | ICQ_CMDxSUB_CONTACTxLIST | (bMultipleRecipients ? ICQ_CMDxSUB_FxMULTIREC : 0), |
| | 407 | m, e); |
| | 408 | u = gUserManager.FetchUser(szId, LICQ_PPID, LOCK_W); |
| | 409 | } |
| | 410 | else |
| | 411 | { |
| | 412 | u = gUserManager.FetchUser(szId, LICQ_PPID, LOCK_W); |
| | 413 | if (u == NULL) return 0; |
| | 414 | if (u->Secure()) f |= E_ENCRYPTED; |
| | 415 | e = new CEventContactList(vc, false, ICQ_CMDxTCP_START, TIME_NOW, f); |
| | 416 | if (pColor != NULL) e->SetColor(pColor); |
| | 417 | CPT_ContactList *p = new CPT_ContactList(m, nLevel, bMultipleRecipients, pColor, u); |
| | 418 | gLog.Info("%sSending %scontact list to %s (#%ld).\n", L_TCPxSTR, |
| | 419 | nLevel == ICQ_TCPxMSG_URGENT ? "urgent " : "", |
| | 420 | u->GetAlias(), -p->Sequence()); |
| | 421 | result = SendExpectEvent_Client(u, p, e); |
| | 422 | } |
| | 423 | if (u != NULL) |
| | 424 | { |
| | 425 | u->SetSendServer(!online); |
| | 426 | u->SetSendLevel(nLevel); |
| | 427 | gUserManager.DropUser(u); |
| | 428 | } |
| | 429 | |
| | 430 | if (pColor != NULL) CICQColor::SetDefaultColors(pColor); |
| | 431 | |
| | 432 | delete []m; |
| | 433 | if (result != NULL) |
| | 434 | return result->EventId(); |
| | 435 | return 0; |
| | 436 | } |
| | 437 | |