renamed source files back to .c
[cave9.git] / src / cave9-global.pl
blobb8946907c187167c42f607cf428758bc3e353706
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use IO::Socket;
6 my $port = 31559;
7 my $score_len = 16;
8 my $score_file = 'cave9-global.hi';
9 $|=1;
11 my $hiscore = eval { do $score_file } || "0";
12 print time.":hiscore:$hiscore\n";
14 my $sock = IO::Socket::INET->new(
15 LocalPort => $port,
16 Proto => "udp",
17 ) or die "Couldn't be a udp server on port $port : $@\n";
18 print time.":udp:".$sock->sockport."\n";
20 my $score;
21 while ($sock->recv($score, $score_len)) {
22 my($port, $addr) = sockaddr_in($sock->peername);
23 my $host = gethostbyaddr($addr, AF_INET);
24 if($score =~ /^\d+/) {
25 $score = $&;
26 if($& > $hiscore) {
27 $hiscore = $&;
28 print time.":$host:$score!\n";
29 open SCORE, ">$score_file"
30 or die "open $score_file: $!";
31 print SCORE $hiscore;
32 close SCORE;
33 } else {
34 print time.":$host:$score<$hiscore\n";
36 } else {
37 print time.":$host<$hiscore\n";
39 $sock->send($hiscore);
41 die "recv: $!";