<commit_before><?php

namespace ifteam\CustomPacket;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\event\Listener;
use pocketmine\Server;
use ifteam\CustomPacket\event\ReceivePacketEvent;
use ifteam\CustomPacket\event\SendPacketEvent;
use ifteam\CustomPacket\Packet\CustomPacket;
use pocketmine\scheduler\CallbackTask;

class MainLoader extends PluginBase implements Listener {

    /** @var CustomSocket */
    private $socket;
    private $option;
    private $socketManager;
	
	public $stream = null;
    
    private static $instance = null;
    
    public function onEnable() {
    	if(self::$instance == null)
    		self::$instance = $this;
        $defaultOption = [
            "interface" => "0.0.0.0",
            "port" => 19131
        ];
        $this->option = (new Config($this->getDataFolder() . "SocketOption.yml", Config::YAML, $defaultOption))->getAll();
        $this->socket = new CustomSocket($this, $this->option["interface"], $this->option["port"]);
		//$this->socketManager = new SocketManager($this->socket, $this);
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }
    public function onDisable(){
        $this->socket->close();
    }
    
    /** @return CustomPacket */
    /*
	public static function getInstance(){
    	return self::$instance;
    }
	*/
   
    /** @return int */
    public function getDefaultPort() {
        return $this->option["port"];
    }

    /**
     * ReceivePacket and callEvent ReceivePacketEvent
     * or ReceiveJSONPacketEvent (is_numeric check)
     *
     * @param int|string $data            
     * @param int $ip            
     * @param int $port            
     *
     */
    public function receivePacket($data, $ip, $port) {
        if(is_numeric($data)){
            $event = new ReceivePacketEvent($data, $ip, $port);
            $this->getServer()->getPluginManager()->callEvent($event);
        }else{
            $event = new ReceiveJSONPacketEvent(JSON_Decode($data), $ip, $port);
            $this->getServer()->getPluginManager()->callEvent($event);
        }
    }
    /**
     * SendPacket and callEvent SendPacketEvent
     * or SendJSONPacketEvent (is_numeric check)
     *
     * @param int|string $packet
     * @param string $ip            
     * @param int $port            
     *
     */
    public static function sendPacket($packet, $ip, $port) {
        if(is_numeric($packet)){
            $event = new SendPacketEvent($packet, $ip, $port);
            $this->getServer ()->getPluginManager ()->callEvent ($event);
            if(!$event->isCancelled()){
                $packet = $event->getPacket();
                $this->socket->writePacket($packet, $ip, $port);
            }
        }else{
            $event = new SendJSONPacketEvent($this, $packet, $ip, $port);
            $this->getServer()->getPluginManager()->callEvent($event);
            if(!$event->isCancelled()){
                $packet = JSON_Encode($event->getPacket());
                $this->socket->writePacket($packet, $ip, $port);
            }
        }
    }
	
	public function callEvent($type, array $data){
		switch($type){
			case 'recv':
				$this->getServer()->getPluginManager()->callEvent(new ReceivePacketEvent(new CustomPacket($data['rawstring']), $data['ip'], $data['port']));
				break;
			case 'send':
				$this->getServer()->getPluginManager()->callEvent(new SendPacketEvent($data['pk'], $data['ip'], $data['port']));
				break;
		}
		ob_start();
		var_dump($data);
		$dump = ob_get_clean();
		$this->getServer()->getLogger()->debug("[CustomPacket Event debug message]\n".$dump);
	}
}
?><commit_msg>Removed duplicate function of CustomSocket. (#15)<commit_after><?php

namespace ifteam\CustomPacket;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\event\Listener;
use pocketmine\Server;
use ifteam\CustomPacket\event\ReceivePacketEvent;
use ifteam\CustomPacket\event\SendPacketEvent;
use ifteam\CustomPacket\Packet\CustomPacket;
use pocketmine\scheduler\CallbackTask;

class MainLoader extends PluginBase implements Listener {

    /** @var CustomSocket */
    private $socket;
    private $option;
    private $socketManager;
	
	public $stream = null;
    
    private static $instance = null;
    
    public function onEnable() {
    	if(self::$instance == null)
    		self::$instance = $this;
        $defaultOption = [
            "interface" => "0.0.0.0",
            "port" => 19131
        ];
        $this->option = (new Config($this->getDataFolder() . "SocketOption.yml", Config::YAML, $defaultOption))->getAll();
        $this->socket = new CustomSocket($this, $this->option["interface"], $this->option["port"]);
		//$this->socketManager = new SocketManager($this->socket, $this);
        $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }
    public function onDisable(){
        $this->socket->close();
    }
    
    /** @return CustomPacket */
    /*
	public static function getInstance(){
    	return self::$instance;
    }
	*/
   
    /** @return int */
    public function getDefaultPort() {
        return $this->option["port"];
    }

	public function callEvent($type, array $data){
		switch($type){
			case 'recv':
				$this->getServer()->getPluginManager()->callEvent(new ReceivePacketEvent(new CustomPacket($data['rawstring']), $data['ip'], $data['port']));
				break;
			case 'send':
				$this->getServer()->getPluginManager()->callEvent(new SendPacketEvent($data['pk'], $data['ip'], $data['port']));
				break;
		}
		ob_start();
		var_dump($data);
		$dump = ob_get_clean();
		$this->getServer()->getLogger()->debug("[CustomPacket Event debug message]\n".$dump);
	}
}
?>
{'fraction_non_alphanumeric': 0.16368734665264634, 'fraction_numerical': 0.0035050823694356818, 'mean_word_length': 2.9742339832869082, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098155', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1670, 'n_words': 328}