-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cache.php
147 lines (137 loc) · 4.92 KB
/
Cache.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
<?php
//332
function Cache_Channel($Line, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
$Topic = Phrase_Text($Line, 4);
$Channel = trim($Line[3]);
mysql_query("INSERT INTO `Cache_Channels` (`Channel_Name`, `Channel_Topic`) VALUES ('".escape($Channel)."', '".escape($Topic)."')");
}
mysql_close($conn);
}
//353
function Cache_Who($Line, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
array_pop($Line);
$Users = array_slice($Line, 5);
foreach ($Users as $User) {
$User = trim($User, "&~+%@: ");
$UEQ = mysql_query("SELECT * FROM Cache_Users WHERE User_Nick = '".mysql_real_escape_string($User)."'");
$User_Exsists = mysql_num_rows($UEQ);
if ($User_Exsists == 0) {
$C_Nick = mysql_real_escape_string($User);
mysql_query("INSERT INTO Cache_Users (User_Nick) VALUES ('".mysql_real_escape_string($C_Nick)."')");
}
$Channel = $Line[4];
$CID = Cache_Get_Channel_ID($Channel, $db);
$UID = Cache_Get_User_ID($User, $db);
$UinC = mysql_query("SELECT * FROM Cache_UinC WHERE User_ID = '{$UID}' AND Channel_ID = '{$CID}'");
$UinC_Check = mysql_num_rows($UinC);
if ($UinC_Check == 0) {
if ($Line[3] != "*") {
mysql_query("INSERT INTO Cache_UinC (User_ID, Channel_ID) VALUES ('{$UID}', '{$CID}')");
}
}
}
}
mysql_close($conn);
}
//Join
function Cache_Join($UserName, $Channel, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
mysql_query("INSERT INTO Cache_Users (User_Nick) VALUES ('".mysql_real_escape_string($UserName)."')");
$CID = Cache_Get_Channel_ID($Channel, $db);
$UID = Cache_Get_User_ID($UserName, $db);
$UinC = mysql_query("SELECT * FROM Cache_UinC WHERE User_ID = '{$UID}' AND Channel_ID = '{$CID}'");
$UinC_Check = mysql_num_rows($UinC);
if ($UinC_Check == 0) {
mysql_query("INSERT INTO Cache_UinC (User_ID, Channel_ID) VALUES ('{$UID}', '{$CID}')");
}
}
mysql_close($conn);
}
//Part
function Cache_Part($UserName, $Channel, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
$UID = Cache_Get_User_ID($UserName, $db);
$CID = Cache_Get_Channel_ID($Channel, $db);
mysql_query("DELETE FROM Cache_UinC WHERE User_ID = '{$UID}' AND Channel_ID = '{$CID}'");
}
mysql_close($conn);
}
//Quit
function Cache_Quit($UserName, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
$UID = Cache_Get_User_ID($UserName, $db);
mysql_query("DELETE FROM Cache_Users WHERE User_ID = '{$UID}'");
mysql_query("DELETE FROM Cache_UinC WHERE User_ID = '{$UID}'");
}
mysql_close($conn);
}
//Nick Change
function Cache_Nick($UserName, $New_UserName, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
$UID = Cache_Get_User_ID($UserName, $db);
$NewNick = str_replace(":", "", $New_UserName);
mysql_query("UPDATE `Cache_Users` SET `User_Nick` = '".mysql_real_escape_string($New_UserName)."' WHERE User_ID = '{$UID}'");
}
mysql_close($conn);
}
//Kicked
function Cache_Kick($UserName, $Channel, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
$UID = Cache_Get_User_ID($UserName, $db);
$CID = Cache_Get_Channel_ID($Channel, $db);
mysql_query("DELETE FROM Cache_UinC WHERE User_ID = '{$UID}' AND Channel_ID = '{$CID}'");
}
mysql_close($conn);
}
//Get Channel's ID
function Cache_Get_Channel_ID($Channel, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
$Chan1 = mysql_real_escape_string($Channel);
$ChanQ = mysql_query("SELECT Channel_ID FROM Cache_Channels WHERE Channel_Name = '".$Chan1."'");
$ChanID = mysql_fetch_array($ChanQ);
$CID = $ChanID['Channel_ID'];
return $CID;
}
mysql_close($conn);
}
//Get User's ID
function Cache_Get_User_ID($User, $db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
$WhoQ = mysql_query("SELECT User_ID FROM Cache_Users WHERE User_Nick = '".mysql_real_escape_string($User)."'");
$WhoID = mysql_fetch_array($WhoQ);
$UID = $WhoID['User_ID'];
return $UID;
}
mysql_close($conn);
}
//Run function on start up
function Cache_Initiate($db) {
$conn = mysql_connect($db['host'], $db['user'], $db['password']);
if ($conn) {
mysql_select_db($db['database']);
mysql_query("TRUNCATE TABLE `Cache_Users`");
mysql_query("TRUNCATE TABLE `Cache_Channels`");
mysql_query("TRUNCATE TABLE `Cache_UinC`");
}
mysql_close($conn);
}