mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-01 16:05:07 +01:00
Add Support for Room Descriptions
This commit is contained in:
parent
c396e3c6e5
commit
5f0e189238
@ -329,6 +329,7 @@ void Config::ReadValues() {
|
|||||||
}
|
}
|
||||||
UISettings::values.max_player = ReadSetting("max_player", 8).toUInt();
|
UISettings::values.max_player = ReadSetting("max_player", 8).toUInt();
|
||||||
UISettings::values.game_id = ReadSetting("game_id", 0).toULongLong();
|
UISettings::values.game_id = ReadSetting("game_id", 0).toULongLong();
|
||||||
|
UISettings::values.room_description = ReadSetting("room_description", "").toString();
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
@ -533,6 +534,7 @@ void Config::SaveValues() {
|
|||||||
WriteSetting("host_type", UISettings::values.host_type, 0);
|
WriteSetting("host_type", UISettings::values.host_type, 0);
|
||||||
WriteSetting("max_player", UISettings::values.max_player, 8);
|
WriteSetting("max_player", UISettings::values.max_player, 8);
|
||||||
WriteSetting("game_id", UISettings::values.game_id, 0);
|
WriteSetting("game_id", UISettings::values.game_id, 0);
|
||||||
|
WriteSetting("room_description", UISettings::values.room_description, "");
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
|
@ -82,6 +82,7 @@ void ClientRoomWindow::UpdateView() {
|
|||||||
.arg(QString::fromStdString(information.name))
|
.arg(QString::fromStdString(information.name))
|
||||||
.arg(memberlist.size())
|
.arg(memberlist.size())
|
||||||
.arg(information.member_slots));
|
.arg(information.member_slots));
|
||||||
|
ui->description->setText(QString::fromStdString(information.description));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,13 @@
|
|||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="description">
|
||||||
|
<property name="text">
|
||||||
|
<string>Room Description</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -70,6 +70,7 @@ HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list,
|
|||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
ui->game_list->setCurrentIndex(index);
|
ui->game_list->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
ui->room_description->setText(UISettings::values.room_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
HostRoomWindow::~HostRoomWindow() = default;
|
HostRoomWindow::~HostRoomWindow() = default;
|
||||||
@ -108,8 +109,10 @@ void HostRoomWindow::Host() {
|
|||||||
auto port = ui->port->isModified() ? ui->port->text().toInt() : Network::DefaultRoomPort;
|
auto port = ui->port->isModified() ? ui->port->text().toInt() : Network::DefaultRoomPort;
|
||||||
auto password = ui->password->text().toStdString();
|
auto password = ui->password->text().toStdString();
|
||||||
if (auto room = Network::GetRoom().lock()) {
|
if (auto room = Network::GetRoom().lock()) {
|
||||||
bool created = room->Create(ui->room_name->text().toStdString(), "", port, password,
|
bool created =
|
||||||
ui->max_player->value(), game_name.toStdString(), game_id);
|
room->Create(ui->room_name->text().toStdString(),
|
||||||
|
ui->room_description->toPlainText().toStdString(), "", port, password,
|
||||||
|
ui->max_player->value(), game_name.toStdString(), game_id);
|
||||||
if (!created) {
|
if (!created) {
|
||||||
NetworkMessage::ShowError(NetworkMessage::COULD_NOT_CREATE_ROOM);
|
NetworkMessage::ShowError(NetworkMessage::COULD_NOT_CREATE_ROOM);
|
||||||
LOG_ERROR(Network, "Could not create room!");
|
LOG_ERROR(Network, "Could not create room!");
|
||||||
@ -132,6 +135,7 @@ void HostRoomWindow::Host() {
|
|||||||
UISettings::values.room_port = (ui->port->isModified() && !ui->port->text().isEmpty())
|
UISettings::values.room_port = (ui->port->isModified() && !ui->port->text().isEmpty())
|
||||||
? ui->port->text()
|
? ui->port->text()
|
||||||
: QString::number(Network::DefaultRoomPort);
|
: QString::number(Network::DefaultRoomPort);
|
||||||
|
UISettings::values.room_description = ui->room_description->toPlainText();
|
||||||
Settings::Apply();
|
Settings::Apply();
|
||||||
OnConnection();
|
OnConnection();
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>607</width>
|
<width>607</width>
|
||||||
<height>165</height>
|
<height>211</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -131,6 +131,20 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Room Description</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="room_description"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
|
@ -212,7 +212,11 @@ void Lobby::OnRefreshLobby() {
|
|||||||
// To make the rows expandable, add the member data as a child of the first column of the
|
// To make the rows expandable, add the member data as a child of the first column of the
|
||||||
// rows with people in them and have qt set them to colspan after the model is finished
|
// rows with people in them and have qt set them to colspan after the model is finished
|
||||||
// resetting
|
// resetting
|
||||||
if (room.members.size() > 0) {
|
if (!room.description.empty()) {
|
||||||
|
first_item->appendRow(
|
||||||
|
new LobbyItemDescription(QString::fromStdString(room.description)));
|
||||||
|
}
|
||||||
|
if (!room.members.empty()) {
|
||||||
first_item->appendRow(new LobbyItemExpandedMemberList(members));
|
first_item->appendRow(new LobbyItemExpandedMemberList(members));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -228,8 +232,8 @@ void Lobby::OnRefreshLobby() {
|
|||||||
// Set the member list child items to span all columns
|
// Set the member list child items to span all columns
|
||||||
for (int i = 0; i < proxy->rowCount(); i++) {
|
for (int i = 0; i < proxy->rowCount(); i++) {
|
||||||
auto parent = model->item(i, 0);
|
auto parent = model->item(i, 0);
|
||||||
if (parent->hasChildren()) {
|
for (int j = 0; j < parent->rowCount(); j++) {
|
||||||
ui->room_list->setFirstColumnSpanned(0, proxy->index(i, 0), true);
|
ui->room_list->setFirstColumnSpanned(j, proxy->index(i, 0), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,31 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LobbyItemDescription : public LobbyItem {
|
||||||
|
public:
|
||||||
|
static const int DescriptionRole = Qt::UserRole + 1;
|
||||||
|
|
||||||
|
LobbyItemDescription() = default;
|
||||||
|
explicit LobbyItemDescription(QString description) {
|
||||||
|
setData(description, DescriptionRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant data(int role) const override {
|
||||||
|
if (role != Qt::DisplayRole) {
|
||||||
|
return LobbyItem::data(role);
|
||||||
|
}
|
||||||
|
auto description = data(DescriptionRole).toString();
|
||||||
|
description.prepend("Description: ");
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const QStandardItem& other) const override {
|
||||||
|
return data(DescriptionRole)
|
||||||
|
.toString()
|
||||||
|
.localeAwareCompare(other.data(DescriptionRole).toString()) < 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class LobbyItemGame : public LobbyItem {
|
class LobbyItemGame : public LobbyItem {
|
||||||
public:
|
public:
|
||||||
static const int TitleIDRole = Qt::UserRole + 1;
|
static const int TitleIDRole = Qt::UserRole + 1;
|
||||||
|
@ -109,6 +109,7 @@ struct Values {
|
|||||||
QString room_port;
|
QString room_port;
|
||||||
uint host_type;
|
uint host_type;
|
||||||
qulonglong game_id;
|
qulonglong game_id;
|
||||||
|
QString room_description;
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
bool show_console;
|
bool show_console;
|
||||||
|
@ -23,6 +23,7 @@ struct Room {
|
|||||||
u64 game_id;
|
u64 game_id;
|
||||||
};
|
};
|
||||||
std::string name;
|
std::string name;
|
||||||
|
std::string description;
|
||||||
std::string UID;
|
std::string UID;
|
||||||
std::string owner;
|
std::string owner;
|
||||||
std::string ip;
|
std::string ip;
|
||||||
@ -49,13 +50,15 @@ public:
|
|||||||
* Sets the Information that gets used for the announce
|
* Sets the Information that gets used for the announce
|
||||||
* @param uid The Id of the room
|
* @param uid The Id of the room
|
||||||
* @param name The name of the room
|
* @param name The name of the room
|
||||||
|
* @param description The room description
|
||||||
* @param port The port of the room
|
* @param port The port of the room
|
||||||
* @param net_version The version of the libNetwork that gets used
|
* @param net_version The version of the libNetwork that gets used
|
||||||
* @param has_password True if the room is passowrd protected
|
* @param has_password True if the room is passowrd protected
|
||||||
* @param preferred_game The preferred game of the room
|
* @param preferred_game The preferred game of the room
|
||||||
* @param preferred_game_id The title id of the preferred game
|
* @param preferred_game_id The title id of the preferred game
|
||||||
*/
|
*/
|
||||||
virtual void SetRoomInformation(const std::string& uid, const std::string& name, const u16 port,
|
virtual void SetRoomInformation(const std::string& uid, const std::string& name,
|
||||||
|
const std::string& description, const u16 port,
|
||||||
const u32 max_player, const u32 net_version,
|
const u32 max_player, const u32 net_version,
|
||||||
const bool has_password, const std::string& preferred_game,
|
const bool has_password, const std::string& preferred_game,
|
||||||
const u64 preferred_game_id) = 0;
|
const u64 preferred_game_id) = 0;
|
||||||
@ -100,7 +103,8 @@ class NullBackend : public Backend {
|
|||||||
public:
|
public:
|
||||||
~NullBackend() = default;
|
~NullBackend() = default;
|
||||||
void SetRoomInformation(const std::string& /*uid*/, const std::string& /*name*/,
|
void SetRoomInformation(const std::string& /*uid*/, const std::string& /*name*/,
|
||||||
const u16 /*port*/, const u32 /*max_player*/, const u32 /*net_version*/,
|
const std::string& /*description*/, const u16 /*port*/,
|
||||||
|
const u32 /*max_player*/, const u32 /*net_version*/,
|
||||||
const bool /*has_password*/, const std::string& /*preferred_game*/,
|
const bool /*has_password*/, const std::string& /*preferred_game*/,
|
||||||
const u64 /*preferred_game_id*/) override {}
|
const u64 /*preferred_game_id*/) override {}
|
||||||
void AddPlayer(const std::string& /*nickname*/, const MacAddress& /*mac_address*/,
|
void AddPlayer(const std::string& /*nickname*/, const MacAddress& /*mac_address*/,
|
||||||
|
@ -78,10 +78,11 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() {
|
|||||||
}
|
}
|
||||||
Network::RoomInformation room_information = room->GetRoomInformation();
|
Network::RoomInformation room_information = room->GetRoomInformation();
|
||||||
std::vector<Network::Room::Member> memberlist = room->GetRoomMemberList();
|
std::vector<Network::Room::Member> memberlist = room->GetRoomMemberList();
|
||||||
backend->SetRoomInformation(
|
backend->SetRoomInformation(room_information.uid, room_information.name,
|
||||||
room_information.uid, room_information.name, room_information.port,
|
room_information.description, room_information.port,
|
||||||
room_information.member_slots, Network::network_version, room->HasPassword(),
|
room_information.member_slots, Network::network_version,
|
||||||
room_information.preferred_game, room_information.preferred_game_id);
|
room->HasPassword(), room_information.preferred_game,
|
||||||
|
room_information.preferred_game_id);
|
||||||
backend->ClearPlayers();
|
backend->ClearPlayers();
|
||||||
for (const auto& member : memberlist) {
|
for (const auto& member : memberlist) {
|
||||||
backend->AddPlayer(member.nickname, member.mac_address, member.game_info.id,
|
backend->AddPlayer(member.nickname, member.mac_address, member.game_info.id,
|
||||||
|
@ -36,6 +36,7 @@ static void PrintHelp(const char* argv0) {
|
|||||||
std::cout << "Usage: " << argv0
|
std::cout << "Usage: " << argv0
|
||||||
<< " [options] <filename>\n"
|
<< " [options] <filename>\n"
|
||||||
"--room-name The name of the room\n"
|
"--room-name The name of the room\n"
|
||||||
|
"--room-description The room description\n"
|
||||||
"--port The port used for the room\n"
|
"--port The port used for the room\n"
|
||||||
"--max_members The maximum number of players for this room\n"
|
"--max_members The maximum number of players for this room\n"
|
||||||
"--password The password for the room\n"
|
"--password The password for the room\n"
|
||||||
@ -63,6 +64,7 @@ int main(int argc, char** argv) {
|
|||||||
gladLoadGL();
|
gladLoadGL();
|
||||||
|
|
||||||
std::string room_name;
|
std::string room_name;
|
||||||
|
std::string room_description;
|
||||||
std::string password;
|
std::string password;
|
||||||
std::string preferred_game;
|
std::string preferred_game;
|
||||||
std::string username;
|
std::string username;
|
||||||
@ -74,6 +76,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"room-name", required_argument, 0, 'n'},
|
{"room-name", required_argument, 0, 'n'},
|
||||||
|
{"room-description", required_argument, 0, 'd'},
|
||||||
{"port", required_argument, 0, 'p'},
|
{"port", required_argument, 0, 'p'},
|
||||||
{"max_members", required_argument, 0, 'm'},
|
{"max_members", required_argument, 0, 'm'},
|
||||||
{"password", required_argument, 0, 'w'},
|
{"password", required_argument, 0, 'w'},
|
||||||
@ -88,12 +91,15 @@ int main(int argc, char** argv) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
char arg = getopt_long(argc, argv, "n:p:m:w:g:u:t:a:i:hv", long_options, &option_index);
|
char arg = getopt_long(argc, argv, "n:d:p:m:w:g:u:t:a:i:hv", long_options, &option_index);
|
||||||
if (arg != -1) {
|
if (arg != -1) {
|
||||||
switch (arg) {
|
switch (arg) {
|
||||||
case 'n':
|
case 'n':
|
||||||
room_name.assign(optarg);
|
room_name.assign(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
room_description.assign(optarg);
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
port = strtoul(optarg, &endarg, 0);
|
port = strtoul(optarg, &endarg, 0);
|
||||||
break;
|
break;
|
||||||
@ -175,8 +181,8 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
Network::Init();
|
Network::Init();
|
||||||
if (std::shared_ptr<Network::Room> room = Network::GetRoom().lock()) {
|
if (std::shared_ptr<Network::Room> room = Network::GetRoom().lock()) {
|
||||||
if (!room->Create(room_name, "", port, password, max_members, preferred_game,
|
if (!room->Create(room_name, room_description, "", port, password, max_members,
|
||||||
preferred_game_id)) {
|
preferred_game, preferred_game_id)) {
|
||||||
std::cout << "Failed to create room: \n\n";
|
std::cout << "Failed to create room: \n\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ public:
|
|||||||
* The packet has the structure:
|
* The packet has the structure:
|
||||||
* <MessageID>ID_ROOM_INFORMATION
|
* <MessageID>ID_ROOM_INFORMATION
|
||||||
* <String> room_name
|
* <String> room_name
|
||||||
|
* <String> room_description
|
||||||
* <u32> member_slots: The max number of clients allowed in this room
|
* <u32> member_slots: The max number of clients allowed in this room
|
||||||
* <String> uid
|
* <String> uid
|
||||||
* <u16> port
|
* <u16> port
|
||||||
@ -404,6 +405,7 @@ void Room::RoomImpl::BroadcastRoomInformation() {
|
|||||||
Packet packet;
|
Packet packet;
|
||||||
packet << static_cast<u8>(IdRoomInformation);
|
packet << static_cast<u8>(IdRoomInformation);
|
||||||
packet << room_information.name;
|
packet << room_information.name;
|
||||||
|
packet << room_information.description;
|
||||||
packet << room_information.member_slots;
|
packet << room_information.member_slots;
|
||||||
packet << room_information.uid;
|
packet << room_information.uid;
|
||||||
packet << room_information.port;
|
packet << room_information.port;
|
||||||
@ -584,9 +586,10 @@ Room::Room() : room_impl{std::make_unique<RoomImpl>()} {}
|
|||||||
|
|
||||||
Room::~Room() = default;
|
Room::~Room() = default;
|
||||||
|
|
||||||
bool Room::Create(const std::string& name, const std::string& server_address, u16 server_port,
|
bool Room::Create(const std::string& name, const std::string& description,
|
||||||
const std::string& password, const u32 max_connections,
|
const std::string& server_address, u16 server_port, const std::string& password,
|
||||||
const std::string& preferred_game, u64 preferred_game_id) {
|
const u32 max_connections, const std::string& preferred_game,
|
||||||
|
u64 preferred_game_id) {
|
||||||
ENetAddress address;
|
ENetAddress address;
|
||||||
address.host = ENET_HOST_ANY;
|
address.host = ENET_HOST_ANY;
|
||||||
if (!server_address.empty()) {
|
if (!server_address.empty()) {
|
||||||
@ -603,6 +606,7 @@ bool Room::Create(const std::string& name, const std::string& server_address, u1
|
|||||||
room_impl->state = State::Open;
|
room_impl->state = State::Open;
|
||||||
|
|
||||||
room_impl->room_information.name = name;
|
room_impl->room_information.name = name;
|
||||||
|
room_impl->room_information.description = description;
|
||||||
room_impl->room_information.member_slots = max_connections;
|
room_impl->room_information.member_slots = max_connections;
|
||||||
room_impl->room_information.port = server_port;
|
room_impl->room_information.port = server_port;
|
||||||
room_impl->room_information.preferred_game = preferred_game;
|
room_impl->room_information.preferred_game = preferred_game;
|
||||||
|
@ -25,6 +25,7 @@ constexpr std::size_t NumChannels = 1; // Number of channels used for the connec
|
|||||||
|
|
||||||
struct RoomInformation {
|
struct RoomInformation {
|
||||||
std::string name; ///< Name of the server
|
std::string name; ///< Name of the server
|
||||||
|
std::string description; ///< Server description
|
||||||
u32 member_slots; ///< Maximum number of members in this room
|
u32 member_slots; ///< Maximum number of members in this room
|
||||||
std::string uid; ///< The unique ID of the room
|
std::string uid; ///< The unique ID of the room
|
||||||
u16 port; ///< The port of this room
|
u16 port; ///< The port of this room
|
||||||
@ -103,8 +104,9 @@ public:
|
|||||||
* Creates the socket for this room. Will bind to default address if
|
* Creates the socket for this room. Will bind to default address if
|
||||||
* server is empty string.
|
* server is empty string.
|
||||||
*/
|
*/
|
||||||
bool Create(const std::string& name, const std::string& server = "",
|
bool Create(const std::string& name, const std::string& description = "",
|
||||||
u16 server_port = DefaultRoomPort, const std::string& password = "",
|
const std::string& server = "", u16 server_port = DefaultRoomPort,
|
||||||
|
const std::string& password = "",
|
||||||
const u32 max_connections = MaxConcurrentConnections,
|
const u32 max_connections = MaxConcurrentConnections,
|
||||||
const std::string& preferred_game = "", u64 preferred_game_id = 0);
|
const std::string& preferred_game = "", u64 preferred_game_id = 0);
|
||||||
|
|
||||||
|
@ -230,11 +230,13 @@ void RoomMember::RoomMemberImpl::HandleRoomInformationPacket(const ENetEvent* ev
|
|||||||
|
|
||||||
RoomInformation info{};
|
RoomInformation info{};
|
||||||
packet >> info.name;
|
packet >> info.name;
|
||||||
|
packet >> info.description;
|
||||||
packet >> info.member_slots;
|
packet >> info.member_slots;
|
||||||
packet >> info.uid;
|
packet >> info.uid;
|
||||||
packet >> info.port;
|
packet >> info.port;
|
||||||
packet >> info.preferred_game;
|
packet >> info.preferred_game;
|
||||||
room_information.name = info.name;
|
room_information.name = info.name;
|
||||||
|
room_information.description = info.description;
|
||||||
room_information.member_slots = info.member_slots;
|
room_information.member_slots = info.member_slots;
|
||||||
room_information.port = info.port;
|
room_information.port = info.port;
|
||||||
room_information.preferred_game = info.preferred_game;
|
room_information.preferred_game = info.preferred_game;
|
||||||
|
@ -27,6 +27,7 @@ void to_json(nlohmann::json& json, const Room& room) {
|
|||||||
json["id"] = room.UID;
|
json["id"] = room.UID;
|
||||||
json["port"] = room.port;
|
json["port"] = room.port;
|
||||||
json["name"] = room.name;
|
json["name"] = room.name;
|
||||||
|
json["description"] = room.description;
|
||||||
json["preferredGameName"] = room.preferred_game;
|
json["preferredGameName"] = room.preferred_game;
|
||||||
json["preferredGameId"] = room.preferred_game_id;
|
json["preferredGameId"] = room.preferred_game_id;
|
||||||
json["maxPlayers"] = room.max_player;
|
json["maxPlayers"] = room.max_player;
|
||||||
@ -41,6 +42,12 @@ void to_json(nlohmann::json& json, const Room& room) {
|
|||||||
void from_json(const nlohmann::json& json, Room& room) {
|
void from_json(const nlohmann::json& json, Room& room) {
|
||||||
room.ip = json.at("address").get<std::string>();
|
room.ip = json.at("address").get<std::string>();
|
||||||
room.name = json.at("name").get<std::string>();
|
room.name = json.at("name").get<std::string>();
|
||||||
|
try {
|
||||||
|
room.description = json.at("description").get<std::string>();
|
||||||
|
} catch (const nlohmann::detail::out_of_range& e) {
|
||||||
|
room.description = "";
|
||||||
|
LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.name);
|
||||||
|
}
|
||||||
room.owner = json.at("owner").get<std::string>();
|
room.owner = json.at("owner").get<std::string>();
|
||||||
room.port = json.at("port").get<u16>();
|
room.port = json.at("port").get<u16>();
|
||||||
room.preferred_game = json.at("preferredGameName").get<std::string>();
|
room.preferred_game = json.at("preferredGameName").get<std::string>();
|
||||||
@ -59,11 +66,13 @@ void from_json(const nlohmann::json& json, Room& room) {
|
|||||||
|
|
||||||
namespace WebService {
|
namespace WebService {
|
||||||
|
|
||||||
void RoomJson::SetRoomInformation(const std::string& uid, const std::string& name, const u16 port,
|
void RoomJson::SetRoomInformation(const std::string& uid, const std::string& name,
|
||||||
|
const std::string& description, const u16 port,
|
||||||
const u32 max_player, const u32 net_version,
|
const u32 max_player, const u32 net_version,
|
||||||
const bool has_password, const std::string& preferred_game,
|
const bool has_password, const std::string& preferred_game,
|
||||||
const u64 preferred_game_id) {
|
const u64 preferred_game_id) {
|
||||||
room.name = name;
|
room.name = name;
|
||||||
|
room.description = description;
|
||||||
room.UID = uid;
|
room.UID = uid;
|
||||||
room.port = port;
|
room.port = port;
|
||||||
room.max_player = max_player;
|
room.max_player = max_player;
|
||||||
|
@ -20,8 +20,9 @@ public:
|
|||||||
RoomJson(const std::string& host, const std::string& username, const std::string& token)
|
RoomJson(const std::string& host, const std::string& username, const std::string& token)
|
||||||
: client(host, username, token), host(host), username(username), token(token) {}
|
: client(host, username, token), host(host), username(username), token(token) {}
|
||||||
~RoomJson() = default;
|
~RoomJson() = default;
|
||||||
void SetRoomInformation(const std::string& uid, const std::string& name, const u16 port,
|
void SetRoomInformation(const std::string& uid, const std::string& name,
|
||||||
const u32 max_player, const u32 net_version, const bool has_password,
|
const std::string& description, const u16 port, const u32 max_player,
|
||||||
|
const u32 net_version, const bool has_password,
|
||||||
const std::string& preferred_game,
|
const std::string& preferred_game,
|
||||||
const u64 preferred_game_id) override;
|
const u64 preferred_game_id) override;
|
||||||
void AddPlayer(const std::string& nickname,
|
void AddPlayer(const std::string& nickname,
|
||||||
|
Loading…
Reference in New Issue
Block a user