Beispiel #1
0
void Server::MainLoop () // main service loop
{
	while (m_bKeepUp)
	{
		if (ConnectClient()) HandleClient() ;
	}
}
Beispiel #2
0
//---------------------------------------------------------------------------------------
tThreadClient::tThreadClient(const int _handle, QSqlDatabase &_db):my_thread(NULL),this_client(NULL)
{
    my_thread= new QThread();
    this->moveToThread(my_thread);
    this_client=new tClient(_handle, _db);
    this_client->moveToThread(my_thread);
    connect(this_client, SIGNAL(DisconnectClient(int)), this, SLOT(OnDisconnectClient(int)));
    connect(this, SIGNAL(ConnectClient()), this_client, SLOT(OnConnected()));

}
Beispiel #3
0
void AcceptQuery (int ls, struct clientlist * clList)
{
	int fd;

	fd = accept (ls, NULL, NULL); 

	if ( clList->cnt < clList->maxPlayers && !clList->statusStartGame) 
	{
		ConnectClient (clList, fd); 
	}
	else
	{
		DeniedClient (fd);
	}
}
Beispiel #4
0
void TcpClient::Run()
{

	int cnt = 0;

	while (!IsTerminated()) {

		if (_connect_flag) {
	
			if (!_connected_status) {
				ConnectClient();
			}

		} else {

			if (_connected_status) {
				
				if (local_sock) {
					Socket::Close(local_sock);
					local_sock = -1;
				}

				_connected_status = false;
			}
		}
		UploadClient();

		usleep(10000);

		if (_connected_status) {
			cnt++;
			if (cnt > 500) {
				cnt = 0;
				SendHeartBeat();
			}
		}
        }
	
	ClearBuffer();
	local_sock = -1;
	_connected_status = false;
	_connect_flag = false;
}
void JoinGameState::Update(long time)
{
	// Update (reset) all the textWidgets
	mainMenu.Update(time);
	statusBar.Update(time);
	
	user->userName.Update(time);
	user->clientIPAddress.Update(time);
	
	if (statusBar.GetLastMouseStateIndex()==MOUSE_PRESSED && statusBar.GetMouseStateIndex()==MOUSE_OVER)
	{
		// User wants to start connection
		rakClient->Disconnect();
		connectionAttemptionTimer=-1L;
		if (VerifyIPString(user->clientIPAddress.GetUserInput())==false)
		{
			statusBar.SetText("Invalid IP.  Click to attempt new connection.");
		}
		else
		{
			ConnectClient();
		}
	}
}
Beispiel #6
0
void
ReadSocketInfo(void)

{
	int SelectResult;
	struct timeval TimeOut;

	struct DccUser *dccptr;
	struct PortInfo *tempport;
	fd_set readfds,
	writefds;

	time_t curr_ts;
	time_t last_ts = current_ts;

	spill[0] = '\0';

	for (;;)
	{

		/*
		 * DoTimer() will be called from this code, and so we need curr_ts
		 * here. And we also need time setup here -kre
		 */
		curr_ts = current_ts = time(NULL);

#ifdef HIGHTRAFFIC_MODE

		if (HTM)
		{
			int htm_count;

			if (last_ts != curr_ts)
			{
				/*
				 * So DoTimer() doesn't get called a billion times when HTM is
				 * turned off
				 */
				last_ts = curr_ts;

				/*
				 * DoTimer() won't do anything other than update
				 * Network->CheckRecvB since we are in HTM
				 */
				DoTimer(curr_ts);
			} /* if (last_ts != curr_ts) */

			/* Check if HTM should be turned off */
			if ((curr_ts - HTM_ts) >= HTM_TIMEOUT)
			{
				float    currload;

				currload = ((float) (Network->RecvB - Network->CheckRecvB) /
				            (float) 1024) / (float) HTM_INTERVAL;

				if (currload >= (float) ReceiveLoad)
				{
					HTM_ts = curr_ts;
					putlog(LOG1, "Continuing high-traffic mode (%0.2f K/s)",
					       currload);
					SendUmode(OPERUMODE_Y,
					          "*** Continuing high-traffic mode (%0.2f K/s)",
					          currload);
				}
				else
				{
					HTM = HTM_ts = 0;
					putlog(LOG1, "Resuming standard traffic operations (%0.2f K/s)",
					       currload);
					SendUmode(OPERUMODE_Y,
					          "*** Resuming standard traffic operations (%0.2f K/s)",
					          currload);
				}
			}

			for (htm_count = 0; htm_count < HTM_RATIO; htm_count++)
				if (!ReadHub())
				{
					read_socket_done = 1;
					return;
				}

		} /* if (HTM) */
		else

#endif /* HIGHTRAFFIC_MODE */

			if (last_ts != curr_ts)
			{
				if (curr_ts > (last_ts + 1))
				{
					time_t  delta;
					/*
					 * we skipped at least 1 time interval - make up for it
					 * by calling DoTimer() how ever many intervals we missed
					 * (ie: if the TS went from 5 to 8, call DoTimer() twice
					 * since we missed 6 and 7)
					 */
					for (delta = (last_ts + 1); delta < curr_ts; delta++)
						DoTimer(delta);
				}
				last_ts = curr_ts;
				DoTimer(curr_ts);
			}

		FD_ZERO(&readfds);
		FD_ZERO(&writefds);

		TimeOut.tv_sec = 0L;
		TimeOut.tv_usec = 20000L;

		if (currenthub && (HubSock != NOSOCKET))
		{
			if (IsHubConnect(currenthub))
				FD_SET(HubSock, &writefds);
			else
				FD_SET(HubSock, &readfds);
		}

		for (dccptr = connections; dccptr; dccptr = dccptr->next)
		{
			if (IsDccConnect(dccptr))
				FD_SET(dccptr->socket, &writefds);
			else
			{
				FD_SET(dccptr->socket, &readfds);
				if (dccptr->authfd != NOSOCKET)
				{
					FD_SET(dccptr->authfd, &readfds);
					if (dccptr->flags & SOCK_WRID)
						FD_SET(dccptr->authfd, &writefds);
				}
			}
		}

		for (tempport = PortList; tempport; tempport = tempport->next)
			if (tempport->socket != NOSOCKET)
				FD_SET(tempport->socket, &readfds);

		SelectResult = select(FD_SETSIZE, &readfds, &writefds, NULL, &TimeOut);
		if (SelectResult > 0)
		{
			/* something happened */

			if (currenthub && (HubSock != NOSOCKET))
			{
				/* This is for info coming from the hub server */

				if (IsHubConnect(currenthub) && FD_ISSET(HubSock, &writefds))
				{
					if (!CompleteHubConnection(currenthub))
					{
						close(HubSock);
						currenthub->sockfd = HubSock = NOSOCKET;
					}
				}
				else if (FD_ISSET(HubSock, &readfds))
				{
					if (!ReadHub())
					{
						read_socket_done = 1;
						return; /* something bad happened */
					}
				}
			} /* if (currenthub && (HubSock != NOSOCKET)) */

			for (tempport = PortList; tempport; tempport = tempport->next)
			{
				if (tempport->socket == NOSOCKET)
					continue;

				if (FD_ISSET(tempport->socket, &readfds))
				{
					/*
					 * a client has connected on one of our listening ports
					 * (P: lines) - accept their connection, and perform
					 * ident etc
					 */

					ConnectClient(tempport);
				}
			}

			/* this is for info coming from a dcc/telnet/tcm client */
			for (dccptr = connections; dccptr != NULL; dccptr = dccnext)
			{
				assert(dccptr->socket != NOSOCKET);
				dccnext = dccptr->next;

				if (IsDccConnect(dccptr)
				        && FD_ISSET(dccptr->socket, &writefds))
				{
					if (!GreetDccUser(dccptr))
						DeleteDccClient(dccptr);

					continue;
				}

				if (dccptr->authfd >= 0)
				{
					if (FD_ISSET(dccptr->authfd, &writefds) &&
					        (dccptr->flags & SOCK_WRID))
						writeauth(dccptr); /* send ident request */

					if (FD_ISSET(dccptr->authfd, &readfds))
						readauth(dccptr); /* read ident reply */
				}

				if (dccptr->flags & SOCK_NEEDID)
					continue;

				if (FD_ISSET(dccptr->socket, &readfds))
				{
					/* read and parse any data from the socket */
					if (!ReadSock(dccptr))
					{
						CloseConnection(dccptr);
						continue;
					}
				} /* if (FD_ISSET(dccptr->socket, &readfds)) */
			} /* for (dccptr = connections; dccptr; dccptr = dccptr->next) */

			dccnext = NULL;   /* XXX */
		} /* if (SelectResult > 0) */
		else
		{
			/* Also check whether is errno set at all.. -kre */
			if ((SelectResult == (-1)) && errno && (errno != EINTR))
			{
#ifdef DEBUGMODE
				fprintf(stderr,
				        "Connection closed: %s\n",
				        strerror(errno));
#endif

				putlog(LOG1, "Lost connection to %s:%d (%s)",
				       currenthub->hostname,
				       currenthub->port,
				       strerror(errno));

				return;
			}
		}
	} /* for (;;) */
} /* ReadSocketInfo() */
Beispiel #7
0
//---------------------------------------------------------------------------------------
void tThreadClient::Connect()
{
    emit ConnectClient();
}