Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- #use strict;
- use IO::Socket::INET;
- use IO::Select
- $| = 1;
- $filename = "/var/www/serverlist.php";
- @filelist = ($filename,"/var/www/database.txt");
- unlink @filelist;
- $socket = new IO::Socket::INET (
- LocalHost => '0.0.0.0',
- LocalPort => '666',
- Proto => 'tcp',
- Listen => 100,
- Reuse => 1
- ) or die "ERROR in Socket Creation : $!\n";
- $select = IO::Select->new($socket) or die "IO::Select $!";
- $SIG{PIPE} = sub
- {
- if(defined $current_client) {
- $select->remove($current_client);
- $current_client->close;
- }
- };
- my %nickhash = ();
- while(1) {
- @ready_clients = $select->can_read(0);
- foreach my $fh (@ready_clients) {
- print $fh "";
- if($fh == $socket) {
- my $new = $socket->accept();
- $select->add($new);
- } else {
- my $data;
- $fh->recv($data, 1024 * 1024);
- my $unique = ($fh->peerhost() || ""). ":" . ($fh->peerport() || "");
- my $ip = $fh->peerhost();
- if($data && $data =~ /add:=/) {
- @servername = split(/\|\|/, $data);
- $data =~ s/add:=//gi;
- $data =~ s/\{IP\}/$ip/gi;
- open CHK_ARRAY, $filename;
- my @chk_array = <CHK_ARRAY>;
- close CHK_ARRAY;
- if (grep(/$servername[0] . "\|\|"/,@chk_array) eq 0) {
- open (RP2DATA, '>>',$filename);
- print RP2DATA "\n" . $data;
- close (RP2DATA);
- $fh->send("Server Added Successfully! " . $ip . "\n");
- } else {
- $fh->send("Error: Server Already Exists! " . $ip. "\n");
- }
- }
- elsif($data && $data =~ /remove:=/) {
- $data =~ s/remove:=//gi;
- $arg1 = $data;
- chomp $arg1;
- open IN, '<', $filename;
- my @contents = <IN>;
- close IN;
- @contents = grep !/$arg1/, @contents;
- open OUT, '>', $filename;
- @constents = map { chomp $_; $_; } @constents;
- print OUT @contents;
- close OUT;
- $fh->send("Server \"$arg1\" Removed Successfully! " . $ip. "\n");
- }
- elsif($data && $data =~ /update:=/) {
- # Removing
- $data =~ s/update:=//gi;
- @servername = split(/\|\|/, $data);
- $arg1 = $servername[0];
- chomp $arg1;
- open IN, '<', $filename;
- my @contents = <IN>;
- close IN;
- @contents = grep !/$arg1/, @contents;
- open OUT, '>', $filename;
- @constents = map { chomp $_; $_; } @constents;
- print OUT @contents;
- close OUT;
- # Adding
- $data =~ s/\{IP\}/$ip/gi;
- open CHK_ARRAY, $filename;
- my @chk_array = <CHK_ARRAY>;
- close CHK_ARRAY;
- if (grep(/$servername[0] . "\|\|"/,@chk_array) eq 0) {
- open (RP2DATA, '>>',$filename);
- print RP2DATA "\n" . $data;
- @servername = split(/\|\|/, $data);
- close (RP2DATA);
- $fh->send("Server Updated Successfully! " . $ip . "\n");
- } else {
- $fh->send("Error: Server Already Exists! " . $ip. "\n");
- }
- } elsif ($data && $data =~ /ls/) {
- $fh->send("Current Servers Online " . $ip. ":\n");
- open (MYFILE, $filename);
- while (<MYFILE>) {
- chomp;
- $fh->send("$_ \n");
- }
- $fh->send("End Of List \n");
- close (MYFILE);
- } elsif ($data && $data =~ /format/) {
- $fh->send("{SERVNAME}||{MAP}||{TIME}||{PLAYERS}||{NOTHING}||{PORT}||" . $ip . "\n");
- } elsif ($data && $data =~ /help/) {
- $fh->send("Roleplay 2 Server API:\n");
- $fh->send("\*\"add:=\" -- This allows a server to be added to the network\n");
- $fh->send("\*\"remove:=\" -- This allows a server to be removed to the network\n");
- $fh->send("\*\"update:=\" -- This allows a server to be updated on the network\n");
- $fh->send("\*\"ls\" -- This lists a servers on the network\n");
- $fh->send("\*\"help\" -- How did you get to this point\?\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement