448 $this->isActive =
true;
449 $this->lastUpdate = microtime(
true);
450 if($this->state === self::STATE_CONNECTED or $this->state === self::STATE_CONNECTING_2){
451 if($packet::$ID >= 0x80 and $packet::$ID <= 0x8f and $packet instanceof DataPacket){
454 if($packet->seqNumber < $this->windowStart or $packet->seqNumber > $this->windowEnd or isset($this->receivedWindow[$packet->seqNumber])){
458 $diff = $packet->seqNumber - $this->lastSeqNumber;
460 unset($this->NACKQueue[$packet->seqNumber]);
461 $this->ACKQueue[$packet->seqNumber] = $packet->seqNumber;
462 $this->receivedWindow[$packet->seqNumber] = $packet->seqNumber;
465 for($i = $this->lastSeqNumber + 1; $i < $packet->seqNumber; ++$i){
466 if(!isset($this->receivedWindow[$i])){
467 $this->NACKQueue[$i] = $i;
473 $this->lastSeqNumber = $packet->seqNumber;
474 $this->windowStart += $diff;
475 $this->windowEnd += $diff;
478 foreach($packet->packets as $pk){
479 $this->handleEncapsulatedPacket($pk);
482 if($packet instanceof ACK){
484 foreach($packet->packets as $seq){
485 if(isset($this->recoveryQueue[$seq])){
486 foreach($this->recoveryQueue[$seq]->packets as $pk){
487 if($pk instanceof EncapsulatedPacket and $pk->needACK and $pk->messageIndex !== null){
488 unset($this->needACK[$pk->identifierACK][$pk->messageIndex]);
491 unset($this->recoveryQueue[$seq]);
494 }elseif($packet instanceof NACK){
496 foreach($packet->packets as $seq){
497 if(isset($this->recoveryQueue[$seq])){
498 $pk = $this->recoveryQueue[$seq];
499 $pk->seqNumber = $this->sendSeqNumber++;
500 $this->packetToSend[] = $pk;
501 unset($this->recoveryQueue[$seq]);
507 }elseif($packet::$ID > 0x00 and $packet::$ID < 0x80){
509 if($packet instanceof OPEN_CONNECTION_REQUEST_1){
511 $pk =
new OPEN_CONNECTION_REPLY_1();
512 $pk->mtuSize = $packet->mtuSize;
513 $pk->serverID = $this->sessionManager->getID();
514 $this->sendPacket($pk);
515 $this->state = self::STATE_CONNECTING_1;
516 }elseif($this->state === self::STATE_CONNECTING_1 and $packet instanceof OPEN_CONNECTION_REQUEST_2){
517 $this->
id = $packet->clientID;
518 if($packet->serverPort === $this->sessionManager->getPort() or !$this->sessionManager->portChecking){
519 $this->mtuSize = min(abs($packet->mtuSize), 1464);
520 $pk =
new OPEN_CONNECTION_REPLY_2();
521 $pk->mtuSize = $this->mtuSize;
522 $pk->serverID = $this->sessionManager->getID();
523 $pk->clientAddress = $this->address;
524 $pk->clientPort = $this->port;
525 $this->sendPacket($pk);
526 $this->state = self::STATE_CONNECTING_2;