Add success status to player who reports
This commit is contained in:
parent
5b6b38346c
commit
fff6c1d51f
@ -172,6 +172,7 @@ bool ClientLobby::notifyEvent(Event* event)
|
||||
case LE_LIVE_JOIN_ACK: liveJoinAcknowledged(event); break;
|
||||
case LE_KART_INFO: handleKartInfo(event); break;
|
||||
case LE_START_RACE: startGame(event); break;
|
||||
case LE_REPORT_PLAYER: reportSuccess(event); break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
@ -1448,3 +1449,19 @@ void ClientLobby::addSpectateHelperMessage() const
|
||||
"or <%s> for the camera position.", left, right, back);
|
||||
MessageQueue::add(MessageQueue::MT_GENERIC, msg);
|
||||
} // addSpectateHelperMessage
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ClientLobby::reportSuccess(Event* event)
|
||||
{
|
||||
bool succeeded = false;
|
||||
core::stringw reporting_name;
|
||||
succeeded = event->data().getUInt8() == 1;
|
||||
if (succeeded)
|
||||
event->data().decodeStringW(&reporting_name);
|
||||
if (succeeded && !reporting_name.empty())
|
||||
{
|
||||
// I18N: Tell player he has successfully report this named player
|
||||
core::stringw msg = _("Successfully reported %s.", reporting_name);
|
||||
MessageQueue::add(MessageQueue::MT_GENERIC, msg);
|
||||
}
|
||||
} // reportSuccess
|
||||
|
@ -66,6 +66,7 @@ private:
|
||||
void updatePlayerList(Event* event);
|
||||
void handleChat(Event* event);
|
||||
void handleServerInfo(Event* event);
|
||||
void reportSuccess(Event* event);
|
||||
void handleBadTeam();
|
||||
void handleBadConnection();
|
||||
void becomingServerOwner();
|
||||
|
@ -783,12 +783,13 @@ void ServerLobby::cleanupDatabase()
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Run simple query with write lock waiting and optional function, this
|
||||
* function has no callback for the return (if any) by the query.
|
||||
* Return true if no error occurs
|
||||
*/
|
||||
void ServerLobby::easySQLQuery(const std::string& query,
|
||||
bool ServerLobby::easySQLQuery(const std::string& query,
|
||||
std::function<void(sqlite3_stmt* stmt)> bind_function) const
|
||||
{
|
||||
if (!m_db)
|
||||
return;
|
||||
return false;
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
int ret = sqlite3_prepare_v2(m_db, query.c_str(), -1, &stmt, 0);
|
||||
if (ret == SQLITE_OK)
|
||||
@ -802,6 +803,7 @@ void ServerLobby::easySQLQuery(const std::string& query,
|
||||
Log::error("ServerLobby",
|
||||
"Error finalize database for easy query %s: %s",
|
||||
query.c_str(), sqlite3_errmsg(m_db));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -809,7 +811,9 @@ void ServerLobby::easySQLQuery(const std::string& query,
|
||||
Log::error("ServerLobby",
|
||||
"Error preparing database for easy query %s: %s",
|
||||
query.c_str(), sqlite3_errmsg(m_db));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} // easySQLQuery
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -928,7 +932,8 @@ void ServerLobby::writePlayerReport(Event* event)
|
||||
ServerConfig::m_player_reports_table.c_str(),
|
||||
reporter->getAddress().getIP(), reporter_npp->getOnlineId(),
|
||||
reporting_peer->getAddress().getIP(), reporting_npp->getOnlineId());
|
||||
easySQLQuery(query, [reporter_npp, reporting_npp, info](sqlite3_stmt* stmt)
|
||||
bool written = easySQLQuery(query,
|
||||
[reporter_npp, reporting_npp, info](sqlite3_stmt* stmt)
|
||||
{
|
||||
// SQLITE_TRANSIENT to copy string
|
||||
if (sqlite3_bind_text(stmt, 1, ServerConfig::m_server_uid.c_str(),
|
||||
@ -959,6 +964,15 @@ void ServerLobby::writePlayerReport(Event* event)
|
||||
StringUtils::wideToUtf8(reporting_npp->getName()).c_str());
|
||||
}
|
||||
});
|
||||
if (written)
|
||||
{
|
||||
NetworkString* success = getNetworkString();
|
||||
success->setSynchronous(true);
|
||||
success->addUInt8(LE_REPORT_PLAYER).addUInt8(1)
|
||||
.encodeString(reporting_npp->getName());
|
||||
event->getPeer()->sendPacket(success, true/*reliable*/);
|
||||
delete success;
|
||||
}
|
||||
#endif
|
||||
} // writePlayerReport
|
||||
|
||||
|
@ -88,7 +88,7 @@ private:
|
||||
|
||||
void cleanupDatabase();
|
||||
|
||||
void easySQLQuery(const std::string& query,
|
||||
bool easySQLQuery(const std::string& query,
|
||||
std::function<void(sqlite3_stmt* stmt)> bind_function = nullptr) const;
|
||||
|
||||
void checkTableExists(const std::string& table, bool& result);
|
||||
|
Loading…
Reference in New Issue
Block a user