-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.php
57 lines (57 loc) · 1.85 KB
/
proxy.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/** @noinspection PhpComposerExtensionStubsInspection */
echo "Phpcraft Proxy Server\n\n";
if(empty($argv))
{
die("This is for PHP-CLI. Connect to your server via SSH and use `php proxy.php`.\n");
}
require "vendor/autoload.php";
use Asyncore\
{Asyncore, stdin};
use Phpcraft\
{Account, ChatComponent, ClientConnection, Event\ProxyJoinEvent, PluginManager, ProxyServer, Versions};
echo "Would you like to provide an account to be possesed? [y/N] ";
stdin::init(null, false);
if(stdin::getNextLine() == "y")
{
$account = Account::cliLogin();
echo "Authenticated as {$account->username}.\n";
}
$server = new ProxyServer("Phpcraft Proxy", [
"groups" => [
"default" => [
"allow" => "everything"
]
]
], null, null);
echo "Loading plugins...\n";
PluginManager::$command_prefix = "/proxy:";
PluginManager::loadPlugins();
echo "Loaded ".count(PluginManager::$loaded_plugins)." plugin(s).\n";
$server->join_function = function(ClientConnection $con) use (&$account, &$server)
{
if(!Versions::protocolSupported($con->protocol_version))
{
$con->disconnect("You're using an incompatible version.");
return;
}
if(PluginManager::fire(new ProxyJoinEvent($server, $con)))
{
$con->close();
return;
}
$server->connectToIntegratedServer($con);
$con->startPacket("clientbound_chat_message");
if($account instanceof Account)
{
$con->writeChat(ChatComponent::text("Welcome to this Phpcraft proxy, ".$con->username.". This proxy is authenticated as ".$account->username.". Use /proxy:connect <ip> to connect to a Minecraft server."));
}
else
{
$con->writeChat(ChatComponent::text("Welcome to this Phpcraft proxy, ".$con->username.". Use /proxy:connect <ip> <username> to connect to a reverse proxy-compatible server."));
}
$con->writeByte(1);
$con->send();
};
Asyncore::loop();
echo "Proxy is not listening on any ports and has no clients, so it's shutting down.\n";