Skip to content

Commit

Permalink
statswrite ready for test
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyahuyasa committed Jan 9, 2025
1 parent 3b71b1d commit 4c4d822
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 27 deletions.
3 changes: 2 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ SERVER_OBJS= \
mod/cryptomod/polarssl/library/sha2-standalone.o \
mod/cryptomod/polarssl/library/sha4-standalone.o \
mod/banlist-standalone.o \
mod/authservers-standalone.o
mod/authservers-standalone.o \
mod/statswriter.o

# geoip
ifeq ($(USE_GEOIP),true)
Expand Down
81 changes: 60 additions & 21 deletions src/mod/statswriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,24 @@ namespace remod
statsfile->printf(" \"damage\": %d", players[i].damage);
statsfile->printf(" \"effectiveness\": %f,", players[i].effectiveness);
statsfile->printf(" \"suicides\": %d,", players[i].suicides);
statsfile->printf(" \"guninfo\": [", players[i].suicides);
statsfile->printf(" \"guninfo\": [");
loopj(NUMGUNS)
{
if (i != 0)
{
statsfile->printf(",");
}
statsfile->printf("{ \"gun\": %d,", j);
statsfile->printf(" \"shotdamage\": %d,", players[i].guninfo[j].shotdamage);
statsfile->printf(" \"damage\": %d}", players[i].guninfo[j].damage);
statsfile->printf(" \"shotdamage\": %d,", players[i].gi[j].shotdamage);
statsfile->printf(" \"damage\": %d}", players[i].gi[j].damage);
}
statsfile->printf(" ]}");
}
statsfile->printf("]");
}

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

statsfile->printf("{ \"version\": %d,", STATSFILE_FORMAT_VERSION);
write_game(statsfile, stats.game);
statsfile->printf(",");
Expand All @@ -97,27 +90,73 @@ namespace remod
statsfile->printf("}");
};

SVARP(statsdir, "statsdir");

void write(const char *path)
{
static string s;
formatstring(s, "%s/%s", statsdir, path);

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

vector<playerinfo> players;
vector<teaminfo> teams;

loopv(server::clients)
{
playerinfo player = {
.name = server::clients[i]->name,
.authname = server::clients[i]->authname,
.connect_seconds = (unsigned int) server::clients[i]->connectmillis / 1000,
.team = server::clients[i]->team,
.privilege = server::clients[i]->privilege,
.frags = server::clients[i]->state.frags,
.flags = server::clients[i]->state.flags,
.deaths = server::clients[i]->state.deaths,
.teamkills = server::clients[i]->state.teamkills,
.shotdamage = server::clients[i]->state.shotdamage,
.damage = server::clients[i]->state.damage,
.effectiveness = server::clients[i]->state.effectiveness,
.suicides = server::clients[i]->state.ext.suicides};

loopj(NUMGUNS)
{
player.gi[j].shotdamage = server::clients[i]->state.ext.guninfo[j].shotdamage;
player.gi[j].damage = server::clients[i]->state.ext.guninfo[j].damage;
}

players.add(player);
}

struct stats stats = {
players : {
vector<teamscore> scores;

},
teams : {
server::smode->getteamscores(scores);

},
game : {
mode : server::gamemode,
mapname : newstring(server::smapname),
},
vector<teaminfo> teams;
loopv(scores)
{
teaminfo teaminfo = {
.team = newstring(scores[i].team),
.score = scores[i].score,
};
teams.add(teaminfo);
}

stats stats = {
.players = players,
.teams = teams,
.game = {
.mode = server::gamemode,
.mapname = newstring(server::smapname)},
};

writeto(statsfile, stats);
}

COMMANDN(writestats, write, "s");
} // namespace statswriter
} // namespace remod
12 changes: 7 additions & 5 deletions src/mod/statswriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace remod
{
namespace statswriter
{
struct guninfo
{
int shotdamage;
int damage;
};

struct playerinfo
{
const char *name;
Expand All @@ -17,11 +23,7 @@ namespace remod
int frags, flags, deaths, teamkills, shotdamage, damage;
float effectiveness;
int suicides;
struct
{
int shotdamage;
int damage;
} guninfo[NUMGUNS];
guninfo gi[NUMGUNS];
};
struct teaminfo
{
Expand Down

0 comments on commit 4c4d822

Please sign in to comment.