-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path11-debug.php
More file actions
110 lines (87 loc) · 3.63 KB
/
11-debug.php
File metadata and controls
110 lines (87 loc) · 3.63 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
use Clue\React\Quassel\Factory;
use Clue\React\Quassel\Client;
use Clue\React\Quassel\Models\BufferInfo;
require __DIR__ . '/../vendor/autoload.php';
$host = '127.0.0.1';
$user = array();
if (isset($argv[1])) { $host = $argv[1]; }
echo 'Server: ' . $host . PHP_EOL;
echo 'User name: ';
$user['name'] = trim(fgets(STDIN));
echo 'Password: ';
$user['password'] = trim(fgets(STDIN));
$factory = new Factory();
echo '[1/5] Connecting' . PHP_EOL;
$factory->createClient($host)->then(function (Client $client) use ($user) {
echo '[2/5] Connected, now initializing' . PHP_EOL;
$client->writeClientInit();
$client->on('data', function ($message) use ($client, $user) {
if (is_array($message) && isset($message[3]->IrcUsersAndChannels)) {
// print network information except for huge users/channels list
$debug = $message;
$debug[3] = clone $debug[3];
unset($debug[3]->IrcUsersAndChannels);
echo 'Debug (shortened): ' . json_encode($debug, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE) . PHP_EOL;
} else {
echo 'Debug: ' . json_encode($message, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE) . PHP_EOL;
}
$type = null;
if (isset($message->MsgType)) {
$type = $message->MsgType;
}
if ($type === 'ClientInitAck') {
if (!$message->Configured) {
echo '[3/5] Initialization done, but core is not configured yet, you may want to issue a setup call manually' . PHP_EOL;
print_r($message->StorageBackends);
echo 'Hit enter to set-up server with defaults, otherwise cancel program now';
fgets(STDIN);
$client->writeCoreSetupData($user['name'], $user['password']);
return;
}
echo '[3/5] Initialized, now logging in' . PHP_EOL;
$client->writeClientLogin($user['name'], $user['password']);
return;
}
if ($type === 'CoreSetupAck') {
echo '[3/5] Core successfully configured, now logging in' . PHP_EOL;
$client->writeClientLogin($user['name'], $user['password']);
return;
}
if ($type === 'CoreSetupReject') {
echo '[3/5] Failed to set up core! ' . $message['Error'] . PHP_EOL;
$client->close();
return;
}
if ($type === 'ClientLoginReject') {
echo '[4/5] Failed to log in! ' . $message['Error'] . PHP_EOL;
$client->close();
return;
}
if ($type === 'ClientLoginAck') {
echo '[4/5] Logged in, now waiting for session' . PHP_EOL;
return;
}
if ($type === 'SessionInit') {
echo '[5/5] Session initialized, we are ready to go!' . PHP_EOL;
foreach ($message->SessionState->NetworkIds as $nid) {
var_dump('requesting Network for ' . $nid . ', this may take a few seconds');
$client->writeInitRequest("Network", $nid);
}
foreach ($message->SessionState->BufferInfos as $buffer) {
assert($buffer instanceof BufferInfo);
if ($buffer->type === BufferInfo::TYPE_CHANNEL) {
var_dump('requesting IrcChannel for ' . $buffer->name);
$client->writeInitRequest('IrcChannel', $buffer->networkId . '/' . $buffer->id);
}
}
return;
}
});
$client->on('error', 'printf');
$client->on('close', function () {
echo 'Connection closed' . PHP_EOL;
});
})->then(null, function ($e) {
echo $e;
});