I am referring to this code written Here for some help and a bit of guidance.
Well when i try and compile my code I get these error messages:
main.cpp: In function ‘int main()’: main.cpp:8: error: no matching function for call to ‘IrcBot::IrcBot()’ IrcBot.h:7: note: candidates are: IrcBot::IrcBot(char*, char*) IrcBot.h:5: note: IrcBot::IrcBot(const IrcBot&) main.cpp:9: error: invalid use of ‘class IrcBot’
well here is my code:
main.cpp
#include "IrcBot.h"
#include <iostream>
using namespace std;
int main()
{
IrcBot bot;
bot.IrcBot("NICK gr33nbot\r\n","USER gr33nbot notused notused:Gr33n Bot\r\n");
return 0;
}
IrcBot.h
#ifndef IrcBot_H
#define IrcBot_H
class IrcBot
{
public:
IrcBot(char * _nick, char * _user);
virtual ~IrcBot();
bool setup;
void start();
bool charSeach(char *tosearch, char *searchFor);
private:
const char *port;
int sock;//the socket descriptor
char *nick;
char *usr;
bool isConnected(char *buff);
char * timeNow();
bool sendData(char *msg);
void sendPong(char *buf);
void msgHandle(char *buf);
};
#endif /* IRCBOT_H */
IrcBot.cpp
#include "IrcBot.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <signal.h>
#include <time.h>
#include <cstring>
#define MAXDATASIZE 100;
using namespace std;
IrcBot::IrcBot(_nick,_user)
{
nick = _nick;
user = _user;
start();
}
IrcBot::start()
{
struct addrinfo hints, *servinfo;
int sock;
char* port = "6667";
int res;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
if(res = getaddrinfo("irc.freenode.org", port, &hints, &servinfo) != 0)
{
fprintf("Client: getaddrinfo failed:", gai_strerror(res),"\n");
}
if(sock = socket(servinfo->ai_family,servinfo->ai_socktype,servinfo->ai_protocol) == -1)
{
cout << "Client: socket failed: " << errno << endl;
}
if(connect(sock, servinfo->ai_addr, servinfo->ai_addrlen) == -1)
{
cout << "Client: connection failed: " << erno << endl;
}
freeaddrinfo(servinfo);
int numbytes;
char *buf;
count = 0;
while(1)
{
switch( count ){
case:3
sendData(nick);
sendData(usr);
break;
case:4
sendData("JOIN ##newboston\r\n");
default:
break;
}
numbytes = recv(sock,buf,MAXDATASIZE -1,0);
buf[numbytes]="/0";
cout << buf<< endl;
if(charSearch(buf,"PING")
{
sendPong(buf);
}
if(numbytes == 0)
{
cout << "<-------------------connection failed -------------------------->" << endl;
cout << timeNow << cout;
}
}
}
//-----------------------------------------
bool IrcBot::charSearch(char *buf, char *searchFor)
{
char compare[50];
int leng = strlen(buf);
int lengsearch = strlen(searchFor);
bool truefalse;
for(int i = 0; i<leng; i++){
if(leng != lengsearch){
truefalse = false;
goto leave;
}
if(buf[i]==searchFor[i])
{
truefalse = true;
}
else{
cout << "error something wronge happened" << endl;
truefalse = false;
goto leave;
}
leave:;
}
//----------------------------------------
IrcBot::sendPong(const char *buf)
{
char ping[10] = "PING";
char pong[10] = "PONG";
char response[100];
int len = strlen(buf);
int count = 0;
for(int z=0;z<len;z++){
response[z] = buf[z];
}
for(int i = 0;i<len;i++)
{
if(response[i]==ping[0])
{
for(int x = 0;x<3;x++)
{
if(ping[x]==response[count+x])
{
for(int y=0;y<3;y++)
{
response[count] = pong[y];
count++;
}
}
}
}
count++;
}
int l = strlen(response);
numbytes = send(sock,response,l,0);
return 0;
}
//-------------------------------------------------
char * IrcBot::timeNow()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
return asctime (timeinfo);
}
//--------------------------------------------------
bool IrcBot::sendData(char *msg)
{
int leng = strlen(msg);
if (send( sock , msg , leng , 0)
{
return true;
}
else{
return false;
}
}
bool IrcBot::msgHandle(char *msg)
{
if(charSearch(msg,"!help"))
{
sendData("PRIVMSG ##newboston :No commands are working atm\r\n");
}
}
I really am stuck most likely its just a stupid mistake so please help me.

New Topic/Question
Reply



MultiQuote




|