1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Cosmetic improvements for lobby

This commit is contained in:
nordsoft 2022-11-16 04:22:48 +04:00
parent e0aa26e599
commit 15ba4cda70
5 changed files with 42 additions and 20 deletions

View File

@ -380,7 +380,7 @@
"type" : "object",
"default": {},
"additionalProperties" : false,
"required" : [ "repositoryURL", "enableInstalledMods", "extraResolutionsModPath", "autoCheckRepositories", "updateOnStartup", "updateConfigUrl", "lobbyUrl", "lobbyPort", "lobbyUsername" ],
"required" : [ "repositoryURL", "enableInstalledMods", "extraResolutionsModPath", "autoCheckRepositories", "updateOnStartup", "updateConfigUrl", "lobbyUrl", "lobbyPort", "lobbyUsername", "connectionTimeout" ],
"properties" : {
"repositoryURL" : {
"type" : "array",
@ -413,15 +413,23 @@
},
"lobbyUrl" : {
"type" : "string",
"description" : "ip address or web link to remote proxy server",
"default" : "beholder.vcmi.eu"
},
"lobbyPort" : {
"type" : "number",
"description" : "connection port for remote proxy server",
"default" : 5002
},
"lobbyUsername" : {
"type" : "string",
"description" : "username for the client on the remote proxy server",
"default" : ""
},
"connectionTimeout" : {
"type" : "number",
"description" : "maximum time in ms, should be enough to establish socket connection to remote proxy server.",
"default" : 2000
}
}
}

View File

@ -21,16 +21,13 @@ SocketLobby::SocketLobby(QObject *parent) :
connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
}
void SocketLobby::connectServer(const QString & host, int port, const QString & usr)
void SocketLobby::connectServer(const QString & host, int port, const QString & usr, int timeout)
{
const int connectionTimeout = 2000;
username = usr;
emit text("Connecting to " + host + ":" + QString::number(port));
socket->connectToHost(host, port);
if(!socket->waitForDisconnected(connectionTimeout) && !isConnected)
if(!socket->waitForDisconnected(timeout) && !isConnected)
{
emit text("Error: " + socket->errorString());
}

View File

@ -67,7 +67,7 @@ class SocketLobby : public QObject
Q_OBJECT
public:
explicit SocketLobby(QObject *parent = 0);
void connectServer(const QString & host, int port, const QString & username);
void connectServer(const QString & host, int port, const QString & username, int timeout);
void disconnectServer();
void requestNewSession(const QString & session, int totalPlayers, const QString & pswd);
void requestJoinSession(const QString & session, const QString & pswd);

View File

@ -13,7 +13,7 @@ Lobby::Lobby(QWidget *parent) :
ui->setupUi(this);
ui->buttonReady->setEnabled(false);
connect(&socketLobby, SIGNAL(text(QString)), this, SLOT(chatMessage(QString)));
connect(&socketLobby, SIGNAL(text(QString)), this, SLOT(sysMessage(QString)));
connect(&socketLobby, SIGNAL(receive(QString)), this, SLOT(dispatchMessage(QString)));
connect(&socketLobby, SIGNAL(disconnect()), this, SLOT(onDisconnected()));
@ -39,14 +39,14 @@ void Lobby::serverCommand(const ServerCommand & command) try
{
case SRVERROR:
protocolAssert(args.size());
chatMessage("System error:" + args[0]);
chatMessage("System error", args[0], true);
break;
case CREATED:
protocolAssert(args.size());
hostSession = args[0];
session = args[0];
chatMessage("System: new session started");
sysMessage("new session started");
ui->buttonReady->setEnabled(true);
break;
@ -75,12 +75,12 @@ void Lobby::serverCommand(const ServerCommand & command) try
case JOINED:
case KICKED:
protocolAssert(args.size() == 2);
joinStr = (command.command == JOINED ? "System: %1 joined to the session %2" : "System: %1 left session %2");
joinStr = (command.command == JOINED ? "%1 joined to the session %2" : "%1 left session %2");
if(args[1] == username)
{
ui->chat->clear(); //cleanup the chat
chatMessage(joinStr.arg("you", args[0]));
sysMessage(joinStr.arg("you", args[0]));
session = args[0];
ui->stackedWidget->setCurrentWidget(command.command == JOINED ? ui->roomPage : ui->sessionsPage);
if(command.command == KICKED)
@ -88,7 +88,7 @@ void Lobby::serverCommand(const ServerCommand & command) try
}
else
{
chatMessage(joinStr.arg(args[1], args[0]));
sysMessage(joinStr.arg(args[1], args[0]));
}
break;
@ -131,13 +131,13 @@ void Lobby::serverCommand(const ServerCommand & command) try
QString msg;
for(int i = 1; i < args.size(); ++i)
msg += args[i];
chatMessage(QString("%1: %2").arg(args[0], msg));
chatMessage(args[0], msg);
break;
}
}
catch(const ProtocolError & e)
{
chatMessage(QString("System error: %1").arg(e.what()));
chatMessage("System error", e.what(), true);
}
void Lobby::dispatchMessage(QString txt) try
@ -161,7 +161,7 @@ void Lobby::dispatchMessage(QString txt) try
}
catch(const ProtocolError & e)
{
chatMessage(QString("System error: %1").arg(e.what()));
chatMessage("System error", e.what(), true);
}
void Lobby::onDisconnected()
@ -170,11 +170,23 @@ void Lobby::onDisconnected()
ui->connectButton->setChecked(false);
}
void Lobby::chatMessage(QString txt)
void Lobby::chatMessage(QString title, QString body, bool isSystem)
{
QTextCharFormat fmtBody, fmtTitle;
fmtTitle.setFontWeight(QFont::Bold);
if(isSystem)
fmtBody.setFontWeight(QFont::DemiBold);
QTextCursor curs(ui->chat->document());
curs.movePosition(QTextCursor::End);
curs.insertText(txt + "\n");
curs.insertText(title + ": ", fmtTitle);
curs.insertText(body + "\n", fmtBody);
ui->chat->ensureCursorVisible();
}
void Lobby::sysMessage(QString body)
{
chatMessage("System", body, true);
}
void Lobby::protocolAssert(bool expr)
@ -194,13 +206,17 @@ void Lobby::on_connectButton_toggled(bool checked)
if(checked)
{
username = ui->userEdit->text();
const int connectionTimeout = settings["launcher"]["connectionTimeout"].Integer();
Settings node = settings.write["launcher"];
node["lobbyUrl"].String() = ui->hostEdit->text().toStdString();
node["lobbyPort"].Integer() = ui->portEdit->text().toInt();
node["lobbyUsername"].String() = username.toStdString();
socketLobby.connectServer(ui->hostEdit->text(), ui->portEdit->text().toInt(), username);
sysMessage("Connecting to " + ui->hostEdit->text() + ":" + ui->portEdit->text());
ui->chat->repaint();
socketLobby.connectServer(ui->hostEdit->text(), ui->portEdit->text().toInt(), username, connectionTimeout);
}
else
{

View File

@ -17,7 +17,8 @@ public:
private slots:
void on_messageEdit_returnPressed();
void chatMessage(QString);
void chatMessage(QString title, QString body, bool isSystem = false);
void sysMessage(QString body);
void dispatchMessage(QString);
void serverCommand(const ServerCommand &);