-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Conversation
There was a problem hiding this 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_cast
s 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.
servatrice/src/servatrice.cpp
Outdated
"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, " |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha
common/server.cpp
Outdated
Server::~Server() | ||
{ | ||
} | ||
Server::~Server() = default; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
servatrice/src/servatrice.cpp
Outdated
@@ -74,11 +74,11 @@ Servatrice_GameServer::~Servatrice_GameServer() | |||
} | |||
} | |||
|
|||
void Servatrice_GameServer::incomingConnection(qintptr socketDescriptor) | |||
void Servatrice_GameServer::incomingConnection(const int &socketDescriptor) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
servatrice/src/servatrice.cpp
Outdated
result.append(static_cast<AbstractServerSocketInterface *>(clients[i])); | ||
for (auto client : clients) | ||
if (dynamic_cast<AbstractServerSocketInterface *>(client)->getPeerAddress() == address) | ||
result.append(dynamic_cast<AbstractServerSocketInterface *>(client)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
@ctrlaltca I'm not sure why linux is failing... the function |
servatrice/src/servatrice.cpp
Outdated
@@ -566,6 +565,11 @@ void Servatrice::statusUpdate() | |||
return; | |||
|
|||
const int uc = getUsersCount(); // for correct mutex locking order | |||
|
|||
const QList<QString> mods_info = getOnlineModeratorList(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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().
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.