Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411582 Posts in 69386 Topics- by 58445 Members - Latest Member: Mansreign

May 06, 2024, 02:00:51 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Making an IRC Client/Bot
Pages: [1]
Print
Author Topic: Making an IRC Client/Bot  (Read 1289 times)
RC
Level 0
***



View Profile
« on: September 19, 2009, 05:44:03 PM »

Before I begin, let me analyze my thoughts and gather your minds, for I know the world has enough IRC clients to piss a dog off. So why exactly am I making one? The answer is simple: I want experience, and the thrill of making something that could be useful one day is a factor in this too.


I'm using C++ and Winsock2 for this project, after countless hours wasted today through trial and error, I finally managed to get it to successfully connect to a SlashNet IRC server... or so it said.

I'm not receiving any messages from the server, yet I'm sending it. Maybe I'm doing something wrong but will I ever know? Yes, probably, but I'd rather not figure this out for myself. I'm asking for the help of anyone who could possibly understand this problem, unless I figure it out before then, and that would truly be a miracle.

Bear in mind I just began learning socket programming and IRC protocol today, and this is what I came up with thanks to a few nifty tutorials on winsock2.

Code:
#include <iostream>
#include <winsock2.h>

using namespace std;

char buffer[512];
int received;

int main(int argc, char *argv[])
{
    WSADATA wsaData;

    if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
    {
          cout << "Error: " << WSAGetLastError() << " occurred!" << endl;
          system("PAUSE >nul");
         
          WSACleanup();
          return 0;
    }

    cout << "WSAStartup Successful!" << endl;
    system("PAUSE >nul");
   
    SOCKET mysock = socket(AF_INET, SOCK_STREAM, 0);
   
    if(mysock == INVALID_SOCKET)
    {
          cout << "Error: " << WSAGetLastError() << " occurred!" << endl;
          system("PAUSE >nul");
         
          WSACleanup();
          return 0;
    }
   
    cout << "Socket creation successful!" << endl;
    system("PAUSE >nul");
   
    sockaddr_in anews;
    anews.sin_port = htons(6697);
    anews.sin_addr.s_addr = inet_addr("38.99.109.26");
    anews.sin_family = AF_INET;
   
    if(connect(mysock, (sockaddr*)&anews, sizeof(anews)) == SOCKET_ERROR)
    {
          cout << "Error: " << WSAGetLastError() << " occurred!" << endl;
          system("PAUSE >nul");
         
          WSACleanup();
          return 0;
    }
   
    cout << "Socket has connected successfully!" << endl;
   
    char *data = "NICK RCBot\n";
    cout << data << endl;
    send(mysock, data, strlen(data), 0);
    data = "USER rcbot \"live.com\" \"irc.slashnet.org\" :Rcbot\n";
    cout << data << endl;
    send(mysock, data, strlen(data), 0);
   
    while(true)
    {
          received = recv(mysock,buffer,1023,0);
         
          if(received > 0)
          {
                char *result = NULL;
                result = strtok(buffer, "\n");
               
                while(result != NULL)
                {
                      cout << result << endl;
                }
          }
    }
   
    system("PAUSE >nul");
   
    closesocket(mysock);
    WSACleanup();
   
    return 0;
}
That's the source so far, I know I'm not ponging back the ping, but that's not necessary right now since I'm not even being pinged! Shocked

Edit: Never mind, I figured out I had the wrong port. Still, I'm getting an infiloop of ":moo.slashnet.org NOTICE AUTH :*** Looking up your hostname..."
« Last Edit: September 19, 2009, 08:26:40 PM by RC » Logged

HannesP
Level 0
***


View Profile WWW
« Reply #1 on: September 20, 2009, 06:59:09 AM »

Try \r\n instead of just \n
Logged
RC
Level 0
***



View Profile
« Reply #2 on: September 20, 2009, 07:29:28 AM »

Try \r\n instead of just \n
I have, and just tried it again with no success. Sad
Logged

Core Xii
Level 10
*****


the resident dissident


View Profile WWW
« Reply #3 on: September 20, 2009, 08:40:47 AM »

Still, I'm getting an infiloop of ":moo.slashnet.org NOTICE AUTH :*** Looking up your hostname..."

I remember having this problem myself. But I can't recall how I solved it. Shrug

If I recall correctly I think it's a separate service running on your computer, that the server connects to, to verify that you are who you claim to be, and there's nothing you need to do about it.

A Google search hints that you should send the USER command when you see that.
Logged
mcc
Level 10
*****


glitch


View Profile WWW
« Reply #4 on: September 20, 2009, 03:42:07 PM »

This is a bit lower level than any of my interactions with IRC have been. But what I would suggest doing is running Wireshark and snooping on the stream between the server and a "real" irc client. That way you at least will have a clear idea of what it is the real irc client is doing to get the server to talk to it.
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
RC
Level 0
***



View Profile
« Reply #5 on: September 20, 2009, 04:25:28 PM »

Okay guys, I fixed it as far as I know. That while loop was causing the problems.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic