Guest User

Untitled

a guest
Aug 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.31 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #################################
  3. #4x4 Evolution Game UDP service #
  4. #Version v2.0    April, 15 2012 #
  5. #Author: sponji@mindboggle.us   #
  6. #################################
  7. use warnings;
  8. use strict;
  9. use IO::Socket;
  10. use constant DATAGRAM_MAXLEN => 128;
  11. my $cnt;
  12. $|=1;
  13.  
  14. my $socket = IO::Socket::INET->new(LocalPort => '1234', Proto => 'udp')
  15.     or die "Cound't open listening socket: $@\n";
  16.  
  17. while (my $remote_address = recv($socket, my $message = "", DATAGRAM_MAXLEN, 0)) {
  18.     return unless defined $remote_address;
  19.     #my $count = `lsof -Pnl +M -i4 | grep 6667 | grep ircd | wc -l`; #For Linux IRCd user count.
  20.     my $count = 444;
  21.     $count = &dec2hex($count);
  22.     my ($peer_port,$peer_addr) = unpack_sockaddr_in($remote_address);
  23.     my $human_addr = inet_ntoa($peer_addr);
  24.     my $hexip = unpack "H*", inet_aton("$human_addr");
  25.     my $hexport = unpack "H*", inet_aton("$peer_port");
  26.     $hexport =~ s/0000//;
  27.     $message =~ s/"//;
  28.     $message =~ s/(.*?)#//;
  29.     $message  =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
  30.     $hexip .= $hexport;
  31.     my $complete = '23' . $message . $hexip . '0042' . '0000000' . $count;
  32.     $complete =~ s/([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  33.     send( $socket, $complete, 0, $remote_address );
  34. }
  35.  
  36. sub dec2hex($) { return sprintf("%lx", $_[0]) }
Add Comment
Please, Sign In to add comment