All pastes #715454 Raw Edit

Miscellany

public text v1 · immutable
#715454 ·published 2007-09-26 10:05 UTC
rendered paste body
sub game_loop {
        our @players;
        my $gameevent;
        my $rp;
        my $senderid = "nobody";
        my $host = shift || 'chaos';
        my $port = shift || 160;
        our  $sock = new IO::Socket::INET(

                   PeerAddr => $host,
                   PeerPort => $port,
                   Proto    => 'tcp');
        $sock or die "no socket :$!";

        $sock->autoflush(1);


        while( !$ProneServer::STOP ) {
                while ($gameevent = $ProneServer::GameQueue->dequeue_nb) {
                                print STDERR "Popped $gameevent off the queue\n";
                                $gameevent =~ /\[(.*) -.*\]/;
                                #I may have to change senderid for $local_player's id
                                $senderid = $1;

                                #TYPE:TARGET:WHO:WHAT ARGS      
                                if( $gameevent  =~ /REQUEST:server:(.*):LISTPLAYERS/ ){
                                        print STDERR "PLAYER LIST REQUEST FROM $1\n";
                                        my $who = $1 ;
                                        foreach my $p ( @players ) {
                                                if( $p->name =~ /$who/ ) {
                                                        $senderid = $p->id;
                                                }
                                        }
                                        foreach my $p ( @players ) {
                                                 #a accorder avec 'chat' plus bas.
                                                 my $paquet  = "SENDTO:";
                                                    $paquet .= "JOIN:";
                                                    $paquet .= "$senderid:";
                                                    $paquet .= $p->name ;
                                                    $paquet .= ":";
                                                    $paquet .= "JOINGAME";
                                                    if( $p->id != $senderid ) {
                                                        print $sock $paquet ."\n";
                                                   }


                                        }
                                }

                                if( $gameevent =~ /INFO:server:(.*):JOIN/  ) {
                                                              if( $gameevent =~ /CHAT:everyone:(.*):(.*)/  ) { ;
                                        #for now settings are fixed, exept name
                                        #later the login function in the client will update other informations
                                        my $who = $1 ;
                                        my $words = $2;
                                        foreach my $p ( @players ) {
                                                        my $paquet  = "SENDTO:";
                                                        $paquet .= "CHAT:";
                                                        $paquet .= $p->id;
                                                        $paquet .= ":";
                                                        $paquet .= $who .":";
                                                        $paquet .= $words;
                                                        print "**:$paquet \n";
                                                        print $sock $paquet ."\n";
                                                }
                                }

                        }

#               print "users :\n";
#               print STDERR Dumper ( @players );
        }