greeting for login/logout

This commit is contained in:
notify 2023-04-20 15:06:52 +08:00
parent 1b80a2b2ca
commit 553022db14
2 changed files with 16 additions and 4 deletions

View File

@ -29,6 +29,18 @@
</message>
</context>
<context>
<name>Server</name>
<message>
<source>%1 logged in</source>
<translation> &lt;b>%1&lt;/b> </translation>
</message>
<message>
<source>%1 logged out</source>
<translation> &lt;b>%1&lt;/b> </translation>
</message>
</context>
<context>
<name>Init</name>
<message>

View File

@ -81,7 +81,7 @@ Server::~Server() {
}
bool Server::listen(const QHostAddress &address, ushort port) {
bool ret = server->listen(address, port);
bool ret = server->listen(address, port);
isListening = ret;
return ret;
}
@ -330,6 +330,7 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name,
player->setScreenName(name);
player->setAvatar(obj["avatar"].toString());
player->setId(obj["id"].toString().toInt());
broadcast("ServerMessage", tr("%1 logged in").arg(player->getScreenName()));
players.insert(player->getId(), player);
// tell the lobby player's basic property
@ -373,6 +374,7 @@ void Server::onRoomAbandoned() {
void Server::onUserDisconnected() {
ServerPlayer *player = qobject_cast<ServerPlayer *>(sender());
qInfo() << "Player" << player->getId() << "disconnected";
broadcast("ServerMessage", tr("%1 logged out").arg(player->getScreenName()));
Room *room = player->getRoom();
if (room->isStarted()) {
if (room->getObservers().contains(player)) {
@ -401,6 +403,4 @@ void Server::readConfig() {
// defaults
}
QJsonValue Server::getConfig(const QString &key) {
return config.value(key);
}
QJsonValue Server::getConfig(const QString &key) { return config.value(key); }