Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


IRC Bot Skeleton

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Sep 01, 2008 9:00 pm    Post subject: IRC Bot Skeleton Reply with quote

Code is sloppy, but works

You have to change Stephen@Blank to your first name + vhost

Code:
#include <winsock.h>
#include <stdio.h>
#include <windows.h>


#pragma comment (lib, "Ws2_32.lib")
#define NETWORK_ERROR -1
#define NETWORK_OK      0
#define BOT_VERSION 1
void parse (char* buf);


char buffer[256];
char userpacket[] = "USER blankbot 0 0 blankbot \r\n";
char nickpacket[] = "NICK blankbot \r\n";
char identifypacket[] = "PRIVMSG NickServ IDENTIFY pass\r\n";
char joinpacket[] = "JOIN #blankbot \r\n";
char privmsgpacket[] = "PRIVMSG #blankbot Hello\r\n";


char *pch, *pch2, *pch3, *pch4;
WORD sockVersion;
WSADATA wsaData;
int nret;
LPHOSTENT hostEntry;
SOCKET ircsocket;
SOCKADDR_IN serverInfo;

int main() {
sockVersion = MAKEWORD(1,1);
WSAStartup(sockVersion, &wsaData);

hostEntry = gethostbyname("irc.p2p-network.net");

if(!hostEntry){
   nret = WSAGetLastError();
   printf("Error: %d", nret);
   WSACleanup();
   return NETWORK_ERROR;
}

ircsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(ircsocket == INVALID_SOCKET){
   nret = WSAGetLastError();
   printf("Error: %d", nret);
   WSACleanup();
   return NETWORK_ERROR;
}

serverInfo.sin_family = AF_INET;
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
serverInfo.sin_port = htons(6667);

nret = connect(ircsocket, (LPSOCKADDR)&serverInfo,
            sizeof(struct sockaddr));

if(nret == SOCKET_ERROR){
   nret = WSAGetLastError();
   printf("Error: %d", nret);
   WSACleanup();
   return NETWORK_ERROR;
}
send(ircsocket, userpacket, strlen(userpacket), 0);
printf ("%s\n", userpacket);
Sleep(100);
send(ircsocket, nickpacket, strlen(nickpacket), 0);
printf ("%s\n", nickpacket);
Sleep(100);

while(1){
   memset(buffer, 0, 255);
   recv(ircsocket, buffer, 255, 0);

   parse(buffer);
   if ( strlen(buffer) == 0)
      break;
   else {
   }
}

Sleep(1000);
closesocket(ircsocket);
WSACleanup();
return NETWORK_OK;
}

void parse (char * buf) {
char *say, *temp1, *sch, *join, *cocks;

   //parse login packets
   printf("%s\n",buf);
   pch = strstr(buf, "PING :");
   if (pch) {
      strncpy(pch, "PONG  ", 6);
      for (int i = 5; i < strlen(pch); i++)
            pch[i] = pch[i+1];
      send(ircsocket, pch, strlen(pch), 0);
      printf("\n%s\n", pch);
      send(ircsocket, joinpacket, strlen(joinpacket), 0);
      printf ("\n%s\n", joinpacket);
      Sleep(400);
      send(ircsocket, identifypacket, strlen(identifypacket), 0);
      printf ("%s\n", identifypacket);
      Sleep(400);

   }

   //parse !say ; !say message
   say = strstr(buf, "!say");
   if(say) {
      temp1 = strstr(buf, "Stephen@Blank");
      if(temp1) {
      say = strstr(buf, "PRIVMSG");
      pch = strchr(say, '!say');
      if(pch!=NULL) {
         int pos;
         for(pos=0; pos<strlen(say); ++pos)
             if( memcmp( "!say", say+pos, 4 ) == 0 )
                  break;

         //!say in current channel PRIVMSG #channel :!say message
         memmove(say+pos, say+pos+5, strlen(say)-pos );
         send(ircsocket, say, strlen(say), 0);
         printf("%s\n", say);
         }
      }
   }

   //parse !sch ; !sch #channel message
   sch = strstr(buf, "!sch");
   if(sch) {
      int posspace = 0, i, x;
      temp1 = strstr(buf, "Stephen@Blank");
      if(temp1) {
         sch = strstr(buf, "PRIVMSG");
         pch2 = strchr(sch, '!sch');
         if(pch2 !=NULL) {
            int pos = 0;
            for(pos=0; pos<strlen(sch); ++pos)
               if( memcmp("!sch", sch+pos, 3 ) == 0 )
                  break;
            memmove(sch+pos, sch+pos+5, strlen(sch)-pos); //remove !sch from sch array

            for(posspace=pos; posspace<strlen(sch); ++posspace)
               if( memcmp(" ", sch+posspace, 1) == 0)
                  break;
            char *temp3 = new char[posspace - pos +2];
            char *temp4 = new char[strlen(sch) - posspace + 2];

            for(i=0; i<posspace-pos; ++i)
               temp3[i] = sch[pos+i];
               temp3[i] = '\0';
            for(x=0; x<strlen(sch) - posspace; ++x)
               temp4[x] = sch[posspace+x+1];
               temp4[x] = '\0';
            sprintf(sch, "PRIVMSG %s :%s\r\n", temp3, temp4);
            send(ircsocket, sch, strlen(sch), 0);
            printf("%s\n", sch);
            delete temp3;
            delete temp4;
         }
      }
   }

   //parse !join ; !join #channel
   join = strstr(buf, "!join");
   if(join) {
      temp1 = strstr(buf, "Stephen@Blank");
      if(temp1) {
         int posspace, i;
         join = strstr(buf, "PRIVMSG");
         pch3 = strstr(join, "!join");
         if(pch3 != NULL) {
            int pos = 0;
            for(pos=0; pos<strlen(join); ++pos)
               if( memcmp("!join", join+pos, 5 ) == 0 )
                  break;
            memmove(join+pos, join+pos+6, strlen(join)-pos); //remove !join from join array
            for(posspace=pos; posspace<strlen(join); ++posspace)
               if( memcmp(" ", join+posspace, 1) == 0)
                  break;   
            char *temp3 = new char[posspace - pos +2];
            for(i=0; i<posspace-pos; ++i)
               temp3[i] = join[pos+i];
               temp3[i] = '\0';
            sprintf(join, "JOIN %s\r\n", temp3);
            send(ircsocket, join, strlen(join), 0);
            delete temp3;
         }
      }
   }

   //parse !cocks for renkokuken
   cocks = strstr(buf, "!cocks");
      if(cocks) {
      temp1 = strstr(buf, "Renkokuke");
      if(temp1) {
         cocks = strstr(buf, "PRIVMSG");
         pch4 = strstr(cocks, "!cocks");
         if(pch4) {
            int pos = 0, posspace, i;
            for(pos=0; pos<strlen(cocks); ++pos)
               if( memcmp("#", cocks+pos, 1 ) == 0 )
                  break;
            for(posspace=pos; posspace<strlen(cocks); ++posspace)
               if( memcmp(" ", cocks+posspace, 1) == 0)
                  break;   
            char *temp3 = new char[posspace - pos +2];
            for(i=0; i<posspace-pos; ++i)
               temp3[i] = cocks[pos+i];
               temp3[i] = '\0';

            memset(cocks, 0, strlen(cocks));
            sprintf(cocks, "PRIVMSG %s Renkokuken!!!\r\n", temp3);
            printf("%s\n", cocks);
            send(ircsocket, cocks, strlen(cocks), 0);
            delete temp3;
            }
         }
      }

}

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites