Exemplo n.º 1
0
void KGameChat::setKGame(KGame* g)
{
 if (d->mGame) {
	slotUnsetKGame();
 }
 qCDebug(GAMES_PRIVATE_KGAME) << "game=" << g;
 d->mGame = g;

 if (d->mGame) {
	connect(d->mGame, SIGNAL(signalPlayerJoinedGame(KPlayer*)), 
			this, SLOT(slotAddPlayer(KPlayer*)));
	connect(d->mGame, SIGNAL(signalPlayerLeftGame(KPlayer*)), 
			this, SLOT(slotRemovePlayer(KPlayer*)));
	connect(d->mGame, SIGNAL(signalNetworkData(int,QByteArray,quint32,quint32)),
			this, SLOT(slotReceiveMessage(int,QByteArray,quint32,quint32)));
	connect(d->mGame, SIGNAL(destroyed()), this, SLOT(slotUnsetKGame()));

	QList<KPlayer*> playerList = *d->mGame->playerList();
	for (int i = 0; i < playerList.count(); i++) {
		slotAddPlayer(playerList.at(i));
	}
 }
Exemplo n.º 2
0
void StartUi::slotStartServer()
{
    /* todo GameFrame
    if(!settings->getShowIpStats())
        ip_stats->hide();
*/
    menuTabFrame->setSettings();

    if(settings->isServer())
    {
        qsrand(QDateTime::currentDateTime().toTime_t());
        adminPassword.setNum(qrand ());
        if(server)
        {
            server->kill();
            delete server;
        }
        server = new QProcess(this);
        connect(server, SIGNAL(started()), this, SLOT(slotServerLaunched()));
        connect(server, SIGNAL(error(QProcess::ProcessError)), this, SLOT(slotServerLaunchedError(QProcess::ProcessError)));
        //read debug ouputs
        connect(server,SIGNAL(readyReadStandardOutput()),this,SLOT(slotReadServerDebug()));
        server->setReadChannelMode(QProcess::MergedChannels);

		QString serverCmdLine("./Serverd");
		serverCmdLine += " --port ";
		serverCmdLine += QString::number(settings->getServerPort());
		serverCmdLine += " --admin-password " + adminPassword;
        if(settings->isDebugMode())
            serverCmdLine += " --debug-mode";
        serverCmdLine += " --started-from-gui";

        server->start(serverCmdLine);
    }
    else
    {
        adminPassword = menuTabFrame->getAdminPassword();
    }
    gamePlay = new GamePlay(settings, menuTabFrame->getGraphicPreview(), menuTabFrame->getPlayerName());
    NetClient *netclient = gamePlay->getNetClient();

    connect( gamePlay, SIGNAL(quitGame()), this, SLOT(closeGame()), Qt::QueuedConnection );
    connect( gamePlay, SIGNAL(sigLoadInterGame()), this, SLOT(slotLoadInterGame()) );

    /* Connect some signals to the ourselves */
    connect( netclient, SIGNAL(sigConnectionError()), this, SLOT(slotConnectionError()), Qt::QueuedConnection);
    connect( netclient, SIGNAL(sigGameStarted()), this, SLOT(slotGameStarted()));
    connect( netclient, SIGNAL(sigNetClientEnd()), this, SLOT(closeGame()));

    /* Connect some signals to the IP stats widget */
    connect( netclient, SIGNAL(sigStatPing(int)), &ipStats, SLOT(slotStatPing(int)));
    connect( netclient, SIGNAL(sigStatPacketLoss(double)), &ipStats, SLOT(slotStatPacketLoss(double)));

    /* Connect some signals to the frame menu */
    connect( netclient, SIGNAL(sigConnected()), menuTabFrame, SLOT(slotConnectedToServer()));
    connect( netclient, SIGNAL(sigIsServerAdmin()), menuTabFrame, SLOT(slotIsServerAdmin()));
    connect( netclient, SIGNAL(sigUpdatePlayerData(qint8,QString)), menuTabFrame, SLOT(slotUpdatePlayerData(qint8,QString)));
    connect( netclient, SIGNAL(sigMaxPlayersChanged(int)), menuTabFrame, SLOT(slotMaxPlayersValueChanged(int)));
    connect( netclient, SIGNAL(sigMaxWinsChanged(int)), menuTabFrame, SLOT(slotMaxWinsValueChanged(int)));
    connect( netclient, SIGNAL(sigMapRandom(bool)), menuTabFrame, SLOT(slotMapRandom(bool)));
    connect( netclient, SIGNAL(mapPreviewReceived(MapClient*)), menuTabFrame,SLOT(slotMapPreviewReceived(MapClient*)));
    connect( netclient, SIGNAL(sigPlayerLeft(qint8)), menuTabFrame, SLOT(slotPlayerLeft(qint8)));

    /* Connect some signals to the player list */
    connect( netclient, SIGNAL(sigUpdatePlayerData(qint8, QString)), &playerListWidget, SLOT(slotAddPlayer(qint8, QString)));
    connect( gamePlay, SIGNAL(sigNewPlayerGraphic(qint8,const QPixmap &)), &playerListWidget, SLOT(slotNewPlayerGraphic(qint8,const QPixmap &)));
    connect( netclient, SIGNAL(sigPlayerLeft(qint8)), &playerListWidget, SLOT(slotRemovePlayer(qint8)));
    connect( netclient, SIGNAL(sigScoreUpdate(qint8, qint16)), &playerListWidget, SLOT(slotUpdatePlayerScore(qint8, qint16)));
    // must be queued otherwise NetClient instance is deleted before finishing its processing
    connect( netclient, SIGNAL(sigServerStopped()), this, SLOT(slotServerStopped()), Qt::QueuedConnection);

    // if the server is remote, try to connect immediately (otherwise server's output must be checked)
    if(!settings->isServer())
        gamePlay->cliConnect(adminPassword);
}