Пример #1
0
void ChatBox::sendMessage(const QString &msg)
{
	if(msg.at(0) == '/') {
		// Special commands

		int split = msg.indexOf(' ');
		if(split<0)
			split = msg.length();

		QString cmd = msg.mid(1, split-1).toLower();
		QString params = msg.mid(split).trimmed();

		if(cmd == "clear") {
			// client side command: clear chat window
			clear();

		} else if(cmd.at(0)=='!') {
			// public announcement
			emit message(msg.mid(2), true, false);

		} else if(cmd == "me") {
			if(!params.isEmpty())
				emit message(msg.mid(msg.indexOf(' ')+1), false, true);

		} else if(cmd == "roll") {
			if(params.isEmpty())
				params = "1d6";

			utils::DiceRoll result = utils::diceRoll(params);
			if(result.number>0)
				emit message("rolls " + result.toString(), false, true);
			else
				systemMessage(tr("Invalid dice roll description: %1").arg(params));

#ifndef NDEBUG
		} else if(cmd == "rolltest") {
			if(params.isEmpty())
				params = "1d6";

			QList<float> d = utils::diceRollDistribution(params);
			QString msg(params + "\n");
			for(int i=0;i<d.size();++i)
				msg += QStringLiteral("%1: %2\n").arg(i+1).arg(d.at(i) * 100);
			systemMessage(msg);
#endif
		} else {
			// operator commands
			if(!params.isEmpty())
				params.prepend(' ');
			emit opCommand(cmd + params);
		}

	} else {
		// A normal chat message
		emit message(msg, false, false);
	}
}
Пример #2
0
void ServerLogDialog::redoSelected()
{
	auto user = selectedUserId();
	if(user)
		emit opCommand(protocol::MessagePtr(new protocol::Undo(0, user, true)));
}
Пример #3
0
void ServerLogDialog::banSelected()
{
	auto user = selectedUserId();
	if(user)
		emit opCommand(net::command::kick(user, true));
}