Skip to content

Commit 53f8184

Browse files
committed
[Database] Allow to save kart color, kart characteristics and powerup config names, disconnection time
Please note that the results table schema may change later before merging #5. In this commit, the changes are: - added items TEXT, kart_color REAL, is_quit INTEGER - result stores kart's race time independently of whether it's a quit or not - config stores kart characteristics file name, items stores powerup file name, empty if the name is default. One may need to change NULL values in config and items to an empty string.
1 parent 005ea99 commit 53f8184

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/karts/kart_properties_manager.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class KartPropertiesManager: public NoCopy
7070
std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_kart_type_characteristics;
7171
std::map<std::string, std::unique_ptr<AbstractCharacteristic> > m_player_characteristics;
7272

73+
std::string m_file_name;
74+
7375
protected:
7476

7577
typedef PtrVector<KartProperties> KartPropertiesVector;
@@ -149,6 +151,11 @@ class KartPropertiesManager: public NoCopy
149151
// ------------------------------------------------------------------------
150152
void onDemandLoadKartTextures(const std::set<std::string>& kart_list,
151153
bool unload_unused = true);
154+
// ------------------------------------------------------------------------
155+
void setFileName(const std::string file_name) { m_file_name = file_name; }
156+
// ------------------------------------------------------------------------
157+
std::string getFileName() { return m_file_name; }
158+
152159
};
153160

154161
extern KartPropertiesManager *kart_properties_manager;

src/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,7 @@ void initRest()
19601960
std::string char_file;
19611961
if (!CommandLine::has("--char-file", &char_file))
19621962
char_file = "kart_characteristics.xml";
1963+
kart_properties_manager->setFileName(char_file);
19631964
XMLNode characteristicsNode(file_manager->getAsset(char_file));
19641965
kart_properties_manager->loadCharacteristics(&characteristicsNode);
19651966

src/network/protocols/server_lobby.cpp

+26-7
Original file line numberDiff line numberDiff line change
@@ -6763,6 +6763,14 @@ void ServerLobby::updateGnuElimination()
67636763
void ServerLobby::storeResults()
67646764
{
67656765
#ifdef ENABLE_SQLITE3
6766+
std::string powerup_string = powerup_manager->getFileName();
6767+
std::string kc_string = kart_properties_manager->getFileName();
6768+
// TODO: don't use file names as constants
6769+
if (powerup_string == "powerup.xml")
6770+
powerup_string = "";
6771+
if (kc_string == "kart_characteristics.xml")
6772+
kc_string = "";
6773+
67666774
bool racing_mode = false;
67676775
bool ffa = RaceManager::get()->getMinorMode() ==
67686776
RaceManager::MINOR_MODE_FREE_FOR_ALL;
@@ -6792,9 +6800,11 @@ void ServerLobby::storeResults()
67926800
{
67936801
std::string get_query = StringUtils::insertValues("SELECT username, "
67946802
"result FROM '%s' WHERE venue = '%s' and reverse = '%s' "
6795-
"and mode = '%s' and laps = %d order by result asc, time asc limit 1;",
6803+
"and mode = '%s' and laps = %d and config = '%s' "
6804+
"and items = '%s' and is_quit = 0 "
6805+
"order by result asc, time asc limit 1;",
67966806
records_table_name.c_str(), track_name.c_str(), reverse_string.c_str(), mode_name.c_str(),
6797-
laps_number);
6807+
laps_number, kc_string.c_str(), powerup_string.c_str());
67986808
auto ret = vectorSQLQuery(get_query, 2);
67996809
record_fetched = ret.first;
68006810
if (record_fetched && ret.second[0].size() > 0)
@@ -6821,8 +6831,11 @@ void ServerLobby::storeResults()
68216831
std::vector<std::string> scores;
68226832
std::vector<std::string> karts;
68236833
std::vector<int> lap_counts;
6834+
std::vector<float> colors;
6835+
std::vector<int> has_quit;
68246836
for (int i = 0; i < player_count; i++)
68256837
{
6838+
// TODO why I cannot use get()->getPlayerName?
68266839
std::string username = StringUtils::wideToUtf8(
68276840
RaceManager::get()->getKartInfo(i).getPlayerName());
68286841
for (std::string& username: usernames) {
@@ -6835,11 +6848,12 @@ void ServerLobby::storeResults()
68356848
double score = DISCONNECT_TIME;
68366849
std::string kart_name = w->getKart(i)->getIdent();
68376850
std::stringstream elapsed_string;
6851+
float kart_color = RaceManager::get()->getKartColor(i);
68386852

68396853
if (racing_mode)
68406854
{
6841-
if (!w->getKart(i)->isEliminated())
6842-
score = RaceManager::get()->getKartRaceTime(i);
6855+
score = RaceManager::get()->getKartRaceTime(i);
6856+
has_quit.push_back(w->getKart(i)->isEliminated() ? 1 : 0);
68436857
elapsed_string << std::setprecision(4) << std::fixed << score;
68446858
if (best_cur_player_idx == -1 || score < best_cur_time)
68456859
{
@@ -6852,6 +6866,7 @@ void ServerLobby::storeResults()
68526866
{
68536867
if (w->getKart(i)->isEliminated())
68546868
continue;
6869+
has_quit.push_back(0);
68556870
if (ffa_world)
68566871
{
68576872
score = ffa_world->getKartScore(i);
@@ -6863,6 +6878,7 @@ void ServerLobby::storeResults()
68636878
scores.push_back(elapsed_string.str());
68646879
karts.push_back(kart_name);
68656880
lap_counts.push_back(laps_number);
6881+
colors.push_back(kart_color);
68666882
}
68676883
if (ServerConfig::m_preserve_battle_scores)
68686884
{
@@ -6872,6 +6888,8 @@ void ServerLobby::storeResults()
68726888
lap_counts.push_back(0);
68736889
scores.push_back(std::to_string(p.second));
68746890
karts.push_back("unknown");
6891+
colors.push_back(-1);
6892+
has_quit.push_back(1);
68756893
}
68766894
}
68776895
m_saved_ffa_points.clear();
@@ -6881,18 +6899,19 @@ void ServerLobby::storeResults()
68816899
"INSERT INTO %s "
68826900
"(username, venue, reverse, mode, laps, result"
68836901
#ifdef ENABLE_RECORDS_V2
6884-
", difficulty, kart, config"
6902+
", difficulty, kart, config, items, kart_color, is_quit"
68856903
#endif
68866904
") "
68876905
"VALUES (?, '%s', '%s', '%s', %d, '%s'"
68886906
#ifdef ENABLE_RECORDS_V2
6889-
", %d, '%s', '%s'"
6907+
", %d, '%s', '%s', '%s', %f, %d"
68906908
#endif
68916909
");",
68926910
m_results_table_name.c_str(), track_name.c_str(),
68936911
reverse_string.c_str(), mode_name.c_str(), lap_counts[i], scores[i].c_str()
68946912
#ifdef ENABLE_RECORDS_V2
6895-
, getDifficulty(), karts[i].c_str(), ""
6913+
, getDifficulty(), karts[i].c_str(), kc_string.c_str(),
6914+
powerup_string.c_str(), colors[i], has_quit[i]
68966915
#endif
68976916
);
68986917
std::string name = usernames[i];

0 commit comments

Comments
 (0)