Server Help

ASSS Questions - Mainloop Timer

Hakaku - Sat Jun 26, 2010 4:38 pm
Post subject: Mainloop Timer
Why is it that everytime I try to loop over every player within a timer, it just ends up triggering a deadlock? If I remove the FOR_EACH_PLAYER loop, then it continues without a hitch. What exactly am I doing wrong and how else can I achieve this?

Edit: Nevermind, I typo'd playerdata -_-;

Code: Show/Hide

#include "asss.h"

local Imodman     *mm;
local Iarenaman   *aman;
local Imainloop   *mainloop;
local Iplayerdata *pd;

local int timer(void *arena_)
{
   Arena *arena = arena_;

   Player *p;
   Link *link;

   pd->Lock();
   FOR_EACH_PLAYER(p)
   {
      //crashes here
   }
   pd->Unlock();

   return 1;
}

EXPORT int MM_mymodule(int action, Imodman *mm_, Arena *arena)
{
   if (action == MM_LOAD)
   {
      mm = mm_;
      aman = mm->GetInterface(I_ARENAMAN, ALLARENAS);
      mainloop = mm->GetInterface(I_MAINLOOP, ALLARENAS);
      pd = mm->GetInterface(I_PLAYERDATA, ALLARENAS);

      if (!aman || !mainloop || !pd)
         return MM_FAIL;

      return MM_OK;
   }
   else if (action == MM_UNLOAD)
   {
      mainloop->ClearTimer(timer, NULL);
      mm->ReleaseInterface(pd);
      mm->ReleaseInterface(mainloop);
      mm->ReleaseInterface(aman);
      return MM_OK;
   }
   else if (action == MM_ATTACH)
   {
      mainloop->SetTimer(timer, 500, 100, arena, arena);
      return MM_OK;
   }
   else if (action == MM_DETACH)
   {
      mainloop->ClearTimer(timer, arena);
      return MM_OK;
   }
   return MM_FAIL;
}

All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group