void ChannelAgent::MessageReceived(BMessage* msg) { int32 i(0); switch (msg->what) { case M_USER_QUIT: { const char* nick(NULL); msg->FindString("nick", &nick); if (RemoveUser(nick)) { BMessage display; if (msg->FindMessage("display", &display) == B_NO_ERROR) ClientAgent::MessageReceived(&display); } } break; case M_USER_ADD: { const char* nick(NULL); bool ignore(false); int32 iStatus(STATUS_NORMAL_BIT); msg->FindString("nick", &nick); msg->FindBool("ignore", &ignore); if (nick == NULL) { printf("ERROR: attempted to AddUser an empty nick in ChannelAgent, channel: %s\n", fId.String()); break; } if (ignore) iStatus |= STATUS_IGNORE_BIT; AddUser(nick, iStatus); BMessage display; if (msg->FindMessage("display", &display) == B_NO_ERROR) ClientAgent::MessageReceived(&display); } break; case M_CHANGE_NICK: { const char* oldNick(NULL), *newNick(NULL); NameItem* item(NULL); int32 thePos(-1); if ((msg->FindString("oldnick", &oldNick) != B_OK) || (msg->FindString("newnick", &newNick) != B_OK)) { printf("Error: invalid pointer, ChannelAgent::MessageReceived, M_CHANGE_NICK"); break; } if (fMyNick.ICompare(oldNick) == 0 && !IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_NICK, newNick); if (((thePos = FindPosition(oldNick)) >= 0) && ((item = (static_cast<NameItem*>(fNamesList->ItemAt(thePos)))) != 0)) { item->SetName(newNick); fNamesList->SortItems(SortNames); if (fLastExpansion.ICompare(oldNick, fLastExpansion.Length()) == 0) { int32 count(fRecentNicks.CountItems()); BString* name(NULL); for (i = 0; i < count; i++) if ((name = fRecentNicks.ItemAt(i))->ICompare(oldNick) == 0) { if (fLastExpansion.ICompare(newNick, fLastExpansion.Length()) == 0) name->SetTo(newNick); else delete fRecentNicks.RemoveItemAt(i); break; } count = fCompletionNicks.CountItems(); for (i = 0; i < count; i++) if ((name = fCompletionNicks.ItemAt(i))->ICompare(oldNick) == 0) { if (fLastExpansion.ICompare(newNick, fLastExpansion.Length()) == 0) name->SetTo(newNick); else delete fCompletionNicks.RemoveItemAt(i); break; } } } else break; ClientAgent::MessageReceived(msg); } break; case M_CHANNEL_NAMES: { for (i = 0; msg->HasString("nick", i); ++i) { const char* nick(NULL); bool founder(false), protect(false), op(false), voice(false), helper(false), ignored(false); msg->FindString("nick", i, &nick); msg->FindBool("founder", i, &founder); msg->FindBool("protect", i, &protect); msg->FindBool("op", i, &op); msg->FindBool("voice", i, &voice); msg->FindBool("helper", i, &helper); msg->FindBool("ignored", i, &ignored); if (FindPosition(nick) < 0) { int32 iStatus(ignored ? STATUS_IGNORE_BIT : 0); if (founder) { ++nick; ++fOpsCount; iStatus |= STATUS_FOUNDER_BIT; } else if (protect) { ++nick; ++fOpsCount; iStatus |= STATUS_PROTECTED_BIT; } else if (op) { ++nick; ++fOpsCount; iStatus |= STATUS_OP_BIT; } else if (voice) { ++nick; iStatus |= STATUS_VOICE_BIT; } else if (helper) { ++nick; iStatus |= STATUS_HELPER_BIT; } else iStatus |= STATUS_NORMAL_BIT; fUserCount++; fNamesList->AddItem(new NameItem(nick, iStatus)); } } fNamesList->SortItems(SortNames); if (!IsHidden()) { BString buffer; buffer << fOpsCount; vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_OPS, buffer.String()); buffer = ""; buffer << fUserCount; vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_USERS, buffer.String()); } } break; case M_RESIZE_VIEW: { BPoint point; msg->FindPoint("loc", &point); point.x -= Frame().left; float offset((int32)(point.x - (fNamesScroll->Frame().left))); fResize->MoveBy(offset, 0.0); fTextScroll->ResizeBy(offset, 0.0); fNamesScroll->ResizeBy(-offset, 0.0); fNamesScroll->MoveBy(offset, 0.0); BRect namesRect(0, 0, fNamesScroll->Bounds().Width(), 0); vision_app->SetRect("namesListRect", namesRect); } break; case M_SERVER_DISCONNECT: { // clear names list on disconnect fNamesList->ClearList(); fOpsCount = 0; fUserCount = 0; // clear heuristics completion list - this ensures that no stale nicks are left // over in it after reconnect -- list will quickly be rebuilt anyhow if there // is any conversation whatsoever going on while (fRecentNicks.CountItems() > 0) delete fRecentNicks.RemoveItemAt(0L); } break; case M_REJOIN: { const char* newNick(NULL); if (msg->FindString("nickname", &newNick) != B_OK) { printf("Error: ChannelAgent::MessageReceived, M_REJOIN: invalid pointer\n"); break; } fMyNick = newNick; // update nickname (might have changed on reconnect) if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_NICK, fMyNick.String()); Display(S_CHANNEL_RECON_REJOIN B_UTF8_ELLIPSIS "\n", C_ERROR, C_BACKGROUND, F_SERVER); // send join cmd BMessage send(M_SERVER_SEND); AddSend(&send, "JOIN "); AddSend(&send, fId); if (fChanKey != "") { AddSend(&send, " "); AddSend(&send, fChanKey); } AddSend(&send, endl); } break; case M_CHANNEL_TOPIC: { const char* theTopic(NULL); BString buffer; if (msg->FindString("topic", &theTopic) != B_OK) { printf("ChannelAgent::MessageReceived, M_CHANNEL_TOPIC: invalid pointer\n"); break; } fTopic = theTopic; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue( STATUS_META, FilterCrap(theTopic, true).String()); BMessage display; if (msg->FindMessage("display", &display) == B_NO_ERROR) ClientAgent::MessageReceived(&display); } break; case M_OPEN_MSGAGENT: { const char* theNick(NULL); msg->FindString("nick", &theNick); if (theNick == NULL) { NameItem* myUser; int32 pos = fNamesList->CurrentSelection(); if (pos >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(pos)); BString targetNick = myUser->Name(); msg->AddString("nick", targetNick.String()); } } fSMsgr.SendMessage(msg); } break; case M_CHANNEL_GOT_KICKED: { const char* theChannel(NULL), *kicker(NULL), *rest(NULL); if ((msg->FindString("channel", &theChannel) != B_OK) || (msg->FindString("kicker", &kicker) != B_OK) || (msg->FindString("rest", &rest) != B_OK)) { printf("Error: ClientAgent::MessageReceived, M_CHANNEL_GOT_KICKED, invalid pointer\n"); break; } BMessage wegotkicked(M_DISPLAY); // "you were kicked" BString buffer; buffer += S_CHANNEL_GOT_KICKED; buffer += theChannel; buffer += " " S_CHANNEL_GOT_KICKED2 " "; buffer += kicker; buffer += " ("; buffer += rest; buffer += ")\n"; PackDisplay(&wegotkicked, buffer.String(), C_QUIT, C_BACKGROUND, F_TEXT); // clean up fNamesList->ClearList(); fOpsCount = 0; fUserCount = 0; fMsgr.SendMessage(&wegotkicked); BMessage attemptrejoin(M_DISPLAY); // "you were kicked" buffer = S_CHANNEL_REJOIN; buffer += theChannel; buffer += B_UTF8_ELLIPSIS "\n"; PackDisplay(&attemptrejoin, buffer.String(), C_QUIT, C_BACKGROUND, F_TEXT); fMsgr.SendMessage(&attemptrejoin); BMessage send(M_SERVER_SEND); AddSend(&send, "JOIN "); AddSend(&send, theChannel); if (fChanKey != "") { AddSend(&send, " "); AddSend(&send, fChanKey); } AddSend(&send, endl); } break; case M_CHANNEL_MODE: { ModeEvent(msg); } break; case M_CHANNEL_MSG: { bool hasNick(false); BString tempString, theNick, knownAs; msg->FindString("msgz", &tempString); msg->FindString("nick", &theNick); if (theNick != fMyNick) FirstKnownAs(tempString, knownAs, &hasNick); if (IsHidden()) { UpdateStatus((hasNick) ? WIN_NICK_BIT : WIN_NEWS_BIT); if (hasNick) { if (tempString[0] == '\1') { tempString.RemoveFirst("\1ACTION "); tempString.RemoveLast("\1"); } BNotification notification(B_INFORMATION_NOTIFICATION); notification.SetGroup(BString("Vision")); entry_ref ref = vision_app->AppRef(); notification.SetOnClickFile(&ref); notification.SetTitle(fServerName.String()); BString content; content.SetToFormat("%s - %s said: %s", fId.String(), theNick.String(), tempString.String()); notification.SetContent(content); notification.Send(); } } else if (hasNick) system_beep(kSoundEventNames[(uint32)seNickMentioned]); ClientAgent::MessageReceived(msg); } break; case M_CHANNEL_MODES: { const char* mode(NULL), *chan(NULL), *msgz(NULL); if ((msg->FindString("mode", &mode) != B_OK) || (msg->FindString("chan", &chan) != B_OK) || (msg->FindString("msgz", &msgz) != B_OK)) { printf("Error: ChannelAgent::MessageReceived, M_CHANNEL_MODES: invalid pointer\n"); break; } if (fId.ICompare(chan) == 0) { BString realMode(GetWord(mode, 1)); int32 place(2); if (realMode.FindFirst("l") >= 0) fChanLimit = GetWord(mode, place++); if (realMode.FindFirst("k") >= 0) { fChanKey = GetWord(mode, place++); // u2 may not send the channel key, thats why we stored the /join cmd // in a string in ParseCmd if (fChanKey == "*" && fIrcdtype == IRCD_UNDERNET) { BString tempId(fId); tempId.Remove(0, 1); // remove any #, &, !, blah. if (vision_app->pClientWin()->joinStrings.FindFirst(tempId) < 1) { // can't find the join cmd for this channel in joinStrings! } else { BString joinStringsL(vision_app->pClientWin()->joinStrings); // FindLast to make sure we get the last attempt (user might have // tried several keys) int32 idPos(joinStringsL.FindLast(tempId)); BString tempKeyString; joinStringsL.MoveInto(tempKeyString, idPos, joinStringsL.Length()); fChanKey = GetWord(tempKeyString.String(), 2); } } // end u2-kludge stuff } fChanMode = mode; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_MODES, fChanMode.String()); } BMessage dispMsg(M_DISPLAY); PackDisplay(&dispMsg, msgz, C_OP, C_BACKGROUND, F_TEXT); BMessenger display(this); display.SendMessage(&dispMsg); } break; case M_NAMES_POPUP_MODE: { const char* inaction(NULL); msg->FindString("action", &inaction); int32 count(0), index(0); BString victims, targetNick, action(inaction), modechar, polarity; NameItem* myUser(NULL); /// action /// if (action.FindFirst("voice") >= 0) modechar = "v"; else if (action.FindFirst("op") >= 0) modechar = "o"; else break; /// polarity /// if (action.FindFirst("de") >= 0) polarity += " -"; else polarity += " +"; /// iterate /// while ((i = fNamesList->CurrentSelection(index++)) >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(i)); targetNick = myUser->Name(); victims += " "; victims += targetNick; count++; } BString command("/mode "); command += fId; command += polarity; for (i = 0; i < count; i++) command += modechar; command += victims; ParseCmd(command.String()); } break; case M_NAMES_POPUP_CTCP: { const char* inaction(NULL); msg->FindString("action", &inaction); int32 index(0); BString victims, targetNick, action(inaction); NameItem* myUser(NULL); action.ToUpper(); /// iterate /// while ((i = fNamesList->CurrentSelection(index++)) >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(i)); targetNick = myUser->Name(); victims += targetNick; victims += ","; } victims.RemoveLast(","); BString command("/ctcp "); command += victims; command += " "; command += action; ParseCmd(command.String()); } break; case M_NAMES_POPUP_WHOIS: { int32 index(0); BString victims, targetNick; NameItem* myUser(NULL); /// iterate /// while ((i = fNamesList->CurrentSelection(index++)) >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(i)); targetNick = myUser->Name(); victims += targetNick; victims += ","; } victims.RemoveLast(","); BString command("/whois "); command += victims; ParseCmd(command.String()); } break; case M_NAMES_POPUP_NOTIFY: { int32 index(0); BString victims, targetNick; NameItem* myUser(NULL); /// iterate /// while ((i = fNamesList->CurrentSelection(index++)) >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(i)); targetNick = myUser->Name(); victims += targetNick; victims += " "; } victims.RemoveLast(","); BString command("/notify "); command += victims; ParseCmd(command.String()); } break; case M_NAMES_POPUP_DCCCHAT: { int32 index(0); BString targetNick; NameItem* myUser(NULL); /// iterate /// while ((i = fNamesList->CurrentSelection(index++)) >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(i)); targetNick = myUser->Name(); BString command("/dcc chat "); command += targetNick; ParseCmd(command.String()); } } break; case M_NAMES_POPUP_DCCSEND: { int32 index(0); BString targetNick; NameItem* myUser(NULL); /// iterate /// while ((i = fNamesList->CurrentSelection(index++)) >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(i)); targetNick = myUser->Name(); BString command("/dcc send "); command += targetNick; ParseCmd(command.String()); } } break; case M_NAMES_POPUP_KICK: { int32 index(0); BString targetNick, kickMsg(vision_app->GetCommand(CMD_KICK)); NameItem* myUser(NULL); /// iterate /// while ((i = fNamesList->CurrentSelection(index++)) >= 0) { myUser = static_cast<NameItem*>(fNamesList->ItemAt(i)); targetNick = myUser->Name(); BString command("/kick "); command += targetNick; command += " "; command += kickMsg; ParseCmd(command.String()); } } break; case M_STATUS_ADDITEMS: { vision_app->pClientWin()->pStatusView()->AddItem(new StatusItem(0, ""), true); vision_app->pClientWin()->pStatusView()->AddItem( new StatusItem(S_STATUS_LAG, "", STATUS_ALIGN_LEFT), true); vision_app->pClientWin()->pStatusView()->AddItem(new StatusItem(0, "", STATUS_ALIGN_LEFT), true); vision_app->pClientWin()->pStatusView()->AddItem(new StatusItem(S_STATUS_USERS, ""), true); vision_app->pClientWin()->pStatusView()->AddItem(new StatusItem(S_STATUS_OPS, ""), true); vision_app->pClientWin()->pStatusView()->AddItem(new StatusItem(S_STATUS_MODES, ""), true); vision_app->pClientWin()->pStatusView()->AddItem(new StatusItem("", "", STATUS_ALIGN_LEFT), true); // The false bool for SetItemValue() tells the StatusView not to Invalidate() the view. // We send true on the last SetItemValue(). vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_SERVER, fServerName.String(), false); vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_LAG, fMyLag.String(), false); vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_NICK, fMyNick.String(), false); vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_MODES, fChanMode.String(), false); vision_app->pClientWin()->pStatusView()->SetItemValue( STATUS_META, FilterCrap(fTopic.String(), true).String()); BString buffer; buffer << fUserCount; vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_USERS, buffer.String(), false); buffer = ""; buffer << fOpsCount; vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_OPS, buffer.String(), true); } break; case M_CHANNEL_OPTIONS_SHOW: { if (fChanOpt) fChanOpt->Activate(); else { fChanOpt = new ChannelOptions(fId.String(), this); fChanOpt->Show(); } } break; case M_CHANNEL_OPTIONS_CLOSE: { fChanOpt = NULL; } break; case M_CLIENT_QUIT: { if ((msg->HasBool("vision:part") && msg->FindBool("vision:part")) || (msg->HasBool("vision:winlist") && msg->FindBool("vision:winlist"))) { BMessage send(M_SERVER_SEND); AddSend(&send, "PART "); AddSend(&send, fId); if (msg->HasString("vision:partmsg")) { AddSend(&send, " :"); AddSend(&send, msg->FindString("vision:partmsg")); } AddSend(&send, endl); } ClientAgent::MessageReceived(msg); } break; default: ClientAgent::MessageReceived(msg); } }
bool ServerAgent::ParseENums (const char *data, const char *sWord) { int num (atoi (sWord)); switch (num) { case ZERO: // 0 { // wasn't a numeric, or the server is playing tricks on us } return false; case ERR_UNKNOWNCOMMAND: // 421 { BString tempString (RestOfString (data, 4)), badCmd (GetWord (data, 4)); if (badCmd == "VISION_LAG_CHECK") { int32 difference (system_time() - fLagCheck); if (difference > 0) { int32 secs (difference / 1000000); int32 milli (difference / 1000 - secs * 1000); char lag[15] = ""; sprintf (lag, "%0" B_PRId32 ".%03" B_PRId32, secs, milli); fMyLag = lag; fLagCount = 0; fCheckingLag = false; fMsgr.SendMessage (M_LAG_CHANGED); } } else { tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); } } return true; case RPL_WELCOME: // 001 case RPL_YOURHOST: // 002 case RPL_CREATED: // 003 case RPL_MYINFO: // 004 { fConnected = true; fIsConnecting = false; fInitialMotd = true; fRetry = 0; if (num == RPL_WELCOME) { BString message = B_TRANSLATE("Established"); message.Prepend("[@] ").Append("\n"); Display(message.String(), C_ERROR, C_BACKGROUND, F_SERVER); } if (fNetworkData.FindBool ("lagCheck")) { fMyLag = "0.000"; fMsgr.SendMessage (M_LAG_CHANGED); } BString theNick (GetWord (data, 3)); fMyNick = theNick; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue (STATUS_NICK, theNick.String()); BString theMsg (RestOfString (data, 4)); theMsg.RemoveFirst (":"); theMsg.Prepend ("* "); theMsg.Append ("\n"); Display (theMsg.String()); if (num == RPL_MYINFO) { // set "real" hostname fServerHostName = (GetWord (data, 1)); fServerHostName.RemoveFirst (":"); BString hostName (fId.String()); hostName += " - ["; hostName += fServerHostName.String(); hostName += "]"; fAgentWinItem->SetName (hostName.String()); // detect IRCd fIrcdtype = IRCD_STANDARD; if (theMsg.FindFirst("hybrid") > 0) fIrcdtype = IRCD_HYBRID; // ultimate and unreal share the same numerics, so treat them with the same // identifier for now else if ((theMsg.FindFirst("UltimateIRCd") > 0) || (theMsg.FindFirst("Unreal") > 0)) fIrcdtype = IRCD_ULTIMATE; else if (theMsg.FindFirst("comstud") > 0) fIrcdtype = IRCD_COMSTUD; else if (theMsg.FindFirst("u2.") > 0) fIrcdtype = IRCD_UNDERNET; else if (theMsg.FindFirst("PTlink") > 0) fIrcdtype = IRCD_PTLINK; else if (theMsg.FindFirst ("CR") > 0) fIrcdtype = IRCD_CONFERENCEROOM; else if (theMsg.FindFirst ("nn-") > 0) fIrcdtype = IRCD_NEWNET; } } return true; case RPL_PROTOCTL: // 005 { // this numeric also serves as RPL_NNMAP on Newnet BString theMsg (RestOfString (data, 4)); theMsg.RemoveFirst (":"); theMsg.Append ("\n"); switch (fIrcdtype) { case IRCD_NEWNET: { // RPL_NNMAP Display (theMsg.String()); } break; default: { // RPL_PROTOCTL theMsg.Prepend ("* "); Display (theMsg.String()); } } } return true; case RPL_LUSERHIGHESTCONN: // 250 case RPL_LUSERCLIENT: // 251 case RPL_LUSEROP: // 252 case RPL_LUSERUNKNOWN: // 253 case RPL_LUSERCHANNELS: // 254 case RPL_LUSERME: // 255 case RPL_LUSERLOCAL: // 265 case RPL_LUSERGLOBAL: // 266 { BString theMsg (RestOfString (data, 4)); theMsg.RemoveFirst (":"); theMsg.Prepend ("* "); theMsg.Append ("\n"); Display (theMsg.String()); } return true; /// strip and send to server agent /// case RPL_ULMAP: // 006 case RPL_ULMAPEND: // 007 case RPL_U2MAP: // 015 case RPL_U2MAPEND: // 017 case RPL_TRACELINK: // 200 case RPL_TRACECONNECTING: // 201 case RPL_TRACEHANDSHAKE: // 202 case RPL_TRACEUNKNOWN: // 203 case RPL_TRACEOPERATOR: // 204 case RPL_TRACEUSER: // 205 case RPL_TRACESERVER: // 206 case RPL_TRACENEWTYPE: // 208 case RPL_TRACECLASS: // 209 case RPL_STATSLINKINFO: // 211 case RPL_STATSCOMMANDS: // 212 case RPL_STATSCLINE: // 213 case RPL_STATSNLINE: // 214 case RPL_STATSILINE: // 215 case RPL_STATSKLINE: // 216 case RPL_STATSQLINE: // 217 case RPL_STATSYLINE: // 218 case RPL_ENDOFSTATS: // 219 case RPL_STATSBLINE: // 220 case RPL_DALSTATSE: // 223 case RPL_DALSTATSF: // 224 case RPL_DALSTATSZ: // 225 case RPL_DALSTATSN: // 226 case RPL_DALSTATSG: // 227 case RPL_STATSLLINE: // 241 case RPL_STATSUPTIME: // 242 case RPL_STATSOLINE: // 243 case RPL_STATSHLINE: // 244 case RPL_STATSSLINE: // 245 case RPL_DALSTATSX: // 246 case RPL_STATSXLINE: // 247 case RPL_STATSPLINE: // 249 case RPL_ADMINME: // 256 case RPL_ADMINLOC1: // 257 case RPL_ADMINLOC2: // 258 case RPL_ADMINEMAIL: // 259 case RPL_TRACELOG: // 261 case RPL_ENDOFTRACE: // 262 case RPL_SILELIST: // 271 case RPL_ENDOFSILELIST: // 272 case RPL_ENDOFWHO: // 315 case RPL_CHANSERVURL: // 328 case RPL_COMMANDSYNTAX: // 334 case RPL_VERSION: // 351 case RPL_WHOREPLY: // 352 case RPL_BANLIST: // 367 case RPL_ENDOFBANLIST: // 368 case RPL_INFO: // 371 case RPL_ENDOFINFO: // 374 case RPL_YOUREOPER: // 381 case RPL_REHASHING: // 382 case RPL_TIME: // 391 case ERR_NOORIGIN: // 409 case ERR_NOTEXTTOSEND: // 412 case ERR_TOOMANYAWAY: // 429 case ERR_NICKCHANGETOOFAST: // 438 case ERR_TARGETCHANGETOOFAST: // 439 case ERR_SUMMONDISABLED: // 445 case ERR_USERSDISABLED: // 446 case ERR_NOTREGISTERED: // 451 case ERR_NEEDMOREPARMS: // 461 case ERR_PASSWDMISMATCH: // 464 case ERR_YOUREBANNEDCREEP: // 465 case ERR_NOPRIVILEGES: // 481 case ERR_NOOPERHOST: // 491 case ERR_USERSDONTMATCH: // 502 case ERR_SILELISTFULL: // 511 case ERR_TOOMANYWATCH: // 512 case ERR_TOOMANYDCC: // 514 case ERR_CANTINVITE: // 518 case ERR_LISTSYNTAX: // 521 case ERR_WHOSYNTAX: // 522 case ERR_WHOLIMEXCEED: // 523 case RPL_LOGON: // 600 case RPL_LOGOFF: // 601 case RPL_WATCHOFF: // 602 case RPL_WATCHSTAT: // 603 case RPL_NOWON: // 604 case RPL_NOWOFF: // 605 case RPL_WATCHLIST: // 606 case RPL_ENDOFWATCHLIST: // 607 case RPL_DCCALLOWLIST: // 618 case RPL_DCCALLOWEND: // 619 case RPL_DCCALLOW: // 620 { BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); } return true; case RPL_UMODEIS: // 221 { BString theMode (GetWord (data, 4)); BString tempString = B_TRANSLATE("Your current mode is %1"); tempString.ReplaceFirst("%1", theMode); tempString += '\n'; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS); PostActive (&msg); } return true; /// strip and send to active agent /// case RPL_TRYAGAIN: // 263 case RPL_UNAWAY: // 305 case RPL_NOWAWAY: // 306 case ERR_NOSUCHNICK: // 401 case ERR_NOSUCHSERVER: // 402 case ERR_NOSUCHCHANNEL: // 403 case ERR_CANNOTSENDTOCHAN: // 404 case ERR_TOOMANYCHANNELS: // 405 case ERR_WASNOSUCHNICK: // 406 case ERR_TOOMANYTARGETS: // 407 case ERR_NOCOLORSONCHAN: // 408 case ERR_YOUCANTDOTHAT: // 460 case ERR_CHANOPRIVSNEEDED: // 482 { BString tempString ("[x] "); if (num == ERR_CHANOPRIVSNEEDED) tempString += RestOfString (data, 5); else tempString += RestOfString (data, 4); tempString.RemoveFirst (":"); tempString.Append ("\n"); BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_AWAY: // 301 { BString theNick (GetWord(data, 4)); BString tempString ("[x] "), theReason (RestOfString(data, 5)); theReason.RemoveFirst(":"); tempString += "Away: "; tempString += theReason; tempString += '\n'; if (fRemoteAwayMessages.find(theNick) != fRemoteAwayMessages.end()) { if (fRemoteAwayMessages[theNick] == theReason) { return true; } } fRemoteAwayMessages[theNick] = theReason; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_USERHOST: // 302 { BString theHost (GetWord (data, 4)), theHostname (GetAddress (theHost.String())); theHost.RemoveFirst (":"); BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); if (fGetLocalIP && (tempString.IFindFirst (fMyNick.String()) == 0)) { fGetLocalIP = false; struct addrinfo *info; struct addrinfo hints; memset(&hints, 0, sizeof(addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; int result = getaddrinfo(theHostname.String(), NULL, &hints, &info); if (result == 0) { char addr_buf[INET6_ADDRSTRLEN]; getnameinfo(info->ai_addr, info->ai_addrlen, addr_buf, sizeof(addr_buf), NULL, 0, NI_NUMERICHOST); fLocalip = addr_buf; printf("Got address: %s\n", fLocalip.String()); freeaddrinfo(info); return true; } } } return true; case RPL_ISON: // 303 { BString nicks (RestOfString (data, 4)); BString onlined, offlined; nicks.RemoveFirst (":"); int hasChanged (0); BMessage msg (M_NOTIFYLIST_UPDATE); for (int32 i = 0; i < fNotifyNicks.CountItems(); i++) { NotifyListItem *item (((NotifyListItem *)fNotifyNicks.ItemAt(i))); int32 nickidx (nicks.IFindFirst(item->Text())); // make sure that the nick isn't a partial match. if ((nickidx >= 0) && ((nicks[nickidx + strlen(item->Text())] == ' ') || (nicks[nickidx + strlen(item->Text())] == '\0'))) { if (item->GetState() != true) { item->SetState (true); hasChanged = 1; if (onlined.Length()) onlined << ", "; onlined << item->Text(); #ifdef USE_INFOPOPPER if (be_roster->IsRunning(InfoPopperAppSig) == true) { entry_ref ref = vision_app->AppRef(); BMessage infoMsg(InfoPopper::AddMessage); infoMsg.AddString("appTitle", S_INFOPOPPER_TITLE); infoMsg.AddString("title", fId.String()); infoMsg.AddInt8("type", (int8)InfoPopper::Information); infoMsg.AddInt32("iconType", InfoPopper::Attribute); infoMsg.AddRef("iconRef", &ref); BString content; content << item->Text() << " is online"; infoMsg.AddString("content", content); BMessenger(InfoPopperAppSig).SendMessage(&infoMsg); }; #endif } } else { if (item->GetState() == true) { item->SetState (false); hasChanged = 2; if (offlined.Length()) offlined << ", "; offlined << item->Text(); #ifdef USE_INFOPOPPER if (be_roster->IsRunning(InfoPopperAppSig) == true) { entry_ref ref = vision_app->AppRef(); BMessage infoMsg(InfoPopper::AddMessage); infoMsg.AddString("appTitle", S_INFOPOPPER_TITLE); infoMsg.AddString("title", fId.String()); infoMsg.AddInt8("type", (int8)InfoPopper::Information); infoMsg.AddInt32("iconType", InfoPopper::Attribute); infoMsg.AddRef("iconRef", &ref); BString content; content << item->Text() << " is offline"; infoMsg.AddString("content", content); BMessenger(InfoPopperAppSig).SendMessage(&infoMsg); }; #endif } } #ifdef __HAIKU__ if (offlined.Length()) { BNotification notification(B_INFORMATION_NOTIFICATION); notification.SetGroup(BString("Vision")); entry_ref ref = vision_app->AppRef(); notification.SetOnClickFile(&ref); notification.SetTitle(fServerName.String()); BString content; content << offlined; if (offlined.FindFirst(' ') > -1) content << " are offline"; else content << " is offline"; notification.SetContent(content); notification.Send(); } if (onlined.Length()) { BNotification notification(B_INFORMATION_NOTIFICATION); notification.SetGroup(BString("Vision")); entry_ref ref = vision_app->AppRef(); notification.SetOnClickFile(&ref); notification.SetTitle(fServerName.String()); BString content; content << onlined; if (onlined.FindFirst(' ') > -1) content << " are online"; else content << " is online"; notification.SetContent(content); notification.Send(); } #endif } fNotifyNicks.SortItems(SortNotifyItems); msg.AddPointer ("list", &fNotifyNicks); msg.AddPointer ("source", this); msg.AddInt32 ("change", hasChanged); Window()->PostMessage (&msg); } return true; case RPL_WHOISIDENTIFIED: // 307 { BString theInfo (RestOfString (data, 5)); theInfo.RemoveFirst (":"); if (theInfo == "-9z99") { // USERIP reply? (RPL_U2USERIP) BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String()); return true; } BMessage display (M_DISPLAY); BString buffer; buffer += "[x] "; buffer += theInfo; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOISADMIN: // 308 case RPL_WHOISSERVICESADMIN: // 309 case RPL_WHOISHELPOP: // 310 case RPL_WHOISOPERATOR: // 313 case RPL_WHOISREGNICK: // 320 case RPL_WHOISACTUALLY: // 338 case RPL_WHOISMASK: // 550 case RPL_WHOWASIP: // 612 case RPL_WHOISUSERMODESALT: // 614 case RPL_WHOISUSERMODES: // 615 case RPL_WHOISREALHOSTNAME: // 616 { BString theInfo (RestOfString (data, 5)); theInfo.RemoveFirst (":"); BMessage display (M_DISPLAY); BString buffer; buffer += "[x] "; buffer += theInfo; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOISUSER: // 311 { BString theNick (GetWord (data, 4)), theIdent (GetWord (data, 5)), theAddress (GetWord (data, 6)), theName (RestOfString (data, 8)); theName.RemoveFirst (":"); BMessage display (M_DISPLAY); BString buffer; buffer += "[x] "; buffer += theNick; buffer += " ("; buffer += theIdent; buffer += "@"; buffer += theAddress; buffer += ")\n"; buffer += "[x] "; buffer += theName; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOISSERVER: // 312 { BString theNick (GetWord (data, 4)), theServer (GetWord (data, 5)), theInfo (RestOfString (data, 6)); theInfo.RemoveFirst (":"); BMessage display (M_DISPLAY); BString buffer; buffer += "[x] Server: "; buffer += theServer; buffer += " ("; buffer += theInfo; buffer += ")\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_WHOWASUSER: // 314 { BString theNick (GetWord (data, 4)), theIdent (GetWord (data, 5)), theAddress (GetWord (data, 6)), theName (RestOfString (data, 8)), tempString ("[x] "); theName.RemoveFirst (":"); tempString += B_TRANSLATE("%1 was (%2)"); tempString.ReplaceFirst("%1", theNick); BString nickString = theIdent << "@" << theAddress; tempString.ReplaceFirst("%2", nickString.String()); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_WHOISIDLE: // 317 { BString theNick (GetWord (data, 4)), tempString ("[x] "), tempString2 ("[x] "), theTime (GetWord (data, 5)), signOnTime (GetWord (data, 6)); int64 idleTime (strtoul(theTime.String(), NULL, 0)); tempString += B_TRANSLATE("Idle"); tempString += ": "; tempString += DurationString(idleTime * 1000 * 1000); tempString += "\n"; int32 serverTime = strtoul(signOnTime.String(), NULL, 0); struct tm ptr; time_t st; char str[80]; st = serverTime; localtime_r (&st, &ptr); strftime (str,80,"%A %b %d %Y %I:%M %p %Z", &ptr); BString signOnTimeParsed (str); signOnTimeParsed.RemoveAll ("\n"); tempString2 += B_TRANSLATE("Signon"); tempString2 += ": "; tempString2 += signOnTimeParsed; tempString2 += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); PackDisplay (&msg, tempString2.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } return true; case RPL_ENDOFWHOIS: // 318 case RPL_ENDOFNAMES: // 366 case RPL_ENDOFWHOWAS: // 369 { // nothing } return true; case RPL_WHOISCHANNELS: // 319 { BString theChannels (RestOfString (data, 5)); theChannels.RemoveFirst(":"); BMessage display (M_DISPLAY); BString buffer = "[x] "; buffer += B_TRANSLATE("Channels"); buffer += ": "; buffer += theChannels; buffer += "\n"; PackDisplay (&display, buffer.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&display); } return true; case RPL_LISTSTART: // 321 { BMessage msg (M_LIST_BEGIN); if (fListAgent) vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent); } return true; case RPL_LIST: // 322 { BMessage msg (M_LIST_EVENT); BString channel (GetWord (data, 4)), users (GetWord (data, 5)), topic (RestOfString (data, 6)); topic.RemoveFirst (":"); msg.AddString ("channel", channel.String()); msg.AddString ("users", users.String()); msg.AddString ("topic", topic.String()); if (fListAgent) vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent); } return true; case RPL_LISTEND: // 323 { BMessage msg (M_LIST_DONE); if (fListAgent) vision_app->pClientWin()->DispatchMessage(&msg, (BView *)fListAgent); } return true; case RPL_CHANNELMODEIS: // 324 { BString theChan (GetWord (data, 4)), theMode (GetWord (data, 5)), tempStuff (RestOfString (data, 6)); if (tempStuff != "-9z99") { theMode.Append(" "); theMode.Append(tempStuff); // avoid extra space w/o params } ClientAgent *aClient (ActiveClient()), *theClient (Client (theChan.String())); BString tempString("*** "); tempString += B_TRANSLATE("Channel mode for %1: %2"); tempString.ReplaceFirst("%1", theChan.String()); tempString.ReplaceFirst("%2", theMode.String()); tempString += '\n'; BMessage msg (M_CHANNEL_MODES); msg.AddString ("msgz", tempString.String()); msg.AddString ("chan", theChan.String()); msg.AddString ("mode", theMode.String()); if (theClient) theClient->fMsgr.SendMessage (&msg); else if (aClient) aClient->fMsgr.SendMessage (&msg); else Display (tempString.String(), C_OP); } return true; case RPL_CHANNELMLOCK: // 325 { BString theChan (GetWord (data, 4)), mLock (GetWord (data, 8)), lockMessage ("*** "); lockMessage += B_TRANSLATE("Channel mode lock for %1: %2"); lockMessage.ReplaceFirst("%1", theChan); lockMessage.ReplaceFirst("%2", mLock); lockMessage += "\n"; BMessage display (M_DISPLAY); PackDisplay (&display, lockMessage.String(), C_OP, C_BACKGROUND, F_TEXT); ClientAgent *theClient (Client (theChan.String())); if (theClient) theClient->fMsgr.SendMessage (&display); else fMsgr.SendMessage (&display); } return true; case RPL_CHANNELCREATED: // 329 { BString theChan (GetWord (data, 4)), theTime (GetWord (data, 5)), tempString; int32 serverTime (strtoul(theTime.String(), NULL, 0)); struct tm ptr; time_t st; char str[80]; st = serverTime; localtime_r (&st, &ptr); strftime (str,80,"%a %b %d %Y %I:%M %p %Z",&ptr); BString theTimeParsed (str); theTimeParsed.RemoveAll ("\n"); tempString = B_TRANSLATE("Channel %1 was created at %2"); tempString.ReplaceFirst("%1", theChan); tempString.ReplaceFirst("%2", theTimeParsed); tempString += '\n'; Display (tempString.String()); } return true; case RPL_NOTOPIC: // 331 { BString theChan (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("No topic set in %1"); tempString.ReplaceFirst("%1", theChan); tempString += '\n'; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case RPL_TOPIC: // 332 { BString theChannel (GetWord (data, 4)), theTopic (RestOfString (data, 5)); ClientAgent *client (Client (theChannel.String())); theTopic.RemoveFirst (":"); if (client) { BMessage display (M_DISPLAY); BString buffer; buffer += "*** "; buffer += B_TRANSLATE("Topic: %1"); buffer.ReplaceFirst("%1", theTopic); buffer += '\n'; PackDisplay (&display, buffer.String(), C_WHOIS); BMessage msg (M_CHANNEL_TOPIC); msg.AddString ("topic", theTopic.String()); msg.AddMessage ("display", &display); if (client->fMsgr.IsValid()) client->fMsgr.SendMessage (&msg); } } return true; case RPL_TOPICSET: // 333 { BString channel (GetWord (data, 4)), user (GetWord (data, 5)), theTime (GetWord (data, 6)); int32 serverTime (strtoul(theTime.String(), NULL, 0)); struct tm ptr; time_t st; char str[80]; st = serverTime; localtime_r (&st, &ptr); strftime (str,80,"%A %b %d %Y %I:%M %p %Z",&ptr); BString theTimeParsed (str); theTimeParsed.RemoveAll ("\n"); ClientAgent *client (Client (channel.String())); if (client) { BMessage display (M_DISPLAY); BString buffer = "*** "; buffer += B_TRANSLATE("Topic set by %1 at %2"); buffer.ReplaceFirst("%1", user); buffer.ReplaceFirst("%2", theTimeParsed); buffer += '\n'; PackDisplay (&display, buffer.String(), C_WHOIS); if (client->fMsgr.IsValid()) client->fMsgr.SendMessage (&display); } } return true; case RPL_INVITING: // 341 { BString channel (GetWord (data, 5)), theNick (GetWord (data, 4)), tempString; tempString += "*** "; tempString += B_TRANSLATE("%1 has been invited to %2."); tempString.ReplaceFirst("%1", theNick); tempString.ReplaceFirst("%2", channel); tempString += "\n"; BMessage display (M_DISPLAY); PackDisplay (&display, tempString.String(), C_WHOIS); PostActive (&display); } return true; case RPL_NAMEREPLY: // 353 { BString channel (GetWord (data, 5)), names (RestOfString (data, 6)); ClientAgent *client (Client (channel.String())); names.RemoveFirst (":"); BString tempString ("*** "); tempString += B_TRANSLATE("Users in %1: %2"); tempString.ReplaceFirst("%1", channel); tempString.ReplaceFirst("%2", names); tempString += '\n'; Display (tempString.String(), C_TEXT); if (client) // in the channel { BMessage msg (M_CHANNEL_NAMES); BString nick; int32 place (1); while ((nick = GetWord (names.String(), place)) != "-9z99") { const char *sNick (nick.String()); bool founder (false), protect (false), op (false), voice (false), helper (false), ignored; if (nick[0] == '*') { ++sNick; founder = true; } else if (nick[0] == '!') { ++sNick; protect = true; } else if (nick[0] == '@') { ++sNick; op = true; } else if (nick[0] == '+') { ++sNick; voice = true; } else if (nick[0] == '%') { ++sNick; helper = true; } ignored = false; // BMessage aMsg (M_IS_IGNORED), reply; // aMsg.AddString ("server", fServerName.String()); // aMsg.AddString ("nick", sNick); // be_app_messenger.SendMessage (&aMsg, &reply); // reply.FindBool ("ignored", &ignored); msg.AddString ("nick", nick.String()); msg.AddBool ("founder", founder); msg.AddBool ("protect", protect); msg.AddBool ("op", op); msg.AddBool ("voice", voice); msg.AddBool ("helper", helper); msg.AddBool ("ignored", ignored); ++place; } if (client->fMsgr.IsValid()) client->fMsgr.SendMessage (&msg); } } return true; case RPL_MOTD: // 372 case RPL_MOTDALT: // 378 case RPL_OPERMOTDSTART: // 609 case RPL_OPERMOTD: // 610 case RPL_OPERENDOFMOTD: // 611 { BString tempString (RestOfString(data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER); } return true; case RPL_MOTDSTART: // 375 { BString tempString ("- "); tempString += B_TRANSLATE("Server Message Of the Day"); tempString += ":\n"; Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER); } return true; case RPL_ENDOFMOTD: // 376 case ERR_NOMOTD: // 422 { BString tempString (RestOfString (data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); Display (tempString.String(), C_SERVER, C_BACKGROUND, F_SERVER); if (fInitialMotd && fCmds.Length()) { BMessage msg (M_SUBMIT_INPUT); const char *place (fCmds.String()), *eol; msg.AddInt32 ("which", PASTE_MULTI_NODELAY); while ((eol = strchr (place, '\n')) != 0) { BString line; line.Append (place, eol - place); msg.AddString ("data", line.String()); ParseAutoexecChans (line); place = eol + 1; } if (*place) { // check in case this was the only line ParseAutoexecChans (BString(place)); msg.AddString ("data", place); } msg.AddInt32 ("which", 3); msg.AddBool ("autoexec", true); fMsgr.SendMessage (&msg); } BString IPCommand ("/userhost "); IPCommand += fMyNick; ParseCmd (IPCommand.String()); if (fReconnecting) { BString reString = "[@] "; reString += B_TRANSLATE("Successful reconnect"); reString += "\n"; Display (reString.String(), C_ERROR); DisplayAll (reString.String(), C_ERROR, C_BACKGROUND, F_SERVER); fMsgr.SendMessage (M_REJOIN_ALL); fReconnecting = false; } fInitialMotd = false; } return true; case RPL_USERSSTART: // 392 { // empty for now } return true; case RPL_USERS: // 393 { // empty for now } return true; case ERR_ERRONEOUSNICKNAME: // 432 case ERR_NICKNAMEINUSE: // 433 case ERR_RESOURCEUNAVAILABLE: // 437 { BString theNick (GetWord (data, 4)); if (fIsConnecting) { BString nextNick (GetNextNick()); if (nextNick != "") { BString tempString = "* "; tempString += B_TRANSLATE("Nickname \"%1\" in use or unavailable, trying \"%2\""); tempString.ReplaceFirst("%1", theNick.String()); tempString.ReplaceFirst("%2", nextNick.String()); tempString += "\n"; Display (tempString.String()); tempString = "NICK "; tempString += nextNick; SendData (tempString.String()); return true; } else { BString tempString = "* "; tempString += B_TRANSLATE("All your pre-selected nicknames are in use."); tempString += "\n"; Display (tempString.String()); tempString = "* "; tempString += B_TRANSLATE("Please type /NICK <NEWNICK> to try another."); tempString += "\n"; Display (tempString.String()); return true; } } BString tempString = "[x] "; tempString += B_TRANSLATE("Nickname/Channel \"%1\" is already in use or unavailable."); tempString.ReplaceFirst("%1", theNick); tempString += "\n"; BMessage display (M_DISPLAY); PackDisplay (&display, tempString.String(), C_NICK); PostActive (&display); } return true; case ERR_USERNOTINCHANNEL: // 441 { BString theChannel (GetWord (data, 5)), theNick (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("%1 not in %2."); tempString.ReplaceFirst("%1", theNick); tempString.ReplaceFirst("%2", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_NOTONCHANNEL: // 442 { BString theChannel (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("You're not in %1."); tempString.ReplaceFirst("%1", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_USERONCHANNEL: // 443 { BString theChannel (GetWord (data, 5)), theNick (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("%1 is already in %2."); tempString.ReplaceFirst("%1", theNick); tempString.ReplaceFirst("%2", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_KEYSET: // 467 { BString theChannel (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("Channel key already set in %1."); tempString.ReplaceFirst("%1", theChannel); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_ERROR); PostActive (&msg); } return true; case ERR_UNKNOWNMODE: // 472 { BString theMode (GetWord (data, 4)), tempString ("[x] "); tempString += B_TRANSLATE("Unknown channel mode: '%1'."); tempString.ReplaceFirst("%1", theMode); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT); PostActive (&msg); } return true; case ERR_INVITEONLYCHAN: // 473 { BString theChan (GetWord (data, 4)), tempString ("[x] "), theReason (RestOfString (data, 5)); theReason.RemoveFirst(":"); theReason.ReplaceLast("channel", theChan.String()); tempString << theReason < " "; tempString += B_TRANSLATE("(invite only)"); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER); PostActive (&msg); RemoveAutoexecChan (theChan); } return true; case ERR_BANNEDFROMCHAN: // 474 { BString theChan (GetWord (data, 4)), tempString ("[x] "), theReason (RestOfString (data, 5)); theReason.RemoveFirst(":"); theReason.ReplaceLast("channel", theChan.String()); tempString << theReason < " "; tempString += B_TRANSLATE("(you're banned)"); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER); PostActive (&msg); RemoveAutoexecChan (theChan); } return true; case ERR_BADCHANNELKEY: // 475 { BString theChan (GetWord(data, 4)), theReason (RestOfString(data, 5)), tempString("[x] "); theReason.RemoveFirst(":"); theReason.ReplaceLast("channel", theChan.String()); tempString << theReason << " "; tempString += B_TRANSLATE("(bad channel key)"); tempString += "\n"; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_QUIT, C_BACKGROUND, F_SERVER); PostActive (&msg); RemoveAutoexecChan (theChan); } return true; case ERR_UMODEUNKNOWNFLAG: // 501 { BMessage msg (M_DISPLAY); BString buffer = "[x] "; buffer += B_TRANSLATE("Unknown mode flag."); buffer += "\n"; PackDisplay (&msg, buffer.String(), C_QUIT); PostActive (&msg); } return true; // not sure what these numerics are, // but they are usually on-connect messages case RPL_290: // 290 case RPL_291: // 291 case RPL_292: // 292 { BString tempString (RestOfString(data, 4)); tempString.RemoveFirst (":"); tempString.Append ("\n"); tempString.Prepend ("- "); Display (tempString.String()); } return true; case RPL_WHOISREGISTEREDBOT: // 617 { // conflicts with RPL_DCCALLOWCHANGE BString theNick (GetWord (data, 4)), theMessage (RestOfString (data, 5)), tempString; theNick.RemoveFirst (":"); theMessage.RemoveFirst (":"); theMessage.Append ("\n"); switch (fIrcdtype) { case IRCD_ULTIMATE: { tempString += "[@] "; tempString += theMessage; BMessage msg (M_DISPLAY); PackDisplay (&msg, tempString.String(), C_WHOIS, C_BACKGROUND, F_SERVER); PostActive (&msg); } break; default: { tempString += theNick; tempString += " "; tempString += theMessage; Display (tempString.String()); } } } return true; default: break; } return false; }
void ChannelAgent::ModeEvent(BMessage* msg) { int32 modPos(0), targetPos(1); const char* mode(0), *target(0), *theNick(0); char theOperator(0); bool hit(false); // TODO Change Status to bitmask -- Too hard this way msg->FindString("mode", &mode); msg->FindString("target", &target); msg->FindString("nick", &theNick); BString buffer, targetS(target); buffer += "*** "; buffer += theNick; buffer += S_CHANNEL_SET_MODE; buffer += mode; if (targetS != "-9z99") { buffer += " "; buffer += targetS; } buffer += "\n"; BMessenger display(this); BMessage modeMsg(M_DISPLAY); PackDisplay(&modeMsg, buffer.String(), C_OP, C_BACKGROUND, F_TEXT); display.SendMessage(&modeMsg); // at least one if (mode && *mode && *(mode + 1)) theOperator = mode[modPos++]; while (theOperator && mode[modPos]) { char theModifier(mode[modPos]); if (theModifier == 'o' || theModifier == 'v' || theModifier == 'h') { BString myTarget(GetWord(target, targetPos++)); NameItem* item; int32 pos; if ((pos = FindPosition(myTarget.String())) < 0 || (item = static_cast<NameItem*>(fNamesList->ItemAt(pos))) == 0) { printf("[ERROR] Couldn't find %s in NamesView\n", myTarget.String()); return; } int32 iStatus(item->Status()); if (theOperator == '+' && theModifier == 'o') { hit = true; if ((iStatus & STATUS_OP_BIT) == 0) { item->SetStatus((iStatus & ~STATUS_NORMAL_BIT) | STATUS_OP_BIT); ++fOpsCount; buffer = ""; buffer << fOpsCount; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_OPS, buffer.String()); } } else if (theModifier == 'o') { hit = true; if ((iStatus & STATUS_OP_BIT) != 0) { iStatus &= ~STATUS_OP_BIT; if ((iStatus & STATUS_VOICE_BIT) == 0) iStatus |= STATUS_NORMAL_BIT; item->SetStatus(iStatus); --fOpsCount; buffer = ""; buffer << fOpsCount; if (!IsHidden()) vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_OPS, buffer.String()); } } if (theOperator == '+' && theModifier == 'v') { hit = true; item->SetStatus((iStatus & ~STATUS_NORMAL_BIT) | STATUS_VOICE_BIT); } else if (theModifier == 'v') { hit = true; iStatus &= ~STATUS_VOICE_BIT; if ((iStatus & STATUS_OP_BIT) == 0) iStatus |= STATUS_NORMAL_BIT; item->SetStatus(iStatus); } if (theOperator == '+' && theModifier == 'h') { hit = true; item->SetStatus((iStatus & ~STATUS_NORMAL_BIT) | STATUS_HELPER_BIT); } else if (theModifier == 'h') { hit = true; iStatus &= ~STATUS_HELPER_BIT; if ((iStatus & STATUS_HELPER_BIT) == 0) iStatus |= STATUS_NORMAL_BIT; item->SetStatus(iStatus); } } else if (theModifier == 'l' && theOperator == '-') { BString myTarget(GetWord(target, targetPos++)); UpdateMode('-', 'l'); fChanLimit = ""; } else if (theModifier == 'l') { BString myTarget(GetWord(target, targetPos++)); fChanLimitOld = fChanLimit; fChanLimit = myTarget; UpdateMode('+', 'l'); } else if (theModifier == 'k' && theOperator == '-') { UpdateMode('-', 'k'); fChanKey = ""; } else if (theModifier == 'k') { BString myTarget(GetWord(target, targetPos++)); fChanKeyOld = fChanKey; fChanKey = myTarget; UpdateMode('+', 'k'); } else if (theModifier == 'b' || theModifier == 'a' || theModifier == 'q') { // dont do anything else } else { UpdateMode(theOperator, theModifier); } ++modPos; if (mode[modPos] == '+' || mode[modPos] == '-') theOperator = mode[modPos++]; } if (hit) { fNamesList->SortItems(SortNames); fNamesList->Invalidate(); } }
bool ServerWindow::ParseEvents (const char *data) { BString firstWord = GetWord(data, 1).ToUpper(); BString secondWord = GetWord(data, 2).ToUpper(); if(firstWord == "PING") { BString tempString, theServer (GetWord(data, 2)); theServer.RemoveFirst(":"); tempString << "PONG " << myNick << " " << theServer; SendData (tempString.String()); tempString = ""; tempString << "PONG " << theServer; // fix for some noncompliant servers SendData (tempString.String()); return true; } if (secondWord == "JOIN") { BString nick (GetNick (data)); BString channel (GetWord (data, 3)); channel.RemoveFirst (":"); ClientWindow *client (Client (channel.String())); if (nick == myNick) { if (!client) { client = new ChannelWindow ( channel.String(), sid, serverName.String(), sMsgr, myNick.String()); clients.AddItem (client); client->Show(); } BString tempString ("MODE "); tempString << channel; SendData (tempString.String()); } else if (client) { // someone else BString ident (GetIdent (data)); BString address (GetAddress (data)); const char *expansions[3]; BString tempString, addy; expansions[0] = nick.String(); expansions[1] = ident.String(); expansions[2] = address.String(); tempString = ExpandKeyed (events[E_JOIN], "NIA", expansions); BMessage display (M_DISPLAY); PackDisplay ( &display, tempString.String(), &joinColor, 0, true); addy << ident << "@" << address; BMessage aMsg (M_IS_IGNORED), reply; bool ignored; aMsg.AddString ("server", serverName.String()); aMsg.AddString ("nick", nick.String()); aMsg.AddString ("address", addy.String()); be_app_messenger.SendMessage (&aMsg, &reply); reply.FindBool ("ignored", &ignored); BMessage msg (M_USER_ADD); msg.AddString ("nick", nick.String()); msg.AddBool ("ignore", ignored); msg.AddMessage ("display", &display); client->PostMessage (&msg); } return true; } if (secondWord == "PART") { BString nick (GetNick (data)); BString channel (GetWord (data, 3)); ClientWindow *client; if ((client = Client (channel.String())) != 0) { BString ident (GetIdent (data)); BString address (GetAddress (data)); const char *expansions[3]; BString buffer; expansions[0] = nick.String(); expansions[1] = ident.String(); expansions[2] = address.String(); buffer = ExpandKeyed (events[E_PART], "NIA", expansions); BMessage display (M_DISPLAY); PackDisplay (&display, buffer.String(), &joinColor, 0, true); BMessage msg (M_USER_QUIT); msg.AddString ("nick", nick.String()); msg.AddMessage ("display", &display); client->PostMessage (&msg); } return true; } if(secondWord == "PRIVMSG") { BString theNick (GetNick (data)), ident (GetIdent (data)), address (GetAddress (data)), addy; addy << ident << "@" << address; BMessage aMsg (M_IS_IGNORED), reply; bool ignored; aMsg.AddString ("server", serverName.String()); aMsg.AddString ("nick", theNick.String()); aMsg.AddString ("address", addy.String()); be_app_messenger.SendMessage (&aMsg, &reply); reply.FindBool ("ignored", &ignored); if (ignored) { BMessage msg (M_IGNORED_PRIVMSG); const char *rule; reply.FindString ("rule", &rule); msg.AddString ("nick", theNick.String()); msg.AddString ("address", addy.String()); msg.AddString ("rule", rule); Broadcast (&msg); return true; } BString theTarget (GetWord (data, 3).ToUpper()), theTargetOrig (GetWord (data, 3)), theMsg (RestOfString (data, 4)); ClientWindow *client (0); theMsg.RemoveFirst(":"); if(theMsg[0] == '\1' && GetWord(theMsg.String(), 1) != "\1ACTION") // CTCP { ParseCTCP (theNick, theTargetOrig, theMsg); return true; } if (theTarget[0] == '#') client = Client (theTarget.String()); else if (!(client = Client (theNick.String()))) { BString ident = GetIdent(data); BString address = GetAddress(data); BString addyString; addyString << ident << "@" << address; client = new MessageWindow ( theNick.String(), sid, serverName.String(), sMsgr, myNick.String(), addyString.String(), false, // not a dcc chat true); // initated by server clients.AddItem (client); client->Show(); } if (client) client->ChannelMessage ( theMsg.String(), theNick.String(), ident.String(), address.String()); return true; } if (secondWord == "NICK") { BString oldNick (GetNick (data)), ident (GetIdent (data)), address (GetAddress (data)), newNick (GetWord (data, 3)), buffer; const char *expansions[4]; newNick.RemoveFirst (":"); expansions[0] = oldNick.String(); expansions[1] = newNick.String(); expansions[2] = ident.String(); expansions[3] = address.String(); buffer = ExpandKeyed (events[E_NICK], "NnIA", expansions); BMessage display (M_DISPLAY); PackDisplay (&display, buffer.String(), &nickColor, 0, bowser_app->GetStampState()); BMessage msg (M_CHANGE_NICK); msg.AddString ("oldnick", oldNick.String()); msg.AddString ("newnick", newNick.String()); msg.AddString ("ident", ident.String()); msg.AddString ("address", address.String()); msg.AddMessage ("display", &display); Broadcast (&msg); // Gotta change the server as well! if (myNick.ICompare (oldNick) == 0) { myNick = newNick; status->SetItemValue (STATUS_NICK, newNick.String()); } bowser_app->PostMessage (&msg); // for ignores return true; } if (secondWord == "QUIT") { BString theNick (GetNick (data).String()), theRest (RestOfString (data, 3)), ident (GetIdent (data)), address (GetAddress (data)), theMsg, firstNick; const char *expansions[4]; theRest.RemoveFirst (":"); expansions[0] = theNick.String(); expansions[1] = theRest.String(); expansions[2] = ident.String(); expansions[3] = address.String(); theMsg = ExpandKeyed (events[E_QUIT], "NRIA", expansions); BMessage display (M_DISPLAY); PackDisplay (&display, theMsg.String(), &quitColor, 0, true); BMessage msg (M_USER_QUIT); msg.AddMessage ("display", &display); msg.AddString ("nick", theNick.String()); Broadcast (&msg); // see if it was our first nickname. if so, change firstNick = (const char *)lnicks->ItemAt (0); if (theNick == firstNick) { BString tempCmd ("/nick "); tempCmd << firstNick; ParseCmd (tempCmd.String()); } return true; } if (secondWord == "KICK") { BString kicker (GetNick (data)), kickee (GetWord (data, 4)), rest (RestOfString (data, 5)), channel (GetWord (data, 3)); ClientWindow *client (Client (channel.String())); rest.RemoveFirst (":"); if ((client = Client (channel.String())) != 0 && kickee == myNick) { BMessage display (M_DISPLAY); // "you were kicked" BString buffer; buffer << "*** You have been kicked from " << channel << " by " << kicker << " (" << rest << ")\n"; PackDisplay (&display, buffer.String(), &quitColor, 0, true); BMessage display2 (M_DISPLAY); // "attempting auto rejoin" buffer = "*** Attempting to automagically rejoin "; buffer << channel << "...\n"; PackDisplay (&display2, buffer.String(), &quitColor, 0, true); BMessage msg (M_CHANNEL_GOT_KICKED); msg.AddString ("channel", channel.String()); msg.AddMessage ("display", &display); // "you were kicked" msg.AddMessage ("display2", &display2); // "attempting auto rejoin" client->PostMessage (&msg); } if (client && kickee != myNick) { BMessage display (M_DISPLAY); const char *expansions[4]; BString buffer; expansions[0] = kickee.String(); expansions[1] = channel.String(); expansions[2] = kicker.String(); expansions[3] = rest.String(); buffer = ExpandKeyed (events[E_KICK], "NCnR", expansions); PackDisplay (&display, buffer.String(), &quitColor, 0, true); BMessage msg (M_USER_QUIT); msg.AddString ("nick", kickee.String()); msg.AddMessage ("display", &display); client->PostMessage (&msg); } return true; } if(secondWord == "TOPIC") { BString theNick (GetNick (data)), theChannel (GetWord (data, 3)), theTopic (RestOfString (data, 4)); ClientWindow *client (Client (theChannel.String())); theTopic.RemoveFirst (":"); if (client && client->Lock()) { BString ident (GetIdent (data)); BString address (GetAddress (data)); const char *expansions[5]; BString buffer; expansions[0] = theNick.String(); expansions[1] = theTopic.String(); expansions[2] = client->Id().String(); expansions[3] = ident.String(); expansions[4] = address.String(); if(bowser_app->GetShowTopicState()) { buffer << client->Id() << " : " << theTopic; client->SetTitle (buffer.String()); client->Unlock(); } else { buffer << client->Id(); client->SetTitle (buffer.String()); client->Unlock(); } BMessage topic (M_CHANNEL_TOPIC); topic.AddString("topic", theTopic.String()); BMessage display (M_DISPLAY); buffer = ExpandKeyed (events[E_TOPIC], "NTCIA", expansions); PackDisplay (&display, buffer.String(), &whoisColor, 0, true); topic.AddMessage("display", &display); client->PostMessage (&topic); } return true; } if (secondWord == "MODE") { BString theNick (GetNick (data)), theChannel (GetWord (data, 3)), theMode (GetWord (data, 4)), theTarget (RestOfString (data, 5)); ClientWindow *client (Client (theChannel.String())); if (client) { BMessage msg (M_CHANNEL_MODE); msg.AddString("nick", theNick.String()); msg.AddString("mode", theMode.String()); msg.AddString("target", theTarget.String()); client->PostMessage (&msg); } else { BMessage msg (M_DISPLAY); BString buffer; theMode.RemoveFirst(":"); buffer << "*** User mode changed: " << theMode << "\n"; PackDisplay (&msg, buffer.String(), 0, 0, true); PostActive (&msg); } return true; } if(firstWord == "NOTICE") // _server_ notice { BString theNotice (RestOfString(data, 3)); const char *expansions[1]; theNotice.RemoveFirst(":"); expansions[0] = theNotice.String(); theNotice = ExpandKeyed (events[E_SNOTICE], "R", expansions); Display (theNotice.String(), 0, 0, true); return true; } if (firstWord == "ERROR") // server error (on connect?) { BString theError (RestOfString (data, 2)); theError.RemoveAll (":"); theError.Append ("\n"); Display (theError.String(), &quitColor); isConnecting = false; return true; } if(secondWord == "NOTICE") // _user_ notice { BString theNick (GetNick (data)), ident (GetIdent (data)), address (GetAddress (data)), addy; addy << theNick << "@" << address; BMessage aMsg (M_IS_IGNORED), reply; bool ignored; aMsg.AddString ("server", serverName.String()); aMsg.AddString ("nick", theNick.String()); aMsg.AddString ("address", addy.String()); be_app_messenger.SendMessage (&aMsg, &reply); reply.FindBool ("ignored", &ignored); if (ignored) return true; BString theNotice = RestOfString(data, 4); theNotice.RemoveFirst(":"); if(theNotice[0] == '\1') { ParseCTCPResponse(theNick, theNotice); return true; } const char *expansions[4]; BString tempString; expansions[0] = theNick.String(); expansions[1] = theNotice.String(); expansions[2] = ident.String(); expansions[3] = address.String(); tempString = ExpandKeyed (events[E_UNOTICE], "NRIA", expansions); BMessage display (M_DISPLAY); PackDisplay (&display, tempString.String(), ¬iceColor, 0, true); PostActive (&display); return true; } return ParseENums (data, secondWord.String()); }