Last active
June 1, 2018 05:25
-
-
Save userid/e94b3b217ca77d3732add280bf711afa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| # | |
| use 5.010; | |
| use strict; | |
| use AnyEvent::Socket; | |
| use AnyEvent::Handle; | |
| use EV; | |
| $| = 1; | |
| sub pack_msg{ | |
| my $msg = shift; | |
| pack "iia*a*a", length($msg)+9, length($msg)+9, "\xb1\x02\x0\x0", $msg, "\0"; | |
| } | |
| my $roomid = shift || 3484; | |
| my $handle; | |
| $handle = new AnyEvent::Handle ( | |
| connect =>["openbarrage.douyutv.com", 8601], | |
| on_connect => sub{ | |
| my $hd = shift; | |
| say "connected"; | |
| my $buf = sprintf("type@=loginreq/username@%s=/password@=%s/roomid@=%s/ct@=2/", | |
| "abc", "123", 3484); | |
| $hd->push_write(pack_msg $buf); | |
| #syswrite $hd->fh, $buf; | |
| }, | |
| on_read => sub{ | |
| my $hd = shift; | |
| $hd->push_read(chunk =>12, sub{ | |
| my $len = unpack("i", @_[1]); | |
| my ($hd) = @_; | |
| my $body = $hd->rbuf; | |
| $hd->rbuf = ''; | |
| if ($body=~/^type@=loginres/){ | |
| $hd->push_write(pack_msg sprintf("type@=joingroup/rid@=%s/gid@=%s/", $roomid, "-9999")); | |
| }elsif($body=~/type@=chatmsg(.+)$/){ | |
| my $msg = $1; | |
| #say $msg; | |
| if ($msg=~m%/nn\@=(.+?)/.*txt\@=(.+?)/cid\@% ){ | |
| my ($nick,$text) = ($1,$2); | |
| $text =~s/\@A/@/g; | |
| say "$nick said:\t$text"; | |
| } | |
| }elsif($body=~/type@=synexp/){ | |
| $hd->push_write(pack_msg sprintf("type@=keeplive/tick@=%ld/", time())); | |
| } | |
| }); | |
| }, | |
| ); | |
| EV::loop; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment