mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
new code
This commit is contained in:
parent
6c93b1e9b7
commit
0d4717f40b
28 changed files with 591 additions and 375 deletions
|
|
@ -99,170 +99,6 @@ void Client::readData()
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
while (socket->canReadLine()) {
|
||||
QString line = QString(socket->readLine()).trimmed();
|
||||
|
||||
if (line.isNull())
|
||||
break;
|
||||
qDebug(QString("<< %1").arg(line).toLatin1());
|
||||
QStringList values = line.split("|");
|
||||
QString prefix = values.takeFirst();
|
||||
// prefix is one of {welcome, private, public, resp, list_games, list_players, list_counters, list_zones, dump_zone}
|
||||
if ((prefix == "private") || (prefix == "public")) {
|
||||
ServerEventData event(line);
|
||||
emit gameEvent(event);
|
||||
} else if (prefix == "chat") {
|
||||
emit chatEvent(ChatEventData(line));
|
||||
} else if (prefix == "resp") {
|
||||
if (values.size() != 2) {
|
||||
qDebug("Client::parseCommand: Invalid response");
|
||||
continue;
|
||||
}
|
||||
bool ok;
|
||||
int msgid = values.takeFirst().toInt(&ok);
|
||||
PendingCommand *pc = pendingCommands.value(msgid, 0);
|
||||
if (!ok || !pc) {
|
||||
qDebug("Client::parseCommand: Invalid msgid");
|
||||
continue;
|
||||
}
|
||||
ServerResponse resp;
|
||||
if (values[0] == "ok")
|
||||
resp = RespOk;
|
||||
else if (values[0] == "name_not_found")
|
||||
resp = RespNameNotFound;
|
||||
else if (values[0] == "login_needed")
|
||||
resp = RespLoginNeeded;
|
||||
else if (values[0] == "syntax")
|
||||
resp = RespSyntaxError;
|
||||
else if (values[0] == "context")
|
||||
resp = RespContextError;
|
||||
else if (values[0] == "password")
|
||||
resp = RespPasswordWrong;
|
||||
else if (values[0] == "spectators_not_allowed")
|
||||
resp = RespSpectatorsNotAllowed;
|
||||
else
|
||||
resp = RespInvalid;
|
||||
pc->responseReceived(resp);
|
||||
} else if (prefix == "list_games") {
|
||||
if (values.size() != 8) {
|
||||
emit protocolError();
|
||||
continue;
|
||||
}
|
||||
emit gameListEvent(ServerGame(values[0].toInt(), values[5], values[1], values[2].toInt(), values[3].toInt(), values[4].toInt(), values[6].toInt(), values[7].toInt()));
|
||||
} else if (prefix == "welcome") {
|
||||
if (values.size() != 2) {
|
||||
emit protocolError();
|
||||
disconnectFromServer();
|
||||
} else if (values[0].toInt() != protocolVersion) {
|
||||
emit protocolVersionMismatch();
|
||||
disconnectFromServer();
|
||||
} else {
|
||||
emit welcomeMsgReceived(values[1]);
|
||||
setStatus(StatusLoggingIn);
|
||||
login(playerName, password);
|
||||
}
|
||||
} else if (prefix == "list_players") {
|
||||
if (values.size() != 4) {
|
||||
emit protocolError();
|
||||
continue;
|
||||
}
|
||||
int cmdid = values.takeFirst().toInt();
|
||||
PendingCommand *pc = pendingCommands.value(cmdid, 0);
|
||||
ServerPlayer sp(values[0].toInt(), values[1], values[2].toInt());
|
||||
|
||||
PendingCommand_ListPlayers *pcLP = qobject_cast<PendingCommand_ListPlayers *>(pc);
|
||||
if (pcLP)
|
||||
pcLP->addPlayer(sp);
|
||||
else {
|
||||
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
|
||||
if (pcDA)
|
||||
pcDA->addPlayer(sp);
|
||||
else
|
||||
emit protocolError();
|
||||
}
|
||||
} else if (prefix == "dump_zone") {
|
||||
if (values.size() != 11) {
|
||||
emit protocolError();
|
||||
continue;
|
||||
}
|
||||
int cmdid = values.takeFirst().toInt();
|
||||
PendingCommand *pc = pendingCommands.value(cmdid, 0);
|
||||
ServerZoneCard szc(values[0].toInt(), values[1], values[2].toInt(), values[3], values[4].toInt(), values[5].toInt(), values[6].toInt(), values[7] == "1", values[8] == "1", values[9]);
|
||||
|
||||
PendingCommand_DumpZone *pcDZ = qobject_cast<PendingCommand_DumpZone *>(pc);
|
||||
if (pcDZ)
|
||||
pcDZ->addCard(szc);
|
||||
else {
|
||||
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
|
||||
if (pcDA)
|
||||
pcDA->addCard(szc);
|
||||
else
|
||||
emit protocolError();
|
||||
}
|
||||
} else if (prefix == "list_zones") {
|
||||
if (values.size() != 6) {
|
||||
emit protocolError();
|
||||
continue;
|
||||
}
|
||||
int cmdid = values.takeFirst().toInt();
|
||||
PendingCommand *pc = pendingCommands.value(cmdid, 0);
|
||||
ServerZone::ZoneType type;
|
||||
if (values[2] == "private")
|
||||
type = ServerZone::PrivateZone;
|
||||
else if (values[2] == "hidden")
|
||||
type = ServerZone::HiddenZone;
|
||||
else
|
||||
type = ServerZone::PublicZone;
|
||||
ServerZone sz(values[0].toInt(), values[1], type, values[3] == "1", values[4].toInt());
|
||||
|
||||
PendingCommand_ListZones *pcLZ = qobject_cast<PendingCommand_ListZones *>(pc);
|
||||
if (pcLZ)
|
||||
pcLZ->addZone(sz);
|
||||
else {
|
||||
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
|
||||
if (pcDA)
|
||||
pcDA->addZone(sz);
|
||||
else
|
||||
emit protocolError();
|
||||
}
|
||||
} else if (prefix == "list_counters") {
|
||||
if (values.size() != 7) {
|
||||
emit protocolError();
|
||||
continue;
|
||||
}
|
||||
int cmdid = values.takeFirst().toInt();
|
||||
PendingCommand *pc = pendingCommands.value(cmdid, 0);
|
||||
ServerCounter sc(values[0].toInt(), values[1].toInt(), values[2], numberToColor(values[3].toInt()), values[4].toInt(), values[5].toInt());
|
||||
|
||||
PendingCommand_ListCounters *pcLC = qobject_cast<PendingCommand_ListCounters *>(pc);
|
||||
if (pcLC)
|
||||
pcLC->addCounter(sc);
|
||||
else {
|
||||
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
|
||||
if (pcDA)
|
||||
pcDA->addCounter(sc);
|
||||
else
|
||||
emit protocolError();
|
||||
}
|
||||
} else if (prefix == "list_arrows") {
|
||||
if (values.size() != 10) {
|
||||
emit protocolError();
|
||||
continue;
|
||||
}
|
||||
int cmdid = values.takeFirst().toInt();
|
||||
PendingCommand *pc = pendingCommands.value(cmdid, 0);
|
||||
ServerArrow sa(values[0].toInt(), values[1].toInt(), values[2].toInt(), values[3], values[4].toInt(), values[5].toInt(), values[6], values[7].toInt(), numberToColor(values[8].toInt()));
|
||||
|
||||
PendingCommand_DumpAll *pcDA = qobject_cast<PendingCommand_DumpAll *>(pc);
|
||||
if (pcDA)
|
||||
pcDA->addArrow(sa);
|
||||
else
|
||||
emit protocolError();
|
||||
} else
|
||||
emit protocolError();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void Client::processProtocolItem(ProtocolItem *item)
|
||||
|
|
@ -365,14 +201,3 @@ void Client::ping()
|
|||
} else
|
||||
sendCommand(new Command_Ping);
|
||||
}
|
||||
/*
|
||||
QColor Client::numberToColor(int colorValue) const
|
||||
{
|
||||
return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
|
||||
}
|
||||
|
||||
int Client::colorToNumber(const QColor &color) const
|
||||
{
|
||||
return color.red() * 65536 + color.green() * 256 + color.blue();
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue