Skip to content

Commit

Permalink
Skeleton of JSON stats writer
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyahuyasa committed Jan 7, 2025
1 parent bede188 commit 59658a8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ server-init.cfg
.deps
.libs
src/mod/discord/discord.so
src/.cache
70 changes: 70 additions & 0 deletions src/mod/statswriter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* remod: statswriter.cpp
* date: 2025
* author: degrave
*
* JSON stats writer
*/

#include "remod.h"
#include "tools.h"

EXTENSION(STATSWRITER);

namespace remod {
namespace statswriter {
struct playerinfo {
const char *name;
const char *authname;
unsigned int connect_seconds;
const char *team;
int privilege;
int frags, flags, deaths, teamkills, shotdamage, damage;
float effectiveness;
int suicides;
struct {
int shotdamage;
int damage;
} guninfo[NUMGUNS];
};
struct teaminfo {
const char *team;
int score;
};
struct gameinfo {
int mode;
const char *mapname;
};
struct stats {
vector<playerinfo> players;
vector<teaminfo> teams;
struct gameinfo game;
};

void write_game(stream *statsfile, gameinfo game) {
statsfile->printf("\"game\":{\"mode\": %d, \"map\": \"%s\"}", game.mode,
game.mapname);
}

void write_teams(stream *statsfile, gameinfo game) {
// TODO
}

void write_players(stream *statsfile, gameinfo game) {
// TODO
}

void write(const char *path, stats stats) {
stream *statsfile = openfile(path, "wb");
if (!statsfile) {
conoutf("could not write stats to \"%s\"", path);
return;
}

statsfile->printf("{");
write_game(statsfile, stats.game);
statsfile->printf("}");
};

} // namespace statswriter
} // namespace remod

0 comments on commit 59658a8

Please sign in to comment.