SOCKET sock;
char *server = "irc.ft-gaming.com";
int port = 6667;
char *nick = "FBot";
char *chan = "#bottest";
char buff[4096];
char tmp[4096];
char name[256];
bool spam;
char ID[256];
int irc_connect()//char server[256], char channel[256], char name[256], int port
{
WSADATA WSAData;
WSAStartup(MAKEWORD(2,0), &WSAData);
SOCKADDR_IN sin;
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = inet_addr(server);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
connect(sock, (SOCKADDR *)&sin, sizeof(sin));
memset(tmp,0,255);
sprintf(tmp,"USER %s 0 0 :%s%c",nick,nick,10);
send(sock,tmp,strlen(tmp),0);
printf("Sent-> %s", tmp);
memset(tmp,0,255);
BotId = (rand() % 100);
sprintf(ID,"!%d",BotId);
sprintf(name,"%s[%d]",nick,BotId);
sprintf(tmp,"NICK %s%c",name,10);
send(sock,tmp,strlen(tmp),0);
printf("Sent-> %s", tmp);
Sleep(100);
memset(tmp,0,255);
sprintf(tmp,"JOIN %s%c",chan,10);
send(sock,tmp,strlen(tmp),0);
printf("Sent-> %s", tmp);
sprintf(tmp,"PRIVMSG %s :Hello %s!%c",chan,chan,10);
send(sock,tmp,strlen(tmp),0);
printf("Sent-> %s", tmp);
printf("Name-> %s\n", name);
memset(buff,0,255);
return 0;
}
void StayAlive()
{
char buff[2048];
char msg[256];
char tmp[256];
char BotName[64];
memset(msg,0,255);
memset(BotName,0,64);
sprintf(BotName, "!%s", name);
while (1)
{
memset(buff,0,255);
memset(tmp,0,255);
recv( sock,buff,255,0);
if(strlen(buff) != 0)
{
printf("Received-> %s\n", buff);
//send(sock,"PONG :\r\n",6,0);
//printf("Sent-> Pong");
if (strncmp(buff,"PING", 4) == 0 )
{
buff[1] = 'O';
send(sock,buff,strlen(buff),0);
printf("Sent-> %s\n", buff);
}
if (strncmp(buff,"QUIT", 4) == 0 )
{
irc_connect();
printf("Bot-> Reconnecting\n");
}
else if(strstr(buff, "PRIVMSG") != NULL)
{
memset(tmp,0,255);
sprintf(tmp, "PRIVMSG %s :Got a message!%c",chan,10);
//send(sock,tmp,strlen(tmp),0);
printf("Sent-> %s\n", tmp);
}
}
if ( strlen(buff) == 0 ) {
closesocket(sock);
break;
}
}
}
void IRC::Created(GameObject *obj) {
srand(GetTickCount());
UpTimeS = GetTickCount();
if(irc_connect() != 0)
Console_Input("msg ERROR");
StayAlive();
getchar();
WSACleanup();
}
ScriptRegistrant<IRC> IRC_Registrant("IRC","");