Beispiel #1
0
 /**
  * Send the message to a group of target ids
  */
 public static function sendToGroup(Player $sender, array $groupTargets, $message, $type)
 {
     if (!$sender || !$sender->id()) {
         throw new \Exception('Error: Message sender not set.');
     }
     $id = $sender->id();
     foreach ($groupTargets as $target_id) {
         Message::create(['message' => $message, 'send_to' => $target_id, 'send_from' => $id, 'type' => $type]);
     }
     return true;
 }
 /**
  * Send a private message to a player
  *
  * @param Container
  */
 public function sendPersonal(Container $p_dependencies)
 {
     $request = RequestWrapper::$request;
     if ((int) $request->get('target_id')) {
         $recipient = Player::find((int) $request->get('target_id'));
     } else {
         if ($request->get('to')) {
             $recipient = Player::findByName($request->get('to'));
         } else {
             $recipient = null;
         }
     }
     if ($recipient) {
         Message::create(['send_from' => $p_dependencies['session']->get('player_id'), 'send_to' => $recipient->id(), 'message' => $request->get('message', null), 'type' => 0]);
         return new RedirectResponse('/messages?command=personal&individual_or_clan=1&message_sent_to=' . rawurlencode($recipient->name()) . '&informational=' . rawurlencode('Message sent to ' . $recipient->name() . '.'));
     } else {
         return new RedirectResponse('/messages?command=personal&error=' . rawurlencode('No such ninja to message.'));
     }
 }
 public function sendPersonal()
 {
     if ((int) in('target_id')) {
         $target_id = (int) in('target_id');
     } else {
         if (in('to')) {
             $target_id = get_user_id(in('to'));
         } else {
             $target_id = null;
         }
     }
     if ($target_id) {
         Message::create(['send_from' => self_char_id(), 'send_to' => $target_id, 'message' => in('message', null, null), 'type' => 0]);
         $recipient = get_char_name($target_id);
         return new RedirectResponse('/messages.php?command=personal&individual_or_clan=1&message_sent_to=' . url($recipient) . '&informational=' . url('Message sent to ' . $recipient . '.'));
     } else {
         return new RedirectResponse('/messages.php?command=personal&error=' . url('No such ninja to message.'));
     }
 }
Beispiel #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();
 }
Beispiel #5
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));
 }
Beispiel #6
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]);
 }