Exemplo n.º 1
0
bool ChannelAgent::RemoveUser(const char* data)
{
	ASSERT(data != NULL);
	/*
	 * Function purpose: Remove nickname {data} from the ChannelAgent's
	 *                   NamesView and update the status counts
	 */

	if (fNamesList == NULL) return false;

	// if nickname is present in tab completion lists, remove
	RemoveNickFromList(fRecentNicks, data);
	RemoveNickFromList(fCompletionNicks, data);

	int32 myIndex(FindPosition(data));

	if (myIndex >= 0) {
		NameItem* item;

		fNamesList->Deselect(myIndex);
		if ((item = static_cast<NameItem*>(fNamesList->RemoveItem(myIndex))) != NULL) {
			BString buffer;

			if ((item->Status() & STATUS_OP_BIT) != 0) {
				--fOpsCount;
				buffer << fOpsCount;

				if (!IsHidden())
					vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_OPS,
																		  buffer.String());

				buffer = "";
			}

			--fUserCount;
			buffer << fUserCount;
			if (!IsHidden())
				vision_app->pClientWin()->pStatusView()->SetItemValue(STATUS_USERS,
																	  buffer.String());

			delete item;
			return true;
		}
	}

	return false;
}
Exemplo n.º 2
0
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();
	}
}