+ private function tell($dest, $msg) {
+ if (!$dest || !$msg) {
+ $this->error('400', 'expected `dest` and `msg` fields');
+ return;
+ }
+ $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;
+ }
+ $this->insert(
+ 'INSERT INTO messages (message,type,destination,source) VALUES(?,?,?,?)',
+ 'ssii', $msg, 'say', $player['id'], $this->player->id);
+ }
+
+ private function move($direction) {
+ $directions = array(
+ 'north' => array('x' => $this->player->x, 'y' => $this->player->y-1),
+ 'east' => array('x' => $this->player->x+1, 'y' => $this->player->y),
+ 'south' => array('x' => $this->player->x, 'y' => $this->player->y+1),
+ 'west' => array('x' => $this->player->x-1, 'y' => $this->player->y),
+ );
+ if ($directions[$direction]) {
+ $rooms = $this->query(
+ 'SELECT id, state, description FROM rooms WHERE x = ? and y = ?',
+ 'ii', $directions[$direction]['x'], $directions[$direction]['y']);
+ if ($rooms[0] && !$rooms[0]['state']) {
+ $this->update('UPDATE players SET room = ? WHERE players.id = ?',
+ 'si', $rooms[0]['id'], $this->player->id);
+ return array('description' => $rooms[0]['description']);
+ } else {
+ $this->error(403, 'your path is blocked');
+ }
+ } else
+ $this->error(400, 'expected `direction` field with value {north|east|south|west}');