Jump to content
  • Advertisement
Sign in to follow this  
fitfool

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

This topic is 3919 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!