#include "nexusserver.h" #include #include #include #include #include #include "stdio.h" #include "furnitureprofile.h" #include "furniture.h" #include "utils.h" #include "moduleengine.h" #include "configengine.h" NexusServer::NexusServer(QObject *parent) : QObject(parent) { //Console::println(" ** NexusServer **"); printf("\n ** NexusServer v1.2.0 **\n\n"); printf("Loading configuration..."); ConfigEngine::init(); printf(" [OK]\n\nLoading modules..."); int count = ModuleEngine::init(); printf(" [%i Modules loaded]\n\n", count); printf("Connecting to MySQL database... "); //qDebug() << " Connecting to MySQL Database"; // use printf // its in debug mode, qDebug should work fine >.> // Attempt to find a usable driver QString DBDir = ConfigEngine::getValue("SQLitePath"); // Thats a Qt specific C++ thing :D //printf(DBDir.replace("/", "\n").toStdString().c_str()); //printf((QString("DBSTR: \"") + DBDir.replace("/", "/\n") + "\"\n").toStdString().c_str()); // Add the Database Driver to this Database Instance //printf((QString("SQL Driver: \"") + ConfigEngine::getValue("SQLDriver") + "\"\n").toStdString().c_str()); //QMYSQL QString sqldriver = ConfigEngine::getValue("SQLDriver"); db = QSqlDatabase::addDatabase(sqldriver); if(sqldriver.operator == ("QSQLITE")){ // Set Connection Info db.setDatabaseName(DBDir); }else if(sqldriver.operator == ("QMYSQL")){ db.setHostName(ConfigEngine::getValue("SQLHost")); db.setUserName(ConfigEngine::getValue("SQLUsername")); db.setPassword(ConfigEngine::getValue("SQLPassword")); }else{ printf(" [UNKNOWN SQLDRIVER]\n"); abort(); } if(!db.open()){ //qCritical() << "FUCK" << db.lastError() << DBDir; printf(" [CRITICAL ERROR]\n"); abort(); } Utils::verifyDatabase(); int port = 11420; QString t = ConfigEngine::getValue("ServerPort"); if(t != NULL){ port = t.toInt(); } printf("\nStarting NexusServer on port %i...", port); // start listening for connections if(!socket.listen(QHostAddress::Any, port)){ //qCritical() << "FUCK" << "Unable to Bind 11420 for Making Clients Connect"; printf(" [CRITICAL ERROR]\n"); abort(); } printf(" [OK]\n\nNexusServer online and ready for connections.\n"); //qDebug() << "Listening for Connections"; // bind the newConnection() signal of QTcpServer // to the newConnection() slot of this class connect(&socket, SIGNAL(newConnection()), this, SLOT(newConnection())); } NexusServer::~NexusServer(){ qDebug() << "Shutdown Started"; } void NexusServer::newConnection(){ // this is called when a new connection is made qDebug() << "Client Connected"; // Create a new Client object // Pass this class as its parent // and give it the new connection clients << new Client(this, socket.nextPendingConnection()); // TODO: maybe signal something that a client was connected? idk lol } void NexusServer::broadcastGlobal(QString packet){ foreach(Client* c, clients){ c->sendPacket(packet); } } /* can I tell you what im trying to make? sure but sec ok go on qdebug? ya it gives qDebug(), qWarning() and qCritical() oh cool, dunno what that is buyt I wana tell you what I wana make its the habbo server thing, you probably guessed but I want to have it create a new instance of something like a class for each connection that I can put code into and how do I do array lists of classes? */