]>
Commit | Line | Data |
---|---|---|
e6274ac9 VP |
1 | <?php |
2 | ||
3 | ||
4 | /** | |
5 | * Does a complete checkup of the network. | |
6 | */ | |
7 | class CheckUp | |
8 | { | |
9 | public $num_of_problems = [ | |
10 | "chanmodes" => 0, | |
11 | "usermodes" => 0, | |
12 | "modules" => 0, | |
13 | "other" => 0, | |
14 | ]; | |
15 | public $problems = [ | |
16 | "chanmodes" => [], | |
17 | "usermodes" => [], | |
18 | "modules" => [], | |
19 | "other" => [], | |
20 | ]; | |
21 | ||
22 | public $serverlist = []; | |
23 | ||
24 | /** | |
25 | * Construct0r | |
26 | */ | |
27 | function __construct() | |
28 | { | |
29 | global $rpc; | |
30 | ||
31 | $this->serverlist = $rpc->server()->getAll(); | |
32 | $this->chanmode_check(); | |
33 | $this->usermode_check(); | |
34 | //$this->module_check(); | |
35 | ||
36 | } | |
37 | ||
38 | /** | |
39 | * Checks channel modes of servers against other servers | |
40 | * @return void | |
41 | */ | |
42 | function chanmode_check() : void | |
43 | { | |
44 | foreach($this->serverlist as $s) // cycle through each server | |
45 | { | |
46 | /* make a single string from the array of groups */ | |
47 | $ourchmodes = ""; | |
48 | foreach ($s->server->features->chanmodes as $set) | |
49 | for ($i=0; isset($set[$i]); $i++) | |
50 | strcat($ourchmodes,$set[$i]); | |
51 | ||
52 | /* take a look at every other server... yep, we do this for every server */ | |
53 | foreach ($this->serverlist as $serv) | |
54 | { | |
55 | /* except for ourselves lol */ | |
56 | if ($serv->id == $s->id) | |
57 | continue; | |
58 | ||
59 | /* hmm if it's not unreal, skip it too */ | |
60 | if (!strstr($serv->server->features->software,"UnrealIRCd")) | |
61 | continue; | |
62 | ||
63 | /* make a single string from the array of groups but for them this time */ | |
64 | $theirchmodes = ""; | |
65 | foreach ($serv->server->features->chanmodes as $set) | |
66 | for ($i=0; isset($set[$i]); $i++) | |
67 | strcat($theirchmodes,$set[$i]); | |
68 | ||
69 | /* check ours against theirs */ | |
70 | for ($i=0; isset($ourchmodes[$i]) && $m = $ourchmodes[$i]; $i++) | |
71 | { | |
72 | /* if we have a mode that they don't have */ | |
73 | if (!strstr($theirchmodes, $m)) | |
74 | { | |
75 | ++$this->num_of_problems['chanmodes']; | |
76 | $this->problems['chanmodes'][] = "Channel mode $m is present on $s->name but missing on $serv->name"; | |
77 | } | |
78 | } | |
79 | } | |
80 | } | |
81 | } | |
82 | ||
83 | /** | |
84 | * Checks user modes of servers against other servers | |
85 | * @return void | |
86 | */ | |
87 | function usermode_check() : void | |
88 | { | |
89 | /* make a single string from the array of groups */ | |
90 | $ourumodes = $s->server->features->usermodes; | |
91 | ||
92 | /* take a look at every other server... yep, we do this for every server */ | |
93 | foreach ($this->serverlist as $serv) | |
94 | { | |
95 | /* except for ourselves lol */ | |
96 | if ($serv->id == $s->id) | |
97 | continue; | |
98 | ||
99 | /* hmm if it's not unreal, skip it too */ | |
100 | if (!strstr($serv->server->features->software,"UnrealIRCd")) | |
101 | continue; | |
102 | ||
103 | $theirumodes = $serv->server->features->usermodes; | |
104 | ||
105 | /* check ours against theirs */ | |
106 | for ($i=0; isset($ourumodes[$i]) && $m = $ourumodes[$i]; $i++) | |
107 | { | |
108 | /* if we have a mode that they don't have */ | |
109 | if (!strstr($theirumodes, $m)) | |
110 | { | |
111 | ++$this->num_of_problems['usermodes']; | |
112 | $this->problems['usermodes'][] = "User mode $m is present on $s->name but missing on $serv->name"; | |
113 | } | |
114 | } | |
115 | } | |
116 | } | |
117 | ||
118 | /** | |
119 | * Checks modules of servers against other servers | |
120 | * @return void | |
121 | */ | |
122 | function module_check() : void | |
123 | { | |
124 | global $rpc; | |
125 | $modlist = []; | |
126 | $modarray = []; | |
127 | foreach ($this->serverlist as $serv) | |
128 | $modlist[$serv->name] = json_decode(json_encode($rpc->server()->module_list($serv->id)->list), true); | |
129 | ||
130 | echo highlight_string(var_export($modlist,true)); | |
131 | } | |
132 | } |