Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
persist

 
Post new topic   Reply to topic Printable version
 View previous topic  error compiling asss on CentOS Post :: Post help on asss  View next topic  
Author Message
JoWie
Server Help Squatter


Gender:Gender:Male
Joined: Feb 25 2004
Posts: 215
Offline

PostPosted: Tue Sep 18, 2007 9:44 am    Post subject: persist Reply to topic Reply with quote

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:


  • When a new flag game begins, the information of the old flag game must be removed.
  • When the module is detached (MM_DETACH), the game is ended and the information has to be removed
  • If the flag game is running in for example Public 0 and Public 5, switching between these publics does not reset the statistics of the other public.
  • Being able to store non integral data. (Not a problem with persist, but perhaps a problem with other available methods)



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
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Tue Sep 18, 2007 10:14 am    Post subject: Reply to topic Reply with quote

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).
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
JoWie
Server Help Squatter


Gender:Gender:Male
Joined: Feb 25 2004
Posts: 215
Offline

PostPosted: Thu Sep 20, 2007 4:40 pm    Post subject: Reply to topic Reply with quote

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?
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Sep 20, 2007 6:11 pm    Post subject: Reply to topic Reply with quote

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)?
Back to top
View users profile Send private message Add User to Ignore List AIM Address
JoWie
Server Help Squatter


Gender:Gender:Male
Joined: Feb 25 2004
Posts: 215
Offline

PostPosted: Fri Sep 21, 2007 7:25 am    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 23 page(s) served in previous 5 minutes.

phpBB Created this page in 0.477224 seconds : 30 queries executed (94.0%): GZIP compression disabled