1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Minor changes

This commit is contained in:
nordsoft
2022-10-27 01:39:57 +04:00
parent 1455c65e1a
commit 6eb43d3834
5 changed files with 23 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
#include "lobby_moc.h" #include "lobby_moc.h"
#include "ui_lobby_moc.h" #include "ui_lobby_moc.h"
#include "../mainwindow_moc.h"
#include "../lib/GameConstants.h" #include "../lib/GameConstants.h"
#include "../jsonutils.h" #include "../jsonutils.h"
#include "../../lib/CConfigHandler.h" #include "../../lib/CConfigHandler.h"
@@ -106,6 +107,7 @@ Lobby::Lobby(QWidget *parent) :
ui(new Ui::Lobby) ui(new Ui::Lobby)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->buttonReady->setEnabled(false);
connect(&socketLobby, SIGNAL(text(QString)), this, SLOT(chatMessage(QString))); connect(&socketLobby, SIGNAL(text(QString)), this, SLOT(chatMessage(QString)));
connect(&socketLobby, SIGNAL(receive(QString)), this, SLOT(dispatchMessage(QString))); connect(&socketLobby, SIGNAL(receive(QString)), this, SLOT(dispatchMessage(QString)));
@@ -137,6 +139,7 @@ void Lobby::serverCommand(const ServerCommand & command) try
hostSession = args[0]; hostSession = args[0];
session = args[0]; session = args[0];
chatMessage("System: new session started"); chatMessage("System: new session started");
ui->buttonReady->setEnabled(true);
break; break;
case SESSIONS: case SESSIONS:
@@ -172,6 +175,8 @@ void Lobby::serverCommand(const ServerCommand & command) try
chatMessage(joinStr.arg("you", args[0])); chatMessage(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)
ui->buttonReady->setEnabled(false);
} }
else else
{ {
@@ -202,8 +207,11 @@ void Lobby::serverCommand(const ServerCommand & command) try
node["server"].String() = ui->hostEdit->text().toStdString(); node["server"].String() = ui->hostEdit->text().toStdString();
node["serverport"].Integer() = ui->portEdit->text().toInt(); node["serverport"].Integer() = ui->portEdit->text().toInt();
node["uuid"].String() = args[0].toStdString(); node["uuid"].String() = args[0].toStdString();
startGame = true;
//on_startGameButton_clicked
//node["names"].Vector().clear(); //node["names"].Vector().clear();
//node["names"].Vector().pushBack(username.toStdString()); //node["names"].Vector().pushBack(username.toStdString());
break; break;
} }
@@ -247,6 +255,9 @@ void Lobby::dispatchMessage(QString txt) try
ServerCommand cmd(ctype, parseArgs); ServerCommand cmd(ctype, parseArgs);
serverCommand(cmd); serverCommand(cmd);
} }
if(startGame)
qobject_cast<MainWindow *>(qApp->activeWindow())->on_startGameButton_clicked();
} }
catch(const ProtocolError & e) catch(const ProtocolError & e)
{ {

View File

@@ -123,6 +123,7 @@ private:
QString hostSession; QString hostSession;
QString session; QString session;
QString username; QString username;
bool startGame = false;
private: private:
void protocolAssert(bool); void protocolAssert(bool);

View File

@@ -35,6 +35,6 @@ public:
explicit MainWindow(QWidget * parent = 0); explicit MainWindow(QWidget * parent = 0);
~MainWindow(); ~MainWindow();
private slots: public slots:
void on_startGameButton_clicked(); void on_startGameButton_clicked();
}; };

View File

@@ -207,13 +207,13 @@ def startSession(session: Session):
session.started = True session.started = True
session.host_uuid = str(uuid.uuid4()) session.host_uuid = str(uuid.uuid4())
hostMessage = f":>>HOST:{session.host_uuid}:{session.joined - 1}" #one client will be connected locally hostMessage = f":>>HOST:{session.host_uuid}:{session.joined - 1}" #one client will be connected locally
#host message must be before start message
send(session.host, hostMessage)
for player in session.players: for player in session.players:
client_sockets[player]['uuid'] = str(uuid.uuid4()) client_sockets[player]['uuid'] = str(uuid.uuid4())
msg = f":>>START:{client_sockets[player]['uuid']}" msg = f":>>START:{client_sockets[player]['uuid']}"
send(player, msg) send(player, msg)
#host message must be after start message
send(session.host, hostMessage)
def dispatch(client: socket, sender: dict, arr: bytes): def dispatch(client: socket, sender: dict, arr: bytes):
@@ -355,6 +355,8 @@ def dispatch(client: socket, sender: dict, arr: bytes):
return return
sender["session"].total = int(tag_value) sender["session"].total = int(tag_value)
message = f":>>CREATED:{sender['session'].name}"
send(client, message)
#now session is ready to be broadcasted #now session is ready to be broadcasted
message = f":>>JOIN:{sender['session'].name}:{sender['username']}" message = f":>>JOIN:{sender['session'].name}:{sender['username']}"
send(client, message) send(client, message)

View File

@@ -170,8 +170,12 @@ void CVCMIServer::run()
#endif #endif
startAsyncAccept(); startAsyncAccept();
if(!remoteConnectionsThread) if(!remoteConnectionsThread && !settings["server"]["lobby"].isNull() && settings["server"]["lobby"].Bool())
{
remoteConnectionsThread = vstd::make_unique<boost::thread>(&CVCMIServer::establishRemoteConnections, this); remoteConnectionsThread = vstd::make_unique<boost::thread>(&CVCMIServer::establishRemoteConnections, this);
Settings node = settings.write["server"]["lobby"];
node->Bool() = false;
}
#if defined(VCMI_ANDROID) #if defined(VCMI_ANDROID)
CAndroidVMHelper vmHelper; CAndroidVMHelper vmHelper;
@@ -199,12 +203,6 @@ void CVCMIServer::run()
void CVCMIServer::establishRemoteConnections() void CVCMIServer::establishRemoteConnections()
{ {
if(settings["server"]["lobby"].isNull() || !settings["server"]["lobby"].Bool())
return;
Settings node = settings.write["server"];
node["lobby"].Bool() = false;
uuid = settings["server"]["host"]["uuid"].String(); uuid = settings["server"]["host"]["uuid"].String();
int numOfConnections = settings["server"]["host"]["connections"].Integer(); int numOfConnections = settings["server"]["host"]["connections"].Integer();
auto address = settings["server"]["server"].String(); auto address = settings["server"]["server"].String();