|
1
|
|
|
<?php |
|
2
|
|
|
namespace PHPDaemon\Clients\IRC; |
|
3
|
|
|
|
|
4
|
|
|
use PHPDaemon\Structures\ObjectStorage; |
|
5
|
|
|
use PHPDaemon\Utils\IRC; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @package NetworkClients |
|
9
|
|
|
* @subpackage IRCClient |
|
10
|
|
|
* @author Vasily Zorin <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class Channel extends ObjectStorage |
|
13
|
|
|
{ |
|
14
|
|
|
use \PHPDaemon\Traits\EventHandlers; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var Connection |
|
18
|
|
|
*/ |
|
19
|
|
|
public $irc; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public $name; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
public $nicknames = []; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var |
|
33
|
|
|
*/ |
|
34
|
|
|
public $self; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
public $type; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
public $topic; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Connection $irc |
|
48
|
|
|
* @param string $name |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct($irc, $name) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->irc = $irc; |
|
53
|
|
|
$this->name = $name; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @TODO DESCR |
|
58
|
|
|
*/ |
|
59
|
|
|
public function who() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->irc->command('WHO', $this->name); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @TODO DESCR |
|
66
|
|
|
* @param array|string $mask |
|
67
|
|
|
* @param mixed $msg |
|
68
|
|
|
*/ |
|
69
|
|
|
public function onPart($mask, $msg = null) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
if (is_string($mask)) { |
|
72
|
|
|
$mask = IRC::parseUsermask($mask); |
|
73
|
|
|
} |
|
74
|
|
|
if (($mask['nick'] === $this->irc->nick) && ($mask['user'] === $this->irc->user)) { |
|
|
|
|
|
|
75
|
|
|
$this->destroy(); |
|
76
|
|
|
} else { |
|
77
|
|
|
unset($this->nicknames[$mask['nick']]); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @TODO DESCR |
|
83
|
|
|
*/ |
|
84
|
|
|
public function destroy() |
|
85
|
|
|
{ |
|
86
|
|
|
unset($this->irc->channels[$this->name]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @TODO DESCR |
|
91
|
|
|
* @param string $type |
|
92
|
|
|
*/ |
|
93
|
|
|
public function setChanType($type) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->type = $type; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @TODO DESCR |
|
100
|
|
|
* @return array |
|
101
|
|
|
*/ |
|
102
|
|
|
public function exportNicksArray() |
|
103
|
|
|
{ |
|
104
|
|
|
$nicks = []; |
|
105
|
|
|
foreach ($this as $participant) { |
|
106
|
|
|
$nicks[] = $participant->flag . $participant->nick; |
|
107
|
|
|
} |
|
108
|
|
|
return $nicks; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @TODO DESCR |
|
113
|
|
|
* @param string $msg |
|
114
|
|
|
*/ |
|
115
|
|
|
public function setTopic($msg) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->topic = $msg; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @TODO DESCR |
|
122
|
|
|
* @param string $nick |
|
123
|
|
|
* @param string $mode |
|
124
|
|
|
*/ |
|
125
|
|
View Code Duplication |
public function addMode($nick, $mode) |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
|
|
if (!isset($this->nicknames[$nick])) { |
|
128
|
|
|
return; |
|
129
|
|
|
} |
|
130
|
|
|
$participant = $this->nicknames[$nick]; |
|
131
|
|
|
if (mb_orig_strpos($participant->mode, $mode) === false) { |
|
132
|
|
|
$participant->mode .= $mode; |
|
133
|
|
|
} |
|
134
|
|
|
$participant->onModeUpdate(); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @TODO DESCR |
|
139
|
|
|
* @param string $target |
|
140
|
|
|
* @param string $mode |
|
141
|
|
|
*/ |
|
142
|
|
View Code Duplication |
public function removeMode($target, $mode) |
|
|
|
|
|
|
143
|
|
|
{ |
|
144
|
|
|
if (!isset($this->nicknames[$target])) { |
|
145
|
|
|
return; |
|
146
|
|
|
} |
|
147
|
|
|
$participant = $this->nicknames[$target]; |
|
148
|
|
|
$participant->mode = str_replace($mode, '', $participant->mode); |
|
149
|
|
|
$participant->onModeUpdate(); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @TODO DESCR |
|
154
|
|
|
*/ |
|
155
|
|
|
public function join() |
|
156
|
|
|
{ |
|
157
|
|
|
$this->irc->join($this->name); |
|
|
|
|
|
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @TODO DESCR |
|
162
|
|
|
* @param mixed $msg |
|
163
|
|
|
*/ |
|
164
|
|
|
public function part($msg = null) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->irc->part($this->name, $msg); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @TODO DESCR |
|
171
|
|
|
* @param string $type |
|
172
|
|
|
* @return $this |
|
173
|
|
|
*/ |
|
174
|
|
|
public function setType($type) |
|
175
|
|
|
{ |
|
176
|
|
|
$this->type = $type; |
|
177
|
|
|
return $this; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @TODO DESCR |
|
182
|
|
|
* @param object $obj |
|
183
|
|
|
*/ |
|
184
|
|
|
public function detach($obj) |
|
185
|
|
|
{ |
|
186
|
|
|
parent::detach($obj); |
|
187
|
|
|
unset($this->nicknames[$obj->nick]); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.