mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Continue development
This commit is contained in:
parent
75613a947d
commit
05cba08b40
@ -44,6 +44,18 @@ void SocketLobby::requestJoinSession(const QString & session, const QString & ps
|
||||
send(sessionMessage);
|
||||
}
|
||||
|
||||
void SocketLobby::requestLeaveSession(const QString & session)
|
||||
{
|
||||
const QString sessionMessage = ProtocolStrings[LEAVE].arg(session);
|
||||
send(sessionMessage);
|
||||
}
|
||||
|
||||
void SocketLobby::requestReadySession(const QString & session)
|
||||
{
|
||||
const QString sessionMessage = ProtocolStrings[READY].arg(session);
|
||||
send(sessionMessage);
|
||||
}
|
||||
|
||||
void SocketLobby::send(const QString & msg)
|
||||
{
|
||||
socket->write(qPrintable(msg));
|
||||
@ -100,6 +112,8 @@ Lobby::~Lobby()
|
||||
void Lobby::serverCommand(const ServerCommand & command) try
|
||||
{
|
||||
//initialize variables outside of switch block
|
||||
const QString statusPlaceholder("%1 %2\n");
|
||||
QString resText;
|
||||
const auto & args = command.arguments;
|
||||
int amount, tagPoint;
|
||||
QString joinStr;
|
||||
@ -137,7 +151,6 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
||||
QTableWidgetItem * sessionProtectedItem = new QTableWidgetItem(args[tagPoint++]);
|
||||
ui->sessionsTable->setItem(i, 2, sessionProtectedItem);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case JOINED:
|
||||
@ -147,7 +160,10 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
||||
|
||||
if(args[1] == username)
|
||||
{
|
||||
ui->chat->clear(); //cleanup the chat
|
||||
chatMessage(joinStr.arg("you", args[0]));
|
||||
session = args[0];
|
||||
ui->stackedWidget->setCurrentWidget(command.command == JOINED ? ui->roomPage : ui->sessionsPage);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -155,6 +171,25 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
||||
}
|
||||
break;
|
||||
|
||||
case STATUS:
|
||||
protocolAssert(args.size() > 0);
|
||||
amount = args[0].toInt();
|
||||
protocolAssert(amount * 2 == (args.size() - 1));
|
||||
|
||||
tagPoint = 1;
|
||||
ui->roomChat->clear();
|
||||
resText.clear();
|
||||
for(int i = 0; i < amount; ++i, tagPoint += 2)
|
||||
{
|
||||
resText += statusPlaceholder.arg(args[tagPoint], args[tagPoint + 1] == "True" ? "ready" : "");
|
||||
}
|
||||
ui->roomChat->setPlainText(resText);
|
||||
break;
|
||||
|
||||
case START:
|
||||
//actually start game
|
||||
break;
|
||||
|
||||
case CHAT:
|
||||
protocolAssert(args.size() > 1);
|
||||
QString msg;
|
||||
@ -241,3 +276,15 @@ void Lobby::on_joinButton_clicked()
|
||||
socketLobby.requestJoinSession(item->text(), ui->passwordInput->text());
|
||||
}
|
||||
|
||||
|
||||
void Lobby::on_buttonLeave_clicked()
|
||||
{
|
||||
socketLobby.requestLeaveSession(session);
|
||||
}
|
||||
|
||||
|
||||
void Lobby::on_buttonReady_clicked()
|
||||
{
|
||||
socketLobby.requestReadySession(session);
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,10 @@ public:
|
||||
enum ProtocolConsts
|
||||
{
|
||||
//client consts
|
||||
GREETING, USERNAME, MESSAGE, VERSION, CREATE, JOIN,
|
||||
GREETING, USERNAME, MESSAGE, VERSION, CREATE, JOIN, LEAVE, READY,
|
||||
|
||||
//server consts
|
||||
SESSIONS, CREATED, JOINED, KICKED, ERROR, CHAT
|
||||
SESSIONS, CREATED, JOINED, KICKED, ERROR, CHAT, START, STATUS
|
||||
};
|
||||
|
||||
const QMap<ProtocolConsts, QString> ProtocolStrings
|
||||
@ -28,12 +28,16 @@ const QMap<ProtocolConsts, QString> ProtocolStrings
|
||||
{MESSAGE, "<MSG>%1"},
|
||||
{CREATE, "<NEW>%1<PSWD>%2<COUNT>%3"},
|
||||
{JOIN, "<JOIN>%1<PSWD>%2"},
|
||||
{LEAVE, "<LEAVE>%1"}, //session
|
||||
{READY, "<READY>%1"}, //session
|
||||
|
||||
//server consts
|
||||
{CREATED, "CREATED"},
|
||||
{SESSIONS, "SESSIONS"}, //amount:session_name:joined_players:total_players:is_protected
|
||||
{JOINED, "JOIN"}, //session_name:username
|
||||
{KICKED, "KICK"}, //session_name:username
|
||||
{START, "START"}, //session_name
|
||||
{STATUS, "STATUS"}, //joined_players:player_name:is_ready
|
||||
{ERROR, "ERROR"},
|
||||
{CHAT, "MSG"} //username:message
|
||||
};
|
||||
@ -56,6 +60,8 @@ public:
|
||||
void disconnectServer();
|
||||
void requestNewSession(const QString & session, int totalPlayers, const QString & pswd);
|
||||
void requestJoinSession(const QString & session, const QString & pswd);
|
||||
void requestLeaveSession(const QString & session);
|
||||
void requestReadySession(const QString & session);
|
||||
|
||||
void send(const QString &);
|
||||
|
||||
@ -103,6 +109,10 @@ private slots:
|
||||
|
||||
void on_joinButton_clicked();
|
||||
|
||||
void on_buttonLeave_clicked();
|
||||
|
||||
void on_buttonReady_clicked();
|
||||
|
||||
private:
|
||||
Ui::Lobby *ui;
|
||||
SocketLobby socketLobby;
|
||||
|
Loading…
Reference in New Issue
Block a user