}
private function yell($msg) {
- if (!$msg) {
- $this->error('400', 'expected `msg` field');
- return;
- }
+ if (!$msg) $this->error('400', 'expected `msg` field');
$this->insert(
'INSERT INTO messages (message,type,room,source) VALUES(?,?,?,?)',
'ssii', $msg, 'yell', $this->player->room, $this->player->id);
}
private function say($msg) {
- if (!$msg) {
- $this->error('400', 'expected `dest` field');
- return;
- }
+ if (!$msg) $this->error('400', 'expected `dest` field');
$this->insert(
'INSERT INTO messages (message,type,room,source) VALUES(?,?,?,?)',
'ssii', $msg, 'say', $this->player->room, $this->player->id);
}
private function tell($dest, $msg) {
- if (!$dest || !$msg) {
- $this->error('400', 'expected `dest` and `msg` fields');
- return;
- }
+ if (!$dest || !$msg) $this->error('400', 'expected `dest` and `msg` fields');
$player = $this->query('SELECT id FROM players where name = ?', 's', $dest);
- if (!($player && $player['id'])) {
- $this->error('400', "could not find a player with `name` == $dest");
- return;
- }
+ if (!($player && $player['id']))
+ $this->error(400, "could not find a player with `name` == $dest");
$this->insert(
'INSERT INTO messages (message,type,destination,source) VALUES(?,?,?,?)',
'ssii', $msg, 'say', $player['id'], $this->player->id);
public function command($cmd) {
if (!$_GET['cmd'])
$this->error(400, 'Missing command: expected `cmd` field');
- if ($_GET['cmd'] != 'join' && $_GET['cmd'] != 'start' && !isset($_SESSION['id']))
+ if (($_GET['cmd'] != 'join' && $_GET['cmd'] != 'kick')
+ && $_GET['cmd'] != 'start' && !isset($_SESSION['id']))
$this->error(401, 'Missing user ID: please join first');
if (isset($_SESSION['id'])) $this->player = new player($this);
switch ($cmd) {
$this->yell($_GET['msg']);
break;
case 'say':
- $this->say($_GET['dest'], $_GET['msg']);
+ $this->say($_GET['msg']);
break;
case 'tell':
- $this->tell();
+ $this->tell($_GET['dest'], $_GET['msg']);
break;
case 'poll':
- echo json_encode($this->poll());
+ $this->response($this->poll());
+ break;
+ case 'kick':
+ $this->update('DELETE FROM players');
break;
default:
- $this->error(400, 'Unknown command');
+ $this->error(400, 'unknown command');
}
}
private function error($status, $msg) {
header("HTTP/1.0 $status");
echo $msg;
+ exit;
}
}