Esempio n. 1
0
 /**
  * Take in a chat and record it to the database.
  *
  * @return Response
  */
 public function receive()
 {
     $char_id = SessionFactory::getSession()->get('player_id');
     $message = RequestWrapper::getPostOrGet('message');
     $error = null;
     if (!empty($message)) {
         if ($char_id) {
             Message::sendChat($char_id, $message);
         } else {
             $error = 'You must be logged in to chat.';
         }
     }
     return new RedirectResponse('/village/' . ($error ? '?error=' . rawurlencode($error) : ''));
 }
Esempio n. 2
0
 private function jsonSendChat($msg)
 {
     if (SessionFactory::getSession()->get('authenticated', false)) {
         $msg = trim($msg);
         $player = Player::find(SessionFactory::getSession()->get('player_id'));
         $success = Message::sendChat($player->id(), $msg);
         if (!$success) {
             return false;
         } else {
             return ['message' => $msg, 'sender_id' => $player->id(), 'uname' => $player->name()];
         }
     }
 }