Beispiel #1
0
void SendClientBufferList(int session_id,buffer_node *blist)
{
	session_node *s;
	
	s = GetSessionByID(session_id);
	if (s == NULL)
	{
		DeleteBufferList(blist);
		return;
	}
	
	switch (s->state)
	{
	case STATE_GAME :
		SendGameClientBufferList(s,blist,epoch);
		break;
	case STATE_SYNCHED :
		SendGameClientBufferList(s,blist,0);
		break;
	case STATE_ADMIN :
	case STATE_MAINTENANCE :
	case STATE_TRYSYNC :
		SendBufferList(s,blist);
		break;
	}
}
Beispiel #2
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);
		}
		
	}
}
Beispiel #3
0
void SendClient(int session_id,char *data,unsigned short len_data)
{
	session_node *s;
	
	s = GetSessionByID(session_id);
	if (s == NULL)
	{
		/* the session has already closed, so happens all the time */
		/* eprintf("SendClient can't output to non-session %i\n",session_id); */
		return;
	}
	
	switch (s->state)
	{
	case STATE_GAME :
		SendGameClient(s,data,len_data,epoch);
		break;
	case STATE_SYNCHED :
		SendGameClient(s,data,len_data,0);
		break;
	case STATE_ADMIN :
	case STATE_MAINTENANCE :
	case STATE_TRYSYNC :
		SendBytes(s,data,len_data);
		break;
	}
}
Beispiel #4
0
void PollSession(int session_id)
{
	session_node *s;
	
	s = GetSessionByID(session_id);
	if (s == NULL)
		return;
	
	if (!s->connected)
		return;
	
	if (s->conn.type != CONN_SOCKET)
		return;
	
		/* someone hung up session or if the read/write thread for this session is dead, 
	hang it up. */
	if (s->hangup == True)
	{
		CloseSession(s->session_id);
		return;
	}
	
	if (WaitForSingleObject(s->muxReceive,10000) != WAIT_OBJECT_0)
	{
		eprintf("PollSession bailed waiting for mutex on session %i\n",s->session_id);
		HangupSession(s);
		return;
	}
	
	/*
	if (s->num_receiving > 0)
	{
	int i;
	dprintf("got in %s\n",GetStateName(s));
	for (i=0;i<s->num_receiving;i++)
	dprintf("%5u",s->receiving_buf[i]);
	dprintf("\n");
	}
	*/
	
	if (s->receive_list != NULL)
		ProcessSessionBuffer(s);
	
	
	if (!ReleaseMutex(s->muxReceive))
	{
		eprintf("PollSession released mutex it didn't own in session %i\n",s->session_id);
		HangupSession(s);
	}
}
Beispiel #5
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);
   }
}
void MaintenanceInputChar(session_node *s,char ch)
{
   int len,session_id;

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

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

   cprintf(s->session_id,"> %s\n",s->mtn->command);
   session_id = s->session_id;
   
   if (!strnicmp(s->mtn->command,"QUIT",4))
   {
      cprintf(s->session_id,"Bye\n");
      HangupSession(s);
      return;
      
   }
   
   TryAdminCommand(s->session_id,s->mtn->command);
   
   /* 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_MAINTENANCE)
   {
      /* 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->mtn->command[0] = 0;
      memset(s->mtn->command,0,MAX_ADMIN_COMMAND);
   }
}
Beispiel #7
0
void VerifiedLoginSession(int session_id)
{
	session_node *s;
	
	s = GetSessionByID(session_id);
	if (s == NULL)
		return;
	
	if (!s->connected)
		return;
	
	if (s->conn.type != CONN_SOCKET)
		return;
	
	if (s->state != STATE_SYNCHED || s->login_verified)
		return;
	
	VerifyLogin(s);
}
Beispiel #8
0
void InterfaceAddList(int session_id)
{
	session_node *s;
	LV_ITEM lvi;
	int index;
	
	EnterServerLock();
	s = GetSessionByID(session_id);
	if (s == NULL)
	{
		LeaveServerLock();
		return;
	}
	
	index = ListView_GetItemCount(hwndLV);
	
	/* Initialize LV_ITEM members that are common to all items. */
	lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE; 
	lvi.state = 0; 
	lvi.stateMask = 0; 
	lvi.pszText = "  ?";  
	lvi.iImage = -1;
	
	lvi.iItem = index;
	lvi.iSubItem = 0; 
	lvi.lParam = session_id;
	
	ListView_InsertItem(hwndLV,&lvi); 
	
	if (s->account == NULL)
	{
		/* need braces around this macro to use in an if/else */
		ListView_SetItemText(hwndLV,index,1,"");
	}
	else   
		ListView_SetItemText(hwndLV,index,1,s->account->name);
	
	ListView_SetItemText(hwndLV,index,2,ShortTimeStr(s->connected_time));
	ListView_SetItemText(hwndLV,index,3,GetStateName(s));
	ListView_SetItemText(hwndLV,index,4,s->conn.name);
	
	LeaveServerLock();
}
Beispiel #9
0
void SecurePacketBufferList(int session_id, buffer_node *bl)
{
   session_node *s = GetSessionByID(session_id);
   char* pRedbook;

   if (!session_id || !s || !s->account || !s->account->account_id ||
       s->conn.type == CONN_CONSOLE)
   {
      //dprintf("SecurePacketBufferList cannot find session %i", session_id);
      return;
   }
   if (s->version_major < 4)
   {
      return;
   }
   if (bl == NULL || bl->buf == NULL)
   {
//      dprintf("SecurePacketBufferList can't use invalid buffer list");
      return;
   }

//   dprintf("Securing msg %u with %u", (unsigned char)bl->buf[0], (unsigned char)(s->secure_token & 0xFF));

   bl->buf[0] ^= (unsigned char)(s->secure_token & 0xFF);
   pRedbook = GetSecurityRedbook();
   if (s->sliding_token && pRedbook)
   {
      if (s->sliding_token < pRedbook ||
	  s->sliding_token > pRedbook+strlen(pRedbook))
      {
	 lprintf("SecurePacketBufferList lost redbook on session %i account %i (%s), may break session\n",
	    session_id, s->account->account_id, s->account->name);
	 s->sliding_token = pRedbook;
      }

      s->secure_token += ((*s->sliding_token) & 0x7F);
      s->sliding_token++;
      if (*s->sliding_token == '\0')
         s->sliding_token = pRedbook;
   }
}
Beispiel #10
0
void InterfaceUpdateList(int session_id)
{
	session_node *s;
	char buf[20];
	LV_FINDINFO lvf;
	int index;
	
	EnterServerLock();
	s = GetSessionByID(session_id);
	if (s == NULL)
	{
		LeaveServerLock();
		return;
	}
	
	lvf.flags = LVFI_PARAM;
	lvf.lParam = session_id;
	index = ListView_FindItem(hwndLV,-1,&lvf);
	
	if (index >= 0)
	{
		if (s->account == NULL)
		{
			ListView_SetItemText(hwndLV,index,0,"  ?");
			ListView_SetItemText(hwndLV,index,1,"");
		}
		else
		{
			sprintf(buf,"%3i",s->account->account_id);
			ListView_SetItemText(hwndLV,index,0,buf);
			ListView_SetItemText(hwndLV,index,1,s->account->name);
		}      
		ListView_SetItemText(hwndLV,index,2,ShortTimeStr(s->connected_time));
		ListView_SetItemText(hwndLV,index,3,GetStateName(s));
		ListView_SetItemText(hwndLV,index,4,s->conn.name);
	}
	LeaveServerLock();
	
}
Beispiel #11
0
void CloseSession(int session_id)
{
	session_node *s;
	
	s = GetSessionByID(session_id);
	if (s == NULL)
	{
		eprintf("CloseSession can't find session %i\n",session_id);
		return;
	}
	
	if (!s->connected)
	{
		eprintf("CloseSession can't close unconnected session %i\n",
			s->session_id);
		return;
	}
	
	EnterSessionLock();
	
	s->connected = False;
	
	if (!s->exiting_state)	/* if a write error occurred during an exit, don't */
		ExitSessionState(s);	/* go into infinite loop */
	
	if ((s->state != STATE_MAINTENANCE) && (s->account == NULL))
		lprintf("CloseSession closing session with no account from %s\n",
		s->conn.name);
	else
	{
		AccountLogoff(s->account);
		if (s->account != NULL)
			lprintf("CloseSession/4 logging off %i\n",s->account->account_id);
	}
	
	s->account = NULL;
	
	InterfaceLogoff(s);
	
	if (s->conn.type == CONN_SOCKET)
	{
		if (WaitForSingleObject(s->muxSend,10000) != WAIT_OBJECT_0)
			eprintf("CloseSession couldn't get session %i muxSend\n",s->session_id);
		else
		{
			DeleteBufferList(s->send_list);
			s->send_list = NULL;
			
			/* no need to release mutex... we're closing it */
			/*
			if (!ReleaseMutex(s->muxSend))
			eprintf("File %s line %i release of non-owned mutex\n",__FILE__,__LINE__);
			*/
			
		}
		
		if (WaitForSingleObject(s->muxReceive,10000) != WAIT_OBJECT_0)
			eprintf("CloseSession couldn't get session %i muxReceive\n",s->session_id);
		else
		{
			DeleteBufferList(s->receive_list);
			s->receive_list = NULL;
			
			/* no need to release mutex... we're closing it */
			/*
			if (!ReleaseMutex(s->muxReceive))
			eprintf("File %s line %i release of non-owned mutex\n",__FILE__,__LINE__);
			*/
			
		}
		
		if (!CloseHandle(s->muxSend))
			eprintf("CloseSession error (%s) closing send mutex %i in session %i\n",
			GetLastErrorStr(),s->muxSend,s->session_id);
		
		if (!CloseHandle(s->muxReceive))
			eprintf("CloseSession error (%s) closing receive mutex %i in session %i\n",
			GetLastErrorStr(),s->muxReceive,s->session_id);
		
		CloseConnection(s->conn);
	}
	
	s->session_id = -1;
	s->state = -1;
	
	LeaveSessionLock();
}