130 |
130 |
131 // Send nick and username |
131 // Send nick and username |
132 $this->put("NICK $nick\r\n"); |
132 $this->put("NICK $nick\r\n"); |
133 $this->put("USER $username 0 * :$realname\r\n"); |
133 $this->put("USER $username 0 * :$realname\r\n"); |
134 |
134 |
|
135 $need_deghost = false; |
|
136 |
135 // wait for a mode +i or end of the motd |
137 // wait for a mode +i or end of the motd |
136 while ( true ) |
138 while ( true ) |
137 { |
139 { |
138 $msg = $this->get(); |
140 $msg = $this->get(); |
139 if ( empty($msg) ) |
141 if ( empty($msg) ) |
140 continue; |
142 continue; |
|
143 if ( strstr($msg, "433") ) |
|
144 { |
|
145 // nick already in use - try to ghost |
|
146 $this->change_nick("{$nick}|de-ghosting"); |
|
147 $need_deghost = true; |
|
148 } |
141 if ( ( strstr($msg, 'MODE') && strstr($msg, '+i') ) || strstr(strtolower($msg), 'end of /motd') ) |
149 if ( ( strstr($msg, 'MODE') && strstr($msg, '+i') ) || strstr(strtolower($msg), 'end of /motd') ) |
142 { |
150 { |
143 break; |
151 break; |
144 } |
152 } |
145 if ( preg_match('/^PING :(.+?)$/', $msg, $match) ) |
153 if ( preg_match('/^PING :(.+?)$/', $msg, $match) ) |
146 { |
154 { |
147 $this->put("PONG :{$match[1]}\r\n"); |
155 $this->put("PONG :{$match[1]}\r\n"); |
148 } |
156 } |
|
157 } |
|
158 |
|
159 if ( $need_deghost ) |
|
160 { |
|
161 $this->privmsg('NickServ', "GHOST $nick $pass"); |
|
162 while ( $msg = $this->get(10) ) |
|
163 { |
|
164 if ( stristr($msg, 'nickserv') && stristr($msg, 'ghost') ) |
|
165 break; |
|
166 } |
|
167 $this->change_nick($nick); |
149 } |
168 } |
150 |
169 |
151 // identify to nickserv |
170 // identify to nickserv |
152 if ( $pass ) |
171 if ( $pass ) |
153 $this->privmsg('NickServ', "IDENTIFY $pass"); |
172 $this->privmsg('NickServ', "IDENTIFY $pass"); |
302 $timeout = 180; |
321 $timeout = 180; |
303 $timeout_warn = false; |
322 $timeout_warn = false; |
304 } |
323 } |
305 else if ( $match ) |
324 else if ( $match ) |
306 { |
325 { |
|
326 if ( $match['action'] == 'KILL' ) |
|
327 { |
|
328 // be ethical here and die |
|
329 return 'killed'; |
|
330 } |
307 // Received PRIVMSG or other mainstream action |
331 // Received PRIVMSG or other mainstream action |
308 if ( $match['action'] == 'JOIN' || $match['action'] == 'PART' ) |
332 if ( $match['action'] == 'JOIN' || $match['action'] == 'PART' ) |
309 $channel =& $match['message']; |
333 $channel =& $match['message']; |
310 else |
334 else |
311 $channel =& $match['target']; |
335 $channel =& $match['target']; |