⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 5cht.cgi

📁 自己原创的五子棋沙龙游戏
💻 CGI
📖 第 1 页 / 共 2 页
字号:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
&readparse;
($min,$hour,$day,$mon)=(localtime(time))[1,2,3,4];

#####setting####
$path="http://192.168.3.159/5";
$thisfile="$path/5cht.cgi";
$user_file="5user_file/$cgi{'room'}.log";
$user_list_file="5user_lists/5players.log";
$his_file="5user_lists/hist.log";
$his_path="5his_file";
$img_path="$path/5imgs";
$title="五子沙龙";
################
@lists=();@entries=();
open(file,"<$user_list_file")||die"不能打开文件\n";
@lists=<file>;
close file;

if ($cgi{'mu'} eq "hall"){&hall}
if ($cgi{'mu'} eq "new"){&new}

if (-e "$user_file"){
open(file,"<$user_file")||die"不能打开文件\n";
@entries=<file>;
close file;
$timer= (-M "$user_file")*60*24;
$timer=15-int($timer);
}else{$timer=0;}

if ($cgi{'mu'} eq "join"){&join}
if ($cgi{'mu'} eq "play"){&play}
if ($cgi{'mu'} eq "put"){&put}
if ($cgi{'mu'} eq "wmaps"){&print_maps_web}
if ($cgi{'mu'} eq "exit"){&ready_close_room}
if ($cgi{'mu'} eq "close_room"){&close_room}
if ($cgi{'mu'} eq "his"){&his}
if ($cgi{'mu'} eq "joinhis"){&joinhis}
if ($cgi{'mu'} eq "hisplay"){&hisplay}
exit;

sub his{
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</head><body><table border=1 width="100%"><tr bgcolor="#b0c4de"><td>***五子沙龙对战纪录·点击察看(完善中)***</td></tr>

eof
open(file,"<$his_file")||die"不能打开文件\n";
@lists=<file>;
close file;
foreach $line(@lists){@each_his=split(/&&/,$line);
print "<tr><td><a href=$thisfile?mu=joinhis&name=$cgi{'name'}&room=$each_his[0]&hisroom=$each_his[0]$each_his[3]-$each_his[4]-$each_his[5]-$each_his[6]>$each_his[0] & $each_his[1]</a> ($each_his[3]月$each_his[4]日 $each_his[5]:$each_his[6])</td></tr>";
}
print <<eof;
</table><form action="$thisfile" method="POST">
<input type=hidden name=mu value=hall>
<input type=hidden name=name value=$cgi{'name'}>
<input type=submit value=返回大厅></form></body></html>
eof
}
sub hall{
$bai=0;$playing=0;
foreach $line(@lists){@each_room=split(/&&/,$line);
$target=($each_room[1] eq "")?"所有人":$each_room[1];
if (-M "5user_file/$each_room[0].log" > 15/24/60){
if ($each_room[2] ne "ready"){
open(file,">>$his_file")||die"不能打开文件\n";
print file"$line";
close file;
open(file,"<5user_file/$each_room[0].log")||die"不能打开文件\n";
@his_data=<file>;
close file;
open(file,">$his_path/$each_room[0]$each_room[3]-$each_room[4]-$each_room[5]-$each_room[6].log")||die"不能打开文件\n";
foreach $his_line(@his_data){print file"$his_line";}
close file;
unlink("5user_file/$each_room[0].log")}}else {
push (@re_list,"$line");
if ($each_room[2] eq "ready"){
 if (($each_room[1] eq $cgi{'name'}) || ($each_room[1] eq "") || ($each_room[0] eq $cgi{'name'}))
  {$bai++;push (@ready,"<a href=$thisfile?mu=join&name=$cgi{'name'}&room=$each_room[0]>$each_room[0]向$target宣战</a>($each_room[5]:$each_room[6])<br>")}
}else{$playing++;push (@ing,"<a href=$thisfile?mu=join&name=$cgi{'name'}&room=$each_room[0]>$each_room[0] & $each_room[1]</a>($each_room[5]:$each_room[6])<br>")}}
}
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<SCRIPT Language="JavaScript1.2">
<!--
function reload(mode){document.f.mu.value=mode;document.f.submit();}
// -->
</SCRIPT>
</head>
<body><table border=1><tr bgcolor="#b0c4de"><td colspan="1">***欢迎来到五子沙龙***</td><td align="right" colspan="2">-$cgi{'name'}-</td></tr>
<tr bgcolor="#66cdaa"><td colspan="3"><center>【说明】</center>
<li>擂台摆好后<b>15分钟内</b>没有人应战将会被<b>拆除;</b>
<li>一个用户名限制摆<b>一个</b>擂台,但作为<b>打擂者</b>可以同时打<b>多个</b>擂台.
</td></tr>
<tr><td colspan="3" align="center"><form name="f" action="$thisfile" method="POST">
<input type="hidden" name=mu value=new>
<input type="hidden" name=name value=$cgi{'name'}>
<input type="hidden" name=room value=$cgi{'name'}>
<input type="submit" value=摆擂台><input type=checkbox name=check value=1>指名:<input type=text name=target value="" size=10><a href='javaScript:reload("hall");'>  刷新</A>
</form><a href='javaScript:reload("his");'>对战纪录</a></td></tr>
<tr><th>正在摆擂者:$bai人(点击应战)</th><th>正在热战中:$playing组(点击察看)</th></tr><tr><td valign=top>
eof
foreach $line(@ready){print "$line";}
print "</td><td valign=top>";
foreach $line(@ing){print "$line";}
print "</td></tr></table></body></html>";

open(file,">$user_list_file")||die"不能打开文件\n";
foreach $line(@re_list){print file"$line";}
close file;
exit;
}
sub ready_close_room{
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</head><body>
<table border="0" width="100%"><tr bgcolor="#b0c4de"><th>注意!是否真的拆除???</th></tr><tr><td>如果现在有人正在或者试图向你挑战,他将被强行赶出.</td></tr>
<tr><td><form action="$thisfile" method="POST">
<input type=hidden name=mu value=hall>
<input type=hidden name=name value=$cgi{'name'}>
<input type=submit value=返回大厅></form>
</td></tr><tr><td><form action="$thisfile" method="POST">
<input type=hidden name=mu value=close_room>
<input type=hidden name=name value=$cgi{'name'}>
<input type=submit value=拆除擂台></form>
</td></tr></table>
</body></html>
eof
exit;
}
sub close_room{
@re_list=();
unlink("5user_file/$cgi{'name'}.log");
foreach $line(@lists){@each_room=split(/&&/,$line);push (@re_list,"$line") if ($each_room[0] ne $cgi{'name'});}
open(file,">$user_list_file")||die"不能打开文件\n";
foreach $line(@re_list){print file"$line";}
close file;
print <<eof;
<html><head><title>$title</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
</head><body>
<table border="0" width="100%"><tr bgcolor="#b0c4de"><th>拆除完毕.</th></tr>
<tr><td><form action="$thisfile" method="POST">
<input type=hidden name=mu value=hall>
<input type=hidden name=name value=$cgi{'name'}>
<input type=submit value=返回大厅></form>
</td></tr></table>
</body></html>
eof
exit;
}
sub new{
foreach $line(@lists){@each_room=split(/&&/,$line);if ($cgi{'name'} eq $each_room[0]){&err_find_room}}
$cgi{'target'}="" if ($cgi{'check'} ne "1");
open(file,">>$user_list_file")||die"不能打开文件\n";
print file"$cgi{'name'}&&$cgi{'target'}&&ready&&$mon&&$day&&$hour&&$min&&\n";
close file;

open(file,">$user_file")||die"不能打开文件\n";
$a[0]="$cgi{'name'}&&";
$a[1]="&&";
foreach $line(@a){print file"$line\n";}
close file;
&print_frame;
}

sub print_frame{
print <<eof;
<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"><title>$title</title></head>
<FRAMESET COLS="310,*">
  <FRAME SRC="$thisfile?mu=wmaps&room=$cgi{'room'}&name=$cgi{'name'}" NAME="map_frm" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no">
  <FRAME SRC="$thisfile?mu=play&room=$cgi{'room'}&name=$cgi{'name'}" NAME="5msg_frm" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="auto">
</FRAMESET>
</html>
eof
exit;}
sub err_find_room{
print <<eof;
<html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"><title>$title</title></head>
<body><table border="0" width="100%"><tr bgcolor="#b0c4de"><th>错误!</th></tr><tr><td>如想新摆擂台,必须<b>拆除</b>现有擂台.
<form action="$thisfile" method="POST">
<input type=hidden name=mu value=hall>
<input type=hidden name=name value=$cgi{'name'}>
<input type=submit value=返回大厅></form>
<form action="$thisfile" method="POST">
<input type=hidden name=mu value=join>
<input type=hidden name=name value=$cgi{'name'}>
<input type=hidden name=room value=$cgi{'name'}>
<input type=submit value=返回游戏></form>
<form action="$thisfile" method="POST">
<input type=hidden name=mu value=exit>
<input type=hidden name=name value=$cgi{'name'}>
<input type=submit value=拆除擂台></form>
</td></tr></table>
</body></html>
eof
exit;
}
sub print_maps_web{
if ($cgi{'hismu'} ne "hisplay"){$cgi{'hismu'}="put"}
print <<eof;
<HTML><HEAD>
 <META content="text/html; charset=gb2312" http-equiv=Content-Type>
<TITLE>yy5</TITLE>
<SCRIPT Language="JavaScript1.2">
<!--
iu=1;nni="";inn="";
function chage(){
nnn=nni;tys=inn;
nni=window.document.maps.nn.value;
inn=window.document.maps.tc.value;
if (nnn != ""){
if (iu/2 == Math.ceil(iu/2)){
document.images[nnn].src=tys;
}else{if (nnn == nni){document.images[nnn].src=mapImg.src;}else{document.images[nnn].src=tys;}}
iu++;}thetimeout=setTimeout("chage();",500);}
mapImg=new Image(19,19);mapImg.src="$img_path/back.gif";
overImg=new Image(19,19);overImg.src="$img_path/over.gif";
xxImg=new Image(19,19);xxImg.src="$img_path/xx.gif";
yyImg=new Image(19,19);yyImg.src="$img_path/yy.gif";
function over(a){document.maps.puthere.value=a;if(document.images[a].src == mapImg.src){document.images[a].src=overImg.src;}}
function out(a){if(document.images[a].src == overImg.src){document.images[a].src=mapImg.src;}}
function putdown(a){document.maps.puthere.value=a;document.maps.submit();}
Line = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"); 
document.write('<table border="0" cellspacing="0" cellpadding="0"><tr><td><FORM name="maps" action="$thisfile" target="5msg_frm" method="POST"><INPUT TYPE="hidden" VALUE="$cgi{'hismu'}" NAME="mu"><INPUT TYPE="hidden" VALUE="$cgi{'hisroom'}" NAME="hisroom"><input type="hidden" name=nn value=""><input type="hidden" name=tc value=""><INPUT TYPE="hidden" VALUE="" NAME="puthere" onClick="document.maps.submit()"><INPUT TYPE="hidden" VALUE="$cgi{'room'}" NAME="room"><INPUT TYPE="hidden" VALUE="$cgi{'name'}" NAME="name"></FORM></td>');
for (h=0; h<15; h++){document.write("<td align='center'bgcolor='#b0c4de'>",Line[h],"</td>");}
document.write("</tr>");
for (y=1; y<16; y++){
document.write("<tr valign='middle'><td bgcolor='#66cdaa'>",y,"</td>");
 for (x=0; x<15; x++){i=Line[x]+y;v='"';
   document.write("<td><a href='JavaScript://' onClick='putdown(",v,i,v,")'; onMouseOver='over(",v,i,v,")'; onMouseOut='out(",v,i,v,")'><img src=$img_path/back.gif name=",i," border=0 width=19 hight=19 alt=",i,"></a>");
  }
document.write('</tr>');
}
document.write('</table>');document.close;
// -->
</SCRIPT>
</HEAD>
<BODY bgColor="white" SCROLL="NO" onLoad="chage();">
</BODY></HTML>
eof
}

sub join{
@joiner=@entries;@cHost=split(/&&/,$joiner[0]);@dHost=split(/&&/,$joiner[1]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -