#!/usr/local/bin/perl #--------------------------------------# # # # # # w c h a t . c g i - 1.00 # # # # powered by ssw-1.00 # # # # # #--------------------------------------# use ssw; use cgis; # プロパティ # ----------------------------------------------------------------------- #チャットのタイトル $Title="ホワイトチャット"; # 最大保持行数 $MaxLines=30; # 戻り先のURL $URLReturn="index.shtml"; # 表示色の名前とカラーコード @ColorName=("黒", "茶", "オリーブ","青", "紫", "緑" ); @ColorCode=("#000000","#800000","#808000","#000080","#800080","#008000"); # クッキー賞味期限(日) $CExpires =120; # ファイルロック 使用=1,不使用=0 $EnableLock=0; # ログのパス $LogFile="chat.log"; # 人工無脳のプロパティ # 名前 $ssw::Name = "まな"; # 辞書のパス $ssw::MainDicPath = "mana_m.txt"; $ssw::RenderDicPath = "mana_r.txt"; $ssw::GreenDicPath = "mana_g.txt"; # 体調が変化する周期(日) $ssw::VCondInterv = 10; # すべてのユーザに教育を(許可する=1 許可しない=0) $ssw::IsAuthorized = 1; # deck -UCPAE $ssw::Deck = "UUUUC---"; # 発言色 $MunoColor = 0; # ここまで #-------------------------------------------------------------------------- $URLThis="wchat.cgi"; %EventList=("OnStart" =>1, "OnExecute" =>1, "OnLogout" =>1, "OnEducateExecute"=>1, ); $Color=0; @ChatUpkeep=("::Name","::Color","::Next","::Text"); @MunoUpkeep=("ssw::UName","ssw::Queue","ssw::Reserved","ssw::Message", "ssw::PrevInput","ssw::PrevOutput","ssw::PrevTheme", "ssw::CurrentTheme"); @EduUpkeep =("::Key","::Theme","::Command","::Hearsay","::Opinion", "ssw::Teacher","ssw::Value"); #------------- # M A I N cgis::get_param((@ChatUpkeep,@MunoUpkeep,@EduUpkeep)); if( exists $EventList{$Next} ){ &{$Next}; exit 0; } &OnStart; exit 1; #------------------------- # E V E N T # sub OnStart() { %cookie=cgis::get_cookie($URLThis); $ssw::UName=$Name =$cookie{"name"} || ""; $Color=$cookie{"color"} || "0"; ssw::login; &FormShow; exit 0; } sub OnLogout() { ssw::logout; print "Location: $URLReturn\n\n"; exit 1; } sub OnExecute() { if($Name eq "") { print "Content-type: text/html\n\n"; print "

名前が空欄です

"; print "戻って入力を確認してください"; exit 0; } $ssw::UName=$Name; my $reply=ssw::reply($Text); #predispatch if($ssw::Message =~ /color=([0-9]+)/) {$MunoColor=$1;} my $line =&make_line($ssw::Name,cgis::enable_url $reply,$MunoColor); $line .=&make_line($Name, cgis::enable_url $Text ,$Color); &logwrite($line); #postdispatch my $msg=$ssw::Message; $ssw::Message=""; if ($msg eq 'logout') { &OnLogout; } elsif($msg eq 'educate') { &EducateFormShow; exit 1; } &FormShow; #process queue if($ssw::Queue ne "") { logwrite(&make_line( $ssw::Name, cgis::enable_url ssw::ProcessQueue, $MunoColor)) or &ShowBusy; } exit 1; } sub OnEducateExecute() { if(!$Key && $Command eq "execute") { print "Content-type: text/html\n\n"; print "

キーが空欄です

"; print "戻って入力を確認してください"; exit 0; } my ($msg,$line); if($Command eq "cancel") { ssw::EducateCancel; $msg="■ 教育をキャンセルしました ■"; } elsif($Command eq "banned") { ssw::EducateBanned; $msg="■ 教育を拒否しました ■< <"; } else { ssw::writedic($Key,$Theme,$Text,$ssw::Teacher,$ssw::Value,$Hearsay); ssw::EducateAccept; $msg="■ 教育を受け付けました ■" #*Opinionを受ける仕掛け } $line =&make_line($ssw::Name, cgis::enable_url ssw::reply(""),$MunoColor); $line .=&make_line(">",$msg,$Color); &logwrite($line); &FormShow; exit 1; } #----------------------------------------- # HTML出力器 # sub FormShow() { local *LOG; open(LOG,"$LogFile") or die"$LogFile not found"; my @log=; close LOG; my $color_table=""; for my $i (0..$#ColorName) { $color_table .="