📄 user.cgi
字号:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
&readparse;
($min,$hour,$day,$mon)=(localtime(time))[1,2,3,4];
#####setting####
$serverpath=".";
$cfg_file="$serverpath/5user_lists/config.log";
open(file,"<$cfg_file")||die"不能打开文件$cfg_file\n";
@config=<file>;
close file;
foreach $line(@config){
chop $line;@d=split(/=/,$line);
push (@cfg,"$d[1]");}
$path=$cfg[1];
$board_cgi=$cfg[2];
$user_cgi=$cfg[3];
$user_file="$cfg[4]/$cgi{'room'}.log";
$user_list_file=$cfg[5];
$his_file=$cfg[6];
$his_path=$cfg[7];
$img_path=$cfg[8];
$pro_name=$cgi{'name'};
$web_name=pack("h*",$pro_name);
$web_room=pack("h*",$cgi{'room'});
$title=$cfg[9];
################
@lists=();@entries=();
open(file,"<$user_list_file")||die"不能打开文件\n";
@lists=<file>;
close file;
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 "vsrobot"){$temp_name = $cgi{'name'};&create_robot_room;}
if ($cgi{'mu'} eq "join"){&join;&print_frame;}
if ($cgi{'mu'} eq "play"){&play}
if ($cgi{'mu'} eq "con"){&con}
if ($cgi{'mu'} eq "view"){&view}
if ($cgi{'mu'} eq "put"){&put}
if ($cgi{'mu'} eq "wmaps"){$viewhall="";$mode="play";&print_maps_web}
if ($cgi{'mu'} eq "joinhis"){&joinhis}
if ($cgi{'mu'} eq "hisplay"){&hisplay}
if ($cgi{'mu'} eq "hismaps"){$viewhall="his";$mode="hisplay";&print_maps_web}
exit;
sub create_robot_room{
$robot_name = "机器人_".int(rand(1)*1000);
$robot_name_pro = unpack("h*",$robot_name);
$cgi{'room'} = unpack("h*",$robot_name);
$user_file="$cfg[4]/$cgi{'room'}.log";
# $pro_name = $cgi{'name'};
# $web_name = pack("h*",$pro_name);
# $cgi{'puthere'} = "G8";
&new;
# &join;
# &put;
# $cgi{'name'} = $temp_name;
# $pro_name = $cgi{'name'};
# $web_name = pack("h*",$pro_name);
&print_frame;
}
sub new{
#foreach $line(@lists){
#@each_room=split(/&&/,$line);
#if ($web_name eq $each_room[0]){&create_robot_room;}
#}
open(file,">>$user_list_file")||die"不能打开文件\n";
print file"$robot_name&&$web_name&&ing&&$mon&&$day&&$hour&&$min&&\n";
close file;
open(file,">$user_file")||die"不能打开文件\n";
$a[0]="$web_name&&";
$a[1]="$robot_name&&G8!;";
$a[2]="$robot_name::";
$a[3]=":";
foreach $line(@a){print file"$line\n";}
close file;
}
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="$user_cgi" 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="$pro_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();">
<table border=0 bgcolor='#FFFFFF'cellspacing=0 cellpadding=0 width="100%">
<TR><TD><form name="r" action="$user_cgi" method="POST" target="5msg_frm">
<input type=hidden name=mu value=$mode>
<input type=hidden name=name value=$pro_name>
<input type=hidden name=room value=$cgi{'room'}>
<input type=hidden name=hisroom value=$cgi{'hisroom'}>
<input type=submit value=刷新></form></TD>
<TD><form action="$board_cgi" target="_top" method="POST">
<input type=hidden name=mu value=$viewhall>
<input type=hidden name=name value=$pro_name>
<input type=submit value=退出></form></TD>
</TR></TABLE>
</table>
</BODY></HTML>
eof
}
sub join{
@joiner=@entries;@cHost=split(/&&/,$joiner[0]);@dHost=split(/&&/,$joiner[1]);
if (($cHost[0] eq "") || ($dHost[0] eq "")){
if (($cHost[0] ne $web_name) && ($dHost[0] ne $web_name)){
if ($cHost[0] ne $web_room){$joiner[0]="$web_name&&$cHost[1]"} else {$joiner[1]="$web_name&&$cHost[1]"}
open(file,">$user_file")||die"不能打开文件\n";
foreach $line(@joiner){print file"$line";}
close file;
foreach $line(@lists){@each_er=split(/&&/,$line);
if ($each_er[0] eq $web_room){$each_er[1]=$web_name;$each_er[2]="ing";};
push (@re_each_er,"$each_er[0]&&$each_er[1]&&$each_er[2]&&$each_er[3]&&$each_er[4]&&$each_er[5]&&$each_er[6]&&\n");
}
open(file,">$user_list_file")||die"不能打开文件\n";
foreach $line(@re_each_er){print file"$line";}
close file;
}}}
sub print_frame{
print <<eof;
<html><head><META content="text/html; charset=gb2312" http-equiv=Content-Type><title>$title --- 擂主:$web_room</title></head>
<FRAMESET COLS="310,*">
<FRAME SRC="$user_cgi?mu=wmaps&room=$cgi{'room'}&name=$pro_name" NAME="map_frm" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no">
<FRAME SRC="$user_cgi?mu=play&room=$cgi{'room'}&name=$pro_name" NAME="5msg_frm" FRAMEBORDER="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="auto">
</FRAMESET>
</html>
eof
exit;}
##目的:返回$entries[1](最复杂的逻辑运算)
sub ru_{
$tt="zABCDEFGHIJKLMNO";$three=0;$four=0;$h_four=0;$five=0;@pr=();
foreach $st ('A'..'O'){ foreach $i (1..15){$uu=$st.$i;$ps{$uu}="e";}}
$old_tmp=$other_player;
chop($old_tmp);
@pois_tmp=split(/&&/,$old_tmp);
@po_tmp=split(/;/,$pois_tmp[1]);
foreach $line(@po_tmp){@po_ru_tmp=split(/!/,$line);$ps{$po_ru_tmp[0]}="others";}
@pois=split(/&&/,$chk_r);
@po=split(/;/,$pois[1]);
foreach $line(@po){@po_ru=split(/!/,$line);$ps{$po_ru[0]}=$po_ru[0];push (@pr,"$po_ru[0]");}
%turn=(1,"1,0,-1,0",2,"0,1,0,-1",3,"1,1,-1,-1",4,"1,-1,-1,1");
####对于每一个点
foreach $line(@pr){
###检测在周边4条线上有没有连接的点
foreach $i (1..4){
$thl=$line.$i;
next if ($mmm{$thl} eq "checked");
@fd=();@fdfour=();@find=();
$mar[$i]=1;$lin[$i]=1;
@l=split(/,/,$turn{$i});
$nx=substr($line,0,1);$county=substr($line,1);
$countx=index($tt,$nx);
$xx=substr($tt,$countx,1);
$yy=$county;
$count="$xx$yy";
$fin="";$iis=0;$ppp=0;$cut="";
while($fin ne "out"){$ppp++;
$countx+=$l[0];
$yy+=$l[1];
$xx=substr($tt,$countx,1);
$count="$xx$yy";$tl=$count.$i;
if (($ps{$count} eq "others") || ($ps{$count} eq "")){$fin="out";$find[0]=($find[0] eq "empty")?"empty":"";}
else {if ($ps{$count} eq "e"){$cut="ture";$find[0]="empty";$fin=($iis>0)?"out":"";$iis++;}
else {$mar[$i]++;$mmm{$tl}="checked";$find[0]="";$iis=0;if ($cut ne "ture"){$lin[$i]++;}}}
}
$nx=substr($line,0,1);$county=substr($line,1);
$countx=index($tt,$nx);
$xx=substr($tt,$countx,1);
$yy=$county;
$count="$xx$yy";
$fin="";$iiq=0;$cut="";
while($fin ne "out"){$ppp++;
$countx+=$l[2];
$yy+=$l[3];
$xx=substr($tt,$countx,1);
$count="$xx$yy";$tl=$count.$i;
if (($ps{$count} eq "others") || ($ps{$count} eq "") ){$fin="out";$find[1]=($find[1] eq "empty")?"empty":"";}
else {if ($ps{$count} eq "e"){$cut="ture";$find[1]="empty";$fin=($iiq>0)?"out":"";$iiq++;}
else {$mar[$i]++;$mmm{$tl}="checked";$find[1]="";$iiq=0;if ($cut ne "ture"){$lin[$i]++;}}}
}
$ppp++ if ($find[0] ne "empty");$ppp++ if ($find[1] ne "empty");
$fd[$i]="empty" if (($find[0] eq "empty") && ($find[1] eq "empty"));
$fdfour[$i]="empty" if (($find[0] eq "empty") || ($find[1] eq "empty"));
$ppp-=$mar[$i]+3;
$three++ if (($mar[$i] == 3) && ($ppp < 2) && ($fd[$i] eq "empty"));
$four++ if (($mar[$i] == 4) && ($ppp < 2) && ($fdfour[$i] eq "empty"));
$four++ if (($mar[$i] == 4) && ($ppp == 1) && ($fdfour[$i] ne "empty"));
$four++ if (($mar[$i] == 4) && ($ppp == 1) && ($fd[$i] ne "empty"));
$four++ if (($mar[$i] == 5) && ($ppp == 2) && ($lin[$i] == 3));
$h_four++ if (($mar[$i] == 4) && ($ppp == 0) && ($fd[$i] eq "empty"));
#$five++ if (($mar[$i] == 5) && ($ppp == 0));
$five++ if ($lin[$i] == 5);
#print "$mar[$i],$ppp,$lin[$i].";
}
}
$ru="";
$ru="三" if ($three == 1);
$ru="三三" if ($three >= 2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -