--- /dev/null
+<?php
+/*
+ * Ajax Chat for TRPG ver.1.3
+ * (c)2007 Cake All rights reserved.
+ * Mail : cake_67@users.sourceforge.jp
+ * Home : http://trpgtools-onweb.sourceforge.jp/
+ */
+
+/* メンバーチェッカー */
+function member_checker($name= '', $hash= '', $mode= '', $now_member, $getdata_off, $lockfile2) {
+
+ // ファイルロック
+ $lfp2 = fopen($lockfile2,"w");\r
+ stream_set_write_buffer($lfp2, 0);
+ flock($lfp2,LOCK_EX);
+
+ // 初期化
+ $member_data = array();
+ $member = array();
+ $write = array();
+
+ // 既存ファイル内容の格納
+ $member_data[] = file($now_member);
+
+ $flag = 0;
+ if ($member_data[0]) {
+ foreach ($member_data[0] as $k => $v) {
+ $member[$k] = explode("<>", $v);
+
+ // ログアウト:削除
+ if ($mode == "out" && $member[$k][0] == $name && $member[$k][1] == $hash) {
+ $flag = 1;
+ // 名前とパスが一致すれば在室時間更新
+ } elseif ($member[$k][0] == $name && $member[$k][1] == $hash) {
+ $member[$k][2] = time();
+ // コメント時、発言時間更新
+ if ($mode=="com") {
+ $member[$k][3] = time();
+ }
+
+ $write[] = implode("<>",$member[$k]);
+
+ $flag = 1;
+ // ROM更新時間($getdata_off)x10(秒)以内の名前のみ保存:それ以上経過した名前は削除
+ } elseif ((time() - $member[$k][2]) < ($getdata_off * 10)) {
+ $write[] = $v;
+
+ }
+ }
+ }
+ // ログに名前追加
+ if ($mode != "out" && $flag == 0 && $name) {
+ $write[] = $name."<>".$hash."<>".time()."<>".time()."<>\n";
+ }
+
+ // ログファイル更新
+ $fpm = @fopen($now_member, "w+") or die("ログファイルを開けません2");
+ //$bom = "\xef\xbb\xbf";
+ //fwrite($fpm, $bom);
+
+ foreach($write as $k => $v) {
+ fwrite($fpm, $v);
+ }
+ fclose($fpm);
+
+ // ロック解除
+ fflush($lfp2);
+ fclose($lfp2);
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/*
+ * Ajax Chat for TRPG ver.1.3
+ * (c)2007 Cake All rights reserved.
+ * Mail : cake_67@users.sourceforge.jp
+ * Home : http://trpgtools-onweb.sourceforge.jp/
+ */
+
+/*****************
+ * PHPライブラリ:過去ログ用
+ *****************/
+
+/*
+ * 管理パスワードの照合
+ */
+function auth() {
+ if (!MASTERPASS) {
+ error('管理用パスワードが設定されていません。trpgchat-ini.phpの設定を確認してください。');
+ }
+ @session_name('AjaxChatForTRPG');
+ @session_start();
+ if($_SESSION['admin_pwd'] != crypt(MASTERPASS, ADMIN_HASH_KEY)) {
+ error('パスワードが違います');
+ }
+}
+
+/*
+ * ログの成形
+ */
+function read_log($logfile, $hash, $d) {
+ // ログの読み込み
+ $log = array();
+ $log = file($logfile);
+ if (is_array($log)) {
+
+ // データの成形
+ foreach($log as $k => $v) {
+ if ($v[0] != 0) {
+ $unit = explode("<>", $v);
+ $num = $unit[0];
+ $name = $unit[1];
+ $pc = $unit[2];
+ $color = $unit[3];
+ $com = $unit[4];
+ if ($d) $datetime = date("Y/m/d H:i:s", $unit[5]);
+ if (MASTERPASS && $hash == MASTERPASS) $host = '<!-- '.$unit[6].' -->';
+ $whisper_from_pass = $unit[8];
+ $whisper_to_name = $unit[9];
+ $whisper_to_pass = $unit[10];
+
+ $w = 'n';
+ if($unit[9] || $unit[10]) {
+ $w = 'y';
+ if ($hash == MASTERPASS) {
+ $w = 'from';
+ } elseif ($hash == $unit[8]) {
+ $w = 'to';
+ } elseif ($hash == $unit[10]) {
+ $w = 'from';
+ }
+ }
+
+ // 行の成形
+ if ($num && $w != 'y') {
+ $row[$k] = '<span style="font-weight:bold; color:#'.$color.';" title="'.$name.'">【'.$pc.'】</span>:';
+ if ($w == 'to' || $w == 'from') {
+ $row[$k] .= '<span style="color:#'.COLOR_SYSTEM.'">(';
+ if ($w == 'to') $row[$k] .= $unit[9].'さんへ';
+ if ($w == 'from') $row[$k] .= $unit[2].'さんから';
+ $row[$k] .= 'のささやき) </span>';
+ }
+ if ($d) $row[$k] .= '<span title="'.$datetime.'">';
+ $row[$k] .= $com;
+ if ($d) $row[$k] .= '</span>';
+ $row[$k] .= $host;
+ }
+ }
+ }
+ }
+ return $row;
+}
+
+/*
+ * 指定ディレクトリ内のファイル・ディレクトリ一覧
+ */
+function get_dir_contents_list($dir, $sort = 'DESC') {
+ $file_list = array();
+ $dir_list = array();
+
+ $dp = opendir($dir);
+ while($str = readdir($dp)) {
+ if (is_dir($dir.$str) && $str != '.' && $str != '..') {
+ $dir_list[] = $str;
+ } elseif (is_file($dir.$str) && $str != 'index.html') {
+ $file_list[] = $str;
+ }
+ }
+ closedir($dp);
+
+ // ソート
+ if($sort == 'ASC') {
+ sort($file_list);
+ sort($dir_list);
+ } else {
+ rsort($file_list);
+ rsort($dir_list);
+ }
+
+ return array('dirs' => $dir_list, 'files' => $file_list);
+}
+
+/*
+ * ディレクトリ開閉タグの出力
+ */
+function print_toggle_dir($id, $dir_name, $child = false, $default = 'close', $title = 'クリックで開閉', $form = 'false', $past = '') {
+ print '<div>';
+ if ($child) { print "├";}
+ if ($form) { print '<input type="radio" name="dir" value="'.$id.'">';};
+ print '<span onclick="toggleColumn(\''.$id.$past.'\');toggleColumn(\'icon_'.$id.$past.'_s\');toggleColumn(\'icon_'.$id.$past.'_h\');" title="'.$title.'">';
+ print '<image src="'.pastlog_dir_close_icon.'" id="icon_'.$id.$past.'_h"';
+ if ($default == 'open') {
+ print ' style="display:none;"';
+ }
+ print '>'.
+ '<image src="'.pastlog_dir_open_icon.'" id="icon_'.$id.$past.'_s"';
+ if ($default != 'open') {
+ print ' style="display:none;"';
+ }
+ print '>'.
+ $dir_name.
+ "</span></div>\n";
+ print '<div id="'.$id.$past.'"';
+ if ($default != 'open') {
+ print ' style="display:none;"';
+ }
+ print ">\n";
+
+}
+
+/*
+ * 過去ログファイルリスト表示
+ */
+function print_pastloglist($files, $dir, $child = false, $form = false) {
+ foreach($files as $v) {
+ if ($child) { print '│'; }
+ print '├';
+ if ($form) { print '<input type="checkbox" name="file[]" value="'.$dir.$v.'">';}
+ print '<a href="'.$dir.$v.'">'.substr($v, 0, strlen($v)-5)."</a><br>\n";
+ }
+}
+
+/*
+ * 指定ディレクトリ内のファイル・ディレクトリ一覧
+ */
+function print_pastlog_contents_list($dir, $root_name, $sort = 'DESC', $form = '', $path = '', $past = '', $open_root = 'open', $open_child = 'close', $root_name = 'ルートディレクトリ', $title = 'クリックで開閉') {
+ $list = get_dir_contents_list($dir, $sort);
+ if ($list['dirs'] || $list['files']) {
+
+ if ($form) {
+ print '<form action="'.$path.'" method="'.METHOD.'">'."\n";
+ print '<input type="hidden" name="type" value="'.$dir.'">'."\n";
+ }
+
+ // ルートディレクトリ
+ print_toggle_dir($dir, $root_name, false, $open_root, $title, $form);
+
+ // 子ディレクトリ
+ if ($list['dirs'][0]) {
+ foreach ($list['dirs'] as $k => $v) {
+ $child[$k] = get_dir_contents_list($dir.$v."/", $sort);
+ print_toggle_dir($v, $v, true, $open_child, $title, $form, $past);
+ if ($child[$k]['files']) {
+ print_pastloglist($child[$k]['files'], $dir.$v.'/', true, $form);
+ }
+ print "</div>\n";
+ }
+ }
+
+ // ルートファイル一覧表示
+ if ($list['files']) {
+ print_pastloglist($list['files'], $dir, false, $form);
+ }
+ print "</div>\n";
+
+ if ($form) {
+ print "<p>\n";
+ print '<input type="submit" name="mode" value="削除確認"> ';
+ print '<input type="submit" name="mode" value="移動"></p>';
+ print '<p><input type="text" name="new_filename" value="">.html ';
+ print '<input type="submit" name="mode" value="ファイル名変更"><br>ファイル名に使える文字は、半角英数字とハイフン(-)、アンダーバー(_)のみです。<br>
+</p>';
+ print '<input type="reset">';
+ print '</form>'."\n";
+ }
+
+ } else {
+ print 'ログファイルはありません';
+ }
+}
+
+
+/*
+ * ファイル・ディレクトリ名チェック
+ */
+function check_name($name) {
+ if (preg_match("/[^0-9a-zA-Z\-_]/", $name)) {
+ error('使える文字は、半角英数字とハイフン(-)、アンダーバー(_)のみです。');
+ }
+}
+
+
+/*
+ * 完了画面表示
+ */
+function display_finish($title, $msg) {
+ print html_header($title, 'main', false, true);
+ print "<p>".$msg."</p>";
+ print '<form action="./pastlog.php" method="'.METHOD.'">'."\n";
+ print '<p><input type="submit" value="戻る"></p>'."\n";
+ print '</form>'."\n";
+ print html_footer('');
+ exit;
+}
+
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/*
+ * Ajax Chat for TRPG ver.1.3
+ * (c)2007 Cake All rights reserved.
+ * Mail : cake_67@users.sourceforge.jp
+ * Home : http://trpgtools-onweb.sourceforge.jp/
+ */
+
+/*****************
+ * PHPライブラリ:共通
+ *****************/
+
+/* リクエストを取得 */
+function request() {
+ if (!strcasecmp(METHOD, 'GET')) {
+ $request = $_GET;
+ } elseif (!strcasecmp(METHOD, 'POST')) {
+ $request = $_POST;
+ }
+ return $request;
+}
+
+/* 色選択出力 */
+function colorbox($color_code, $id, $select=''){
+ $color_list = array();
+ foreach ($color_code as $k1 => $v1) {
+ foreach ($color_code as $v2) {
+ foreach ($color_code as $v3) {
+ $color_list[] = $v1.$v2.$v3;
+ }
+ }
+ }
+ array_unique($color_list);
+ sort($color_list);
+
+ foreach ($color_list as $k => $v) {
+ print'<option value="'.$v.'" style="color: #'.$v.'; font-weight:bold;" id="'.$id.'_'.$v.'"';
+ if ($select == $v) { print ' selected';}
+ print ' >#'.$v.'</option>'."\n";
+ }
+}
+
+/* ヘッター */
+function html_header($title, $window = false, $js = true, $no_cache = true) {
+ $header = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
+ $header .= '<html>'."\n";
+ $header .= '<head>'."\n";
+ $header .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'."\n";
+ $header .= '<meta http-equiv="Content-Style-Type" content="text/css" />'."\n";
+ if ($js) {
+ $header .= '<meta http-equiv="Content-Script-Type" content="text/javascript" />'."\n";
+ }
+ if ($no_cache) {
+ $header .= '<meta http-equiv="Pragma" content="no-cache">'."\n";
+ $header .= '<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate">'."\n";
+ $header .= '<meta http-equiv="Expires" content="Thu, 01 Feb 2007 00:00:00 GMT">'."\n";
+ }
+ if ($window == 'pastlog') {
+ $header .= '<link rel="stylesheet" type="text/css" href="../css/trpgchat.css">'."\n";
+ } else {
+ $header .= '<link rel="stylesheet" type="text/css" href="./css/trpgchat.css">'."\n";
+ }
+ if ($window == 'index') {
+ $header .= '<link rel="stylesheet" type="text/css" href="./css/index.css">'."\n";
+ } elseif ($window == 'main') {
+ $header .= '<link rel="stylesheet" type="text/css" href="./css/main.css">'."\n";
+ } elseif ($window == 'pastlog') {
+ $header .= '<link rel="stylesheet" type="text/css" href="../css/main.css">'."\n";
+ }
+ $header .= '<title>'.$title.'</title>'."\n";
+ if ($js) {
+ $header .= '<script type="text/javascript" src="./lib/js/jquery.js"></script>'."\n";
+ }
+
+ return $header;
+}
+
+/* フッター */
+function html_footer($copyright = 'true') {
+ if ($copyright) $footer = '<p class="copyright">'.COPYRIGHT.'</p>'."\n";
+ $footer .= '</body>'."\n";
+ $footer .= '</html>'."\n";
+
+ return $footer;
+}
+
+/* エラー表示 */
+function error($msg) {
+ print html_header('エラー', false, false, false);
+ print "</head>\n";
+ print "<body>\n";
+ print '<font color="red">エラー</font><br>'."\n";
+ print $msg."\n";
+ print html_footer('');
+ exit;
+}
+
+/* トリップ生成 */
+function create_hash($name,$pwd) {
+ //パスワードがなければ中止
+ if (!$pwd) {
+ return false;
+ }
+ $key = substr(substr($pwd,1,2)."dummy",0,2);
+ $key = strtr($key,':;<=>?@[\]^_`','ABCDEFGabcdef');
+ $pwd = substr(crypt($name, $key), -10);
+
+ return $pwd;
+}
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/*
+ * Ajax Chat for TRPG ver.1.3
+ * (c)2007 Cake All rights reserved.
+ * Mail : cake_67@users.sourceforge.jp
+ * Home : http://trpgtools-onweb.sourceforge.jp/
+ */
+
+/*****************
+ * PHPライブラリ:書きこみ用
+ *****************/
+
+/*
+ * 直近の過去ログ取得
+ */
+function write_recent_past($write, $pdata) {
+ $pfp = @fopen($pdata, "a+") or die("過去ログファイルを開けません。");
+
+ fwrite($pfp, $write);
+
+ return true;
+}
+
+/*
+ * ダイス
+ */
+function dice_convert($dicenum, $dicenumber, $revision) {
+ // ダイス本体
+ if($dicenum >= 1 && $dicenum <= (int)DICE_MAX) {
+ if ($dicenumber >= 2 && $dicenumber <= 100) {
+ mt_srand((double) microtime() * 1000000);
+ $dicesum = 0;
+ for ($i=0; $i<$dicenum; $i++) {
+ $d_result[$i] = mt_rand(1,$dicenumber);
+ $dice_sum += $d_result[$i];
+ if ($i != 0) {
+ $dice_list .= ", ".$d_result[$i];
+ } else {
+ $dice_list = " (".$d_result[$i];
+ }
+ }
+ $dice_list .= ")";
+ } else {
+ return '['.$dicenum.'d'.$dicenumber.$revision.' (d2~d100の範囲で指定してください)';
+ }
+ } else {
+ return '['.$dicenum.'d'.$dicenumber.$revision.' (ダイスの数は1から'.DICE_MAX.'の間で指定してください)';
+ }
+
+ // 修正値を加えた結果の計算
+ if(rtrim($revision, "]")) {
+ $dice = preg_replace("/\s/","+",$dice);
+ $value = calc_value($dice_sum, $revision);
+ } else {
+ $value = $dice_sum;
+ }
+
+ if (!is_numeric($value)) {
+ return '<span style="color:#'.DICE_COLOR.';">'.$dice.' ('.$value.')</span>';
+ } else {
+ $dice = '<span style="color:#'.DICE_COLOR.'; font-weight: bold;">['.$dicenum.'d'.$dicenumber.$revision.' :'.$dice_list.' = '.$value.'</span>';
+ return $dice;
+ }
+}
+
+/* ダイス修正値の計算
+ */
+function calc_value($dice_sum, $revision) {
+ $multi = preg_match("/\*/", $revision);
+ $dev = preg_match("/\//", $revision);
+ $add = preg_match("/\+/", $revision);
+ $subtract = preg_match("/\-/", $revision);
+
+ // +-*/で分割
+ $revision = preg_replace("/\+/","<>+<>",$revision);
+ $revision = preg_replace("/\-/","<>-<>",$revision);
+ $revision = preg_replace("/\*/","<>*<>",$revision);
+ $revision = preg_replace("/\//","<>/<>",$revision);
+ $parts = explode("<>",$revision);
+ array_splice($parts, 0, 1, $dice_sum);
+
+ // 乗算&除算
+ if ($multi || $dev) {
+ foreach ($parts as $k => $v) {
+ if ($v != '0' && $v == '*') {
+ if (!preg_match("/[0-9]{1,}/", $parts[$k+1])) return "演算子が連続してます";
+ $flg = $k;
+ array_splice($parts, $k+1, 1, $parts[$k-1] * $parts[$k+1]);
+ array_splice($parts, $k-1, 1, 0);
+ array_splice($parts, $k, 1, $parts[$k-2]);
+ array_splice($parts, $k-2, 1, '+');
+ }
+ if ($v != '0' && $v == '/') {
+ if (!preg_match("/[0-9]{1,}/", $parts[$k+1])) return "演算子が連続してます";
+ array_splice($parts, $k+1, 1, $parts[$k-1] / $parts[$k+1]);
+ array_splice($parts, $k-1, 1, 0);
+ array_splice($parts, $k, 1, $parts[$k-2]);
+ array_splice($parts, $k-2, 1, '+');
+ }
+ }
+ }
+
+ // 加減算
+ foreach ($parts as $k => $v){
+ if ($v != '0') {
+ if ($v == '+') {
+ if (!preg_match("/[0-9]{1,}/", $parts[$k+1])) return "演算子が連続してます";
+ array_splice($parts, 0, 1, $parts[0] + $parts[$k+1]);
+ } elseif ($v == '-') {
+ if (!preg_match("/[0-9]{1,}/", $parts[$k+1])) return "演算子が連続してます";
+ array_splice($parts, 0, 1, $parts[0] - $parts[$k+1]);
+ }
+ }
+ }
+
+ return round($parts[0], 1);
+}
+
+ ?>
\ No newline at end of file