2004-12-22 18:25:29 +00:00
|
|
|
// irc_test.cpp
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning ( disable : 4786 )
|
|
|
|
#endif//_MSC_VER
|
|
|
|
|
2004-12-22 21:53:02 +00:00
|
|
|
#include <time.h>
|
2004-12-22 18:25:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-12-22 21:53:02 +00:00
|
|
|
#include "File.h"
|
|
|
|
#include "ssprintf.h"
|
|
|
|
|
2004-12-22 18:25:29 +00:00
|
|
|
#include "IRCClient.h"
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2004-12-22 21:53:02 +00:00
|
|
|
const char* ArchBlackmann = "ArchBlackmann";
|
|
|
|
|
|
|
|
vector<string> tech_replies;
|
|
|
|
|
|
|
|
const char* TechReply()
|
|
|
|
{
|
|
|
|
return tech_replies[rand()%tech_replies.size()].c_str();
|
|
|
|
}
|
|
|
|
|
2004-12-22 18:25:29 +00:00
|
|
|
// do custom stuff with the IRCClient from your subclass via the provided callbacks...
|
|
|
|
class MyIRCClient : public IRCClient
|
|
|
|
{
|
2004-12-22 21:53:02 +00:00
|
|
|
File flog;
|
2004-12-22 18:25:29 +00:00
|
|
|
public:
|
2004-12-22 21:53:02 +00:00
|
|
|
MyIRCClient()
|
|
|
|
{
|
|
|
|
flog.open ( "arch.log", "w+" );
|
|
|
|
}
|
2004-12-22 18:25:29 +00:00
|
|
|
// see IRCClient.h for documentation on these callbacks...
|
|
|
|
bool OnConnected()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OnJoin ( const string& user, const string& channel )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OnEndChannelUsers ( const string& channel )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OnPrivMsg ( const string& from, const string& text )
|
|
|
|
{
|
|
|
|
printf ( "<%s> %s\n", from.c_str(), text.c_str() );
|
2004-12-22 21:53:02 +00:00
|
|
|
flog.printf ( "<%s> %s\n", from.c_str(), text.c_str() );
|
|
|
|
return PrivMsg ( from, "hey, your tongue doesn't belong there!" );
|
2004-12-22 18:25:29 +00:00
|
|
|
}
|
|
|
|
bool OnChannelMsg ( const string& channel, const string& from, const string& text )
|
|
|
|
{
|
|
|
|
printf ( "%s <%s> %s\n", channel.c_str(), from.c_str(), text.c_str() );
|
2004-12-22 21:53:02 +00:00
|
|
|
flog.printf ( "%s <%s> %s\n", channel.c_str(), from.c_str(), text.c_str() );
|
|
|
|
string text2(text);
|
|
|
|
strlwr ( &text2[0] );
|
|
|
|
if ( !strnicmp ( text2.c_str(), ArchBlackmann, strlen(ArchBlackmann) ) )
|
|
|
|
{
|
|
|
|
string reply = ssprintf("%s: %s", from.c_str(), TechReply());
|
|
|
|
flog.printf ( "TECH-REPLY: %s\n", reply.c_str() );
|
|
|
|
return PrivMsg ( channel, reply );
|
|
|
|
}
|
2004-12-22 18:25:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OnChannelMode ( const string& channel, const string& mode )
|
|
|
|
{
|
|
|
|
//printf ( "OnChannelMode(%s,%s)\n", channel.c_str(), mode.c_str() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OnUserModeInChannel ( const string& src, const string& channel, const string& user, const string& mode )
|
|
|
|
{
|
|
|
|
//printf ( "OnUserModeInChannel(%s,%s%s,%s)\n", src.c_str(), channel.c_str(), user.c_str(), mode.c_str() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OnMode ( const string& user, const string& mode )
|
|
|
|
{
|
|
|
|
//printf ( "OnMode(%s,%s)\n", user.c_str(), mode.c_str() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool OnChannelUsers ( const string& channel, const vector<string>& users )
|
|
|
|
{
|
|
|
|
printf ( "[%s has %i users]: ", channel.c_str(), users.size() );
|
|
|
|
for ( int i = 0; i < users.size(); i++ )
|
|
|
|
{
|
|
|
|
if ( i )
|
|
|
|
printf ( ", " );
|
|
|
|
printf ( "%s", users[i].c_str() );
|
|
|
|
}
|
|
|
|
printf ( "\n" );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main ( int argc, char** argv )
|
|
|
|
{
|
2004-12-22 21:53:02 +00:00
|
|
|
srand ( time(NULL) );
|
|
|
|
File f ( "tech.txt", "r" );
|
|
|
|
string line;
|
|
|
|
while ( f.next_line ( line, true ) )
|
|
|
|
tech_replies.push_back ( line );
|
|
|
|
f.close();
|
|
|
|
|
2004-12-22 18:25:29 +00:00
|
|
|
printf ( "initializing IRCClient debugging\n" );
|
|
|
|
IRCClient::SetDebug ( true );
|
|
|
|
printf ( "calling suStartup()\n" );
|
|
|
|
suStartup();
|
|
|
|
printf ( "creating IRCClient object\n" );
|
|
|
|
MyIRCClient irc;
|
|
|
|
printf ( "connecting to freenode\n" );
|
2004-12-22 21:53:02 +00:00
|
|
|
if ( !irc.Connect ( "212.204.214.114" ) ) // irc.freenode.net
|
2004-12-22 18:25:29 +00:00
|
|
|
{
|
|
|
|
printf ( "couldn't connect to server\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf ( "sending user command\n" );
|
2004-12-22 21:53:02 +00:00
|
|
|
if ( !irc.User ( "ArchBlackmann", "", "irc.freenode.net", "Arch Blackmann" ) )
|
2004-12-22 18:25:29 +00:00
|
|
|
{
|
|
|
|
printf ( "USER command failed\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf ( "sending nick\n" );
|
2004-12-22 21:53:02 +00:00
|
|
|
if ( !irc.Nick ( "ArchBlackmann" ) )
|
2004-12-22 18:25:29 +00:00
|
|
|
{
|
|
|
|
printf ( "NICK command failed\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf ( "setting mode\n" );
|
|
|
|
if ( !irc.Mode ( "+i" ) )
|
|
|
|
{
|
|
|
|
printf ( "MODE command failed\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf ( "joining #ReactOS\n" );
|
|
|
|
if ( !irc.Join ( "#ReactOS" ) )
|
|
|
|
{
|
|
|
|
printf ( "JOIN command failed\n" );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
printf ( "entering irc client processor\n" );
|
2004-12-22 21:53:02 +00:00
|
|
|
irc.Run ( false ); // do the processing in this thread...
|
2004-12-22 18:25:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|