Пример #1
0
void MainWindow::checkVersion(const QString &server_version){
    Client *client = qobject_cast<Client *>(sender());
    QString client_version = Sanguosha->getVersion();

    if(server_version == client_version){
        client->signup();
        connect(client, SIGNAL(server_connected()), SLOT(enterRoom()));

        if(qApp->arguments().contains("-hall")){
            HallDialog *dialog = HallDialog::GetInstance(this);
            connect(client, SIGNAL(server_connected()), dialog, SLOT(accept()));
        }

        return;
    }

    client->disconnectFromHost();

    static QString link = "http://github.com/Moligaloo/QSanguosha/downloads";
    QString text = tr("Server version is %1, client version is %2 <br/>").arg(server_version).arg(client_version);
    if(server_version > client_version)
        text.append(tr("Your client version is older than the server's, please update it <br/>"));
    else
        text.append(tr("The server version is older than your client version, please ask the server to update<br/>"));

    text.append(tr("Download link : <a href='%1'>%1</a> <br/>").arg(link));
    QMessageBox::warning(this, tr("Warning"), text);
}
Пример #2
0
void MainWindow::checkVersion(const QString &server_version, const QString &server_mod){
	QString client_mod = Bang->getMODName();
	if(client_mod != server_mod){
		QMessageBox::warning(this, tr("Warning"), tr("Client MOD name is not same as the server!"));
		return;
	}

	Client *client = qobject_cast<Client *>(sender());
	QString client_version = Bang->getVersionNumber();

	if(server_version == client_version){
		client->signup();
		connect(client, SIGNAL(server_connected()), SLOT(enterRoom()));

		if(qApp->arguments().contains("-hall")){
			HallDialog *dialog = HallDialog::GetInstance(this);
			connect(client, SIGNAL(server_connected()), dialog, SLOT(accept()));
		}

		return;
	}

	client->disconnectFromHost();

	static QString link = "http://code.google.com/p/onepiecebang/downloads/list";
	QString text = tr("Server version is %1, client version is %2 <br/>").arg(server_version).arg(client_version);
	if(server_version > client_version)
		text.append(tr("Your client version is older than the server's, please update it <br/>"));
	else
		text.append(tr("The server version is older than your client version, please ask the server to update<br/>"));

	text.append(tr("Download link : <a href='%1'>%1</a> <br/>").arg(link));
	QMessageBox::warning(this, tr("Warning"), text);
}
Пример #3
0
void MainWindow::checkVersion(const QString &server_version, const QString &server_mod)
{
    QString client_mod = Sanguosha->getMODName();
    if (client_mod != server_mod) {
        QMessageBox::warning(this, tr("Warning"), tr("Client MOD name is not same as the server!"));
        return;
    }

    Client *client = qobject_cast<Client *>(sender());
    QString client_version = Sanguosha->getVersionNumber();

    if (server_version == client_version) {
        client->signup();
        connect(client, SIGNAL(server_connected()), SLOT(enterRoom()));
        return;
    }

    client->disconnectFromHost();

    static QString link = "http://github.com/Mogara/QSanguosha-v2";
    QString text = tr("Server version is %1, client version is %2 <br/>").arg(server_version).arg(client_version);
    if (server_version > client_version)
        text.append(tr("Your client version is older than the server's, please update it <br/>"));
    else
        text.append(tr("The server version is older than your client version, please ask the server to update<br/>"));

    text.append(tr("Download link : <a href='%1'>%1</a> <br/>").arg(link));
    QMessageBox::warning(this, tr("Warning"), text);
}
Пример #4
0
void MainWindow::on_actionReplay_triggered()
{
	QString location = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
	QString last_dir = Config.value("LastReplayDir").toString();
	if(!last_dir.isEmpty())
		location = last_dir;

	QString filename = QFileDialog::getOpenFileName(this,
													tr("Select a reply file"),
													location,
													tr("Pure text replay file (*.txt);; Image replay file (*.png)"));

	if(filename.isEmpty())
		return;

	QFileInfo file_info(filename);
	last_dir = file_info.absoluteDir().path();
	Config.setValue("LastReplayDir", last_dir);

	Client *client = new Client(this, filename);

	connect(client, SIGNAL(server_connected()), SLOT(enterRoom()));

	client->signup();
}
Пример #5
0
void Client::setup(const QString &setup_str){
    if(socket && !socket->isConnected())
        return;

    QRegExp rx("(\\d+):(\\d+):([+\\w]*):([F]*)");
    if(!rx.exactMatch(setup_str))
        return;

    QStringList texts = rx.capturedTexts();
    int player_count = texts.at(1).toInt();
    int timeout = texts.at(2).toInt();
    ban_packages = texts.at(3).split("+");
    QString flags = texts.at(4);

    Config.PlayerCount = player_count;
    if(timeout == 0)
        Config.OperationNoLimit = true;
    else{
        Config.OperationNoLimit = false;
        Config.OperationTimeout = timeout;
    }

    Config.FreeChoose = flags.contains("F");

    emit server_connected();
}
void MainWindow::on_actionReplay_triggered() {
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QString location = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
#else
    QString location = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
#endif
    QString last_dir = Config.value("LastReplayDir").toString();
    if (!last_dir.isEmpty())
        location = last_dir;

    QString filename = QFileDialog::getOpenFileName(this,
        tr("Select a reply file"),
        location,
        tr("QSanguosha Replay File(*.qsgs);; Image replay file (*.png)"));

    if (filename.isEmpty())
        return;

    QFileInfo file_info(filename);
    last_dir = file_info.absoluteDir().path();
    Config.setValue("LastReplayDir", last_dir);

    Client *client = new Client(this, filename);
    connect(client, SIGNAL(server_connected()), SLOT(enterRoom()));
    client->signup();
}
Пример #7
0
void Client::setup(const QString &setup_str){
    if(socket && !socket->isConnected())
        return;

    ServerInfo.parse(setup_str);
    emit server_connected();
}
Пример #8
0
void MainWindow::startConnection(){
    Client *client = new Client(this);

    connect(client, SIGNAL(error_message(QString)), SLOT(networkError(QString)));
    connect(client, SIGNAL(server_connected()), SLOT(enterRoom()));

    //client->signup();
}
Пример #9
0
void Client::setup(const QString &setup_str){
    if(socket && !socket->isConnected())
        return;

    if(ServerInfo.parse(setup_str)){
        signup();
        emit server_connected();
    }else{
        QMessageBox::warning(NULL, tr("Warning"), tr("Setup string can not be parsed: %1").arg(setup_str));
    }
}
Пример #10
0
void Client::setup(const QJsonValue &setup){
	if(socket && !socket->isConnected())
		return;

	QString setup_str = setup.toString();
	if(ServerInfo.parse(setup_str)){
		emit server_connected();
		notifyServer(BP::ToggleReady);
	}else{
		QMessageBox::warning(NULL, tr("Warning"), tr("Setup string can not be parsed: %1").arg(setup_str));
	}
}
Пример #11
0
void DnDController::comm_proto_resp (DnDClient*, quint16 major, quint16 minor)
{
  if (major != COMM_PROTO_MAJOR || minor != COMM_PROTO_MINOR) {
    server_message ("Incompatible communication protocol with server",
                    MESSAGE_ERROR, true);
    disconnect ();

    return;
  }

  server_connected ();
  _client->user_add_req (_name);
}
Пример #12
0
// --------------------------------------------------------------------------
//
// Function
//      Name:  void BBSInterfacePoolThread::run()
//      Purpose: Thread execution function
//      Created: 31/1/08
//
// ------------------
void BBSInterfacePoolThread::run()
{
    qDebug() << "BBSInterfacePoolThread::run: Begin";
    int oldvalue=-1,value;
    bool oldconnected=false,connected;
    BBSInterface::BBSStatus currentstatus=BBSInterface::BBSS_UNKNOWN,prevstatus=BBSInterface::BBSS_UNKNOWN;
    while(true)
    {
        try 
        {
            currentstatus = bbsi->check_status();
        }
        catch(BoxException & e)
        {
            qDebug() << "BBSInterfacePoolThread::run: Captured exception";
            currentstatus = BBSInterface::BBSS_UNKNOWN;
        }
        switch(currentstatus)
        {
            case BBSInterface::BBSS_AVAILABLE: 
                value=get_account_usage();
                connected = true;
                break;
            case BBSInterface::BBSS_UNAVAILABLE:
                value=-1;
                connected = false;
                break;
            case BBSInterface::BBSS_UNKNOWN:
                value=-1;
                connected = false;
                break;
        }
        if (value!=oldvalue){
            emit server_usage_changed(value);
            oldvalue=value;
        }
        if (currentstatus!=prevstatus){
            emit server_status_changed(currentstatus);
            prevstatus = currentstatus;
        }
        if (connected!=oldconnected){
            emit server_connected(connected);
            oldconnected=connected;
        }
        sleep(60);
    }
}
Пример #13
0
void MainWindow::on_actionReplay_triggered()
{
    QString location = QDesktopServices::storageLocation(QDesktopServices::HomeLocation);
    QString filename = QFileDialog::getOpenFileName(this,
                                                    tr("Select a reply file"),
                                                    location,
                                                    tr("Replay file (*.txt)"));

    if(filename.isEmpty())
        return;

    Client *client = new Client(this, filename);

    connect(client, SIGNAL(server_connected()), SLOT(enterRoom()));

    client->signup();
}
Пример #14
0
struct msg *
req_send_next(struct context *ctx, struct conn *conn)
{
    rstatus_t status;
    struct msg *msg, *nmsg; /* current and next message */

    ASSERT((!conn->client && !conn->proxy) || (!conn->dnode_client && !conn->dnode_server));

    if (conn->connecting) {
        if (!conn->dyn_mode && !conn->client) {
           server_connected(ctx, conn);
        } else if (conn->dyn_mode && !conn->dnode_client) {
           dnode_peer_connected(ctx, conn);
        }
    }

    nmsg = TAILQ_FIRST(&conn->imsg_q);
    if (nmsg == NULL) {
        /* nothing to send as the server inq is empty */
        status = event_del_out(ctx->evb, conn);
        if (status != DN_OK) {
            conn->err = errno;
        }

        return NULL;
    }

    msg = conn->smsg;
    if (msg != NULL) {
        ASSERT(msg->request && !msg->done);
        nmsg = TAILQ_NEXT(msg, s_tqe);
    }

    conn->smsg = nmsg;

    if (nmsg == NULL) {
        return NULL;
    }

    ASSERT(nmsg->request && !nmsg->done);

    log_debug(LOG_VVERB, "send next req %"PRIu64" len %"PRIu32" type %d on "
              "s %d", nmsg->id, nmsg->mlen, nmsg->type, conn->sd);

    return nmsg;
}
Пример #15
0
//接收的客户端msg信息通过req_server_enqueue_imsgq添加到该队列 在req_send_next中发往后端真实服务器
//从imsg_q队列中取出msg然后发往后端真实服务器
struct msg *   //发往客户端用rsp_send_next 发往后端服务器用req_send_next    msg_send或者msg_send_chain中执行
req_send_next(struct context *ctx, struct conn *conn) //从imsg_q队列中取出需要发往后端的msg
{//从队列imsg_q中取出msg发送  //msg_send中执行        msg_send或者msg_send_chain中执行
    rstatus_t status;
    struct msg *msg, *nmsg; /* current and next message */

    ASSERT(!conn->client && !conn->proxy);

    if (conn->connecting) { //走到这里说明在server_connect中建立连接,添加写事件后,触发走到这里,说明连接建立成功了
        server_connected(ctx, conn);
    }

    nmsg = TAILQ_FIRST(&conn->imsg_q);
    if (nmsg == NULL) { //说明已经写数据完成,把imsg_q队列上的所有msg信息已经发送完毕
        /* nothing to send as the server inq is empty */
        status = event_del_out(ctx->evb, conn); //没有数据需要发往后端了,去除写事件
        if (status != NC_OK) {
            conn->err = errno;
        }

        return NULL;
    }

    msg = conn->smsg;
    if (msg != NULL) { 
    //如果上次还有未发送的msg,则取出来返回。也就是如果conn->smsg上面有还有未发送出去的数据,则从该smsg取出一个msg发送,否则从imsg_q队列上面取出来发送
        ASSERT(msg->request && !msg->done);
        nmsg = TAILQ_NEXT(msg, s_tqe);  //指向imsg_q的下一个msg
    }

    conn->smsg = nmsg; //需要发送往后端真实服务器的真实msg全部保存到conn->smsg中

    if (nmsg == NULL) {
        return NULL;
    }

    ASSERT(nmsg->request && !nmsg->done);

    log_debug(LOG_VVERB, "send next req %"PRIu64" len %"PRIu32" type %d on "
              "s %d", nmsg->id, nmsg->mlen, nmsg->type, conn->sd);

    return nmsg;
}
Пример #16
0
//= Net finished
void ServerCall::on_net_finished(){

	emit server_connected(true);
	QScriptValue sc;
	//qDebug() << server_string;
	sc = scriptEngine.evaluate("(" + QString(server_string) + ")"); //?? why ?? In new versions it may need to look like engine.evaluate("(" + QString(result) + ")");

	QHash<QString, QString> hash;
	if (sc.property("nodes").isArray())
	{
			QScriptValueIterator it(sc.property("nodes"));
			 while (it.hasNext()) {
				 it.next();
				 //qDebug("Nick %s",it.value().property("node").toString().toStdString().c_str());
				 //qDebug() << " > emit() " << it.value().property("node").toString() << it.value().property("value").toString();
				 emit node_val(it.value().property("node").toString(), it.value().property("value").toString());
				 hash[ it.value().property("node").toString() ] = it.value().property("value").toString();
			 }
	}
	//emit node_vals(hash);
	in_request = false;
	check_q();
}
Пример #17
0
//= Error
void ServerCall::on_net_error(QNetworkReply::NetworkError err){
	qDebug() << "net Error";
	emit server_connected(false);
}