Пример #1
0
void PollSessions()
{
	session_node *s;
	int i,poll_time;
	
	poll_time = GetTime();
	
	ProcessSysTimer(poll_time);
	
	for (i=0;i<num_sessions;i++)
	{
		s = GetSessionByID(i);
		if (s == NULL)
			continue;
		
		PollSession(s->session_id);
		
		if (s->connected)
		{
			if (s->timer != 0 && poll_time >= s->timer)
				ProcessSessionTimer(s);
		}
		
	}
}
Пример #2
0
Bool SuspendAccountAbsolute(account_node *a, int suspend_time)
{
   session_node *s;
   int now = GetTime();

   /* validate arguments */

   if (suspend_time < 0)
   {
      eprintf("SuspendAccountAbsolute: invalid suspend time %d; ignored\n",suspend_time);
      return False;
   }

   if (a == NULL || a->account_id == 0 || a->type == GUEST_ACCOUNT)
   {
      eprintf("SuspendAccountAbsolute: cannot suspend account\n");
      return False;
   }

   /* check for lifting suspension */

   if (suspend_time <= now)
   {
      if (a->suspend_time <= now)
      {
	 /* no report for lifting suspension on unsuspended account */
      }
      else
      {
	 lprintf("Suspension of account %i (%s) lifted\n",
	         a->account_id, a->name);
      }
      a->suspend_time = 0;
      return True;
   }

   /* suspension going into effect or remaining in effect */

   a->suspend_time = suspend_time;

   lprintf("Suspended account %i (%s) until %s\n",
           a->account_id, a->name, TimeStr(suspend_time));

   s = GetSessionByAccount(a);
   if (s != NULL)
   {
      HangupSession(s);
      PollSession(s->session_id);
      if (GetSessionByAccount(a) != NULL)
      {
	 eprintf("SuspendAccountAbsolute: tried to hangup account %i but failed\n",
		 a->account_id);
      }
   }

   return True;
}
Пример #3
0
void DeleteAccountAndAssociatedUsersByID(int account_id)
{
   account_node *a;
   session_node *s;

   /* called from timer loop */

   a = GetAccountByID(account_id);
   if (a == NULL)
   {
      eprintf("DeleteAccountAndAssociatedUsersByID: can't delete account %i\n",account_id);
      return;
   }
   s = GetSessionByAccount(a);
   if (s != NULL)
   {
      HangupSession(s);
      PollSession(s->session_id);
      if (GetSessionByAccount(a) != NULL)
      {
	 eprintf("DeleteAccountAndAssociatedUsersByID: tried to hangup account %i but failed\n",
		 account_id);
	 return;
      }
   }

   lprintf("Attempting delete of account %i (%s) (last login %s)\n",
           account_id, a->name, TimeStr(a->last_login_time));

   ForEachUserByAccountID(AdminDeleteEachUserObject,account_id);
   
   DeleteUserByAccountID(account_id);
   
   if (!DeleteAccount(account_id))
   {
      eprintf("DeleteAccountAndAssociatedUsersByID: unable to delete account %i - unknown reason\n",
	      account_id);
      lprintf("Delete of account %i failed - unknown reason\n",
	      account_id);
   }
   else
   {
      lprintf("Delete of account %i successful\n",
	      account_id);
   }
}
Пример #4
0
void ServiceTimers(void)
{
   MSG msg;
   INT64 ms;

   StartupComplete(); /* for the interface to report no errors on startup */
   InterfaceUpdate();
   lprintf("Status: %i accounts\n",GetNextAccountID());

   lprintf("-------------------------------------------------------------------------------------\n");
   dprintf("-------------------------------------------------------------------------------------\n");
   eprintf("-------------------------------------------------------------------------------------\n");

   in_main_loop = True;
   SetWindowText(hwndMain, ConfigStr(CONSOLE_CAPTION));

	AsyncSocketStart();

   for(;;)
   {
      if (timers == NULL)
			ms = 500;
      else
      {
			ms = timers->time - GetMilliCount();
			if (ms <= 0)
				ms = 0;
	 
			if (ms > 500)
				ms = 500;
      }	 
      
      if (MsgWaitForMultipleObjects(0,NULL,0,(DWORD)ms,QS_ALLINPUT) == WAIT_OBJECT_0)
      {
	 while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	 {
	    if (msg.message == WM_QUIT)
	    {
	       lprintf("ServiceTimers shutting down the server\n");   
	       return;
	    }
	    
	    switch (msg.message)
	    {
	    case WM_BLAK_MAIN_READ :
	       EnterServerLock();
	       
	       PollSession(msg.lParam);
	       TimerActivate();
	       
	       LeaveServerLock();
	       break;
	    case WM_BLAK_MAIN_RECALIBRATE :
	       /* new soonest timer, so we should recalculate our time left... 
		  so we just need to restart the loop! */
	       break;
	    case WM_BLAK_MAIN_DELETE_ACCOUNT :
	       EnterServerLock();
	       DeleteAccountAndAssociatedUsersByID(msg.lParam);
	       LeaveServerLock();
	       break;

	    case WM_BLAK_MAIN_VERIFIED_LOGIN :
	       EnterServerLock();
	       VerifiedLoginSession(msg.lParam);
	       LeaveServerLock();
	       break;
       case WM_BLAK_MAIN_LOAD_GAME :
          EnterServerLock();
          LoadFromKod(msg.lParam);
          LeaveServerLock();
          break;

	    default :
	       dprintf("ServiceTimers got unknown message %i\n",msg.message);
	       break;
	    }
	 }
      }
      else
      {
	 /* a Blakod timer is ready to go */
	 
	 EnterServerLock();
	 PollSessions(); /* really just need to check session timers */
	 TimerActivate();
	 LeaveServerLock();
      }
   }
}