Beispiel #1
0
void DBConsole::swap() {
	//## SHOW FPS #####
	write("FPS: " + std::to_string((int)getFPS()), BUFFER_W - 10, 0);

	//## FPS #####

	long delta = getCurrentTimeMillis() - lastRenderTime;

	if (FPS_LIMITER > 0) {
		while (delta < (1000.0 / (FPS_LIMITER + 3))) {
			delta = getCurrentTimeMillis() - lastRenderTime;
			doSystemSleep(0);
		}
	}

	fpsSum += delta;
	lastRenderTime = getCurrentTimeMillis();
	fpsCount++;
	if (fpsSum > 1000) {
		fps = 1 / (fpsSum / (fpsCount * 1000.0));
		fpsSum = fpsCount = 0;
	}

	//## SWAPPING #####
	for (int x = 0; x < BUFFER_W; x++) {
		for (int y = 0; y < BUFFER_H; y++) {
			if (buffer[x][y] != display[x][y]) {
				writeToConsole(buffer[x][y], x, y);
				display[x][y] = buffer[x][y];
			}
		}
	}
}
Beispiel #2
0
void Database::updatePlayer(Player *player)
{
    if (!isConnected())
        init();

    if (!m_isConnected)
        return;

    PreparedStatement *statement = 0;

    try
    {
        statement = m_database->prepareStatement("UPDATE accounts SET kills = ?, deaths = ? WHERE id = ?");
        statement->setInt(1, player->kills());
        statement->setInt(2, player->deaths());
        statement->setInt(3, player->userId());

        statement->executeQuery();
    }
    catch (SQLException &e)
    {
        emit writeToConsole("Query failed(updatePlayer): " + QLatin1String(e.getSQLStateCStr()));
    }

    delete statement;
}
Beispiel #3
0
bool Database::init()
{
    Driver* driver = get_driver_instance();

    QString loginServerUrl = m_settings.value("loginServerUrl", DefaultSettings::loginServerUrl()).toString();
    QString serverUserName = m_settings.value("serverUserName").toString();
    QString serverPassword = m_settings.value("serverPassword").toString();

    try
    {
        m_database = driver->connect(loginServerUrl.toLatin1().data(),
                                     serverUserName.toLatin1().data(),
                                     serverPassword.toLatin1().data());
        m_database->setSchema("tis");
    }
    catch (SQLException &e)
    {
        emit writeToConsole("DB connect failed: "  + QLatin1String(e.getSQLStateCStr()));
        return false;
    }

    m_isConnected = true;

    return true;
}
Beispiel #4
0
void Database::updatePlayerCount(int count)
{
    if (!isConnected())
        init();

    if (!m_isConnected)
        return;

    PreparedStatement *statement = 0;

    try
    {
        statement = m_database->prepareStatement("UPDATE servers SET connectedPlayers = ? WHERE id = ?");
        statement->setInt(1, count);
        statement->setString(2, m_serverID.toStdString());

        statement->executeQuery();
    }
    catch (SQLException &e)
    {
        emit writeToConsole("Query failed(updatePlayerCount): " + QLatin1String(e.getSQLStateCStr()));
    }

    delete statement;
}
Beispiel #5
0
void Error_stream::flush () {
	if (console) {
		std::cerr.flush();
	}
	else {
		writeToConsole(buf.str());
		buf.str(std::string());
	}
}
Beispiel #6
0
	// IMPORTANT: The two places this function is called from wrap the code in the tag critical section (m_pTagCriticalSection), 
	// so that makes this call thread safe.  If you call this from anywhere else, make sure you wrap it in that critical section.
	//------------------------------------------------------------------------------------------------------------------------------------
	void LogMgr::outputFinalBufferToLogs(const std::string& finalBuffer, const std::string& tag, unsigned char flags)
	{
		if ((flags && LOGFLAG_WRITE_TO_LOG_FILE) > 0)
			writeToLogFile(finalBuffer);
		if ((flags && LOGFLAG_WRITE_TO_DEBUGGER) > 0)
			::OutputDebugStringA(finalBuffer.c_str());
		if ((flags && LOGFLAG_WRITE_TO_CONSOLE) > 0)
			writeToConsole(tag, finalBuffer);
	}
/**
	request HTML finished
	\sa checkForUpdateOfQtSmbstatus
 */
void MainWindows::requestHtmlFinished (  bool error ) {
	debugQt("MainWindows::requestHtmlFinished ()");
	if (!error) {
		bool ok;
		uint available_release=QString(http->readAll()).simplified().toUInt (&ok);
		if (ok) {
			debugQt("Available release: "+QString::number(available_release));
			QSettings settings;
			settings.beginGroup("/Configuration");
			uint last_known_release=settings.value("lastKnownRelease",int_qtsmbstatus_version).toUInt();
			settings.setValue("lastKnownRelease",available_release);
			settings.setValue("dateTimeForlastCheck",QDateTime::currentDateTime());
			if (available_release>last_known_release && available_release>int_qtsmbstatus_version)
			{
				debugQt("A new release is available :-)");
				// New version available
				QDialog * dialog= new QDialog(this);
				dialog->setAttribute(Qt::WA_DeleteOnClose);
				QDialogButtonBox * dialogButton=new QDialogButtonBox ( QDialogButtonBox::Ok, Qt::Horizontal,dialog);
				dialog->setWindowTitle ( tr("Update is available"));
				QGridLayout *layout = new QGridLayout(dialog);
				QLabel * label= new QLabel("<p align='center'>"+
						tr("A new release of %1 is available").arg("qtsmbstatus")+
						".</p><p align='center'>"+
						tr("You can download it here: %1").arg("<br>"+web_qtsmbstatus)+
						"</p><hr>",dialog);
				label->setTextFormat (Qt::RichText);
				label->setTextInteractionFlags (Qt::LinksAccessibleByMouse);
				label->setOpenExternalLinks (true);
				QLabel * labelPixmap= new QLabel(dialog);
				labelPixmap->setPixmap(qApp->windowIcon().pixmap(QSize (32,32)) );
				layout->addWidget(labelPixmap, 0, 0, 5, 1);
				layout->addWidget(label, 0, 1, 5, 1);
				layout->addWidget(dialogButton, 6, 0, 1, 2, Qt::AlignHCenter);
				dialog->setLayout(layout);
				connect(dialogButton,SIGNAL(accepted ()),dialog,SLOT(accept()));
				dialog->show();
			} else debugQt("No new release");
			settings.endGroup();
		} else writeToConsole("impossible to convert release number");
	} else writeToConsole("impossible to check for update");
	http->deleteLater();
}
Beispiel #8
0
void Database::establishServer()
{
    if (!isConnected())
        init();

    if (!m_isConnected)
        return;

    if(m_isConnected)
    {
        PreparedStatement *prep_stmt = 0;
        Statement *stmt= 0;
        ResultSet *res = 0;
        QString IP;

        stmt = m_database->createStatement();

        try
        {
            QString qry = QString("SELECT USER( ) AS a");

            res = stmt->executeQuery(qry.toStdString());

            if (res -> rowsCount() != 0)
            {
                while (res->next())
                {
                    IP =  QString(res->getString("a").c_str());
                }
            }

            m_serverID = Crypto::sessionId(IP).toHex();
            prep_stmt = m_database->prepareStatement("INSERT INTO servers(id, serverName, maxPlayers, connectedPlayers, ipAddr) VALUES (?, ?, ?, ?, ?)");

            prep_stmt->setString(1, m_serverID.toStdString());
            prep_stmt->setString(2, m_settings.value("serverName", DefaultSettings::serverName()).toString().toStdString());
            prep_stmt->setInt(3, m_settings.value("maxPlayers", DefaultSettings::maxPlayers()).toInt());
            prep_stmt->setInt(4, 0);
            prep_stmt->setString(5, m_settings.value("serverIP", "127.0.0.1").toString().toStdString());

            prep_stmt->executeUpdate();
        }
        catch (SQLException &e)
        {
            emit writeToConsole("Query failed(establishServer): " + QLatin1String(e.getSQLStateCStr()));
        }

        delete prep_stmt;
        delete stmt;
        delete res;
    }
}
Beispiel #9
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiaDefaultConsoleLogger::writeMessageToConsole(const char* prefix, const char* message)
{
    std::ostringstream oss;

//    VF_ASSERT(prefix);
    oss << prefix;

    if (message)
    {
        oss << message << std::endl;
    }
    else
    {
        oss << "<no message>" << std::endl;
    }

    writeToConsole(oss.str());
}
Beispiel #10
0
Player *Database::authenticateUser(const QString &user, const QString &password)
{
    if (!isConnected())
        init();

    if (!m_isConnected)
        return 0;

    Player *player = 0;

    Statement *stmt = 0;
    ResultSet *res = 0;

    stmt = m_database->createStatement();

    try {
        QString qry = QString("SELECT id, username, kills, deaths FROM accounts where username='******' and secret='%2'").arg(user, password);

        res = stmt->executeQuery(qry.toStdString());

        if (res -> rowsCount() != 0)
        {
            player = new Player();

            while (res->next())
            {
                player->setUserId(res->getInt("id"));
                player->setUserName(QString::fromStdString(res->getString("username")));
                player->setKills(res->getInt("kills"));
                player->setDeaths(res->getInt("deaths"));
            }
        }
    } catch (SQLException &e)
    {
        emit writeToConsole("Query failed: " + QLatin1String(e.getSQLStateCStr()));
        return false;
    }

    delete stmt;
    delete res;

    return player;
}
Beispiel #11
0
void Database::disestablishServer()
{
    if (!isConnected())
        init();

    if(m_isConnected)
    {
        PreparedStatement *prep_stmt = 0;

        try
        {
            prep_stmt = m_database->prepareStatement("DELETE FROM servers where id = ?");
            prep_stmt->setString(1, m_serverID.toStdString());

            prep_stmt->executeQuery();
        }
        catch (SQLException &e)
        {
            emit writeToConsole("Query failed(disestablishServer): " + QLatin1String(e.getSQLStateCStr()));
        }

        delete prep_stmt;
    }
}
Beispiel #12
0
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    app.setOrganizationName("arksaw");
    app.setApplicationName("tisserver");

    // Initialize settings stuff
    QSettings::setDefaultFormat(QSettings::IniFormat);
    QSettings settings;
    settings.setValue("port", 50000);
    settings.sync();

    Console console;
    Database database;
    SessionManager sessionManager(0, &database);
    GameThread game(0, &database, &sessionManager);
    UdpServer udpServer;

    qRegisterMetaType<Packet>("Packet");
    qRegisterMetaType<QHostAddress>("QHostAddress");
    // Console signals/slots
    QObject::connect(&console, SIGNAL(commandEntered(CommandType,QStringList)),
                     &sessionManager, SLOT(runCommand(CommandType,QStringList)));
    QObject::connect(&console, SIGNAL(commandEntered(CommandType,QStringList)),
                     &game, SLOT(runCommand(CommandType,QStringList)),
                     Qt::DirectConnection); // Need direct connection from cross-thread signals to blocked thread
    QObject::connect(&console, SIGNAL(commandEntered(CommandType,QStringList)),
                     &udpServer, SLOT(runCommand(CommandType,QStringList)));

    // Database signals/slots
    QObject::connect(&database, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)),
                     Qt::QueuedConnection);

    // SessionManager signals/slots
    QObject::connect(&sessionManager, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)));
    QObject::connect(&sessionManager, SIGNAL(responseReady(Packet,QHostAddress,quint16)),
                     &udpServer, SLOT(sendResponse(Packet,QHostAddress,quint16)), Qt::QueuedConnection);

    // GameThread signals/slots
    QObject::connect(&game, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)));
    QObject::connect(&game, SIGNAL(updatePacketReady(Packet)),
                     &sessionManager, SLOT(sendUpdatePacket(Packet)),
                     Qt::QueuedConnection);

    // UdpServer signals/slots
    QObject::connect(&udpServer, SIGNAL(writeToConsole(QString)),
                     &console, SLOT(writeLine(QString)));
    QObject::connect(&udpServer, SIGNAL(packetReceived(Packet,QHostAddress,quint16)),
                     &sessionManager, SLOT(processPacket(Packet,QHostAddress,quint16)),
                     Qt::DirectConnection);

    // Set up threading.
    QThread thread;
    game.moveToThread(&thread);
    thread.start();
    thread.connect(&thread, SIGNAL(finished()), &app, SLOT(quit()));

    // Invoke with Qt::QueuedConnection since the Qt event loop isn't up yet
    QMetaObject::invokeMethod(&database, "init", Qt::QueuedConnection);
    QMetaObject::invokeMethod(&sessionManager, "start", Qt::QueuedConnection);
    QMetaObject::invokeMethod(&game, "start", Qt::QueuedConnection);
    QMetaObject::invokeMethod(&udpServer, "start", Qt::QueuedConnection);

    // Run the primary thread's main event loop.
    // exec() will return when we stop the main event loop via a signal
    return app.exec();
}
Beispiel #13
0
void flushBufferToConsole()
{
    writeToConsole(screenDataBuffer);    
}