I like turtles!!!
That's an adorable picture!
I like turtles!!!
void Host::processTheDatagram(QByteArray data) {
QString maxNrPlayers, mapName, gameType;
QList<QByteArray> splitArray = data.split('\\');
qDebug() << "Message: " << splitArray.at(12);
int index = splitArray.indexOf("g_gametype", 0);
gameType = splitArray.at(index+1);
if(index > 0) {
if(gameType == "dm")
serverData.gameType.append("Free-for-all");
else if(gameType == "war")
serverData.gameType.append("Team Deathmatch");
else if(gameType == "dom")
serverData.gameType.append("Domination");
else if(gameType == "sd")
serverData.gameType.append("Search & Destroy");
else if(gameType == "cft")
serverData.gameType.append("Capture the Flag");
else if(gameType == "koth")
serverData.gameType.append("Headquarters");
else if(gameType == "sab")
serverData.gameType.append("Sabotage");
}
// serverData.gameType.append(splitArray.at(index +1));
index = splitArray.indexOf("mapname", 0);
serverData.mapName.append(splitArray.at(index+1));
index = splitArray.indexOf("sv_maxclients", 0);
serverData.playerCount.second.append(splitArray.at(index+1));
index = data.indexOf("mod\\1", 0);
if(index < 0)
index = data.indexOf("mod\\0", 0);
qDebug() << data.data();
data.remove(0, index+6); //chop the buffer down to just the player list
data.chop(1); //remove the final newline character
qDebug() << data.data();
if(data.isEmpty()) {
serverData.playerCount.first = "0";
return;
}
QList<QByteArray> playerLines = data.split('\n');
QList<QByteArray> playerLine;
QString temp;
serverData.playerCount.first = QString::number(playerLines.size()); //current number of players
qDebug() << playerLines;
for(int i = 0; i < playerLines.size(); i++) {
temp.clear();
playerLine = playerLines[i].split(' '); //split up data for a single player
qDebug() << playerLine;
if(!playerLine[0].isEmpty()) {
serverData.playerScores.push_back(playerLine[0]); //add score
serverData.playerPings.push_back(playerLine[1]); //add ping
}
else {
return;
}
for(int j = 2; j < playerLine.size(); j++) {
temp.append(playerLine[j] + " "); //put the name back together
}
serverData.playerNames.push_back(temp); //add the name
}
for(int i = 0; i < playerLines.size(); i++) {
serverData.playerNames[i].remove("\""); //remove all quotation marks from player names
serverData.playerNames[i] = serverData.playerNames[i].trimmed();
}
//------------------------------sort by score------------------------------
int pos = 1;
while(pos < playerLines.size()){
if (serverData.playerScores[pos].toInt() <= serverData.playerScores[pos-1].toInt()) {
pos++;
}
else {
qDebug() << serverData.playerScores;
serverData.playerScores.swap(pos, pos-1);
qDebug() << serverData.playerScores;
serverData.playerPings.swap(pos, pos-1);
serverData.playerNames.swap(pos, pos-1);
if (pos > 1) {
pos--;
}
}
}
//-------------------------------------------------------------------------
}