コード例 #1
0
ファイル: socket.cpp プロジェクト: ProDotaTrY/ghostcb
void CTCPSocket :: DoRecv( fd_set *fd )
{
	if( m_Socket == INVALID_SOCKET || m_HasError || !m_Connected )
		return;

	if( FD_ISSET( m_Socket, fd ) )
	{
		// data is waiting, receive it

		char buffer[1024];
		int c = recv( m_Socket, buffer, 1024, 0 );

		if( c == SOCKET_ERROR && GetLastError( ) != EWOULDBLOCK )
		{
			// receive error

			m_HasError = true;
			m_Error = GetLastError( );
			if ( !m_SuppressError )
				CONSOLE_Print( "[TCPSOCKET] error (recv) - " + GetErrorString( ) +" from " + GetIPString( ));
			return;
		}
		else if( c == 0 )
		{
			// the other end closed the connection

			if ( !m_SuppressError )
				CONSOLE_Print( "[TCPSOCKET] closed by remote host ["+GetIPString( ) +"]" );
			m_Connected = false;
		}
		else if( c > 0 )
		{
			// success! add the received data to the buffer

			if( !m_LogFile.empty( ) )
			{
				ofstream Log;
				Log.open( m_LogFile.c_str( ), ios :: app );

				if( !Log.fail( ) )
				{
					Log << "					RECEIVE <<< " << UTIL_ByteArrayToHexString( UTIL_CreateByteArray( (unsigned char *)buffer, c ) ) << endl;
					Log.close( );
				}
			}

			m_RecvBuffer += string( buffer, c );
			m_LastRecv = GetTime( );
		}
	}
}
コード例 #2
0
//int main(int argc, char *argv[])
int tzo_getip(unsigned int IPaddr)
{
static int pre_IpAddess=0;	
int nIpAddess = 0 ;
char szIpAddress[32] ;
//nIpAddess=IPaddr;// Arthur

  switch (CheckForNewIPAddress(&nIpAddess)) {
        case -1 :
            printf("There was an error communicating with the TZO Echo Servers\n") ;
            return 0;// fail to communicate with the TZO Echo Servers, the upper layer should update it's IP.
           // break;
        case 1 :
            GetIPString(szIpAddress, nIpAddess) ;
            printf("Current IP Address %s\n", szIpAddress) ;
            if (nIpAddess==pre_IpAddess)
              return 1; // same IP , don't need to update it .
            else
              pre_IpAddess= nIpAddess;
              return 0;  // set the new IP to pre_IpAddess,he upper layer should update it's IP
              
           // break;
        }        

  //return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: users.cpp プロジェクト: Canternet/inspircd
LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr)
	: User(ServerInstance->UIDGen.GetUID(), ServerInstance->FakeClient->server, USERTYPE_LOCAL), eh(this),
	bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0),
	already_sent(0)
{
	exempt = quitting_sendq = false;
	idle_lastmsg = 0;
	ident = "unknown";
	lastping = 0;
	eh.SetFd(myfd);
	memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs));
	memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs));
	dhost = host = GetIPString();
}
コード例 #4
0
ファイル: Logon.cpp プロジェクト: Resinderate/redemption
// ------------------------------------------------------------------------
//  This notifies the handler that there is a new connection
// ------------------------------------------------------------------------
void Logon::Enter()
{
    USERLOG.Log(  
        GetIPString( m_connection->GetRemoteAddress() ) + 
        " - entered login state." );

    m_connection->Protocol().SendString( *m_connection,
        bold + "Welcome To REDEMPTION!\r\n" + 
		"Redemption is a game of resource collecting. A long time ago the devil traded your ancestors for\r\n" +
		"their souls. This in turn lead you to be born without a soul! You must collect enough resources to\r\n" +
		"trade the devil back for your soul. You can trade between resources in the Tradepost, and upgrade\r\n" +
		"your resource collecting abilities in the Workshop.\r\n\r\n" +
        yellow + "Please enter your name, or \"new\" if you are new: " + reset );
}
コード例 #5
0
ファイル: users.cpp プロジェクト: Shawn-Smith/InspIRCd
LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* servaddr)
	: User(ServerInstance->GetUID(), ServerInstance->Config->ServerName, USERTYPE_LOCAL), eh(this),
	localuseriter(ServerInstance->Users->local_users.end()),
	bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0),
	already_sent(0)
{
	exempt = quitting_sendq = dns_done = false;
	idle_lastmsg = 0;
	ident = "unknown";
	lastping = 0;
	eh.SetFd(myfd);
	memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs));
	memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs));
	dhost = host = GetIPString();
}
コード例 #6
0
ファイル: socket.cpp プロジェクト: ProDotaTrY/ghostcb
void CTCPSocket :: DoSend( fd_set *send_fd )
{
	if( m_Socket == INVALID_SOCKET || m_HasError || !m_Connected || m_SendBuffer.empty( ) )
		return;

	if( FD_ISSET( m_Socket, send_fd ) )
	{
		// socket is ready, send it

		int s = send( m_Socket, m_SendBuffer.c_str( ), (int)m_SendBuffer.size( ), MSG_NOSIGNAL );

		if( s == SOCKET_ERROR && GetLastError( ) != EWOULDBLOCK )
		{
			// send error

			m_HasError = true;
			m_Error = GetLastError( );
			if ( !m_SuppressError )
				CONSOLE_Print( "[TCPSOCKET] error (send) - " + GetErrorString( ) +" ["+GetIPString( ) +"]" );
			return;
		}
		else if( s > 0 )
		{
			// success! only some of the data may have been sent, remove it from the buffer

			if( !m_LogFile.empty( ) )
			{
				ofstream Log;
				Log.open( m_LogFile.c_str( ), ios :: app );

				if( !Log.fail( ) )
				{
					Log << "SEND >>> " << UTIL_ByteArrayToHexString( BYTEARRAY( m_SendBuffer.begin( ), m_SendBuffer.begin( ) + s ) ) << endl;
					Log.close( );
				}
			}

			m_SendBuffer = m_SendBuffer.substr( s );
			m_LastSend = GetTime( );
		}
	}
}