Пример #1
0
 //is the [buffer data] (full size - packet header)
 //greater OR equal the [capsule data] length we have been told earlier?
 if ($BUFFER->size() - 5 >= $length) {
     if ($VERBOSE) {
         echo 'Enough bytes, processing...' . "\n";
     }
     //Awesome we have enough bytes now :D
     //Lets continue the "so waited" code part
     //Copy the 5+length first bytes from the buffer to $CAPSULE.
     $CAPSULE = new ByteArray();
     $CAPSULE->append(substr($BUFFER->getBuffer(), 5, $length));
     //position to 5 and read length bytes
     //PROCESS THE CAPSULE (switch and stuff)
     //-----------------------------------------------
     if ($VERBOSE) {
         echo 'Capsule: ' . $CAPSULE->getBuffer() . "\n";
     }
     while (true) {
         //a loop to parse all CMDs in the capsule
         switch ($CAPSULE->readWord()) {
             //-------------------------
             case PCKT_R_WORLD_EOF:
                 echo '[capsuleHandler] End of world server list' . "\n";
                 break;
                 //-------------------------
             //-------------------------
             case PCKT_R_WORLD:
                 echo '[capsuleHandler] New world server' . "\n";
                 $ipv4 = $CAPSULE->readString();
                 $port = $CAPSULE->readWord();
                 $name = $CAPSULE->readString();