Sign in to follow this  
fitfool

Irc Hate's Me(wont let me connect) :/

Recommended Posts

Well, im working on a irc bot, and everything is going dandy, but i cant seem to connect to a server(successfully join a channel, not connect()). Right now, im able to receive all data from the server, break if off at "\r\n"'s throw it in a std::vector, and run it through my parser. First, i Send() my NICK, then i send my USER message, then i wait for a PING, i respond, but nothing happens after that :(. It seems ive tried endless combinations of sending/resending etc. with no luck :/. Ive checked my sends too, and all data seems to be making it to the server. in main i connect to irc.afternet.org via Bot::Init(), that succeeds, then i call Bot::Process.
#include "Bot.h"

#define IRC_END "\r\n"

bool Bot::Init( std::string Address )
{
	if( !Socket.Init() )
		return false;

	if( !Socket.Connect(Address.c_str(), 6667) )
		return false;srand(0);

	return true;
}

int Bot::Send( std::string Message )
{
	Message += IRC_END;
	
	return Socket.Send( Message );
}

void Bot::Process()
{
	std::vector<std::string> Messages;
	std::string Buffer;

	Send( "NICK FitFool23" );
	Send( "USER FitFool543g 0 0 Fatbat" );

	while( 1 )
	{
		while( Socket.ReadyToRead(1) )
		{
			char Temp[512] = { 0 };
			
			Socket.Read( Temp, 512 );
			Buffer += Temp;

			std::cout << Temp;
		}
		
		for( int x = 0; x < Buffer.length(); x++ )
		{
			if( x + 1 < Buffer.length() )
			{
				if( Buffer.substr(x, 2) == IRC_END )
				{
					Messages.push_back( Buffer.substr(0, x) );
					Buffer = Buffer.substr( x + 2 );
					x = -1;
				}
			}
		}

		ParseMessages( Messages );
		Messages.clear();

		Sleep( 5 );
	}
}

void Bot::ParseMessages( const std::vector<std::string>& Messages )
{	
	for( int x = 0; x < Messages.size(); x++ )
	{
		const std::string& Message = Messages.at( x );
		
		if( Message.substr(0, 4) == "PING" )
		{
			std::string Temp = Message;
			Temp[1] = 'O';

			std::cout << Temp << std::endl;

			Send( Temp );
		}
	}
}


thanks

Share this post


Link to post
Share on other sites
I don't know the IRC protocol by hearth (though I once did) but you should look at some documentation to know what is the usual server/client transfer of data for a connection. Even better, download Wireshark and check the paquets yourself when you connect with a client like mIRC.

edit: protocol doc is there http://www.mirc.co.uk/help/rfc1459.txt but if you don't plan to read it all just mimic mIRC paquets :).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this