/
ircMsg.php
99 lines (79 loc) · 2.11 KB
/
ircMsg.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
<?php
class ircMsg
{
private $raw;
private $nick;
private $name;
private $host;
private $command;
private $parameters = array();
public function __construct($message)
{
$this->parse($message);
}
public function getRaw()
{
return $this->raw;
}
public function getNick()
{
return $this->nick;
}
public function getName()
{
return $this->name;
}
public function getHost()
{
return $this->host;
}
public function getCommand()
{
return $this->command;
}
public function getParameters()
{
return $this->parameters;
}
private function parse($preMessage)
{
$this->raw = $preMessage;
$message = substr($preMessage, 1);
$array = explode(" ", $message);
// Define the constants.
$id = $array[0];
$command = $array[1];
$this->command = $command;
$idArray = explode("@", $id);
$userArray = explode("!", $idArray[0]);
if (isset($idArray[1])) {
$this->nick = $userArray[0];
$this->name = $userArray[1];
$this->host = $idArray[1];
$improv = FALSE;
} else {
$this->nick = $idArray[0];
$this->name = $idArray[0];
$this->host = $idArray[0];
$improv = TRUE;
}
$delimiter = strpos($message, " :");
if ($delimiter == FALSE) {
$tempParameters = $array;
unset($tempParameters[0]);
unset($tempParameters[1]);
$tempParams = $tempParameters;
} else {
$delMessage = substr($message, $delimiter + 2);
if ($improv == FALSE) {
$length = strlen($this->nick . "!" . $this->name . "@" . $this->host . " " . $this->command);
} else {
$length = strlen($this->nick . " " . $this->command);
}
$remainingParameters = trim(substr($message, $length, $delimiter - $length));
$tempParams = explode(" ", $remainingParameters);
array_push($tempParams, $delMessage);
}
$this->parameters = array_merge(array(), array_filter($tempParams));
}
}