Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #################################
- #4x4 Evolution Game UDP service #
- #Version v2.0 April, 15 2012 #
- #Author: sponji@mindboggle.us #
- #################################
- use warnings;
- use strict;
- use IO::Socket;
- use constant DATAGRAM_MAXLEN => 128;
- my $cnt;
- $|=1;
- my $socket = IO::Socket::INET->new(LocalPort => '1234', Proto => 'udp')
- or die "Cound't open listening socket: $@\n";
- while (my $remote_address = recv($socket, my $message = "", DATAGRAM_MAXLEN, 0)) {
- return unless defined $remote_address;
- #my $count = `lsof -Pnl +M -i4 | grep 6667 | grep ircd | wc -l`; #For Linux IRCd user count.
- my $count = 444;
- $count = &dec2hex($count);
- my ($peer_port,$peer_addr) = unpack_sockaddr_in($remote_address);
- my $human_addr = inet_ntoa($peer_addr);
- my $hexip = unpack "H*", inet_aton("$human_addr");
- my $hexport = unpack "H*", inet_aton("$peer_port");
- $hexport =~ s/0000//;
- $message =~ s/"//;
- $message =~ s/(.*?)#//;
- $message =~ s/(.|\n)/sprintf("%02lx", ord $1)/eg;
- $hexip .= $hexport;
- my $complete = '23' . $message . $hexip . '0042' . '0000000' . $count;
- $complete =~ s/([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
- send( $socket, $complete, 0, $remote_address );
- }
- sub dec2hex($) { return sprintf("%lx", $_[0]) }
Add Comment
Please, Sign In to add comment