3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Minecraft Server Status Class * @copyright © 2011 Nox Nebula - Patrick Kleinschmidt * @website https://github.com/NoxNebula/MC-Server-Status * @license GNU Public Licence - Version 3 * @author Nox Nebula - Patrick Kleinschmidt * @author Alexey Kachalov **/ class ms { private $Socket, $Info, $to; public $Online, $MOTD, $CurPlayers, $MaxPlayers, $IP, $Port, $Error; public function __construct($IP, $Port = '25565', $timeout='0.5') { $this->IP = $IP; $this->Port = $Port; $this->to = $timeout; // Remove any protocols from serveraddress if(preg_match('/(.*):\/\//', $this->IP)) { $this->IP = preg_replace('/(.*):\/\//', '', $this->IP); } if(strpos($this->IP, '/') !== false) { $this->IP = rtrim($this->IP, '/'); if(strpos($this->IP, '/') !== false) { $this->Failed(); $this->Error = 'Unsupported IP/Domain format, no \'/\'s allowed'; return; } } if(preg_match_all('/:/', $this->IP, $matches) > 1) { unset($matches); // IP6 if(strpos($this->IP, '[') === false && strpos($this->IP, ']') === false) $this->IP = '['.$this->IP.']'; } else if(strpos($this->IP, ':') !== false) { $this->Failed(); $this->Error = 'Unsupported IP/Domain format'; return; } if($this->Socket = @stream_socket_client('tcp://'.$this->IP.':'.$Port, $ErrNo, $ErrStr, $this->to)) { // If IP6 remove brackets if(strpos($this->IP, '[') === 0 && strpos($this->IP, ']') === (strlen($this->IP) - 1)) $this->IP = trim($this->IP, '[]'); $this->Online = true; fwrite($this->Socket, "\xfe"); $Handle = fread($this->Socket, 2048); //$Handle = str_replace("\x00", '', $Handle); //$Handle = substr($Handle, 2); //$this->Info = explode("\xa7", $Handle); // Separate Infos /*if(sizeof($this->Info) == 3) { $this->MOTD = $this->Info[0]; $this->CurPlayers = (int)$this->Info[1]; $this->MaxPlayers = (int)$this->Info[2]; $this->Error = false; } else if(sizeof($this->Info) > 3) { // Handle error, Minecraft don't handle this. $Temp = ''; for($i = 0; $i < sizeof($this->Info) - 2; $i++) { $Temp .= ($i > 0 ? '§' : '').$this->Info[$i]; } $this->MOTD = $Temp; $this->CurPlayers = (int)$this->Info[sizeof($this->Info) - 2]; $this->MaxPlayers = (int)$this->Info[sizeof($this->Info) - 1]; $this->Error = 'Faulty motd or outdated script'; } else { $this->Failed(); $this->Error = 'Unexpected error, cause may be an outdated script'; }*/ $Handle = substr($Handle, 1); if(strpos($Handle, "\x00\x00")!=0) { $Handle = explode("\x00\x00", $Handle); $Handle = str_replace("\x00", '', $Handle); $this->MOTD = $Handle[3]; $this->CurPlayers = $Handle[4]; $this->MaxPlayers = $Handle[5]; $this->Error = false; } else { $Handle = explode("\xa7", $Handle); $Handle = str_replace("\x00", '', $Handle); $this->MOTD = $Handle[0]; $this->CurPlayers = $Handle[1]; $this->MaxPlayers = $Handle[2]; $this->Error = false; } unset($Handle); fclose($this->Socket); } else { $this->Online = false; $this->Failed(); $this->Error = 'Can not reach the server'; } } public function Info() { return array( 'MOTD' => $this->MOTD, 'CurPlayers' => $this->CurPlayers, 'MaxPlayers' => $this->MaxPlayers ); } private function Failed() { $this->MOTD = false; $this->CurPlayers = false; $this->MaxPlayers = false; } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6s55K
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  118     0  E > > RETURN                                                   1

Class ms:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 49
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 49
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 79
Branch analysis from position: 57
2 jumps found. (Code = 46) Position 1 = 65, Position 2 = 72
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 78
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 107, Position 2 = 207
Branch analysis from position: 107
2 jumps found. (Code = 46) Position 1 = 114, Position 2 = 124
Branch analysis from position: 114
2 jumps found. (Code = 43) Position 1 = 125, Position 2 = 132
Branch analysis from position: 125
2 jumps found. (Code = 43) Position 1 = 156, Position 2 = 179
Branch analysis from position: 156
1 jumps found. (Code = 42) Position 1 = 201
Branch analysis from position: 201
1 jumps found. (Code = 42) Position 1 = 213
Branch analysis from position: 213
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 179
1 jumps found. (Code = 42) Position 1 = 213
Branch analysis from position: 213
Branch analysis from position: 132
Branch analysis from position: 124
Branch analysis from position: 207
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
Branch analysis from position: 72
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 91
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 91
Branch analysis from position: 49
Branch analysis from position: 23
filename:       /in/6s55K
function name:  __construct
number of ops:  214
compiled vars:  !0 = $IP, !1 = $Port, !2 = $timeout, !3 = $matches, !4 = $ErrNo, !5 = $ErrStr, !6 = $Handle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '25565'
          2        RECV_INIT                                        !2      '0.5'
   16     3        ASSIGN_OBJ                                               'IP'
          4        OP_DATA                                                  !0
   17     5        ASSIGN_OBJ                                               'Port'
          6        OP_DATA                                                  !1
   18     7        ASSIGN_OBJ                                               'to'
          8        OP_DATA                                                  !2
   21     9        INIT_FCALL                                               'preg_match'
         10        SEND_VAL                                                 '%2F%28.%2A%29%3A%5C%2F%5C%2F%2F'
         11        FETCH_OBJ_R                                      ~10     'IP'
         12        SEND_VAL                                                 ~10
         13        DO_ICALL                                         $11     
         14      > JMPZ                                                     $11, ->23
   22    15    >   INIT_FCALL                                               'preg_replace'
         16        SEND_VAL                                                 '%2F%28.%2A%29%3A%5C%2F%5C%2F%2F'
         17        SEND_VAL                                                 ''
         18        FETCH_OBJ_R                                      ~13     'IP'
         19        SEND_VAL                                                 ~13
         20        DO_ICALL                                         $14     
         21        ASSIGN_OBJ                                               'IP'
         22        OP_DATA                                                  $14
   24    23    >   INIT_FCALL                                               'strpos'
         24        FETCH_OBJ_R                                      ~15     'IP'
         25        SEND_VAL                                                 ~15
         26        SEND_VAL                                                 '%2F'
         27        DO_ICALL                                         $16     
         28        TYPE_CHECK                                  1018          $16
         29      > JMPZ                                                     ~17, ->49
   25    30    >   INIT_FCALL                                               'rtrim'
         31        FETCH_OBJ_R                                      ~19     'IP'
         32        SEND_VAL                                                 ~19
         33        SEND_VAL                                                 '%2F'
         34        DO_ICALL                                         $20     
         35        ASSIGN_OBJ                                               'IP'
         36        OP_DATA                                                  $20
   26    37        INIT_FCALL                                               'strpos'
         38        FETCH_OBJ_R                                      ~21     'IP'
         39        SEND_VAL                                                 ~21
         40        SEND_VAL                                                 '%2F'
         41        DO_ICALL                                         $22     
         42        TYPE_CHECK                                  1018          $22
         43      > JMPZ                                                     ~23, ->49
   27    44    >   INIT_METHOD_CALL                                         'Failed'
         45        DO_FCALL                                      0          
   28    46        ASSIGN_OBJ                                               'Error'
         47        OP_DATA                                                  'Unsupported+IP%2FDomain+format%2C+no+%27%2F%27s+allowed'
   29    48      > RETURN                                                   null
   32    49    >   INIT_FCALL                                               'preg_match_all'
         50        SEND_VAL                                                 '%2F%3A%2F'
         51        FETCH_OBJ_R                                      ~26     'IP'
         52        SEND_VAL                                                 ~26
         53        SEND_REF                                                 !3
         54        DO_ICALL                                         $27     
         55        IS_SMALLER                                               1, $27
         56      > JMPZ                                                     ~28, ->79
   33    57    >   UNSET_CV                                                 !3
   35    58        INIT_FCALL                                               'strpos'
         59        FETCH_OBJ_R                                      ~29     'IP'
         60        SEND_VAL                                                 ~29
         61        SEND_VAL                                                 '%5B'
         62        DO_ICALL                                         $30     
         63        TYPE_CHECK                                    4  ~31     $30
         64      > JMPZ_EX                                          ~31     ~31, ->72
         65    >   INIT_FCALL                                               'strpos'
         66        FETCH_OBJ_R                                      ~32     'IP'
         67        SEND_VAL                                                 ~32
         68        SEND_VAL                                                 '%5D'
         69        DO_ICALL                                         $33     
         70        TYPE_CHECK                                    4  ~34     $33
         71        BOOL                                             ~31     ~34
         72    > > JMPZ                                                     ~31, ->78
   36    73    >   FETCH_OBJ_R                                      ~36     'IP'
         74        CONCAT                                           ~37     '%5B', ~36
         75        CONCAT                                           ~38     ~37, '%5D'
         76        ASSIGN_OBJ                                               'IP'
         77        OP_DATA                                                  ~38
         78    > > JMP                                                      ->91
   37    79    >   INIT_FCALL                                               'strpos'
         80        FETCH_OBJ_R                                      ~39     'IP'
         81        SEND_VAL                                                 ~39
         82        SEND_VAL                                                 '%3A'
         83        DO_ICALL                                         $40     
         84        TYPE_CHECK                                  1018          $40
         85      > JMPZ                                                     ~41, ->91
   38    86    >   INIT_METHOD_CALL                                         'Failed'
         87        DO_FCALL                                      0          
   39    88        ASSIGN_OBJ                                               'Error'
         89        OP_DATA                                                  'Unsupported+IP%2FDomain+format'
   40    90      > RETURN                                                   null
   43    91    >   BEGIN_SILENCE                                    ~45     
         92        INIT_FCALL                                               'stream_socket_client'
         93        FETCH_OBJ_R                                      ~46     'IP'
         94        CONCAT                                           ~47     'tcp%3A%2F%2F', ~46
         95        CONCAT                                           ~48     ~47, '%3A'
         96        CONCAT                                           ~49     ~48, !1
         97        SEND_VAL                                                 ~49
         98        SEND_REF                                                 !4
         99        SEND_REF                                                 !5
        100        FETCH_OBJ_R                                      ~50     'to'
        101        SEND_VAL                                                 ~50
        102        DO_ICALL                                         $51     
        103        END_SILENCE                                              ~45
        104        ASSIGN_OBJ                                       ~44     'Socket'
        105        OP_DATA                                                  $51
        106      > JMPZ                                                     ~44, ->207
   45   107    >   INIT_FCALL                                               'strpos'
        108        FETCH_OBJ_R                                      ~52     'IP'
        109        SEND_VAL                                                 ~52
        110        SEND_VAL                                                 '%5B'
        111        DO_ICALL                                         $53     
        112        IS_IDENTICAL                                     ~54     $53, 0
        113      > JMPZ_EX                                          ~54     ~54, ->124
        114    >   INIT_FCALL                                               'strpos'
        115        FETCH_OBJ_R                                      ~55     'IP'
        116        SEND_VAL                                                 ~55
        117        SEND_VAL                                                 '%5D'
        118        DO_ICALL                                         $56     
        119        FETCH_OBJ_R                                      ~57     'IP'
        120        STRLEN                                           ~58     ~57
        121        SUB                                              ~59     ~58, 1
        122        IS_IDENTICAL                                     ~60     $56, ~59
        123        BOOL                                             ~54     ~60
        124    > > JMPZ                                                     ~54, ->132
   46   125    >   INIT_FCALL                                               'trim'
        126        FETCH_OBJ_R                                      ~62     'IP'
        127        SEND_VAL                                                 ~62
        128        SEND_VAL                                                 '%5B%5D'
        129        DO_ICALL                                         $63     
        130        ASSIGN_OBJ                                               'IP'
        131        OP_DATA                                                  $63
   48   132    >   ASSIGN_OBJ                                               'Online'
        133        OP_DATA                                                  <true>
   50   134        INIT_FCALL                                               'fwrite'
        135        FETCH_OBJ_R                                      ~65     'Socket'
        136        SEND_VAL                                                 ~65
        137        SEND_VAL                                                 '%FE'
        138        DO_ICALL                                                 
   51   139        INIT_FCALL                                               'fread'
        140        FETCH_OBJ_R                                      ~67     'Socket'
        141        SEND_VAL                                                 ~67
        142        SEND_VAL                                                 2048
        143        DO_ICALL                                         $68     
        144        ASSIGN                                                   !6, $68
   75   145        INIT_FCALL                                               'substr'
        146        SEND_VAR                                                 !6
        147        SEND_VAL                                                 1
        148        DO_ICALL                                         $70     
        149        ASSIGN                                                   !6, $70
   76   150        INIT_FCALL                                               'strpos'
        151        SEND_VAR                                                 !6
        152        SEND_VAL                                                 '%00%00'
        153        DO_ICALL                                         $72     
        154        IS_NOT_EQUAL                                             $72, 0
        155      > JMPZ                                                     ~73, ->179
   78   156    >   INIT_FCALL                                               'explode'
        157        SEND_VAL                                                 '%00%00'
        158        SEND_VAR                                                 !6
        159        DO_ICALL                                         $74     
        160        ASSIGN                                                   !6, $74
   79   161        INIT_FCALL                                               'str_replace'
        162        SEND_VAL                                                 '%00'
        163        SEND_VAL                                                 ''
        164        SEND_VAR                                                 !6
        165        DO_ICALL                                         $76     
        166        ASSIGN                                                   !6, $76
   80   167        FETCH_DIM_R                                      ~79     !6, 3
        168        ASSIGN_OBJ                                               'MOTD'
        169        OP_DATA                                                  ~79
   81   170        FETCH_DIM_R                                      ~81     !6, 4
        171        ASSIGN_OBJ                                               'CurPlayers'
        172        OP_DATA                                                  ~81
   82   173        FETCH_DIM_R                                      ~83     !6, 5
        174        ASSIGN_OBJ                                               'MaxPlayers'
        175        OP_DATA                                                  ~83
   83   176        ASSIGN_OBJ                                               'Error'
        177        OP_DATA                                                  <false>
        178      > JMP                                                      ->201
   87   179    >   INIT_FCALL                                               'explode'
        180        SEND_VAL                                                 '%A7'
        181        SEND_VAR                                                 !6
        182        DO_ICALL                                         $85     
        183        ASSIGN                                                   !6, $85
   88   184        INIT_FCALL                                               'str_replace'
        185        SEND_VAL                                                 '%00'
        186        SEND_VAL                                                 ''
        187        SEND_VAR                                                 !6
        188        DO_ICALL                                         $87     
        189        ASSIGN                                                   !6, $87
   89   190        FETCH_DIM_R                                      ~90     !6, 0
        191        ASSIGN_OBJ                                               'MOTD'
        192        OP_DATA                                                  ~90
   90   193        FETCH_DIM_R                                      ~92     !6, 1
        194        ASSIGN_OBJ                                               'CurPlayers'
        195        OP_DATA                                                  ~92
   91   196        FETCH_DIM_R                                      ~94     !6, 2
        197        ASSIGN_OBJ                                               'MaxPlayers'
        198        OP_DATA                                                  ~94
   92   199        ASSIGN_OBJ                                               'Error'
        200        OP_DATA                                                  <false>
   95   201    >   UNSET_CV                                                 !6
   96   202        INIT_FCALL                                               'fclose'
        203        FETCH_OBJ_R                                      ~96     'Socket'
        204        SEND_VAL                                                 ~96
        205        DO_ICALL                                                 
        206      > JMP                                                      ->213
   98   207    >   ASSIGN_OBJ                                               'Online'
        208        OP_DATA                                                  <false>
   99   209        INIT_METHOD_CALL                                         'Failed'
        210        DO_FCALL                                      0          
  100   211        ASSIGN_OBJ                                               'Error'
        212        OP_DATA                                                  'Can+not+reach+the+server'
  102   213    > > RETURN                                                   null

End of function __construct

Function info:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6s55K
function name:  Info
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  106     0  E >   FETCH_OBJ_R                                      ~0      'MOTD'
          1        INIT_ARRAY                                       ~1      ~0, 'MOTD'
  107     2        FETCH_OBJ_R                                      ~2      'CurPlayers'
          3        ADD_ARRAY_ELEMENT                                ~1      ~2, 'CurPlayers'
  108     4        FETCH_OBJ_R                                      ~3      'MaxPlayers'
          5        ADD_ARRAY_ELEMENT                                ~1      ~3, 'MaxPlayers'
          6      > RETURN                                                   ~1
  110     7*     > RETURN                                                   null

End of function info

Function failed:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6s55K
function name:  Failed
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  113     0  E >   ASSIGN_OBJ                                               'MOTD'
          1        OP_DATA                                                  <false>
  114     2        ASSIGN_OBJ                                               'CurPlayers'
          3        OP_DATA                                                  <false>
  115     4        ASSIGN_OBJ                                               'MaxPlayers'
          5        OP_DATA                                                  <false>
  116     6      > RETURN                                                   null

End of function failed

End of class ms.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.51 ms | 1416 KiB | 39 Q