ok, this is kinda long, and very sloppy, i dug it up from a long time ago, alot of the code is just plain wrong and redundant, but i want the players to be able to communicate with eachother, so here goes:
#!/usr/bin/perl
use strict;
use threads;
use IO::Socket::INET;
$| ++;
my $listener = IO::Socket::INET->new
(
LocalPort => 1337,
Listen => 5,
Reuse => 1
) || die "Cannot create socket\n";
warn "server up and ready for connections...... \n";
our $hold;
our $client;
our $m = 2;
my $client_num = 0;
while (1){
our $client = $listener->accept;
threads->create(\&start_thread, $client, ++ $client_n
+um);
}
sub start_thread{
my @grab;
our $st = 100;
our $hp = 100;
my ($client, $client_num) = @_;
print "thread created for client $client_num\n";
push @grab, $client;
print @grab;
print $client "\t\t\t****** ****** ********\n\r";
print $client "\t\t\t* * * * *\n\r";
print $client "\t\t\t* * * * *\n\r";
print $client "\t\t\t****** * * * *****\n\r";
print $client "\t\t\t* * * * *\n\r";
print $client "\t\t\t* # ****** # ******** #\n\r";
print $client "Welcome to the POG Test server!\n\r";
print $client "you will be know as player $client_num\n\r";
print $client "type : HELP for list of commands\n\r";
&begin;
return;
}
sub begin{
while(our $line = <$client>){
print $line;
if($line =~ /slp/i){&slp;}
if($line =~ /med/i){&med;}
if($line =~ /kik/i){&kik;}
if($line =~ /help/i){&help;}
if($line =~ /wke/i){&wke;}
if($line =~ /hp/i){&hp;}
if($line =~ /pun/i){&pun;}
if($line =~ /st/i){&st;}
}
}
sub hp{
if (our $m eq 1){
print $client "you are sleeping/meditating.\n\r";
&begin;
}
print $client "your health is: ";
print $client our $hp;
print $client "\n\r";
}
sub st{
if (our $m eq 1){
print $client "you are sleeping/meditating.\n\r";
&begin;
}
print $client "you stamina is: ";
print $client our $st;
print $client "\n\r";
}
sub slp{
if (our $m eq 1){
print $client "you are already sleeping/meditatin
+g.\n\r";
&begin;
}
our $time = time;
our $m = 1;
print $client "you fall into a deep slumber.....\n\r";
&begin;
}
sub med{
if (our $m eq 1){
print $client "you are already sleeping/medita
+ting.\n\r";
&begin;
}
our $time = time;
our $m = 1;
print $client "you sit down cross-legged on the floor and pres
+s your palms together, you slip into a deep stage of meditation\n\r";
&begin;
}
sub wke{
if (our $m eq 2){
print $client "you are already awake\n\r";
&begin;
}
our $time2 = time;
our $check = our $time2 - our $time;
our $hp = $hp + $check;
our $m = 2;
print $client "you wake up from your deep sleep, feeling very
+refreshed!\n\r";
&begin;
}
sub kik{
if (our $m eq 1){
print $client "you are sleeping/meditating.\n\
+r";
&begin;
}
print $client "You kick yourself in the shin, and loose 10 HP\
+n\r";
our $hp = $hp - 10;
if(our $hp < 1)
{
print "$client_num has died......\n\r";
print $client "$client_num has died......\n\r";
&start_thread;
}
&begin;
}
sub pun{
if (our $m eq 1){
print $client "you are sleeping/meditating.\n\r";
&begin;
}
print $client "You punch yourself in the face, and loo
+se 10 HP\n\r";
our $hp = $hp - 10;
if(our $hp < 1){
print "$client_num has died......\n\r";
print $client "$client_num has died......\n\r";
&start_thread;
}
&begin;
}
sub help{
print $client "***************************************
+*****************************************\n\r";
print $client "MED = Allows you to begin meditating, which re
+gains stamina *\n\r";
print $client "SLP = Allows you to sleep, which regains healt
+h *\n\r";
print $client "WKE = Wakes you up from sleeping or meditation
+ *\n\r";
print $client "KIK = Preforms a kick at the first liv
+ing thing you see *\n\r";
print $client "HELP = brings you back to this menu
+ *\n\r";
print $client "HP = prints your Health
+ *\n\r";
print $client "PUN = preforms a punch at the first living thi
+ng you see *\n\r";
print $client "ST = Prints your stamina
+ *\n\r";
print $client "***********************************************
+*********************************\n\r";
&begin;
}
| [reply] [d/l] |