mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Cosmetic improvements for lobby
This commit is contained in:
parent
e0aa26e599
commit
15ba4cda70
@ -380,7 +380,7 @@
|
|||||||
"type" : "object",
|
"type" : "object",
|
||||||
"default": {},
|
"default": {},
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"required" : [ "repositoryURL", "enableInstalledMods", "extraResolutionsModPath", "autoCheckRepositories", "updateOnStartup", "updateConfigUrl", "lobbyUrl", "lobbyPort", "lobbyUsername" ],
|
"required" : [ "repositoryURL", "enableInstalledMods", "extraResolutionsModPath", "autoCheckRepositories", "updateOnStartup", "updateConfigUrl", "lobbyUrl", "lobbyPort", "lobbyUsername", "connectionTimeout" ],
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"repositoryURL" : {
|
"repositoryURL" : {
|
||||||
"type" : "array",
|
"type" : "array",
|
||||||
@ -413,15 +413,23 @@
|
|||||||
},
|
},
|
||||||
"lobbyUrl" : {
|
"lobbyUrl" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
|
"description" : "ip address or web link to remote proxy server",
|
||||||
"default" : "beholder.vcmi.eu"
|
"default" : "beholder.vcmi.eu"
|
||||||
},
|
},
|
||||||
"lobbyPort" : {
|
"lobbyPort" : {
|
||||||
"type" : "number",
|
"type" : "number",
|
||||||
|
"description" : "connection port for remote proxy server",
|
||||||
"default" : 5002
|
"default" : 5002
|
||||||
},
|
},
|
||||||
"lobbyUsername" : {
|
"lobbyUsername" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
|
"description" : "username for the client on the remote proxy server",
|
||||||
"default" : ""
|
"default" : ""
|
||||||
|
},
|
||||||
|
"connectionTimeout" : {
|
||||||
|
"type" : "number",
|
||||||
|
"description" : "maximum time in ms, should be enough to establish socket connection to remote proxy server.",
|
||||||
|
"default" : 2000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,16 +21,13 @@ SocketLobby::SocketLobby(QObject *parent) :
|
|||||||
connect(socket, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
|
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;
|
username = usr;
|
||||||
|
|
||||||
emit text("Connecting to " + host + ":" + QString::number(port));
|
|
||||||
|
|
||||||
socket->connectToHost(host, port);
|
socket->connectToHost(host, port);
|
||||||
|
|
||||||
if(!socket->waitForDisconnected(connectionTimeout) && !isConnected)
|
if(!socket->waitForDisconnected(timeout) && !isConnected)
|
||||||
{
|
{
|
||||||
emit text("Error: " + socket->errorString());
|
emit text("Error: " + socket->errorString());
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ class SocketLobby : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SocketLobby(QObject *parent = 0);
|
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 disconnectServer();
|
||||||
void requestNewSession(const QString & session, int totalPlayers, const QString & pswd);
|
void requestNewSession(const QString & session, int totalPlayers, const QString & pswd);
|
||||||
void requestJoinSession(const QString & session, const QString & pswd);
|
void requestJoinSession(const QString & session, const QString & pswd);
|
||||||
|
@ -13,7 +13,7 @@ Lobby::Lobby(QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->buttonReady->setEnabled(false);
|
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(receive(QString)), this, SLOT(dispatchMessage(QString)));
|
||||||
connect(&socketLobby, SIGNAL(disconnect()), this, SLOT(onDisconnected()));
|
connect(&socketLobby, SIGNAL(disconnect()), this, SLOT(onDisconnected()));
|
||||||
|
|
||||||
@ -39,14 +39,14 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
|||||||
{
|
{
|
||||||
case SRVERROR:
|
case SRVERROR:
|
||||||
protocolAssert(args.size());
|
protocolAssert(args.size());
|
||||||
chatMessage("System error:" + args[0]);
|
chatMessage("System error", args[0], true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CREATED:
|
case CREATED:
|
||||||
protocolAssert(args.size());
|
protocolAssert(args.size());
|
||||||
hostSession = args[0];
|
hostSession = args[0];
|
||||||
session = args[0];
|
session = args[0];
|
||||||
chatMessage("System: new session started");
|
sysMessage("new session started");
|
||||||
ui->buttonReady->setEnabled(true);
|
ui->buttonReady->setEnabled(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -75,12 +75,12 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
|||||||
case JOINED:
|
case JOINED:
|
||||||
case KICKED:
|
case KICKED:
|
||||||
protocolAssert(args.size() == 2);
|
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)
|
if(args[1] == username)
|
||||||
{
|
{
|
||||||
ui->chat->clear(); //cleanup the chat
|
ui->chat->clear(); //cleanup the chat
|
||||||
chatMessage(joinStr.arg("you", args[0]));
|
sysMessage(joinStr.arg("you", args[0]));
|
||||||
session = args[0];
|
session = args[0];
|
||||||
ui->stackedWidget->setCurrentWidget(command.command == JOINED ? ui->roomPage : ui->sessionsPage);
|
ui->stackedWidget->setCurrentWidget(command.command == JOINED ? ui->roomPage : ui->sessionsPage);
|
||||||
if(command.command == KICKED)
|
if(command.command == KICKED)
|
||||||
@ -88,7 +88,7 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chatMessage(joinStr.arg(args[1], args[0]));
|
sysMessage(joinStr.arg(args[1], args[0]));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -131,13 +131,13 @@ void Lobby::serverCommand(const ServerCommand & command) try
|
|||||||
QString msg;
|
QString msg;
|
||||||
for(int i = 1; i < args.size(); ++i)
|
for(int i = 1; i < args.size(); ++i)
|
||||||
msg += args[i];
|
msg += args[i];
|
||||||
chatMessage(QString("%1: %2").arg(args[0], msg));
|
chatMessage(args[0], msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const ProtocolError & e)
|
catch(const ProtocolError & e)
|
||||||
{
|
{
|
||||||
chatMessage(QString("System error: %1").arg(e.what()));
|
chatMessage("System error", e.what(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::dispatchMessage(QString txt) try
|
void Lobby::dispatchMessage(QString txt) try
|
||||||
@ -161,7 +161,7 @@ void Lobby::dispatchMessage(QString txt) try
|
|||||||
}
|
}
|
||||||
catch(const ProtocolError & e)
|
catch(const ProtocolError & e)
|
||||||
{
|
{
|
||||||
chatMessage(QString("System error: %1").arg(e.what()));
|
chatMessage("System error", e.what(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Lobby::onDisconnected()
|
void Lobby::onDisconnected()
|
||||||
@ -170,11 +170,23 @@ void Lobby::onDisconnected()
|
|||||||
ui->connectButton->setChecked(false);
|
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());
|
QTextCursor curs(ui->chat->document());
|
||||||
curs.movePosition(QTextCursor::End);
|
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)
|
void Lobby::protocolAssert(bool expr)
|
||||||
@ -194,13 +206,17 @@ void Lobby::on_connectButton_toggled(bool checked)
|
|||||||
if(checked)
|
if(checked)
|
||||||
{
|
{
|
||||||
username = ui->userEdit->text();
|
username = ui->userEdit->text();
|
||||||
|
const int connectionTimeout = settings["launcher"]["connectionTimeout"].Integer();
|
||||||
|
|
||||||
Settings node = settings.write["launcher"];
|
Settings node = settings.write["launcher"];
|
||||||
node["lobbyUrl"].String() = ui->hostEdit->text().toStdString();
|
node["lobbyUrl"].String() = ui->hostEdit->text().toStdString();
|
||||||
node["lobbyPort"].Integer() = ui->portEdit->text().toInt();
|
node["lobbyPort"].Integer() = ui->portEdit->text().toInt();
|
||||||
node["lobbyUsername"].String() = username.toStdString();
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,8 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void on_messageEdit_returnPressed();
|
void on_messageEdit_returnPressed();
|
||||||
|
|
||||||
void chatMessage(QString);
|
void chatMessage(QString title, QString body, bool isSystem = false);
|
||||||
|
void sysMessage(QString body);
|
||||||
void dispatchMessage(QString);
|
void dispatchMessage(QString);
|
||||||
void serverCommand(const ServerCommand &);
|
void serverCommand(const ServerCommand &);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user