protected function run() { if ($this->check === self::OK) { $messageParams = array('text' => $this->params['text'], 'room' => $this->room['id'], 'game' => $this->game['id']); Chat::addMessage($messageParams); if ($this->game->getIsHNGag()) { if ($this->actualPlayer['actual_lifes'] == 1) { // TODO nejaky priznak ze hrac bol upozorneny a potom mu toto uz nezobrazovat len ho removnut z hry $message = array('text' => 'nesmies hovorit, lebo stratis posledny zivot', 'toUser' => $this->loggedUser['id']); $this->addMessage($message); } else { // TODO info o tom ze hrac stratil zivot kvoli tomu ze keca $this->actualPlayer['actual_lifes'] = $this->actualPlayer['actual_lifes'] - 1; $this->actualPlayer->save(); } } } }
$actualUrl = Utils::getActualUrl(); $room = intval($_GET['id']); if (!$room) { Utils::redirect('rooms.php'); } Room::addUser($loggedUser['id'], $room); $gameRepository = new GameRepository(); $game = $gameRepository->getOneByRoom($room); if ($game) { $GLOBALS['smarty']->assign('game', $game); } if ($_POST && trim($_POST['message'])) { if (strpos($_POST['message'], '.') === 0) { $commandResult = Command::execute($_POST['message'], $game); } else { Chat::addMessage(trim($_POST['message']), $room); } Room::updateUserLastActivity($loggedUser['id'], $room); Utils::redirect($actualUrl); } $messages = Chat::getMessages($room, $loggedUser['id']); $emoticons = Emoticons::getEmoticons(); $GLOBALS['smarty']->assign('loggedUser', $loggedUser); $GLOBALS['smarty']->assign('room', $room); $GLOBALS['smarty']->assign('messages', $messages); $GLOBALS['smarty']->assign('users', Room::getUsers($room)); $GLOBALS['smarty']->assign('emoticonDir', EMOTICONS_DIR); $GLOBALS['smarty']->assign('emoticons', $emoticons); $GLOBALS['smarty']->assign('content', $GLOBALS['smarty']->fetch('room.tpl')); $GLOBALS['smarty']->assign('bodyAdded', 'onload="JavaScript:timedRefresh(10000, ' . $room . ');"'); echo $GLOBALS['smarty']->fetch('content.tpl');
<?php include './classes/chat.php'; $oChat = new Chat(); if ($_POST) { $sMessage = $_POST['message']; $oChat->addMessage($_SESSION['user_id'], $sMessage); }
protected static function beer() { if (GameUtils::checkTurn(self::$game, self::$player)) { if (self::$player['phase'] == 2 || self::$player['actual_lifes'] == 0) { $beer = self::$player->getHasPivoOnHand(); if ($beer) { if (self::$player->addLife()) { GameUtils::throwCard(self::$game, self::$player, $beer); } else { // ma max zivotov } } else { // nema pivo } } else { // najprv musi tahat karty } } else { Chat::addMessage('Nie si na rade.', self::$room, User::SYSTEM, self::$loggedUser['id']); } }
protected final function write() { if ($this->messages && is_array($this->messages)) { foreach ($this->messages as $message) { Chat::addMessage($message); } } }
/** * save the message to the database * @param $to : PartnerId * @param $message : message content * @return array : Containing status */ public function sendMessage($to, $message) { $Object = new Chat(); $result = $Object->addMessage($to, $message); return $result; }
// Load config.php include_once 'includes/config.php'; // Autoload classes spl_autoload_register(function ($class) { include_once 'includes/' . strtolower($class) . '.php'; }); // Instigate classes $db = new Database($mysql_config); $session = new Session(); $token = new Token($session); $chat = new Chat($db, $token, $session); // Post messages $post_action = isset($_POST['action']) ? $_POST['action'] : ''; if ($post_action === 'chat_post') { try { print $chat->addMessage($_POST['name'], $_POST['message'], $_POST['token']); } catch (Exception $e) { print '<li><strong>Error:</strong> <span style="color:red;">' . $e->getMessage() . '</span></li>'; } return; } // Build content $page = isset($_GET['page']) ? $_GET['page'] : ''; if ($page === 'load_chat') { try { print $chat->getPosts(); } catch (Exception $e) { print '<li><strong>Error:</strong> <span style="color:red;">' . $e->getMessage() . '</span></li>'; } return; }
require_once '../include/DB.php'; require_once '../include/Chat.php'; require_once '../include/User.php'; $user = new User(); if ($user->isLogin() !== true) { echo $errorResponse = json_encode(array("status" => false, "message" => array("errorCode" => -4, "errorMessage" => "User not login."))); exit(0); } if (@isset($_GET['action'])) { $action = $_GET['action']; if ($action === 'send') { $chat = new Chat(); if (@isset($_POST['to']) && isset($_POST['message'])) { $to = $_POST['to']; $message = $_POST['message']; echo json_encode($chat->addMessage($user->getUsername(), $to, $message, date('Y-m-d H:i:s', time()))); exit(0); } else { echo $errorResponse = json_encode(array("status" => false, "message" => array("errorCode" => -16, "errorMessage" => "No user for to or no message."))); } } else { if ($action === 'get') { $chat = new Chat(); if (@isset($_POST['to'])) { $to = $_POST['to']; echo json_encode($chat->getMessage($user->getUsername(), $to)); exit(0); } else { echo $errorResponse = json_encode(array("status" => false, "message" => array("errorCode" => -8, "errorMessage" => "the user for to is not find."))); } }