110 likes | 124 Views
Homework 01. Perl programming. IRC bot detail. TA’s bot will maintain a list of members in the channel. ur bot will have 2 status: wait: wait TA’s bot to send FIGHT msg to u fight: in the process of fighting with another user Assume ur bot has energy 10 Can be change when practicing
E N D
Homework 01 Perl programming
IRC bot detail • TA’s bot will maintain a list of members in the channel. • ur bot will have 2 status: • wait: wait TA’s bot to send FIGHT msg to u • fight: in the process of fighting with another user • Assume ur bot has energy 10 • Can be change when practicing • If TA’s bot discover someone can fight with u • u will receive msg from TA’s bot: <@TABOT> MCBSD2: FIGHT MCBSD3 $Seed # $Seed is a random number provide by TA’s bot
IRC bot detail (cont.) • When ur bot receive FIGHT msg • attack ur opponent with “絕招” setting by yourself • < MCBSD2> MCBSD3: MCBSD2下賤地使出無腦的千年殺 • Ur bot should record what “絕招” ur opponet use • < MCBSD3> MCBSD2: MCBSD3科科地使出無敵的卍解 • So this time, u will know ur own “絕招” and ur opponent’s “絕招”
IRC bot detail (cont.) • Using md5_hex hash two “絕招” • Compare two hash string starting from left-most bit one by one (compare by hex) • if larger than ur opponent 5 times • U r the winner • < MCBSD2> WINNER • Go back to member list again (TA’s bot will do this) • else if smaller than ur opponent 5 times • U r the loser • < MCBSD2> LOSER • Kick by TA’s bot anyway (TA’s bot will do this)
Hash example • In the beginning • use Digest::MD5 qw(md5_hex md5_base64); • use Encode; • use MIME::Base64; • binmode(*STDOUT, “:utf8”); #utf8 mode
Hash example (cont.) • $myAttack = “MCBSD2下賤地使出無腦的千年殺”; • $oppAttack = “MCBSD3科科地使出無敵的卍解”; • my $myEncode = encode_base64($myAttack ^ $Seed); • my $myHash = md5_hex $myEncode • my $oppEncode = encode_base64($oppAttack ^ $Seed); • my $oppHash = md5_hex $oppEncode • @chars = split ‘', $xxxHash; #translate hash string to characters • Compare two ‘cahrs’ arrays by youself
Advices • Create a channel for self practice • Try to handle irc event and execute irc command in Perl • TA will announce and explain simple irc bot on BS2 CS-NetAdmin • TA will create a new channel for irc bot practice and let TA’s bot online next week • So don’t test ur program in #nctucsna
Reference • http://search.cpan.org/~fimm/POE-Component-IRC-2.9/IRC.pm • http://www.faqs.org/rfcs/rfc1459.html
Apache log analyzer • TA will provide a html webpage • <form method="POST" action="xxx.pl"> • <input type="text" name="file" size="80" value="http://www.cs.nctu.edu.tw/~mcchung/na/hw1/apacheLog"> • top 10: daily burning hour、user page popularity、file downloading popularity
Apache log • httpd-access.log • 140.113.235.48 - - [02/Mar/2010:13:14:23 +0800] "GET/~is86007/magicshop/ROCid.html HTTP/1.0" 304 - "-" "M> ozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; icafe8; .NET CLR 2.0.50727)"