<commit_before><?php
/*
* BloonJPHP
* Habbo R63 Post-Shuffle
* Based on the work of Burak (<EMAIL>)
*
* https://bloon.burak.fr/ - https://github.com/BurakDev/BloonJPHP
*/
use php\lang\ThreadPool;
use php\io\IOException;
use php\lang\Environment;
use php\net\ServerSocket;
use php\lib\String;

require('res://class/Autoloader.php');

Autoloader::loadClass();

$config = new Config;
$network = new Network;
$rsa = new RSA;
$headermanager = new HeaderManager;

$headermanager->LoadHeader("PRODUCTION-201506161211-776084490");

$config->init("res://habbo.conf");

$rsa->SetPrivate($config->get("crypto.rsaN"), $config->get("crypto.rsaE"), $config->get("crypto.rsaD"));

$pooling = new DatabasePooling($config->get("db.hostname"), $config->get("db.port"), $config->get("db.username"), $config->get("db.password"), $config->get("db.name"), $config->get("db.pool.minsize"), $config->get("db.pool.maxsize"));

$database = new Database();
$database->pool = &$pooling;

$cache = new CacheLoader($database);

$events = array();

Autoloader::loadEvents();

Console::WriteLine("Loaded ".count($events)." events !");
$server = new ServerSocket();
$server->bind($config->get("game.tcp.bindip"), $config->get("game.tcp.port"));
$service = ThreadPool::createFixed($config->get("game.tcp.conlimit"));

$index = new IndexManager();

Console::WriteLine("Server -> READY! (".$config->get("game.tcp.bindip").":".$config->get("game.tcp.port").")");

$environment = new Environment();
foreach(Autoloader::$class as $class){
    $environment->importClass($class);
}

foreach(Autoloader::$events as $event){
    $environment->importClass($event);
}

while(true){
    $socket = $server->accept();
    $user = new User($socket, $socket->getAddress(), $socket->getPort());
    $index->socket[$user->socketid] = &$user;

    $util = new ClassContainer();
    $util->index = &$index;
    $util->HeaderManager = &$headermanager;
    $util->RSA = &$rsa;
    $util->Database = &$database;
    $util->Cache = &$cache;
    $util->Config = &$config;

    $service->execute (function () use ($user, $events, $util) {
        ob_implicit_flush(true);

        while($buffer = $user->socketInput->read(4096)){
            if ($buffer == "<policy-file-request/>" . chr(0)) {
                $user->send(Util::Crossdomain());
                continue;
            }
            
            $buffer = String::decode($buffer, 'ISO-8859-1');

            if ($user->rc4initialized) {
                $buffer = $user->rc4client->Parse($buffer);
            }

            foreach (BufferManager::Parser($buffer) as $packet) {
                $packet = new PacketParser($packet);

                $header = $packet->getHeader();

                if (isset($events[$header])) {
                    eval($events[$header]["parent"].'::'.$events[$header]["method"].'($user, $packet, $util);');
                    Console::WriteLine("- Executed event for " . $header . " (" . $events[$header]["parent"] . '::' . $events[$header]["method"] . ") ");
                }else{
                    Console::WriteLine("- Not found event for " . $header . " : " . $packet->getFullPacket());
                }
            }
        }
        
        $user->disconnect();
        
    }, $environment);

}<commit_msg>Format bootstrap<commit_after><?php

/*
 * BloonJPHP
 * Habbo R63 Post-Shuffle
 * Based on the work of Burak (<EMAIL>)
 *
 * https://bloon.burak.fr/ - https://github.com/BurakDev/BloonJPHP
 */

use php\lang\ThreadPool;
use php\io\IOException;
use php\lang\Environment;
use php\net\ServerSocket;
use php\lib\String;

require('res://class/Autoloader.php');

Autoloader::loadClass();

$config = new Config;
$network = new Network;
$rsa = new RSA;
$headermanager = new HeaderManager;

$headermanager->LoadHeader("PRODUCTION-201506161211-776084490");

$config->init("res://habbo.conf");

$rsa->SetPrivate($config->get("crypto.rsaN"), $config->get("crypto.rsaE"), $config->get("crypto.rsaD"));

$pooling = new DatabasePooling($config->get("db.hostname"), $config->get("db.port"), $config->get("db.username"), $config->get("db.password"), $config->get("db.name"), $config->get("db.pool.minsize"), $config->get("db.pool.maxsize"));

$database = new Database();
$database->pool = &$pooling;

$cache = new CacheLoader($database);

$events = array();

Autoloader::loadEvents();

Console::WriteLine("Loaded " . count($events) . " events !");
$server = new ServerSocket();
$server->bind($config->get("game.tcp.bindip"), $config->get("game.tcp.port"));
$service = ThreadPool::createFixed($config->get("game.tcp.conlimit"));

$index = new IndexManager();

Console::WriteLine("Server -> READY! (" . $config->get("game.tcp.bindip") . ":" . $config->get("game.tcp.port") . ")");

$environment = new Environment();
foreach (Autoloader::$class as $class) {
    $environment->importClass($class);
}

foreach (Autoloader::$events as $event) {
    $environment->importClass($event);
}

while (true) {
    $socket = $server->accept();
    $user = new User($socket, $socket->getAddress(), $socket->getPort());
    $index->socket[$user->socketid] = &$user;

    $util = new ClassContainer();
    $util->index = &$index;
    $util->HeaderManager = &$headermanager;
    $util->RSA = &$rsa;
    $util->Database = &$database;
    $util->Cache = &$cache;
    $util->Config = &$config;

    $service->execute(function () use ($user, $events, $util) {
        ob_implicit_flush(true);

        while ($buffer = $user->socketInput->read(4096)) {
            if ($buffer == "<policy-file-request/>" . chr(0)) {
                $user->send(Util::Crossdomain());
                continue;
            }

            $buffer = String::decode($buffer, 'ISO-8859-1');

            if ($user->rc4initialized) {
                $buffer = $user->rc4client->Parse($buffer);
            }

            foreach (BufferManager::Parser($buffer) as $packet) {
                $packet = new PacketParser($packet);

                $header = $packet->getHeader();

                if (isset($events[$header])) {
                    eval($events[$header]["parent"] . '::' . $events[$header]["method"] . '($user, $packet, $util);');
                    Console::WriteLine("- Executed event for " . $header . " (" . $events[$header]["parent"] . '::' . $events[$header]["method"] . ") ");
                } else {
                    Console::WriteLine("- Not found event for " . $header . " : " . $packet->getFullPacket());
                }
            }
        }

        $user->disconnect();
    }, $environment);
}
{'fraction_non_alphanumeric': 0.21067157313707452, 'fraction_numerical': 0.010732904017172647, 'mean_word_length': 3.152132399745385, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 95, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '7458210', 'n_tokens_mistral': 2133, 'n_tokens_neox': 2033, 'n_words': 343}