Exemplo n.º 1
0
void MainWindow::connect_accept(QString port, QString ip, QString username)
{
    std::string i;
    int         p;

    i = ip.toUtf8().constData();
    p = port.toInt();

    if (username.contains(" "))
    {
        QMessageBox::information(this, QString("Invalid Username"), QString("Spaces are not allowed in username"));
        return;
    }

    #ifdef DEBUG
        username = "******";
        p = 9900;
        i = "127.0.0.1";
    #endif

    if (client_->connectClient(p, i))
    {
        mDialog.close();
        this->hide();
        PickYourShip shipDialog;
        connect(&shipDialog, SIGNAL(shipChosen(QString)), this, SLOT(assignShip(QString)));
        shipDialog.exec();

        Message msg;
        msg.setID(0);
        msg.setType(Message::CONNECTION);
        msg.setData(username.toStdString());

        client_->write(&msg);

        GameWindow *gameWindow = new GameWindow();
        gameWindow->setFocus();
        gameWindow->start();
    }
    else
    {
        QMessageBox::information(this, QString("Connection Error"), QString("Unable to connect to server. Please check your connection settings."));
    }
}
Exemplo n.º 2
0
void ChatDlg::doChat()
{
    Client * client = Client::getInstance();
    std::string sText;

    // This is where we will need to send a Message to server of
    // type CHAT
    GameWindow *p = (GameWindow *) this->parent();
    p->setChatting(false);
    ui->lineEdit_input->setVisible(false);

    sText = "[" + p->getUsername().toStdString() + "] " + ui->lineEdit_input->text().toStdString();
    msg_->setData(sText);
    this->clearFocus();
    p->setFocus();

    client->write(msg_);
    ui->lineEdit_input->clear();
    //this->close();

}