MCPcopy Create free account
hub / github.com/amule-project/amule / SendChatMessage

Method SendChatMessage

src/BaseClient.cpp:2463–2505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2461
2462
2463bool CUpDownClient::SendChatMessage(const wxString& message)
2464{
2465 if (GetChatCaptchaState() == CA_CAPTCHARECV) {
2466 m_nChatCaptchaState = CA_SOLUTIONSENT;
2467 } else if (GetChatCaptchaState() == CA_SOLUTIONSENT) {
2468 wxFAIL; // we responded to a captcha but didn't hear from the client afterwards - hopefully it's just lag and this message will get through
2469 } else {
2470 m_nChatCaptchaState = CA_ACCEPTING;
2471 }
2472
2473 SetSpammer(false);
2474 IncMessagesSent();
2475 // Already connecting?
2476 if (GetChatState() == MS_CONNECTING) {
2477 // Queue all messages till we're able to send them (or discard them)
2478 if (!m_pendingMessage.IsEmpty()) {
2479 m_pendingMessage += "\n";
2480 } else {
2481 // There must be a message to send
2482 // - except if we got disconnected. No need to assert therefore.
2483 }
2484 m_pendingMessage += message;
2485 return false;
2486 }
2487 if (IsConnected()) {
2488 // If we are already connected when we send the first message,
2489 // we have to update the chat status.
2490 SetChatState(MS_CHATTING);
2491 CMemFile data;
2492 data.WriteString(message, GetUnicodeSupport());
2493 CPacket* packet = new CPacket(data, OP_EDONKEYPROT, OP_MESSAGE);
2494 theStats::AddUpOverheadOther(packet->GetPacketSize());
2495 AddDebugLogLineN( logLocalClient, "Local Client: OP_MESSAGE to " + GetFullIP());
2496 SendPacket(packet, true, true);
2497 return true;
2498 } else {
2499 m_pendingMessage = message;
2500 SetChatState(MS_CONNECTING);
2501 // True to ignore "Too Many Connections"
2502 TryToConnect(true);
2503 return false;
2504 }
2505}
2506
2507/* Kad stuff */
2508

Callers

nothing calls this directly

Calls 3

WriteStringMethod · 0.80
GetPacketSizeMethod · 0.80
IsEmptyMethod · 0.45

Tested by

no test coverage detected