4 #pragma warning ( disable : 4786 )
13 #include "IRCClient.h"
18 const char* ArchBlackmann
= "ArchBlackmann";
20 vector
<string
> tech
, module
, dev
, stru
, period
;
22 void ImportList ( vector
<string
>& list
, const char* filename
)
24 File
f ( filename
, "r" );
26 while ( f
.next_line ( line
, true ) )
27 list
.push_back ( line
);
30 const char* ListRand ( const vector
<string
>& list
)
32 return list
[rand()%list
.size()].c_str();
37 string t
= ListRand(tech
);
39 const char* p
= t
.c_str();
44 if ( !strnicmp ( p
, "%dev%", 5 ) )
49 else if ( !strnicmp ( p
, "%period%", 8 ) )
51 out
+= ListRand(period
);
54 else if ( !strnicmp ( p
, "%module%", 8 ) )
56 out
+= ListRand(module
);
59 else if ( !strnicmp ( p
, "%stru%", 6 ) )
61 out
+= ListRand(stru
);
67 const char* p2
= strchr ( p
, '%' );
72 out
+= string ( p
, p2
-p
);
79 // do custom stuff with the IRCClient from your subclass via the provided callbacks...
80 class MyIRCClient
: public IRCClient
86 flog
.open ( "arch.log", "w+" );
88 // see IRCClient.h for documentation on these callbacks...
93 bool OnJoin ( const string
& user
, const string
& channel
)
97 bool OnEndChannelUsers ( const string
& channel
)
101 bool OnPrivMsg ( const string
& from
, const string
& text
)
103 printf ( "<%s> %s\n", from
.c_str(), text
.c_str() );
104 flog
.printf ( "<%s> %s\n", from
.c_str(), text
.c_str() );
105 return PrivMsg ( from
, "hey, your tongue doesn't belong there!" );
107 bool OnChannelMsg ( const string
& channel
, const string
& from
, const string
& text
)
109 printf ( "%s <%s> %s\n", channel
.c_str(), from
.c_str(), text
.c_str() );
110 flog
.printf ( "%s <%s> %s\n", channel
.c_str(), from
.c_str(), text
.c_str() );
112 strlwr ( &text2
[0] );
113 if ( !strnicmp ( text2
.c_str(), ArchBlackmann
, strlen(ArchBlackmann
) ) )
115 string reply
= ssprintf("%s: %s", from
.c_str(), TechReply().c_str());
116 flog
.printf ( "TECH-REPLY: %s\n", reply
.c_str() );
117 return PrivMsg ( channel
, reply
);
121 bool OnChannelMode ( const string
& channel
, const string
& mode
)
123 //printf ( "OnChannelMode(%s,%s)\n", channel.c_str(), mode.c_str() );
126 bool OnUserModeInChannel ( const string
& src
, const string
& channel
, const string
& user
, const string
& mode
)
128 //printf ( "OnUserModeInChannel(%s,%s%s,%s)\n", src.c_str(), channel.c_str(), user.c_str(), mode.c_str() );
131 bool OnMode ( const string
& user
, const string
& mode
)
133 //printf ( "OnMode(%s,%s)\n", user.c_str(), mode.c_str() );
136 bool OnChannelUsers ( const string
& channel
, const vector
<string
>& users
)
138 printf ( "[%s has %i users]: ", channel
.c_str(), users
.size() );
139 for ( int i
= 0; i
< users
.size(); i
++ )
143 printf ( "%s", users
[i
].c_str() );
150 int main ( int argc
, char** argv
)
152 srand ( time(NULL
) );
153 ImportList ( tech
, "tech.txt" );
154 ImportList ( stru
, "stru.txt" );
155 ImportList ( dev
, "dev.txt" );
156 ImportList ( period
, "period.txt" );
157 ImportList ( module
, "module.txt" );
159 printf ( "initializing IRCClient debugging\n" );
160 IRCClient::SetDebug ( true );
161 printf ( "calling suStartup()\n" );
163 printf ( "creating IRCClient object\n" );
165 printf ( "connecting to freenode\n" );
166 if ( !irc
.Connect ( "212.204.214.114" ) ) // irc.freenode.net
168 printf ( "couldn't connect to server\n" );
171 printf ( "sending user command\n" );
172 if ( !irc
.User ( "ArchBlackmann", "", "irc.freenode.net", "Arch Blackmann" ) )
174 printf ( "USER command failed\n" );
177 printf ( "sending nick\n" );
178 if ( !irc
.Nick ( "ArchBlackmann" ) )
180 printf ( "NICK command failed\n" );
183 printf ( "setting mode\n" );
184 if ( !irc
.Mode ( "+i" ) )
186 printf ( "MODE command failed\n" );
189 printf ( "joining #ReactOS\n" );
190 if ( !irc
.Join ( "#ReactOS" ) )
192 printf ( "JOIN command failed\n" );
195 printf ( "entering irc client processor\n" );
196 irc
.Run ( false ); // do the processing in this thread...