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 issues, fuck me sideways

 
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: Sat Aug 30, 2008 9:55 pm    Post subject: IRC Bot issues, fuck me sideways Reply with quote

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

int main() {
WORD sockVersion;
WSADATA wsaData;
int nret;
LPHOSTENT hostEntry;
SOCKET ircsocket;
SOCKADDR_IN serverInfo;

char buffer[256];
char user[] = "USER blankbot 0 0 blankbot \r\n";
char nick[] = "NICK blankbot \r\n";
char identify[] = "PRIVMSG nickserv identify YouWishYouKnew";
char join[] = "JOIN #blankbot \r\n";
char privmsg[] = "PRIVMSG #blankbot Hello world\r\n";
char quit[] = "BUH BYE\r\n";


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, user, strlen(user), 0);
printf ("%s\n", user);
Sleep(100);
send(ircsocket, nick, strlen(nick), 0);
printf ("%s\n", nick);
Sleep(100);

char *pch, *j;
while(1){
   memset(buffer, 0, 255);
   recv(ircsocket, buffer, 255, 0);
   printf(buffer);
   printf("\n");

   pch = strstr(buffer, "PING :");
   if (pch) {
      strncpy(pch, "PONG  ", 6);
      send(ircsocket, pch, sizeof(pch), 0);
      printf(pch);
      printf("\n");
   }
   j = strstr (buffer, "End of /MOTD command.");
   if(j){
      send(ircsocket, identify, strlen(identify), 0);
      printf ("%s\n", identify);
      Sleep(100);

      send(ircsocket, join, strlen(join), 0);
      printf ("%s\n", join);

      send(ircsocket, privmsg, strlen(privmsg), 0);
      printf ("%s\n", privmsg);
   }
      

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

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

the issue is with PING and PONG. I receive PING like this
PING :xxxxxxxx
and PONG has to be sent like
PONG xxxxxxxx
So i have to remove the 6th position (a space) in order to continue with the logging in to irc.

Can anyone please help . Sorry if i don't make sense. I've been frustrating over this.


Fixed the PONG by using
for (int i = 5; i < strlen(pch); i++)
pch[i] = pch[i+1];

but now it still doesn't continue.
I receive nothing after the pong, i should be getting server confirmation

_________________
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Aug 30, 2008 10:48 pm    Post subject: Reply with quote

Well, in my case, anyway (and this happened a few times), you do get a response from the server: "ERROR :Closing Link: blankbot[ip] <Ping timeout>"

Just wait a while, and throw a getchar() right after the while loop.

I'll play around with it, and see what I can find; I'm assuming you're sending a bad PONG.

Edit:

lol. pch is a pointer, therefore its size is 4. You should replace the

Code:
send(ircsocket, pch, sizeof(pch), 0);


with

Code:
send(ircsocket, pch, strlen(pch), 0);


Edit:

I just tried that, and it seemed to work... Then I got like bombed with all sorts of messages and information. =P

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Sat Aug 30, 2008 10:53 pm    Post subject: Reply with quote

add a Sleep(15000) or higher for 15 seconds or so.. attach WPE PRO to your tool and see what packets you send and recieve exactly byte by byte..

Then compare it with the offical mIRC packets.. that will solve any problem I guarantee it..


P.S.
Code:

for (int i = 5; i < strlen(pch); i++)
pch[i] = pch[i+1];



is same as..

Code:


memcpy((char*)pch,(void*)((DWORD)pch+6), strlen(pch)-5);

the strlen(pch)-5 not sure if it will work.. that loop confuses me.. but what I learned so thats how you handle packets in C++



Also P.S. your problem might be actually the strlen.. if it reaches a byte equal to 0, 00 aka 0x0 aka NULL. It will stop counting.. so your counting system could be flawed then..

a few tests you could do also..
DWORD stuffsent;
DWORD stuffgotback;
stuffsent = send(blah,blah,blah);
stuffgotback = recv(bkah,blah,blah);

just printf the stuffgotback and stuffsent.. to see how much bytes you sent and received this for testing if you send the correct stuff and if you receive the correct amount of bytes.


samuri25404 is right about the send() paramaters you have to send the size of packet not size of pointer which is 4.. so it should still work lol cuz PONG is 4 in size anyways. I'd just hardcore the size with a magic number cuz it will never change anyways..


Almost forgot when you send something to IRC protocol you have to send \r\n at the end of every packet or it will not work

sprintf(pch, "PONG/r/n");

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Aug 31, 2008 9:36 am    Post subject: Reply with quote

pkedpker wrote:
Almost forgot when you send something to IRC protocol you have to send \r\n at the end of every packet or it will not work

sprintf(pch, "PONG/r/n");


Seemed to work fine for me, without that.

Btw, it's "\r\n" not "/r/n".

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Sun Aug 31, 2008 11:34 am    Post subject: Reply with quote

Use wireshark, find out what you are actually sending.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
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