-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_functions.inc
243 lines (196 loc) · 8.6 KB
/
server_functions.inc
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
function on_part_msg($irc_connect,$who,$chan) {
global $db_ctrl,$db;
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
$sender_ident=$sender_info[1];
$sender_host=$sender_info[2];
$host_mask=$sender_ident."@".$sender_host;
// prevents chan v and o users from receieving the on part msg
$sql="select user.user from user_host uh, user ,user_chan uc where '$host_mask' like replace(replace(mask,'*!',''),'*','%') and uh.user=user.user and uc.user=user.user and ((user.o='1' or user.f='1' or user.v='1') or (uc.chan='$chan' and (uc.o='1' or uc.v='1' or uc.f='1'))) limit 1";
$result=@$db_ctrl->query($sql,$db);
if ($db_ctrl->num_rows($result)==0) {
$sql="select msg from channels c, part_msg jm where upper(c.chan_name)=upper('$chan') and on_join='1' and c.chan_name=jm.chan_name order by part_msg_id asc";
$result=@$db_ctrl->query($sql,$db);
while($myrow=@$db_ctrl->fetch_array($result)) {
$msg=$myrow["msg"];
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
sleep(1);
fputs($irc_connect, "NOTICE $sender_nick :$msg\n");
$sent=1;
}
if ($sent==1) {
//echo "ON part in $chan sent to $sender_nick \n";
}
}
}
function on_join_msg($irc_connect,$who,$chan) {
global $db_ctrl,$db;
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
$sender_ident=$sender_info[1];
$sender_host=$sender_info[2];
$host_mask=$sender_ident."@".$sender_host;
// prevents chan v and o users from receieving the on join msg
$sql="select user.user from user_host uh, user ,user_chan uc where '$host_mask' like replace(replace(mask,'*!',''),'*','%') and uh.user=user.user and uc.user=user.user and ((user.o='1' or user.f='1' or user.v='1') or (uc.chan='$chan' and (uc.o='1' or uc.v='1' or uc.f='1'))) limit 1";
$result=@$db_ctrl->query($sql,$db);
if ($db_ctrl->num_rows($result)==0) {
$sql="select msg from channels c, join_msg jm where upper(c.chan_name)=upper('$chan') and on_join='1' and c.chan_name=jm.chan_name order by join_msg_id asc";
$result=@$db_ctrl->query($sql,$db);
while($myrow=@$db_ctrl->fetch_array($result)) {
$msg=$myrow["msg"];
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
sleep(1);
fputs($irc_connect, "NOTICE $sender_nick :$msg\n");
$sent=1;
}
if ($sent==1) {
//echo "ON JOIN in $chan sent to $sender_nick \n";
}
}
}
function quit_chan($irc_connect,$who,$reason) {
// user quits update all records for that user on the chan_user table stating his
// reason for leaveing and when he left
update_seen_data_quit($irc_connect,$who,$reason);
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
$sender_ident=$sender_info[1];
$sender_host=$sender_info[2];
//print "$sender_nick ($sender_ident@$sender_host) quit irc \n stating $reason \n";
}
function user_join_chan($irc_connect,$who,$chan) {
// update the chan_user data stating when he joined if he is there remove a reason
// for leaveing and update the seen counter how many tiems he has been here
$who=trim($who);
$chan=trim($chan);
update_seen_data_join($irc_connect,$who,$chan,"u");
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
$sender_ident=$sender_info[1];
$sender_host=$sender_info[2];
print "$sender_nick ($sender_ident@$sender_host) Joined $chan \n";
}
function user_part_chan($irc_connect,$who,$chan) {
global $db_ctrl,$db;
// When a user leaves a chan update the chan_user data with the time they left
// the channel
// update_seen_data_part($irc_connect,$who,$chan);
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
$sender_ident=$sender_info[1];
$sender_host=$sender_info[2];
print "$sender_nick ($sender_ident@$sender_host) left $chan \n";
$sql_find = "select nick from chan_users where nick='$sender_nick' and chan_name='$chan'";
$find_q = $db_ctrl->query($sql_find);
if ($db_ctrl->num_rows($find_q) > 0) {
$sql_update="update chan_users set ident='$sender_ident',host_mask='$sender_host', reason='joined channel' where upper(nick)=upper('$sender_nick') and chan_name='$chan'";
} else {
$sql_update="insert into chan_users (chan_name,nick,mode,ident,host_mask) VALUES ('$chan','$sender_nick','u','$sender_ident','$sender_host')";
}
$result_update=$db_ctrl->query($sql_update,$db);
}
function nick_change($irc_connect,$who,$who_to) {
// if its not been seen before then add it to the chan_user table
// update the user stating the time and reason changing nick to new_nick
global $db_ctrl,$db,$my_nick;
$sender_info=clean_nick($who);
$sender_nick=$sender_info[0];
$sender_ident=$sender_info[1];
$sender_host=$sender_info[2];
/* if ($sender_nick==$my_nick) {
$GLOBALS["my_nick"]=$who_to;
$my_nick=$who_to;
} */
$new_who=$who_to."!".$sender_ident."@".$sender_host;
$sql="select * from chan_users where upper(nick)=upper('$sender_nick')";
$result=$db_ctrl->query($sql,$db);
while($myrow=$db_ctrl->fetch_array($result)) {
$cu_id=$myrow["cu_id"];
$mode=$myrow["mode"];
$chan_name=$myrow["chan_name"];
}
update_seen_data_join($irc_connect,$new_who,$chan_name,$mode);
$sql_update="update chan_users set ident='$sender_ident',host_mask='$sender_host', reason='changed nick to $who_to' where upper(nick)=upper('$sender_nick')";
$result_update=$db_ctrl->query($sql_update,$db);
if (!$sql_update) {
//echo "Error in server_msg change_nick sql_update ".$db_ctrl->error($result_update)."\n";
}
//print "$sender_nick ($sender_ident@$sender_host) is now $who_to \n";
}
function bot_join_topic($irc_connect,$who,$chan,$topic) {
// if chan not in the chan table then add it
// if it is then update the topic
global $db_ctrl,$db;
$topic=addslashes(trim($topic));
$sql="update channels set topic='$topic' where upper(chan_name)=upper('$chan')";
$result=$db_ctrl->query($sql,$db);
$sql="update chan_users set reason='Bot left' where upper(chan_name)=upper('$chan') and reason is null;";
$result=$db_ctrl->query($sql,$db);
//print "Bot joined $chan topic is $topic \n";
}
function bot_join_topic_setby($irc_connect, $chan,$topic_set_by,$topic_set) {
// update the topic set by info and when in the chan table.
global $db_ctrl,$db;
$topic_set_by=addslashes($topic_set_by);
$sql="update channels set topic_set_by='$topic_set_by', topic_set_date='$topic_set' where upper(chan_name)=upper('$chan')";
$result=$db_ctrl->query($sql,$db);
//print "Bot joined $chan topic set by $topic_set_by $topic_set\n";
}
function bot_join_names($irc_connect,$chan,$names) {
global $db_ctrl,$irc_nick;
// check all the names in the table to see who is here and who isnt and new people
// update left on the others that arnt there.
$names=trim($names);
$chan_users=explode(" ",$names);
for ($n=0;$n<count($chan_users);$n++) {
// to prevent the duplicate join entry for the bot its self. use bot name
if (strtoupper($chan_users[$i])!="PHP_EGG") { // gryph: hmm, hardcoded?
$hold=substr($chan_users[$n],0,1);
if ($hold=="@") {
$user=substr($chan_users[$n],1,strlen($chan_users[$n]));
$user=trim($user);
$chan=trim($chan);
$user=addslashes($user);
update_seen_data($irc_connect,$user,$chan,"o");
} else if ($hold=="+") {
$user=trim($user);
$chan=trim($chan);
$user=substr($chan_users[$n],1,strlen($chan_users[$n]));
$user=addslashes($user);
update_seen_data($irc_connect,$user,$chan,"v");
} else {
$chan=trim($chan);
$user=trim($chan_users[$n]);
$user=addslashes($user);
update_seen_data($irc_connect,$user,$chan,"u");
}
}
}
//print "bot joined $chan curent names are \n $names \n";
}
function change_user_mode($irc_connect,$who,$chan,$mode) {
global $db_ctrl,$db;
//print "$who Mode Now $mode \n";
$plus_minus=substr($mode,0,1);
$mode=substr($mode,1,1);
$mode=trim($mode);
if ($plus_minus=="+") {
if (($mode=="v") || ($mode=="o")) {
$sql="update chan_users set mode='$mode' where upper(nick)=upper('$who') and upper(chan_name)=upper('$chan')";
$result=$db_ctrl->query($sql,$db);
}
} else {
if ($mode=="o") {
$sql="update chan_users set mode='u' where upper(nick)=upper('$who') and upper(chan_name)=upper('$chan')";
$result=$db_ctrl->query($sql,$db);
} else if ($mode=="v") {
$sql="update chan_users set mode='u' where upper(nick)=upper('$who') and upper(chan_name)=upper('$chan')";
$result=$db_ctrl->query($sql,$db);
}
}
// update the chan_user table for that user name. to show the new level
}
?>