I am new to rethinkdb and I'm working on an admin tool for a game server in which I need to record player kills and deaths. I have the following structure for a player in which "name" is a secondary index:
"name": NameofPlayer,
"sessions:" [
{
"id": IDofSession,
"kills": NumberofKills,
"deaths": NumberofDeaths,
"hskr": HSKR%,
"weapons": [
{
"name": WeaponName,
"kills": NumberofKills,
"headshots": NumberofHeadshots
},
]
},
]
I get the current session id from the server and an event fires on a kill that returns killer, victim, weapon name, and headshot(true/false). I need to create an update to both players involved with the following:
- If a player session of the current id from the server does not exist, create one
- If a session exists with the current id then
- For the player making the kill
- Update the number of total kills, and headshot-kill ratio
- If a weapon does not exist create one and record name, kills, and headshot
- If a weapon exists update number of kills and headshots
- For player being killed
- Update number of total deaths
- For the player making the kill
I need to keep the above player structure but am open to how to update the players.