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 


My #cef ircbot source

 
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: Fri Apr 02, 2010 9:34 am    Post subject: My #cef ircbot source Reply with quote

No use for it now. Here ya go. My password has been removed and replaced with password. username@host is something like "stephen@Blank" that was mine anyways. Commands are commented on how to use.


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

#pragma comment (linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
/***** Start---Rich Edit Defines *****/
#define RICHEDIT_STYLE ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_HSCROLL | WS_VSCROLL
#define IDC_EDIT 4000
#define IDC_CHATEDIT 4001
#define IDC_CHATSEND 4002
#define WINDOWX 500
#define WINDOWY 500
CHARRANGE cr, crscroll;
HFONT hFont;

HWND CreateRichEdit(HWND ParenthWnd, UINT x, UINT y, UINT uWidth, UINT uHeight, HINSTANCE hInstance)
{
    HWND hWndEdit = CreateWindowEx(0, TEXT("RICHEDIT50W"), NULL, RICHEDIT_STYLE, x, y, uWidth, uHeight,
                                   ParenthWnd, (HMENU)IDC_EDIT, hInstance, NULL);
    if (!hWndEdit)
        MessageBox(NULL, TEXT("Rich Edit could not be loaded!"), NULL, MB_OK | MB_ICONEXCLAMATION);
    return hWndEdit;
}


bool WriteTextToRich(HWND hwndRich, char* Text)
{
   SendMessage(hwndRich, EM_EXSETSEL, 0, (LPARAM)&cr);
   SendMessage(hwndRich, EM_REPLACESEL, 0, (LPARAM)Text);

return TRUE;
}

/***** End---Rich Edit Defines *****/
/***** Start---Winsock Defines *****/
#pragma comment (lib, "Ws2_32.lib")
#define NETWORK_ERROR -1
#define NETWORK_OK      0
#define BOT_VERSION 1

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

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

void parse (char* buf, HWND hwnd);

DWORD WINAPI startIRC(HWND hwnd)
{
HWND hwndEdit = GetDlgItem(hwnd, IDC_EDIT);
char buff[256], buffer[256];
sockVersion = MAKEWORD(1,1);
WSAStartup(sockVersion, &wsaData);

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

if(!hostEntry){
   nret = WSAGetLastError();
   ZeroMemory(buff, 255);
   sprintf(buff, "Error: %d", nret);
   WriteTextToRich(hwndEdit, buff);
   WSACleanup();
   return NETWORK_ERROR;
}

ircsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(ircsocket == INVALID_SOCKET){
   nret = WSAGetLastError();
   ZeroMemory(buff, 255);
   sprintf(buff, "Error: %d", nret);
   WriteTextToRich(hwndEdit, buff);
   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();
   ZeroMemory(buff, 255);
   sprintf(buff, "Error: %d", nret);
   WriteTextToRich(hwndEdit, buff);
   WSACleanup();
   return NETWORK_ERROR;
}
send(ircsocket, userpacket, strlen(userpacket), 0);
ZeroMemory(buff, 255);
sprintf (buff, "%s\n", userpacket);
WriteTextToRich(hwndEdit, buff);
Sleep(100);
send(ircsocket, nickpacket, strlen(nickpacket), 0);
ZeroMemory(buff, 255);
printf (buff, "%s\n", nickpacket);
WriteTextToRich(hwndEdit, buff);
Sleep(100);

while(1){
   memset(buffer, 0, 255);
   recv(ircsocket, buffer, 255, 0);
   parse(buffer, hwnd);
   if ( strlen(buffer) == 0)
      break;
   else {
   }
}
return 0;
}



void parse (char * buf, HWND hwnd)
{
char *say, *temp1, *sch, *join, *cocks, *part, *nick, *identify, *arj, *raw;
HWND hwndEdit = GetDlgItem(hwnd, IDC_EDIT);
char buff[256];

   //parse login packets
   ZeroMemory(buff, 255);
   sprintf(buff, "%s\n",buf);
   WriteTextToRich(hwndEdit, buff);
   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);
      ZeroMemory(buff, 255);
      sprintf(buff, "\n%s\n", pch);
      WriteTextToRich(hwndEdit, buff);
      send(ircsocket, joinpacket, strlen(joinpacket), 0);
      ZeroMemory(buff, 255);
      sprintf (buff, "\n%s\n", joinpacket);
      WriteTextToRich(hwndEdit, buff);
      Sleep(400);
      send(ircsocket, identifypacket, strlen(identifypacket), 0);
      ZeroMemory(buff, 255);
      sprintf (buff, "\n%s\n", identifypacket);
      WriteTextToRich(hwndEdit, buff);

      Sleep(400);

   }

   //parse !say ; !say message
   say = strstr(buf, "!say");
   if(say) {
      temp1 = strstr(buf, "username@host");
      if(temp1) {
      say = strstr(buf, "PRIVMSG");
      pch = strchr(say, '!say');
      if(pch!=NULL) {
         int pos, pospriv;
         for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("username@host", buf+pospriv, 13 ) == 0 )
                  break;
         for(pos=0; pos<strlen(say); ++pos)
             if( memcmp( "!say", say+pos, 4 ) == 0 )
                  break;
         if(pospriv < pos) {
         //!say in current channel PRIVMSG #channel :!say message
         memmove(say+pos, say+pos+5, strlen(say)-pos );
         send(ircsocket, say, strlen(say), 0);
         ZeroMemory(buff, 255);
         sprintf(buff, "%s\n", say);
         WriteTextToRich(hwndEdit, buff);
            }
         }
      }
   }

   //parse !sch ; !sch #channel message
   sch = strstr(buf, "!sch");
   if(sch) {
      int posspace = 0, i, x;
      temp1 = strstr(buf, "username@host");
      if(temp1) {
         sch = strstr(buf, "PRIVMSG");
            int pos = 0, pospriv;
            for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("username@host", buf+pospriv, 13 ) == 0 )
                  break;
            for(pos=0; pos<strlen(sch); ++pos)
               if( memcmp("!sch", sch+pos, 3 ) == 0 )
                  break;
            if(pospriv < pos) {
            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);
            ZeroMemory(buff, 255);
            sprintf(buff, "%s\n", sch);
            WriteTextToRich(hwndEdit, buff);
            delete temp3;
            delete temp4;
            }
         }
      }

   //parse !join ; !join #channel
   join = strstr(buf, "!join");
   if(join) {
      temp1 = strstr(buf, "username@host");
      if(temp1) {
         int posspace, i;
         join = strstr(buf, "PRIVMSG");
            int pos = 0, pospriv;
            for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("username@host", buf+pospriv, 13 ) == 0 )
                  break;
            for(pos=0; pos<strlen(join); ++pos)
               if( memcmp("!join", join+pos, 5 ) == 0 )
                  break;
            if(pospriv < pos) {
            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);
            ZeroMemory(buff, 255);
            sprintf(buff, "%s\n", join);
            WriteTextToRich(hwndEdit, buff);
            delete temp3;
            }
         }
      }


   //parse !cocks for renkokuken
   cocks = strstr(buf, "!cocks");
      if(cocks) {
      temp1 = strstr(buf, "Renkokuke");
      if(temp1) {
         cocks = strstr(buf, "PRIVMSG");
            int pos = 0, posspace, i, pospriv;
            for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("Renkokuke", buf+pospriv, 9 ) == 0 )
                  break;
            for(pos=0; pos<strlen(cocks); ++pos)
               if( memcmp("#", cocks+pos, 1 ) == 0 )
                  break;
            if(pospriv < pos) {
            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);
            ZeroMemory(buff, 255);
            sprintf(buff, "%s\n", cocks);
            WriteTextToRich(hwndEdit, buff);
            send(ircsocket, cocks, strlen(cocks), 0);
            delete temp3;
               }
            }
         }
      

   //parse !part ; !part #channel
   part = strstr(buf, "!part");
   if(part) {
      temp1 = strstr(buf, "username@host");
      if(temp1) {
         int posspace, i;
         part = strstr(buf, "PRIVMSG");
            int pos = 0, pospriv;
            for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("username@host", buf+pospriv, 13 ) == 0 )
                  break;
            for(pos=0; pos<strlen(part); ++pos)
               if( memcmp("!part", part+pos, 5 ) == 0 )
                  break;
            if(pospriv < pos) {
            memmove(part+pos, part+pos+6, strlen(part)-pos); //remove !part from part array
            for(posspace=pos; posspace<strlen(part); ++posspace)
               if( memcmp(" ", part+posspace, 1) == 0)
                  break;   
            char *temp3 = new char[posspace - pos +2];
            for(i=0; i<posspace-pos; ++i)
               temp3[i] = part[pos+i];
               temp3[i] = '\0';
            sprintf(part, "PART %s\r\n", temp3);
            send(ircsocket, part, strlen(part), 0);
            delete temp3;
            ZeroMemory(buff, 255);
            sprintf(buff, "%s\n", part);
            WriteTextToRich(hwndEdit, buff);
            }
         }
      }
   

   //parse !nick ; !nick newnick
   nick = strstr(buf, "!nick");
   if(nick) {
      temp1 = strstr(buf, "username@host");
      if(temp1) {
         int posspace, i;
         nick = strstr(buf, "PRIVMSG");
            int pos = 0, pospriv;
            for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("username@host", buf+pospriv, 13 ) == 0 )
                  break;
            for(pos=0; pos<strlen(nick); ++pos)
               if( memcmp("!nick", nick+pos, 5 ) == 0 )
                  break;
            if(pospriv < pos) {
            memmove(nick+pos, nick+pos+6, strlen(nick)-pos);
            for(posspace=pos; posspace<strlen(nick); ++posspace)
               if( memcmp(" ", nick+posspace, 1) == 0)
                  break;   
            char *temp3 = new char[posspace - pos +2];
            for(i=0; i<posspace-pos; ++i)
               temp3[i] = nick[pos+i];
               temp3[i] = '\0';
            sprintf(nick, "NICK %s\r\n", temp3);
            send(ircsocket, nick, strlen(nick), 0);
            delete temp3;
            ZeroMemory(buff, 255);
            sprintf(buff, "%s\n", nick);
            WriteTextToRich(hwndEdit, buff);
            }
         }
      }
   

   //parse !identify ; !identify password
   identify = strstr(buf, "!identify");
   if(identify) {
      temp1 = strstr(buf, "username@host");
      if(temp1) {
         int posspace, i;
         identify = strstr(buf, "PRIVMSG");
            int pos = 0, pospriv;
            for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("username@host", buf+pospriv, 13 ) == 0 )
                  break;
            for(pos=0; pos<strlen(identify); ++pos)
               if( memcmp("!identify", identify+pos, 5 ) == 0 )
                  break;
            if(pospriv < pos) {
            memmove(identify+pos, identify+pos+6, strlen(identify)-pos);
            for(posspace=pos; posspace<strlen(identify); ++posspace)
               if( memcmp(" ", identify+posspace, 1) == 0)
                  break;   
            char *temp3 = new char[posspace - pos +2];
            for(i=0; i<posspace-pos; ++i)
               temp3[i] = identify[pos+i];
               temp3[i] = '\0';
            sprintf(identify, "PRIVMSG NickServ IDENTIFY %s\r\n", temp3);
            send(ircsocket, identify, strlen(identify), 0);
            ZeroMemory(buff, 255);
            sprintf(buff, "%s\n", identify);
            WriteTextToRich(hwndEdit, buff);
            delete temp3;
            }
         }
      }
   
   //parse autorejoin
   arj = strstr(buf, "KICK");
   if(arj) {
      ZeroMemory(buff, 255);
      arj = strstr(buf, "KICK");
      pch = strstr(arj, "blankbot");
      if( pch ) {
         int pos, posspace, i;
            for(pos=0; pos<strlen(arj); ++pos)
               if( memcmp("KICK", arj+pos, 4 ) == 0 )
                  break;

            memmove(arj+pos, arj+pos+5, strlen(arj)-pos);
            
            for(posspace=pos; posspace<strlen(arj); ++posspace)
               if( memcmp(" ", arj+posspace, 1) == 0)
                  break;   
            
         char *temp3 = new char[posspace - pos +2];
            for(i=0; i<posspace-pos; ++i)
               temp3[i] = arj[pos+i];
               temp3[i] = '\0';
               
            sprintf(arj, "JOIN %s\r\n", temp3);
            send(ircsocket, arj, strlen(arj), 0);

            ZeroMemory(buff, 255);
            sprintf(buff, "%s\n", arj);
            WriteTextToRich(hwndEdit, buff);
            delete temp3;
      }
   }

   //parse !raw ; !raw packet
   raw = strstr(buf, "!raw");
   if(raw) {
      temp1 = strstr(buf, "username@host");
      if(temp1) {
         int pos, pospriv, posbuf;
         for(pospriv=0; pospriv<strlen(buf); ++pospriv)
               if( memcmp("username@host", buf+pospriv, 13 ) == 0 )
                  break;
         for(pos=0; pos<strlen(raw); ++pos)
             if( memcmp( "!raw", raw+pos, 4 ) == 0 )
                  break;
         for(posbuf=0; posbuf<strlen(buf); ++posbuf)
             if( memcmp( "!raw", buf+pos, 4 ) == 0 )
                  break;
         if(pospriv < posbuf) {
         //!raw sends straight packet

         memmove(raw+pos, raw+pos+5, strlen(raw)-pos );
         send(ircsocket, raw, strlen(raw), 0);
         ZeroMemory(buff, 255);
         sprintf(buff, "%s\n", raw);
         WriteTextToRich(hwndEdit, buff);
            }
         }
      }
   ZeroMemory(buff, 255);
}


void parseSend(char* buf)
{



}




LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static char sClassName[] = "MyClass";
static HINSTANCE zhInstance = NULL;
RECT clientRect;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
    int nCmdShow) {
     cr.cpMin = -1;
     cr.cpMax = -1;
     hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);

       WNDCLASSEX WndClass;
       HWND hwnd = NULL;
       MSG Msg;

      LoadLibrary(TEXT("Msftedit.dll"));
       zhInstance = hInstance;

       WndClass.cbSize        = sizeof(WNDCLASSEX);
       WndClass.style         = NULL;
       WndClass.lpfnWndProc   = WndProc;
       WndClass.cbClsExtra    = 0;
       WndClass.cbWndExtra    = 0;
       WndClass.hInstance     = zhInstance;
       WndClass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
       WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
       WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
       WndClass.lpszMenuName  = NULL;
       WndClass.lpszClassName = sClassName;
       WndClass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

       if(!RegisterClassEx(&WndClass)) {
               MessageBox(0, "Error Registering Class!", "Error!", MB_ICONSTOP | MB_OK);
               return 0;
       }

       hwnd = CreateWindowEx(WS_EX_STATICEDGE, sClassName, "Window", WS_OVERLAPPEDWINDOW,
                    CW_USEDEFAULT, CW_USEDEFAULT,
                      WINDOWX, WINDOWY, NULL, NULL, zhInstance, NULL);

       if(hwnd == NULL) {
               MessageBox(0, "Error Creating Window!", "Error!", MB_ICONSTOP | MB_OK);
               return 0;
       }
       ShowWindow(hwnd, nCmdShow);
       UpdateWindow(hwnd);

            while(GetMessage(&Msg, NULL, 0, 0)) {
               TranslateMessage(&Msg);
               DispatchMessage(&Msg);
       }

       return Msg.wParam;
}




LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
HWND hwndEdit, chatEdit, chatSend;
   switch(Message) {

         case WM_CREATE:
         GetClientRect(hwnd, &clientRect);
         hwndEdit = CreateRichEdit(hwnd, 2, 2, clientRect.right - 4, clientRect.bottom - 25, zhInstance);
         SendMessage(hwndEdit, WM_SETFONT, (WPARAM)hFont, TRUE);
         //SendMessage(hwndEdit, EM_SETOPTIONS, (WPARAM)ECOOP_SET, (LPARAM)ECO_READONLY);
         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)startIRC, hwnd, 0, NULL);
         
         chatEdit = CreateWindow("edit", "",
            WS_BORDER | WS_CHILD | WS_VISIBLE ,
         2, clientRect.bottom - 23, clientRect.right - 50, 21,
            hwnd, (HMENU)IDC_CHATEDIT, 0,0);

         chatSend = CreateWindow("button", "Send",
            WS_BORDER | WS_CHILD | WS_VISIBLE,
         clientRect.right - 53, clientRect.bottom - 23, 50, 21,
            hwnd, (HMENU)IDC_CHATSEND, 0,0);

         break;
         case WM_COMMAND:
            if(wParam == IDC_CHATSEND)
            {
               char szChat[256], szSend[256], buff[256], *join;
               GetDlgItemText(hwnd, IDC_CHATEDIT, szChat, sizeof(szChat));
               join = strstr(szChat, "!join");
               if(join)
               {
                  send(ircsocket, "JOIN #cef \r\n", strlen("JOIN #cef\r\n"), 0);
                     ZeroMemory(buff, 255);
                     sprintf (buff, "\n%s\n", "JOIN #cef\r\n");
                     WriteTextToRich(GetDlgItem(hwnd, IDC_EDIT), buff);
               }
               if(!join)
               {
               sprintf(szSend, "PRIVMSG #cef %s\r\n", szChat);
               send(ircsocket, szSend, strlen(szSend), 0);
               sprintf(buff, "%s\n", szSend);
               WriteTextToRich(GetDlgItem(hwnd, IDC_EDIT), buff);
               }
            }
         break;
            case WM_CLOSE:
                       DestroyWindow(hwnd);
            break;

            case WM_DESTROY:
                       PostQuitMessage(0);
            break;

            default:
                        return DefWindowProc(hwnd, Message, wParam, lParam);
       }
       return 0;
}





_________________
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