Witam. Napisałem prostego IRCbota, jednak po polaczeniu do serwera i podaniu komend USER i NICK rozlacza sie z serwerem. Zapis z loga wyglada tak:

Log bota Ircowego stworzonego przez Attila!

USER OOberbot OOberbot irc.quakenet.org :OOberbot
NOTICE AUTH :*** Looking up your hostname

NICK OOberbot
NOTICE AUTH :*** Checking Ident

NOTICE AUTH :*** Found your hostname

NOTICE AUTH :*** No ident response

Natomiast kod programu to:

#include <iostream>
#include <fstream>
#include <winsock2.h>
#include <string>
#include <cstring>

#pragma comment(lib, "ws2_32.lib")

using namespace std;

u_long resolveHost(const string &host)
{
	LPHOSTENT entryHost = gethostbyname(host.c_str());

	if(!entryHost)
	{
		unsigned int addr = inet_addr(host.c_str());

		entryHost = gethostbyaddr((char*)&addr, 4, AF_INET);

		if(!entryHost)
			return 0;
	}
	return *((int*)*entryHost->h_addr_list);
}

int main()
{
	WSADATA		wsaData;
	SOCKADDR_IN	saddr;
	SOCKET		sock;
	char		buffer[1024*8] = {"0"};
	string		adres_hosta = "irc.quakenet.org";
	string		sbuffer;
	string		nick = "OOberbot";
	fstream		fs("log.txt", ios::in | ios::out | ios::trunc);
	string		kanal = "#asd";

	fs << "Log bota Ircowego stworzonego przez Attila!" << endl << endl;
	cout << "Log bota Ircowego stworzonego przez Attila!" << endl << endl;

	WSAStartup(MAKEWORD(2, 2), &wsaData);

	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	saddr.sin_addr.S_un.S_addr = resolveHost(adres_hosta);
	saddr.sin_port =  htons(6667);
	saddr.sin_family = AF_INET;

	if(connect(sock, (sockaddr*)&saddr, sizeof(sockaddr)) == SOCKET_ERROR)
	{
		cout << "Nie udalo sie nawiazac polaczenia z " << adres_hosta << ".";
		return 0;
	}

	Sleep(500);

	recv(sock, buffer, 1024*8, 0);
	
	fs << buffer << endl << endl;
	cout << buffer << endl << endl;

	sbuffer = "USER ";
	sbuffer += nick;
	sbuffer += " ";
	sbuffer += nick;
	sbuffer += " ";
	sbuffer += adres_hosta;
	sbuffer += " :";
	sbuffer += nick;

	send(sock, sbuffer.c_str(), strlen(sbuffer.c_str()), 0);
	recv(sock, buffer, 1024*8, 0);
	
	fs << sbuffer.c_str() << endl << buffer << endl << endl;
	cout << sbuffer.c_str() << endl << buffer << endl << endl;

	sbuffer = "NICK ";
	sbuffer += nick;
	send(sock, sbuffer.c_str(), strlen(sbuffer.c_str()), 0);
	recv(sock, buffer, 1024*8, 0);
	
	fs << sbuffer.c_str() << endl << buffer << endl << endl;
	cout << sbuffer.c_str() << endl << buffer << endl << endl;

	sbuffer = "JOIN ";
	sbuffer += kanal;

	send(sock, sbuffer.c_str(), strlen(sbuffer.c_str()), 0);
	recv(sock, buffer, 1024*8, 0);

	fs << sbuffer.c_str() << endl << buffer << endl << endl;
	cout << sbuffer.c_str() << endl << buffer << endl << endl;

	while(true)
	{
		recv(sock, buffer, 1024*8, 0);

		fs << buffer << endl << endl;
		cout << buffer << endl << endl;

		if(buffer[0] == 'PING')
		{
			sbuffer = "PONG :";
			sbuffer += adres_hosta;
			send(sock, sbuffer.c_str(), strlen(sbuffer.c_str()), 0);

			fs << sbuffer.c_str() << endl << buffer << endl << endl;
			cout << sbuffer.c_str() << endl << buffer << endl << endl;
		}
	}
	return 1;
}

Prosze o wyjasnienie, co robie zle :) Szukalem na googlach rozwiazania, jednak wiekszosc poradnikow dotyczy tworzenia botow w Perlu lub w PHP. Z gory dziekuje za pomoc!

EDIT: Dodalem Sleep i wyglada na to, ze po prostu moje msg "USER..." nie dociera/serwer mi nie odpowiada... Czemu tak sie dzieje?

EDIT2: Dziala! :) Nie doczytalem, ze trzeba dodac po kazdej wiadomosci do serwera "\r\n"