示例#1
0
    public function json()
    {
        if ($_GET) {
            header('Content-Type: application/json');
            // escape your parameters to prevent sql injection
            $id = (int) $_GET['id'];
            $sth = $this->db->prepare('SELECT ip_address,port,players,maxplayers FROM servers WHERE server_id=?');
            $sth->execute(array($id));
            if ($sth->rowCount() == 1) {
                $row = $sth->fetch(\PDO::FETCH_ASSOC);
                try {
                    $query = new \Classes\MinecraftServerPing($row['ip_address'], $row['port']);
                    $info = $query->Query();
                } catch (\Classes\MinecraftPingException $e) {
                    $info['players'] = 0;
                    $info['playerlist'] = Null;
                    $info['maxplayers'] = $row['maxplayers'];
                    $info['status'] = 0;
                }
                $sth = $this->db->prepare('UPDATE servers SET 
									players=?,
									maxplayers=?,status=?
									WHERE server_id=?');
                $sth->execute(array($info['players'], $info['maxplayers'], $info['status'], $id));
                echo json_encode($info, true);
            } else {
                header('Location:' . URL . 'error');
            }
        } else {
            header('Location:' . URL . 'error');
        }
    }
示例#2
0
 public function getServerInfo($id)
 {
     $this->getId($id);
     $sth = $this->db->prepare('SELECT s.*,COUNT(v.vote_id) AS votes 
                                 FROM servers s
                                 LEFT JOIN votes v ON s.server_id=v.server_id
                                 WHERE s.server_id =?');
     $sth->execute(array($id));
     if ($sth->rowCount() == 1) {
         $row = $sth->fetch(\PDO::FETCH_ASSOC);
         try {
             $query = new \Classes\MinecraftServerPing($row['ip_address'], $row['port']);
             $serverinfo = $query->Query();
         } catch (\Classes\MinecraftPingException $e) {
             $serverinfo['players'] = 0;
             $serverinfo['status'] = 0;
         }
         $info = array_merge($row, $serverinfo);
         $info['motd'] = $row['motd'];
         return $info;
     } else {
         return false;
     }
 }
 public function addServer()
 {
     if ($this->validateFields()) {
         try {
             $query = new \Classes\MinecraftServerPing($this->ip_address, $this->port);
             $info = $query->Query();
         } catch (\Classes\MinecraftPingException $e) {
             $this->data['error'][] = 'За да бъде записан,сървърът трябва да е ОНЛАЙН.';
             return false;
         }
         $sql = 'SELECT server_id FROM servers WHERE ip_address=? AND port=?';
         $sth = $this->db->prepare($sql);
         $sth->execute(array($this->ip_address, $this->port));
         if ($sth->rowCount() != 0) {
             $this->data['error'][] = 'Има вече сървър с такова IP:Port';
             return false;
         } else {
             if ($this->server_name == null) {
                 $this->server_name = $info['motd'];
             }
             $sql = 'INSERT INTO servers (ip_address,port,motd,description,tags,user_id,youtubevid,favicon,website,players,maxplayers,status) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)';
             $sth = $this->db->prepare($sql);
             $user_id = \Frame\Application::getInstance()->getSession()->user_info['user_id'];
             $sth->execute(array($this->ip_address, $this->port, $this->server_name, $this->description, $this->tags, $user_id, $this->youtubeVideo, $info['favicon'], $this->website, $info['players'], $info['maxplayers'], $info['status']));
             $id = $this->db->lastInsertId();
             $this->data['message'][] = "Благодарим ви за добавянето на сървъра";
             $this->data['message'][] = 'Страница на сървъра: <a href="' . URL . $id . '-' . \Classes\Common::createSlug($this->server_name) . '">ТУК</a>';
         }
     } else {
         return false;
     }
 }