Ejemplo n.º 1
0
        $goto[0] = '/' . $special[1];
    } else {
        if ($special) {
            $goto[0] = '/:' . implode('/', $special);
        }
    }
    $goto = implode('?', $goto);
    $view->goto = $goto;
    $view->wrong = FALSE;
    if (isset($_POST['user']) && isset($_POST['password'])) {
        $stmt = $pdo->prepare('SELECT * FROM ewiki_users WHERE "user" = :user AND "password" = :password');
        $stmt->execute(array('user' => $_POST['user'], 'password' => sha1($_POST['password'])));
        $user = $stmt->fetchObject();
        $stmt->closeCursor();
        if ($user) {
            $session = gentoken(10);
            $stmt = $pdo->prepare('UPDATE ewiki_users SET "session" = :session WHERE "user" = :user');
            $stmt->execute(array('user' => $user->user, 'session' => $session));
            $stmt->closeCursor();
            setcookie('session', $session, 0, Config::PATH . '/');
            redirect(Config::PATH . $goto);
            exit(0);
        } else {
            $view->wrong = TRUE;
        }
    }
    $view->display();
} else {
    if ($special[0] == 'recent' || $special[0] == "rss20") {
        if ($special[0] == "rss20") {
            $view->setTemplate('rss20.php');
Ejemplo n.º 2
0
 public function onMessage(IWebSocketConnection $conn, IWebSocketMessage $msg)
 {
     $arr = json_decode($msg->getData(), true);
     // If this is a new websocket connection, handle the user up front
     if ($arr['messageType'] == 'myid') {
         if (isset($this->users[$arr['id']])) {
             $user = $this->users[$arr['id']];
         } else {
             $user = new Player(gentoken(), $conn->getId());
         }
         $this->users[$user->id()] = $user;
         $this->conns[$conn->getId()] = $user;
         $user->setConnection($conn);
         $user->send('myname', array('name' => $user->name(), 'id' => $user->id(), 'ingame' => $user->game() != null));
         if ($user->game() != null) {
             if ($user->game()->started) {
                 $user->rejoinGame();
             } else {
                 $user->rejoinWaitingRoom();
             }
         } else {
             foreach ($this->games as $game) {
                 if ($game->started) {
                     continue;
                 }
                 $user->send('newgame', array('name' => $game->name, 'creator' => $game->creator->name(), 'id' => $game->id));
             }
         }
         $this->say("{$user->id()} connected");
         return;
     }
     // Otherwise we better have a user set for them, and then continue on
     // as normally when processing the message
     if (!isset($this->conns[$conn->getId()])) {
         return;
     }
     $user = $this->conns[$conn->getId()];
     switch ($arr['messageType']) {
         case 'newgame':
             if ($user->game() != null) {
                 return;
             }
             // ERRORS NOT SHOWING ON CLIENT: FIX FIX FIX
             if ($arr['name'] == '') {
                 return $user->send('error', 'Game needs a valid name');
             }
             $game = new SevenWonders();
             $game->maxplayers = intval($arr['players']);
             $game->name = $arr['name'];
             $game->id = gentoken();
             $game->server = $this;
             $game->addPlayer($user);
             $this->games[$game->id] = $game;
             if ($game->maxplayers > 1) {
                 $this->broadcast('newgame', array('name' => $game->name, 'creator' => $game->creator->name(), 'id' => $game->id), $user);
             }
             break;
         case 'joingame':
             if ($user->game() != null) {
                 break;
             }
             $id = $arr['id'];
             if (!isset($this->games[$id]) || $this->games[$id]->started) {
                 break;
             }
             $this->games[$id]->addPlayer($user);
             break;
         case 'changename':
             if ($user->game() == null && $arr['name'] != '') {
                 $user->setName($arr['name']);
             }
             // Broadcast name change here in case they're hosting a game?
             break;
         default:
             if ($user->game() != null) {
                 $user->game()->onMessage($user, $arr);
             } else {
                 $user->send('error', "Error: could not recognize command " . $arr['messageType']);
             }
             break;
     }
 }