Server Help

ASSS Questions - persist

JoWie - Tue Sep 18, 2007 9:44 am
Post subject: persist
I do not fully understand the API of persist, so I am hoping someone can tell me how to solve my problem.

Lets say I want to record some statistics of a player during a flag game. (This is not what I actually want to do, but it allows me to simplify my problem)

Code: Show/Hide

/* this code very simplified, removed sanity checks,  etc */

local int playerKey;
struct playerData {
  int kills;
  int deaths;
}

//raise kills and deaths
local void Kill(Arena *arena, Player *killer, Player *killed, int bounty, int flags, int *pts, int *green) {
  struct playerData *killerData = PPDATA(killer, playerKey);
  struct playerData *killedData = PPDATA(killed, playerKey);
  killerData->kills++;
  killedData->deaths++;
}

//reset kills and deaths when a new game begins
local void StartGame (Arena *arena) {
  Player *p;
  Link *link;

  pd->Lock();
  FOR_EACH_PLAYER(p)  {
     if (arena == p->arena) {
        struct playerData *pData = PPDATA(p, playerKey);
        pData->deaths = pData->kills = 0;
     }
  }
  pd->Unlock();
}

//reset kills and deaths when entering a new arena
local void PlayerAction (Player *p, int action, Arena *arena)
{
  if (action == PA_ENTERARENA)
  {
     struct playerData *pData = PPDATA(p, playerKey);
     pData->deaths = pData->kills = 0;
  }


The problem is, when a player gets disconnected for some reason, he ofcourse looses all his statistics.

So I want to cache his statistics using the persist module, while being able to do the following things:




After looking at the persist module I figured I need the following:
Code: Show/Hide

local PlayerPersistentData persistData = {
  5560050, INTERVAL_GAME, PERSIST_ALLARENAS,
  getData, setData, clearData
};

EXPORT int MM_mymodule(int action, Imodman *mm_, Arena *arena)
{
  if (action == MM_LOAD) {
     ...
     persist->RegPlayerPD(&persistData);
     ...
  } else if (action == MM_UNLOAD) {
     ...
     persist->UnregPlayerPD(&persistData);
     ...
  }
}

local int GetData(Player *p, void *data, int len, void *clos) {
//..
}
local void SetData(Player *p, void *data, int len, void *clos) {
//..
}
local void ClearData(Player *p, void *clos) {
//..
}


So, my real questions are:

Am I correct that I need INTERVAL_GAME? Or do I need INTERVAL_FOREVER_NONSHARED?
What is the correct way to handle everything in GetData, SetData and Cleardata?
How do I remove the statistics when a new game begins?


Thank you
Bak - Tue Sep 18, 2007 10:14 am
Post subject:
there's a kickass wrapper i wrote for persist that deals with per player data that takes care of GetData, SetData, and ClearData such that it works like the playerdata interface. It's at http://rshl.org/bak/asss.html

Your other issues still exist though, my guess would be to use interval INTERVAL_GAME, scope PERSIST_ALLARENAS, and to make the scores reset when the game ends, call Ipersist->EndInterval when the game ends (and on arena unloading).
JoWie - Thu Sep 20, 2007 4:40 pm
Post subject:
That's one kick ass wrapper.
It works very good, I am just having one problem.

Whenever a game begins or ends I call
Code: Show/Hide
persist->EndInterval(NULL, arena, INTERVAL_GAME);

Which is working fine. However if I add this to MM_DETACH, ASSS kicks everyone of when switching arenas.

Not doing this in MM_DETACH is not a real problem gameplay wise, since when an arena is created, a new game begins.

My only concerns are that the database could contain old unused items and that there will be random crashes.
Could this be a threading issue?
Bak - Thu Sep 20, 2007 6:11 pm
Post subject:
if the game restarts when an arena is created than that shouldn't be a problem for you, I was only concerned with scores saving after a arena is destroyed and then created again.

although asss shouldn't kick everyone out for this reason.

is asss kicking everyone out? or is it crashing and restarting?

also: does it occur when a player switches arenas or when an arena gets destroyed (when mm_detach occurs)?
JoWie - Fri Sep 21, 2007 7:25 am
Post subject:
As far as I have been able to test:

- ASSS does not crash, nothing appears in the console(all=WE), no restart.
- Everyone times out, I can immediately reconnect. It's like ASSS removes all players from memory.

It happens when:
1. Public (0) has two players: ABC and XYZ
2. ABC Switches to Public (1), game begins in Public (1)
3. ABC goes back from Public (1) to Public (0). Game is still running in Public (0) because of XYZ
4. In Public (1), MM_DETACH is called, everything is fine.
5. ABC switches back to Public (1), ABC and XYZ timeout before MM_ATTACH is called. (Immediately after ?go is sent).

I remember Hyperspace having the same kind of crashing behavior a while back. Perhaps it is an unknown bug in the ASSS distribution.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group