예제 #1
0
void Client::setPlayerProperty(const QJsonValue &cmd){
	QJsonArray texts = cmd.toArray();

	bool self = texts.at(0).toBool();

	if(self){
		//client it Self
		if(Self){
			QString property = texts.at(1).toString();
			QVariant value = texts.at(2).toVariant();
			Self->setProperty(property.toLatin1().data(), value);
		}
	}else{
		//others
		QString object_name = texts.at(1).toString();
		QString property = texts.at(2).toString();
		QVariant value = texts.at(3).toVariant();
		ClientPlayer *player = getPlayer(object_name);
		if(player){
			player->setProperty(property.toLatin1().data(), value);
		}else{
			QMessageBox::warning(NULL, tr("Warning"), tr("There is no player named %1").arg(object_name));
		}
	}
}
예제 #2
0
void Client::gameOver(const QJsonValue &argdata){
	if(!argdata.isArray()) return;
	QJsonArray arg = argdata.toArray();
	is_game_over = true;
	setStatus(Client::NotActive);
	QString winner = arg[0].toString();
	QStringList roles;
	BP::tryParse(arg[1], roles);

	Q_ASSERT(roles.length() == players.length());

	for(int i = 0; i < roles.length(); i++){
		QString name = players.at(i)->objectName();
		getPlayer(name)->setRole(roles.at(i));
	}

	if(winner == "."){
		emit standoff();
		return;
	}

	QSet<QString> winners = winner.split("+").toSet();
	foreach(const ClientPlayer *player, players){
		QString role = player->getRole();
		bool win = winners.contains(player->objectName()) || winners.contains(role);

		ClientPlayer *p = const_cast<ClientPlayer *>(player);
		p->setProperty("win", win);
	}
예제 #3
0
void Client::processReply(char *reply){
    if(strlen(reply) <= 2)
        return;

    static char self_prefix = '.';
    static char other_prefix = '#';

    if(reply[0] == self_prefix){
        // client it Self
        if(Self){
            buffer_t property, value;
            sscanf(reply, ".%s %s", property, value);
            Self->setProperty(property, value);
        }
    }else if(reply[0] == other_prefix){
        // others
        buffer_t object_name, property, value;
        sscanf(reply, "#%s %s %s", object_name, property, value);
        ClientPlayer *player = getPlayer(object_name);
        if(player){
            player->setProperty(property, value);
        }else
            QMessageBox::warning(NULL, tr("Warning"), tr("There is no player named %1").arg(object_name));

    }else{
        // invoke methods
        buffer_t method_name, arg;
        sscanf(reply, "%s %s", method_name, arg);
        QString method = method_name;

        if(replayer && (method.startsWith("askFor") || method.startsWith("do") || method == "activate"))
            return;

        static QSet<QString> deprecated;
        if(deprecated.isEmpty()){
            deprecated << "increaseSlashCount" // replaced by addHistory
                    << "addProhibitSkill"; // add all prohibit skill at game start
        }

        Callback callback = callbacks.value(method, NULL);
        if(callback){
            QString arg_str = arg;
            (this->*callback)(arg_str);
        }else if(!deprecated.contains(method))
            QMessageBox::information(NULL, tr("Warning"), tr("No such invokable method named \"%1\"").arg(method_name));
    }
}
예제 #4
0
void Client::addPlayer(const QString &player_info){
    QStringList texts = player_info.split(":");
    QString name = texts.at(0);
    QString base64 = texts.at(1);
    QByteArray data = QByteArray::fromBase64(base64.toAscii());
    QString screen_name = QString::fromUtf8(data);
    QString avatar = texts.at(2);

    ClientPlayer *player = new ClientPlayer(this);
    player->setObjectName(name);
    player->setScreenName(screen_name);
    player->setProperty("avatar", avatar);

    alive_count ++;

    emit player_added(player);
}
예제 #5
0
void Client::addPlayer(const QJsonValue &player_info){
	QJsonArray texts = player_info.toArray();
	QString name = texts.at(0).toString();
	QString screen_name = texts.at(1).toString();
	QString avatar = texts.at(2).toString();

	ClientPlayer *player = new ClientPlayer(this);
	player->setObjectName(name);
	player->setScreenName(screen_name);
	player->setProperty("avatar", avatar);

	players << player;

	alive_count++;

	emit player_added(player);
}
예제 #6
0
void Client::processReply(char *reply){
    if(strlen(reply) <= 2)
        return;

    static char self_prefix = '.';
    static char other_prefix = '#';

    if(reply[0] == self_prefix){
        // client it Self
        if(Self){
            buffer_t property, value;
            sscanf(reply, ".%s %s", property, value);
            Self->setProperty(property, value);
        }
    }else if(reply[0] == other_prefix){
        // others
        buffer_t object_name, property, value;
        sscanf(reply, "#%s %s %s", object_name, property, value);
        ClientPlayer *player = getPlayer(object_name);
        if(player){
            bool declared = player->setProperty(property, value);
            if(!declared){
                QMessageBox::warning(NULL, tr("Warning"), tr("There is no such property named %1").arg(property));
            }
        }else
            QMessageBox::warning(NULL, tr("Warning"), tr("There is no player named %1").arg(object_name));

    }else{
        // invoke methods
        buffer_t method_name, arg;
        sscanf(reply, "%s %s", method_name, arg);
        Callback callback = callbacks.value(method_name, NULL);

        QString method = method_name;
        if(replayer && (method.startsWith("askFor") || method.startsWith("do") || method == "activate"))
            return;

        if(callback){
            QString arg_str = arg;
            (this->*callback)(arg_str);
        }else
            QMessageBox::information(NULL, tr("Warning"), tr("No such invokable method named \"%1\"").arg(method_name));
    }
}