This repository has been archived by the owner on Feb 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserIRC_User.php
175 lines (139 loc) · 3.75 KB
/
UserIRC_User.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
class UserIRC_User{
const MAX_MESSAGE_STORAGE = 2500;
private $nick = "";
private $ident = "";
private $host = "";
private $msgs = array();
private $channels = array();
private $chanmodes = array();
private $loggedin = false;
private $userid = 0;
private $username = "";
private $nodes = array();
public function __construct($address){
if(preg_match("/(.*)!(.*)@(.*)/", $address, $matches)){
$this->nick = $matches[1];
$this->ident = $matches[2];
$this->host = $matches[3];
}else
$this->nick = $address;
}
public function addMessage(MessIRC $message){
$channel = $message->getReplyTarget();
if(!isset($this->msgs[$channel]))
$this->msgs[$channel] = array();
array_unshift($this->msgs[$channel], $message);
$this->msgs[$channel] = array_slice($this->msgs[$channel], 0, self::MAX_MESSAGE_STORAGE);
$this->updateHost($message);
}
public function getMessage($channel, $number){
if(!isset($this->msgs[$channel][$number]))
return null;
return $this->msgs[$channel][$number];
}
public function getMessageCount($channel){
if(isset($this->msgs[$channel]))
return count($this->msgs[$channel]);
else return null;
}
public function getNick(){
return $this->nick;
}
public function getFullHost(){
return $this->ident."@".$this->host;
}
public function setNick($nick){
$this->nick = $nick;
}
public function setLogin($userid, $username){
if(!is_numeric($userid) || !is_string($username))
throw new Exception("Given values are not the correct type.");
$this->loggedin = true;
$this->userid = (int) $userid;
$this->username = $username;
}
public function logout(){
$this->loggedin = false;
$this->userid = 0;
$this->username = "";
}
public function getNode($node, $ignoreWildcard = false){
$nodes = $this->nodes;
if(isset($nodes[$node]))
return $nodes[$node];
if($ignoreWildcard)
return null;
$nodeGroups = explode('.', $node);
unset($nodeGroups[count($nodeGroups) - 1]);
while(count($nodeGroups) != 0){
$nodePointer = implode('.', $nodeGroups);
if(isset($nodes["$nodePointer.*"]))
return $nodes["$nodePointer.*"];
unset($nodeGroups[count($nodeGroups) - 1]);
}
if(isset($nodes['*']))
return $nodes['*'];
return null;
}
public function setNode($node, $setting){
$this->nodes[$node] = $setting;
}
public function getUserID(){
return $this->userid;
}
public function destroyNodeTree(){
$this->nodes = array();
}
public function getUsername(){
if($this->username == "")
return $this->nick;
return $this->username;
}
public function loginStatus(){
return $this->loggedin;
}
public function addChan($channel){
$this->channels[$channel] = $channel;
$this->chanmodes[$channel] = array();
}
public function rmChan($channel){
if(isset($this->channels[$channel])){
unset($this->channels[$channel]);
unset($this->chanmodes[$channel]);
}
}
public function getChans(){
return $this->channels;
}
public function mode($channel, $mode){
if(preg_match_all('/([+-])([qaohv]+)/', $mode, $regex, PREG_PATTERN_ORDER)){
$letterPointer = 0;
for($modePointer = 0; isset($regex[0][$modePointer]); $modePointer++){
$modeSymbol = $regex[1][$modePointer];
$modeLetters= $regex[2][$modePointer];
$letterArray= str_split($modeLetters);
foreach($letterArray as $letter){
if($modeSymbol == "+")
$this->chanmodes[$channel][] = $letter;
else{
if(($chanmodeKey = array_search($letterArray, $this->chanmodes[$channel])) !== false)
unset($this->chanmodes[$channel][$chanmodeKey]);
}
$letterPointer++;
}
}
}
return false;
}
public function getModes($channel){
if(!isset($this->chanmodes[$channel]))
return array();
return $this->chanmodes[$channel];
}
public function updateHost(MessIRC $MessIRC){
$this->nick = $MessIRC->getNick();
$this->ident = $MessIRC->getIdent();
$this->host = $MessIRC->getHostmask();
}
}