1 / 11

Homework 01

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

ntoth
Download Presentation

Homework 01

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Homework 01 Perl programming

  2. 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

  3. 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 “絕招”

  4. 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)

  5. Hash example • In the beginning • use Digest::MD5 qw(md5_hex md5_base64); • use Encode; • use MIME::Base64; • binmode(*STDOUT, “:utf8”); #utf8 mode

  6. 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

  7. 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

  8. Reference • http://search.cpan.org/~fimm/POE-Component-IRC-2.9/IRC.pm • http://www.faqs.org/rfcs/rfc1459.html

  9. 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

  10. 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)"

  11. After parsing

More Related