<?php
//
//ヒッキー板チャットクライアント
//
// サイト: http://c...content-available-to-author-only...l.cx/
//
//定数的データ
$client = "SJIS";
$server = "UTF-8";
$url = 'http://c...content-available-to-author-only...l.cx/api/';
'enter' => 1,
'read' => 1,
'write' => 1,
'leave' => 1
);
//文字エンコード
function enc($str) {
global $client, $server;
if ($client == $server) return $str;
}
function dec($str) {
global $client, $server;
if ($client == $server) return $str;
}
//通信処理
function postit($cmd, $msg = '') {
global $url, $name, $commands;
//コマンドの確認
if (!isset($commands[$cmd])) { return false;
}
//送信データの用意
$data = array('name' => $name); if ($cmd == 'write') {
if ($msg == false) {
return false;
}
$data['body'] = enc($msg);
}
//通信部
return $result;
}
//名前の入力
do {
echo 'Name?: ';
} while ($name == false);
$name = enc($name);
//入室
if (postit('enter') === false) {
die("failed to enter." . PHP_EOL
); }
//ループ
do {
//チャットの読み込みと表示
if (($json = postit('read')) === false) {
die("failed to read." . PHP_EOL
); }
if (json_last_error() != JSON_ERROR_NONE) {
postit('leave');
die("failed by json.(" . json_last_error
() .")\n"); }
foreach ($chat as $value) {
echo '[', $value->time, ']', dec
($value->name),': ', dec
($value->body), PHP_EOL
; }
echo PHP_EOL;
//コマンドの入力
echo 'Command: write read leave', PHP_EOL;
do {
echo '? ';
} while (!isset($commands[$cmd]));
//メッセージの入力
if ($cmd == 'write') {
do {
echo 'message? ';
} while ($mes == false);
if (postit('write', $mes) === false) {
die('failed to write.' . PHP_EOL
); }
}
} while ($cmd != 'leave');
//退室
postit('leave');
?>
PD9waHAKLy8KLy/jg5Ljg4Pjgq3jg7zmnb/jg4Hjg6Pjg4Pjg4jjgq/jg6njgqTjgqLjg7Pjg4gKLy8KLy8g44K144Kk44OI77yaICBodHRwOi8vYy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4ubC5jeC8KLy8KCi8v5a6a5pWw55qE44OH44O844K/CiRjbGllbnQgPSAiU0pJUyI7CiRzZXJ2ZXIgPSAiVVRGLTgiOwokd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