Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Online Monitor

Comments in 'Plugin Development' started by wrewolf, Jan 22, 2014.

  1. wrewolf
    Offline

    wrewolf New Member Plugin Developer

    Joined:
    Nov 9, 2013
    Posts:
    45
    Plugins:
    4
    Minecraft User:
    isprion
    Idea, concept

    PHP:
    <?php
      
    /*
    __PocketMine Plugin__
    name=OnlineCount
    description=OnlineCount
    version=0.5
    author=WreWolf
    class=OnlineCount
    apiversion=9
    */

      
    class OnlineCount implements Plugin
      
    {
        private 
    $api$path$config$server$db;

        public function 
    __construct(ServerAPI $api$server false)
        {
          
    $this->api    $api;
          
    $this->server ServerAPI::request();
        }

        public function 
    init()
        {
          
    $this->path $this->api->plugin->configPath($this);
          @
    mkdir($this->path);
          
    $this->api->schedule(100, array($this"tickHandler"), array(), true"server.schedule");

          if (
    $this->db = new SQLite3($this->path."main.db")) {
            
    // first let the engine check table, and create it eventualy
            
    $q = @$this->db->query('CREATE TABLE IF NOT EXISTS main (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "timestamp" NOT NULL DEFAULT CURRENT_TIMESTAMP, tps real, online int);');
          }
        }

        public function 
    tickHandler($data$event)
        {
           
    $info             $this->server->debugInfo();
     
          
    preg_match_all('!\d+\.*\d*!'$info['tps'], $matches);
          
    $tps $matches[0][0];
          
    $this->db->query("INSERT INTO main (tps,online) VALUES ('$tps','{$info["players"]}')");
        }

        public function 
    __destruct()
        {
        }
      }
    PHP:
    <?php
      
    /*
    __PocketMine Plugin__
    name=DbConnector
    description=DbConnector
    version=2.0
    author=WreWolf
    class=DbConnector
    apiversion=11
    */

      
    class DbConnector implements Plugin
      
    {
        private 
    $api$path$server$db;

        public function 
    __construct(ServerAPI $api$server false)
        {
          
    $this->api    $api;
          
    $this->server ServerAPI::request();
        }

        public function 
    init()
        {
          
    $this->path $this->api->plugin->configPath($this);
          
    $this->api->addHandler("db.query.exec", array($this"eventHandler"));
          
    $this->db = new mysqli('127.0.0.1''root'null);

          if (
    $this->db->connect_errno)
            die(
    "Failed to connect to MySQL: (" $this->db->connect_errno ") " $this->db->connect_errno);

          
    $this->db->query("CREATE DATABASE `m1` CHARACTER SET utf8 COLLATE utf8_general_ci;");
          
    $this->db->select_db("m1");

          
    $this->db->query("CREATE TABLE `main` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `timestamp` timestamp NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
      `tps` double DEFAULT NULL,
      `online` int(11) DEFAULT NULL,
      KEY `id` (`id`) USING BTREE
    ) ENGINE=InnoDB AUTO_INCREMENT=187 DEFAULT CHARSET=utf8;"
    );
          
    $this->db->query("CREATE TABLE `online` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
      `user` varchar(255) NOT NULL,
      `cnt` int(11) NOT NULL,
      `level` varchar(60) NOT NULL,
      `x` double NOT NULL,
      `y` double NOT NULL,
      `z` double NOT NULL,
      UNIQUE KEY `user` (`user`) USING BTREE,
      KEY `id` (`id`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
    );
          
    $this->db->query("CREATE TABLE `antiGrif` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
      `user` varchar(60) NOT NULL,
      `block` varchar(30) NOT NULL,
      `level` varchar(30) NOT NULL,
      `x` double NOT NULL,
      `y` double NOT NULL,
      `z` double NOT NULL,
      KEY `id` (`id`) USING BTREE,
      KEY `name` (`user`) USING BTREE,
      KEY `block` (`block`) USING BTREE
    ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;"
    );
          
    $this->db->query("SET NAMES 'UTF8'");
          
    $this->db->query("SET CHARACTER SET 'UTF8'");
        }

        public function 
    eventHandler($data$event)
        {
          
    //console($data['query']);
          
    $this->db->multi_query($data['query']);
          if (
    $this->db->more_results())
            do {
              ;
            } while (
    $this->db->next_result());
        }

        public function 
    __destruct()
        {
        }
      }
  2. TheMoDragon
    Offline

    TheMoDragon New Member

    Joined:
    Jan 6, 2014
    Posts:
    29
    Minecraft User:
    TheMoDragon
    Do you want it to be tested or what?
  3. twixi
    Offline

    twixi New Member

    Joined:
    Jan 31, 2015
    Posts:
    20
    its work or now?
    for pocketmine no working WEb monitoring...
  4. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You should write it for new API
  5. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    I still don't get the whole "new" and "old" api stuff. Everyone should refer to the "new" api as "the api" and the "old API" as "the old API".
    Smarticles101 likes this.
  6. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    It has been a while since the API has released, everyone should be used to it by now. (Example)
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is a whole year now. Don't you think it is just a bit too old?
    iksaku likes this.
  8. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    A lot of Chinese only play on OLD API u know?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then it's their own problem. Old API is no longer supported by this community (generally).

    I am Chinese too (Hong Kong Chinese), and I am strongly against the old API.
    iksaku and hoyinm14mc like this.
  10. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    内存啊大哥,现在中国怎么坑,开个500m的10人50一个月
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then don't use them.
  12. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    你介绍一个好点的,thx
  13. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    大陸人又outdate又固執,不能怪人們在沙田(香港)的反自由行行動:)
    (可能我也偏激了一點...)
  14. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    501
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Old API 大勢已去,為何要這様留戀?
    PEMapModder likes this.
  15. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    不不不....我只是找你介绍一个好点的vps或者专门的客户端....内存大点就ok,只玩old api是因为地图内存小,可以导入地图, NEW API are infinite world u know, and when i instal the map, it will became void *_*
  16. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    香港大部分地方我都去过,也会说广东话.....那个什么反自由行就...IDK,了可能当时我来美国没怎么关注...
  17. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    ホルヘ アレハンドロ ゴンザレス ゲラ :3
    hoyinm14mc likes this.
  18. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    It is not Chinese :D
    A PERSON name?
  19. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    I know xD it's my name in japanese
    EvolSoft, hoyinm14mc and xiaoq like this.
  20. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    wow

Share This Page

Advertisement