Author Topic: messenger C++ bot  (Read 1916 times)

0 Members and 1 Guest are viewing this topic.

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
messenger C++ bot
« on: March 29, 2011, 01:56:18 am »
hey guys Ive been googling for a bot of messenger and Im planning to code it on C++ Ive found this:

about msn protocols:
http://en.wikipedia.org/wiki/Windows_Live_Messenger#Protocol

about sockets:

http://en.wikipedia.org/wiki/Internet_socket

well both are not about how to code a bot but its a client chat program so we can modify it a bit and Im going to need a database right?

http://www.codeproject.com/KB/cpp/chat_client_server.
http://www.velocityreviews.com/forums/t289922-creating-an-instant-messenger.html

Code: [Select]
//************************************************************************
// Boby Thomas Pazheparampil
// May 2006
// Implementation of CIPMessage class and main.
//************************************************************************
#include "chat_client.h"

//Global Message object
CIPMessage MyMessObj;


CIPMessage::CIPMessage()
{
m_bIsConnected = false;
}

void CIPMessage::Init(string sIpAddress, int iPort)
{

m_sServerIPAddress = sIpAddress;
m_iServerPort = iPort;
struct hostent *hp;
unsigned int addr;
struct sockaddr_in server;


WSADATA wsaData;

int wsaret=WSAStartup(0x101,&wsaData);


if(wsaret!=0)
{
return;
}

conn=socket(AF_INET,SOCK_STREAM,0);
if(conn==INVALID_SOCKET)
return;

addr=inet_addr(m_sServerIPAddress.c_str());
hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);

if(hp==NULL)
{
closesocket(conn);
return;
}

server.sin_addr.s_addr=*((unsigned long*)hp->h_addr);
server.sin_family=AF_INET;
server.sin_port=htons(m_iServerPort);
if(connect(conn,(struct sockaddr*)&server,sizeof(server)))
{
closesocket(conn);
return;
}
m_bIsConnected = true;
return;
}

CIPMessage::~CIPMessage()
{
if(m_bIsConnected)
closesocket(conn);
}

int CIPMessage::SendMessagePort(string sMessage)
{
int iStat = 0;

iStat = send(conn,sMessage.c_str(),sMessage.size()+1,0);
if(iStat == -1)
return 1;

return 0;

}

int CIPMessage::RecMessagePort()
{

char acRetData[4096];
int iStat = 0;

iStat = recv(conn,acRetData,4096,0);
if(iStat == -1)
return 1;
cout<<"-->"<<acRetData<<"\n";

return 0;

}



UINT  MessageRecThread(LPVOID pParam)
{
while(1)
{
if(MyMessObj.RecMessagePort())
break;
}
return 0;
}



int main(int argc, char* argv[])
{
char buf[4096];
cout<<"This is a client TCP/IP application\nConnecting to port 8084\n";
cout<<"\nPress ONLY ENTER to quit";
cout<<"\nWritten by Boby Thomas";
cout<<"\n===============================================\n";

FILE *fp = fopen("server.ini","r");
if(fp == NULL)
{
cout<<"\nUnable to open server.ini. Please specify server IPsddress in server.ini";
return 1; // main failed
}
string sServerAddress;
while((fgets(buf,4096,fp)) != NULL)
{
if(buf[0] == '#')
continue;
sServerAddress = buf;

}
fclose(fp);

if(sServerAddress.size() == 0)
{
cout<<"\nUnable to find server IPaddress in server.ini";
cout<<"\nPlease set server IPaddress";
cout<<"\nThis is Boby Signing off. BYE:";
getch();
return 0;
}

MyMessObj.Init(sServerAddress.c_str(),8084);
if(!MyMessObj.IsConnected())
{
cout<<"\nUnable to connect to the IPaddress specified in server.ini";
cout<<"\nPlease check server IPaddress";
cout<<"\nThis is Boby Signing off. BYE:";
getch();
return 0;
}

AfxBeginThread(MessageRecThread,0);
while(gets(buf))
{
if(strlen(buf) == 0)
break;
if(MyMessObj.SendMessagePort(buf))
{
cout<<"Problem in connecting to server. Check whether server is running\n";
break;
}
}

cout<<"\nThis is Boby Signing off. BYE:";
getch();
return 0;
}

what would be my next steps to build it? ty in advance

Offline I_Learning_I

  • Knight
  • **
  • Posts: 267
  • Cookies: 26
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
Re: messenger C++ bot
« Reply #1 on: March 29, 2011, 02:41:02 pm »
A bot like forge human presence?
If so all you would need would be read from socket and write to socket, according to the message received, although that would be a huge list...
To be effective you would need to have checks for smiles, adjectives list, interpret numbers as letters and would probably still fail a lot :O
I haven't coded in WinAPI, but shouldn't there be some interaction with a socket? like a send() or socket<<"Bla bla bla";
Also I believe you need to add \r\n and the end of every strings, but that I can't ensure.
Thanks for reading,
I_Learning_I

Offline gh0st

  • Sir
  • ***
  • Posts: 575
  • Cookies: 8
  • #DEDSec
    • View Profile
Re: messenger C++ bot
« Reply #2 on: March 30, 2011, 10:45:52 pm »
It may be here read this :
 http://www.daniweb.com/software-development/cpp/threads/8020
help me to code it and when the code has 19000 lines of source code and become popular I will give you the 1% of the incomes  8)