예제 #1
1
 /**
  * The standard homepage
  *
  * @return Response
  */
 private function game()
 {
     // Get the actual values of the vars.
     $ninja = Player::find(SessionFactory::getSession()->get('player_id'));
     $playerInfo = $ninja->data();
     $clan = $ninja ? Clan::findByMember($ninja) : null;
     $unreadCount = Message::where(['send_to' => $ninja->id(), 'unread' => 1])->count();
     // Assign these vars to the template.
     $parts = ['main_src' => '/intro', 'body_classes' => 'main-body', 'version' => 'NW Version 1.7.5 2010.12.05', 'ninja' => $ninja, 'player_info' => $playerInfo, 'clan' => $clan, 'unread_message_count' => $unreadCount];
     return new StreamedViewResponse('Live by the Shuriken', 'index.tpl', $parts, ['is_index' => true]);
 }
예제 #2
0
 /**
  * The standard homepage
  *
  * @return ViewSpec
  */
 private function game()
 {
     // Get the actual values of the vars.
     $ninja = new Player(self_char_id());
     $playerInfo = $ninja->dataWithClan();
     $unreadCount = Message::where(['send_to' => $ninja->id(), 'unread' => 1])->count();
     // Assign these vars to the template.
     $parts = ['main_src' => '/intro', 'body_classes' => 'main-body', 'version' => 'NW Version 1.7.5 2010.12.05', 'ninja' => $ninja, 'player_info' => $playerInfo, 'unread_message_count' => $unreadCount];
     return ['template' => 'index.tpl', 'title' => 'Live by the Shuriken', 'parts' => $parts, 'options' => ['is_index' => true]];
 }
예제 #3
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) : ''));
 }
예제 #4
0
 /**
  * Delete a clan after sending a message to all clan members.
  */
 public function disband()
 {
     DatabaseConnection::getInstance();
     $leader = $this->getLeaderID();
     $message = "Your leader has disbanded your clan. You are alone again.";
     $statement = DatabaseConnection::$pdo->prepare("SELECT _player_id FROM clan_player WHERE _clan_id = :clan");
     $statement->bindValue(':clan', $this->getID());
     $statement->execute();
     while ($data = $statement->fetch()) {
         $memberId = $data[0];
         Message::create(['send_from' => $leader, 'send_to' => $memberId, 'message' => $message, 'type' => 0]);
     }
     // Deletion of the clan_player connections should cascade from the deletion of the clan, at least ideally.
     $statement = DatabaseConnection::$pdo->prepare("DELETE FROM clan WHERE clan_id = :clan");
     $statement->bindValue(':clan', $this->getID());
     $statement->execute();
 }
예제 #5
0
 /**
  * Truncate the chat periodically
  * 
  * @return int Number of chats removed
  */
 public function shortenChat()
 {
     return Message::shortenChat();
 }
예제 #6
0
 public function testFindPrivateMessagesForACertainChar()
 {
     $messageCount = 4;
     $this->messageData['send_to'] = $this->char_id;
     $this->messageData['send_from'] = $this->char_id_2;
     for ($count = 0; $count < $messageCount; $count++) {
         $this->messageData['message'] = 'Random phpunit test message' . $count;
         Message::create($this->messageData);
         // Test deletes these
     }
     $char = Player::find($this->char_id);
     $messages = Message::findByReceiver($char)->all();
     $this->assertEquals($messageCount, count($messages));
     Message::deleteByReceiver($char, 0);
     $this->assertEquals(0, Message::countByReceiver($char));
 }
예제 #7
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()];
         }
     }
 }
예제 #8
0
 /**
  * ????
  *
  * @todo Simplify this invite system.
  * @param int $user_id
  * @param int $clan_id
  * @return void
  */
 private function sendClanJoinRequest($user_id, $clan_id)
 {
     DatabaseConnection::getInstance();
     $clan_obj = new Clan($clan_id);
     $leader = $clan_obj->getLeaderInfo();
     $leader_id = $leader['player_id'];
     $username = get_char_name($user_id);
     $confirmStatement = DatabaseConnection::$pdo->prepare('SELECT verification_number FROM players WHERE player_id = :user');
     $confirmStatement->bindValue(':user', $user_id);
     $confirmStatement->execute();
     $confirm = $confirmStatement->fetchColumn();
     // These ampersands get encoded later.
     $url = "[href:clan/review/?joiner={$user_id}&confirmation={$confirm}|Confirm Request]";
     $join_request_message = 'CLAN JOIN REQUEST: ' . htmlentities($username) . " has sent a request to join your clan.\n            If you wish to allow this ninja into your clan click the following link:\n                {$url}";
     Message::create(['send_from' => $user_id, 'send_to' => $leader_id, 'message' => $join_request_message, 'type' => 0]);
 }
예제 #9
0
 /**
  * Delete the all the messages from your clan.
  *
  * @param Container
  */
 public function deleteClan(Container $p_dependencies)
 {
     Message::deleteByReceiver($p_dependencies['current_player'], 1);
     return new RedirectResponse('/messages?command=clan&informational=' . rawurlencode('Messages deleted'));
 }
예제 #10
0
 /**
  * mark all messages of a type for a ninja as read
  */
 public static function markAsRead(Player $char, $type)
 {
     return Message::where(['send_to' => $char->id(), 'type' => $type])->update(['unread' => 0]);
 }
예제 #11
0
 /**
  * Delete the all the messages from your clan.
  */
 public function deleteClan()
 {
     $char_id = self_char_id();
     $type = 1;
     Message::deleteByReceiver(new Player($char_id), $type);
     return new RedirectResponse('/messages.php?command=clan&informational=' . url('Messages deleted'));
 }