SOCKET Socket;
void irc_init()
{
WSADATA d;
if(WSAStartup(MAKEWORD(2, 0), &d) != NO_ERROR)
cout << "Could not initialize WinSock.";
}
int irc_connect(char *server, int port, char *name)
{
SOCKADDR Addr;
SOCKADDR_IN SockAddr;
HOSTENT *HostInfo;
// Init the socket.
Socket = socket(AF_INET, SOCK_STREAM, 0);
if (Socket == INVALID_SOCKET)
{
cout << "Socket creation failed.";
return 0;
}
// Init the host info.
HostInfo = gethostbyname(server);
if (HostInfo == NULL)
{
cout << "Could not resolve host.";
return 0;
}
SockAddr.sin_addr.s_addr=*((unsigned long*)HostInfo->h_addr);
SockAddr.sin_family=AF_INET;
SockAddr.sin_port=htons(port);
// Connect the socket.
if(connect(Socket, (struct sockaddr*)&SockAddr, sizeof(SockAddr)) != 0)
{
cout << "Failed to establish connection with server.";
return 0;
}
//else
// printf("Connected to the server.\n");
irc_send("USER %s . . :%s\r\nNICK %s\r\n", name, "PaintIRC", name);
return 1;
}
void irc_send(char *format, ...)
{
va_list argptr;
static char string[1024];
va_start(argptr, format);
_vsnprintf(string, sizeof(string), format, argptr);
va_end(argptr);
NULLTERMINATE(string);
send(Socket, string, strlen(string), 0);
}
char *irc_get()
{
char Buf[16] = "";
char String[512] = "";
int l;
if(Socket == INVALID_SOCKET)
return NULL;
while(l=recv(Socket, Buf, 1, 0) > 0)
{
if(strstr(Buf, "\n"))
{
//recv(Socket, Buf, 1, 0);
break;
}
sprintf(String, "%s%s", String, Buf);
}
return String;
}
Not exactly what I had in the DP one but its pretty close.