Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log moderation stats in the uptime table #3215

Merged
merged 8 commits into from
May 2, 2018
Merged

log moderation stats in the uptime table #3215

merged 8 commits into from
May 2, 2018

Conversation

ZeldaZach
Copy link
Member

Update the server stats logging to include mods / which mods are logged in. I find it useful as a server operator to know who on my staff is around.

Copy link
Contributor

@ctrlaltca ctrlaltca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build failed because you need to update the database version in https://github.com/Cockatrice/Cockatrice/blob/master/servatrice/src/servatrice_database_interface.h#L12

While i like the c++11-ization of the code, reviewing the main change in the middle of a lot of unrelated changes is harder. I'll try to sum up them here to ease the review:

  • use of the auto specifier where possible
  • change for loops from index-based to range-based (aka "colon")
  • add explicit static_casts where an implicit conversion was previously used, mostly to convert to google::protobuf types
  • add the const attribute to class methods where applicable
  • rename variables to better express their content (eg. from "query" to "forgotPwQuery")

I don't see a good point for a few minor changes: see inline comments.

"insert into {prefix}_uptime (id_server, timest, uptime, users_count, games_count, tx_bytes, rx_bytes) "
"values(:id, NOW(), :uptime, :users_count, :games_count, :tx, :rx)");
"insert into {prefix}_uptime (id_server, timest, uptime, users_count, mods_count, mods_list, games_count, "
"tx_bytes, "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line splitting looks ugly, is this due to clang-format?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... I'll re-do this

common/server.h Outdated
void addExternalUser(const ServerInfo_User &userInfo);
void removeExternalUser(const QString &userName);
virtual void addExternalUser(const ServerInfo_User &userInfo) = delete;
virtual void removeExternalUser(const QString &userName) = delete;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These looks like leftovers as they have been implemented in Server_Room, maybe they can just be deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha

Server::~Server()
{
}
Server::~Server() = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be removed and = default added in the .h?

-- Servatrice db migration from version 24 to version 25

ALTER TABLE `cockatrice_uptime` ADD COLUMN `mods_count` int(11) NOT NULL DEFAULT 0;
ALTER TABLE `cockatrice_uptime` ADD COLUMN `mods_list` BLOB;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are storing text and not binary data, TEXT is a better choice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never knew the diff, thanks!

@@ -74,11 +74,11 @@ Servatrice_GameServer::~Servatrice_GameServer()
}
}

void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor)
void Servatrice_GameServer::incomingConnection(const int &socketDescriptor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base Qt class is declaring a qintptr argument (http://doc.qt.io/qt-5/qtcpserver.html#incomingConnection), i see no reason to change this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change this, which was weird... Clion didn't like the qintptr :P Will readdress this

result.append(static_cast<AbstractServerSocketInterface *>(clients[i]));
for (auto client : clients)
if (dynamic_cast<AbstractServerSocketInterface *>(client)->getPeerAddress() == address)
result.append(dynamic_cast<AbstractServerSocketInterface *>(client));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A client is a Server_ProtocolHandler *, and theAbstractServerSocketInterface is a subclass of Server_ProtocolHandler.
Since we can guarantee that the down-cast is safe, static_cast is a better choice.
dynamic_cast could be a safer choice if we are not sure about the type of client, but still we should check the cast result before dereferencing it.
Also, dynamic_cast has a runtime performance cost.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLion didn't agree with this being static for some reason, but I'll listen

Copy link
Contributor

@ctrlaltca ctrlaltca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to fix the version number in the sql file, then it should be fine

@ZeldaZach
Copy link
Member Author

Done!

ALTER TABLE `cockatrice_uptime` ADD COLUMN `mods_count` int(11) NOT NULL DEFAULT 0;
ALTER TABLE `cockatrice_uptime` ADD COLUMN `mods_list` TEXT;

UPDATE `cockatrice_schema_version` SET `version` = 25 WHERE `version` = 24;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build script is checking for an exact string here; the check fails because the table and column names are surrounded by ` quotes.
Quick fix: remove them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been done with other sql migrations... oh well

common/server.h Outdated
Server(QObject *parent = 0);
~Server();
Server(QObject *parent = nullptr);
Server::~Server() = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Server:: qualifier is not needed here

ALTER TABLE cockatrice_uptime ADD COLUMN mods_count int(11) NOT NULL DEFAULT 0;
ALTER TABLE cockatrice_uptime ADD COLUMN mods_list TEXT;

UPDATE cockatrice_schema_version SET version = 25 WHERE version = 24;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checker script expects the exact string:

UPDATE cockatrice_schema_version SET version=25 WHERE version=24;

Please remove spaces around the equal signs, we'll fix the script later.

@ZeldaZach
Copy link
Member Author

@ctrlaltca I'm not sure why linux is failing... the function join() was introduced in qt4 so it should be in qt5.2.1...

@@ -566,6 +565,11 @@ void Servatrice::statusUpdate()
return;

const int uc = getUsersCount(); // for correct mutex locking order

const QList<QString> mods_info = getOnlineModeratorList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use QStringList instead of QList<QString>, add the #include if needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems silly as they should be equiv... but w/e i'll get that fixed

Copy link
Contributor

@ctrlaltca ctrlaltca May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From https://doc.qt.io/qt-5/qlist.html :

Qt includes a QStringList class that inherits QList and adds a few convenience functions, such as QStringList::join() and QStringList::filter(). QString::split() creates QStringLists from strings.

Seems like they're equiv.. except for split(), join() and filter().

@ZeldaZach ZeldaZach merged commit 2520d07 into Cockatrice:master May 2, 2018
@ZeldaZach ZeldaZach deleted the log_mod_stats branch May 2, 2018 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants