Write report info to table

This commit is contained in:
Benau
2019-05-09 15:45:02 +08:00
parent 65e53f19e5
commit bf3466d4d1
5 changed files with 47 additions and 5 deletions

View File

@@ -275,10 +275,12 @@ CREATE TABLE online_id_ban
CREATE TABLE player_reports
(
reported_online_id INTEGER UNSIGNED NOT NULL, -- Online id of player who reports, 0 for offline player
reported_username TEXT NOT NULL, -- Player name who reports
reporter_ip INTEGER UNSIGNED NOT NULL, -- IP decimal of player who reports
reporter_online_id INTEGER UNSIGNED NOT NULL, -- Online id of player who reports, 0 for offline player
reporter_username TEXT NOT NULL, -- Player name who reports
reported_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, -- Time of reporting
info TEXT NOT NULL, -- Report info by reporter
reporting_ip INTEGER UNSIGNED NOT NULL, -- IP decimal of player being reported
reporting_online_id INTEGER UNSIGNED NOT NULL, -- Online id of player being reported, 0 for offline player
reporting_username TEXT NOT NULL -- Player name being reported
);

View File

@@ -74,7 +74,8 @@ public:
LE_LIVE_JOIN_ACK, // Server tell client live join or spectate succeed
LE_KART_INFO, // Client or server exchange new kart info
LE_CLIENT_BACK_LOBBY, // Client tell server to go back lobby
LE_REPORT_USER // Client report user in server (like abusive behaviour)
LE_REPORT_PLAYER // Client report some player in server
// (like abusive behaviour)
};
enum RejectReason : uint8_t

View File

@@ -613,6 +613,7 @@ bool ServerLobby::notifyEventAsynchronous(Event* event)
case LE_CHANGE_HANDICAP: changeHandicap(event); break;
case LE_CLIENT_BACK_LOBBY:
clientSelectingAssetsWantsToBackLobby(event); break;
case LE_REPORT_PLAYER: writePlayerReport(event); break;
default: break;
} // switch
} // if (event->getType() == EVENT_TYPE_MESSAGE)
@@ -766,6 +767,43 @@ void ServerLobby::checkTableExists(const std::string& table, bool& result)
} // checkTableExists
#endif
//-----------------------------------------------------------------------------
void ServerLobby::writePlayerReport(Event* event)
{
#ifdef ENABLE_SQLITE3
if (!m_db || !m_player_reports_table_exists)
return;
STKPeer* reporter = event->getPeer();
if (!reporter->hasPlayerProfiles())
return;
auto reporter_npp = reporter->getPlayerProfiles()[0];
uint32_t reporting_host_id = event->data().getUInt32();
core::stringw info;
event->data().decodeString16(&info);
if (info.empty())
return;
auto reporting_peer = STKHost::get()->findPeerByHostId(reporting_host_id);
if (!reporting_peer || !reporting_peer->hasPlayerProfiles())
return;
auto reporting_npp = reporting_peer->getPlayerProfiles()[0];
std::string query = StringUtils::insertValues(
"INSERT INTO %s "
"(reporter_ip, reporter_online_id, reporter_username, info, "
"reporting_ip, reporting_online_id, reporting_username) "
"VALUES (%u, %u, \"%s\", \"%s\", %u, %u, \"%s\");",
ServerConfig::m_player_reports_table.c_str(),
reporter->getAddress().getIP(), reporter_npp->getOnlineId(),
StringUtils::wideToUtf8(reporter_npp->getName()).c_str(),
StringUtils::wideToUtf8(info).c_str(),
reporting_peer->getAddress().getIP(), reporting_npp->getOnlineId(),
StringUtils::wideToUtf8(reporting_npp->getName()).c_str());
easySQLQuery(query);
#endif
} // writePlayerReport
//-----------------------------------------------------------------------------
/** Find out the public IP server or poll STK server asynchronously. */
void ServerLobby::asynchronousUpdate()

View File

@@ -323,6 +323,7 @@ private:
void testBannedForIP(STKPeer* peer) const;
void testBannedForOnlineId(STKPeer* peer, uint32_t online_id) const;
void writeDisconnectInfoTable(STKPeer* peer);
void writePlayerReport(Event* event);
public:
ServerLobby();
virtual ~ServerLobby();

View File

@@ -177,8 +177,8 @@ void NetworkUserDialog::onUpdate(float dt)
if (info.empty())
return false;
NetworkString report(PROTOCOL_LOBBY_ROOM);
report.addUInt8(LobbyProtocol::LE_REPORT_USER)
.addUInt32(host_id).encodeString(info);
report.addUInt8(LobbyProtocol::LE_REPORT_PLAYER)
.addUInt32(host_id).encodeString16(info);
STKHost::get()->sendToServer(&report, true/*reliable*/);
return true;
});