mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
support php8019 and some cleanup (by @D-aHTuCT)
This commit is contained in:
parent
cf0f9df267
commit
b60f0877e1
376 changed files with 6528 additions and 13472 deletions
|
|
@ -1,38 +1,55 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
define("ASYNC_CURL_GET", 1);
|
||||
define("ASYNC_CURL_POST", 2);
|
||||
|
||||
class AsyncMultipleQueue extends Thread{
|
||||
|
||||
public $input;
|
||||
public $output;
|
||||
public $stop;
|
||||
|
||||
public function __construct(){
|
||||
$this->input = "";
|
||||
$this->output = "";
|
||||
$this->stop = false;
|
||||
$this->start();
|
||||
}
|
||||
|
||||
|
||||
public function run(){
|
||||
while($this->stop === false){
|
||||
if(isset($this->input[5])){ //len 6 min
|
||||
$rID = Utils::readInt($this->get(4));
|
||||
switch(Utils::readShort($this->get(2), false)){
|
||||
case ASYNC_CURL_GET:
|
||||
$url = $this->get(Utils::readShort($this->get(2), false));
|
||||
$timeout = Utils::readShort($this->get(2));
|
||||
|
||||
$res = (string) Utils::curl_get($url, $timeout);
|
||||
//$this->lock();
|
||||
$this->output .= Utils::writeInt($rID) . Utils::writeShort(ASYNC_CURL_GET) . Utils::writeInt(strlen($res)) . $res;
|
||||
//$this->unlock();
|
||||
break;
|
||||
case ASYNC_CURL_POST:
|
||||
$url = $this->get(Utils::readShort($this->get(2), false));
|
||||
$timeout = Utils::readShort($this->get(2));
|
||||
$cnt = Utils::readShort($this->get(2), false);
|
||||
$d = [];
|
||||
for($c = 0; $c < $cnt; ++$c){
|
||||
$key = $this->get(Utils::readShort($this->get(2), false));
|
||||
$d[$key] = $this->get(Utils::readInt($this->get(4), false));
|
||||
}
|
||||
$res = (string) Utils::curl_post($url, $d, $timeout);
|
||||
//$this->lock();
|
||||
$this->output .= Utils::writeInt($rID) . Utils::writeShort(ASYNC_CURL_POST) . Utils::writeInt(strlen($res)) . $res;
|
||||
//$this->unlock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
|
||||
private function get($len){
|
||||
$str = "";
|
||||
if($len <= 0){
|
||||
|
|
@ -48,65 +65,32 @@ class AsyncMultipleQueue extends Thread{
|
|||
$this->input = (string) substr($this->input, $offset);
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function run(){
|
||||
while($this->stop === false){
|
||||
if(isset($this->input[5])){ //len 6 min
|
||||
$rID = Utils::readInt($this->get(4));
|
||||
switch(Utils::readShort($this->get(2), false)){
|
||||
case ASYNC_CURL_GET:
|
||||
$url = $this->get(Utils::readShort($this->get(2), false));
|
||||
$timeout = Utils::readShort($this->get(2));
|
||||
|
||||
$res = (string) Utils::curl_get($url, $timeout);
|
||||
//$this->lock();
|
||||
$this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_CURL_GET).Utils::writeInt(strlen($res)).$res;
|
||||
//$this->unlock();
|
||||
break;
|
||||
case ASYNC_CURL_POST:
|
||||
$url = $this->get(Utils::readShort($this->get(2), false));
|
||||
$timeout = Utils::readShort($this->get(2));
|
||||
$cnt = Utils::readShort($this->get(2), false);
|
||||
$d = array();
|
||||
for($c = 0; $c < $cnt; ++$c){
|
||||
$key = $this->get(Utils::readShort($this->get(2), false));
|
||||
$d[$key] = $this->get(Utils::readInt($this->get(4), false));
|
||||
}
|
||||
$res = (string) Utils::curl_post($url, $d, $timeout);
|
||||
//$this->lock();
|
||||
$this->output .= Utils::writeInt($rID).Utils::writeShort(ASYNC_CURL_POST).Utils::writeInt(strlen($res)).$res;
|
||||
//$this->unlock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Async extends Thread{
|
||||
public function __construct($method, $params = array()){
|
||||
|
||||
public function __construct($method, $params = []){
|
||||
$this->method = $method;
|
||||
$this->params = $params;
|
||||
$this->result = null;
|
||||
$this->joined = false;
|
||||
}
|
||||
|
||||
public function run(){
|
||||
if(($this->result=call_user_func_array($this->method, $this->params))){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function call($method, $params = array()){
|
||||
public static function call($method, $params = []){
|
||||
$thread = new Async($method, $params);
|
||||
if($thread->start()){
|
||||
return $thread;
|
||||
}
|
||||
}
|
||||
|
||||
public function run(){
|
||||
if(($this->result = call_user_func_array($this->method, $this->params))){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
if(!$this->joined){
|
||||
$this->joined = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue