Ejemplo n.º 1
0
void TrySyncProcessSessionTimer(session_node *s)
{
   /* we're going back to resync mode, which means we wait for the client
      to send us beacon_str.  It might not know that, so we send some
      junk which MUST generate a protocol error, so it resyncs */
   cprintf(s->session_id,"aoeuaoeuaoeutha");      
   SetSessionState(s,STATE_RESYNC);
}
Ejemplo n.º 2
0
void CCustomer::Update(CUser* pUser)
{
	CLock m_csLock;
	CAutoLock autolock(&m_csLock);
	if(!pUser->GetState()){
		m_iClientnum -= 1;
		if (m_iClientnum == 0)
		{
			SetSessionState(FALSE);
			ReSetSessionTime();
		}
	}
}
Ejemplo n.º 3
0
void ResyncInputChar(session_node *s,char ch)
{
   if (ch == beacon_str[s->resyn->beacon_index])
      s->resyn->beacon_index++;
   else
      s->resyn->beacon_index = 0;

   if (s->resyn->beacon_index == LENGTH_BEACON)
   {
      SetSessionState(s,STATE_TRYSYNC);
      return;
   }

}
Ejemplo n.º 4
0
void AdminInputChar(session_node *s,char ch)
{
   int len,session_id;

   if (ch != CR)
   {
      len = strlen(s->adm->command);
      if (len < MAX_ADMIN_COMMAND - 1)
      {
	 s->adm->command[len] = ch;
	 s->adm->command[len+1] = 0;
      }
      return;
   }

   /* they hit CR, so they've done a command */

   cprintf(s->session_id,"> %s\n",s->adm->command);
   session_id = s->session_id;
   
   if (!strnicmp(s->adm->command,"QUIT",4))
   {
      cprintf(s->session_id,"%c%c",27,'G'); /* this tells client to resynchronize */
      SetSessionState(s,STATE_RESYNC);

      return;
      
   }
   
   TryAdminCommand(s->session_id,s->adm->command);
   
   /* this next stuff is fuzzy--not sure how much is needed 7/27/95 */
   
   /* right here, s could be invalid if we got hung up.
      check with the saved id */
   s = GetSessionByID(session_id);
   if (s == NULL)
      return;
   if (s->state == STATE_ADMIN)
   {
      /* set string to zero because the rest of line parameters (R) go past
       * a zero from a strtok, and could have residue from previous commands.
       * Of course, only do this if we didn't change state.
       */
      
      s->adm->command[0] = 0;
      memset(s->adm->command,0,MAX_ADMIN_COMMAND);
   }
}
Ejemplo n.º 5
0
void TrySyncInputChar(session_node *s,char ch)
{
   if (ch == detect_str[s->ts->detect_index])
      s->ts->detect_index++;
   else
   {
      s->ts->detect_index = 0;
      return;
   }

   if (s->ts->detect_index == LENGTH_DETECT)
   {
      SetSessionState(s,STATE_SYNCHED);
      return;
   }
}
Ejemplo n.º 6
0
void GameProcessSessionTimer(session_node *s)
{
   if (s->game->object_id == INVALID_OBJECT)
   {
      /* timed out before credits drain means took too long picking character */
      HangupSession(s);
      return;
   }

   /* they're in the game.  First thing to check is if we haven't gotten any
      message in a while, even ping.  If so, they are so lagged they should
      be hung up. */

   /* dprintf("%u %u %u\n",GetTime(),s->game->game_last_message_time,ConfigInt(INACTIVE_GAME)); */

   if (GetTime() - s->game->game_last_message_time > ConfigInt(INACTIVE_GAME))
   {
      lprintf("GameProcessSessionTimer logging out ACCOUNT %i (%s) which hasn't been heard from.\n",
	 s->account->account_id, s->account->name);
      HangupSession(s);
      return;
   }

   SetSessionTimer(s,ConfigInt(CREDIT_DRAIN_TIME));

   s->account->credits -= ConfigInt(CREDIT_DRAIN_AMOUNT);

   if (s->game->game_state != GAME_NORMAL)
      return;

#if 0   
   /* warn them when they are low */
   if ((s->account->credits <= 100*ConfigInt(CREDIT_WARN1)) &&
       (s->account->credits + ConfigInt(CREDIT_DRAIN_AMOUNT) > 100*ConfigInt(CREDIT_WARN1)) ||
       (s->account->credits == 100*ConfigInt(CREDIT_WARN2)) &&
       (s->account->credits + ConfigInt(CREDIT_DRAIN_AMOUNT) > 100*ConfigInt(CREDIT_WARN2)))
      GameWarnLowCredits(s);

   if (s->account->credits == 0)
   {
      /* send them an out-of-credits message */
      GameClientExit(s);
      SetSessionState(s,STATE_SYNCHED);
   }
#endif
}
Ejemplo n.º 7
0
void GameProtocolParse(session_node *s,client_msg *msg)
{
   user_node *u;
   int object_id;
   char *ptr;

   char password[MAX_LOGIN_PASSWORD+1],new_password[MAX_LOGIN_PASSWORD+1];
   int len,index;

   char admin_cmd[500];
   int admin_len;
   int dm_type;

   GameMessageCount((unsigned char)msg->data[0]);

   switch ((unsigned char)msg->data[0])
   {
   case BP_REQ_QUIT :
      GameClientExit(s);
      SetSessionState(s,STATE_SYNCHED);
      break;
      
   case BP_RESYNC :
      // dprintf("client said it had an error\n");
      GameSyncInit(s);
      GameSyncProcessSessionBuffer(s);
      break;

   case BP_PING :
      GameEchoPing(s);
      break;

   case BP_AD_SELECTED :
      /* they clicked on an ad; log it */
      switch (msg->data[1])
      {
      case 1:
	 ptr = LockConfigStr(ADVERTISE_URL1);
	 lprintf("GameProtocolParse found account %i visited ad 1, %s\n",s->account->account_id,
		 ptr);
	 UnlockConfigStr();
	 break;
      case 2:
	 ptr = LockConfigStr(ADVERTISE_URL2);
	 lprintf("GameProtocolParse found account %i visited ad 2, %s\n",s->account->account_id,
		 ptr);
	 UnlockConfigStr();
	 break;
      default :
	 eprintf("GameProtocolParse found account %i visited unknown ad %i\n",
		 s->account->account_id,msg->data[1]);
      }
      break;
         
   case BP_USE_CHARACTER :
      if (s->game->object_id == INVALID_OBJECT)
      {
	 object_id = *((int *)(msg->data+1));
	 u = GetUserByObjectID(object_id);
	 if (u != NULL && u->account_id == s->account->account_id)
	    GameStartUser(s,u);
	 else
	    eprintf("GameProtocolParse can't find user for obj %i in use char!!!\n",
		    object_id);
	 InterfaceUpdateSession(s);
      }
      break;

   case BP_REQ_ADMIN :
      if (s->account->type != ACCOUNT_ADMIN)
      {
	 eprintf("GameProtocolParse got admin command from non admin account %i\n",
		 s->account->account_id);
	 break;
      }
      admin_len = (int) * ((short *)(msg->data + 1));
      if (admin_len > msg->len - 3)
	 return;
      if (admin_len > sizeof(admin_cmd)-2)
	 return;
      memcpy(admin_cmd,&msg->data[3],admin_len);
      admin_cmd[admin_len] = 0;
      SendSessionAdminText(s->session_id,"> %s\n",admin_cmd); /* echo it to 'em */
      TryAdminCommand(s->session_id,admin_cmd);
      break;

   case BP_REQ_DM :
      if (s->account->type != ACCOUNT_ADMIN && s->account->type != ACCOUNT_DM)
      {
	 eprintf("GameProtocolParse got DM command from non admin or DM account %i\n",
		 s->account->account_id);
	 break;
      }
      dm_type = msg->data[1];

      admin_len = (int) * ((short *)(msg->data + 2));
      if (admin_len > msg->len - 4)
	 return;
      if (admin_len > sizeof(admin_cmd)-2)
	 return;
      memcpy(admin_cmd,&msg->data[4],admin_len);
      admin_cmd[admin_len] = 0;
      GameDMCommand(s,dm_type,admin_cmd);
      break;

   case BP_SEND_CHARACTERS :
      GameTryGetUser(s);
      break;

   case BP_CHANGE_PASSWORD :
      index = 1;
      len = *(short *)(msg->data+index);
      if (index + 2 + len > msg->len) /* 2 = length word len */
	 break;
      if (len-1 > sizeof(password))
	 break;
      memcpy(password,msg->data+index+2,len);
      password[len] = 0; /* null terminate string */
      index += 2 + len;
      
      len = *(short *)(msg->data+index);
      if (index + 2 + len > msg->len)
	 break;
      if (len-1 > sizeof(new_password))
	 break;
      memcpy(new_password,msg->data+index+2,len);
      new_password[len] = 0; /* null terminate string */
      index += 2 + len;

      if (strcmp(s->account->password,password))
      {
	 AddByteToPacket(BP_PASSWORD_NOT_OK);
	 SendPacket(s->session_id);
	 break;
      }

      SetAccountPasswordAlreadyEncrypted(s->account,new_password);
      AddByteToPacket(BP_PASSWORD_OK);
      SendPacket(s->session_id);

      break;

   default :
      ClientToBlakodUser(s,msg->len,msg->data);
      
      break;
   }
}