1 | <?php
|
---|
2 |
|
---|
3 | include_once('../global.php');
|
---|
4 | include_once('webchatsend.php');
|
---|
5 | $Config['Web']['ShowError'] = 1;
|
---|
6 | $Charset = 'latin2';
|
---|
7 | $Database->charset($Charset);
|
---|
8 |
|
---|
9 | $Debug = 0;
|
---|
10 |
|
---|
11 | function Packet($Text2)
|
---|
12 | {
|
---|
13 | global $Debug, $Database, $Config;
|
---|
14 |
|
---|
15 | //echo("{".$Text2."}".ord($Text2[1]).".".strlen($Text2)."\n");
|
---|
16 | //echo($Text2.strlen($Text2)."\n");
|
---|
17 | $Text = StrTr($Text2, "\x8A\x8D\x8E\x9A\x9D\x9E", "\xA9\xAB\xAE\xB9\xBB\xBE");
|
---|
18 | if(strlen($Text) > 1)
|
---|
19 | {
|
---|
20 | $Parts = explode('|',$Text);
|
---|
21 | $TargetIP = $Parts[1];
|
---|
22 | $TargetID = $Parts[2];
|
---|
23 | $SenderIP = $Parts[3];
|
---|
24 | $SenderID = $Parts[4];
|
---|
25 | $Command = $Parts[6];
|
---|
26 | if($Command == 'Message')
|
---|
27 | {
|
---|
28 | $Database->charset($Charset);
|
---|
29 | $Color = $Parts[7];
|
---|
30 | $Text = $Parts[8];
|
---|
31 | $RoomName = $Parts[9];
|
---|
32 | $RoomType = $Parts[10];
|
---|
33 | if($Debug == 1) echo('Message: '.$Text."\n");
|
---|
34 | $DbResult = $Database->select('sunrisechat_onlinelist','*','sender_id='.$SenderID.' AND sender_ip="'.$SenderIP.'"');
|
---|
35 | if($DbResult->num_rows > 0)
|
---|
36 | {
|
---|
37 | $Row = $DbResult->fetch_array();
|
---|
38 | $Nick = $Row['nick'];
|
---|
39 | } else $Nick = '';
|
---|
40 | echo('<'.$Nick.'>'.$Text." ".addslashes($Text)."\n");
|
---|
41 | $Database->insert('sunrisechat_history',array('time' => 'NOW()', 'nick' => $Nick, 'text' => $Text, 'color' => $Color,
|
---|
42 | 'roomname' => $RoomName, 'roomtype' => $RoomType));
|
---|
43 | }
|
---|
44 | if($Command == 'Alive')
|
---|
45 | {
|
---|
46 | $DbResult = $Database->select('sunrisechat_onlinelist','*','sender_id='.$SenderID.' AND sender_ip="'.$SenderIP.'"');
|
---|
47 | if($DbResult->num_rows > 0)
|
---|
48 | {
|
---|
49 | $Row = $DbResult->fetch_array();
|
---|
50 | $Database->update('sunrisechat_onlinelist','sender_ip="'.$SenderIP.'" AND sender_id='.$SenderID,array('lasttime' => 'NOW()'));
|
---|
51 | } else $Database->insert('sunrisechat_onlinelist',array('lasttime' => 'NOW()', 'sender_ip' => $SenderIP, 'sender_id' => $SenderID));
|
---|
52 | }
|
---|
53 | if($Command == 'GoOnline')
|
---|
54 | {
|
---|
55 | $Result = $Database->select('sunrisechat_onlinelist','*','sender_id='.$SenderID.' AND sender_ip="'.$SenderIP.'"');
|
---|
56 | if($DbResult->num_rows() > 0)
|
---|
57 | {
|
---|
58 | $Row = $DbResult->fetch_array();
|
---|
59 | $Database->update('sunrisechat_onlinelist','sender_ip="'.$SenderIP.'" AND sender_id='.$SenderID,array('lasttime' => 'NOW()', 'status' => 'Online'));
|
---|
60 | } else $Database->insert('sunrisechat_onlinelist',array('lasttime' => 'NOW()', 'sender_ip' => $SenderIP, 'sender_id' => $SenderID, 'status' => 'Online'));
|
---|
61 | }
|
---|
62 | if($Command == 'GoAway')
|
---|
63 | {
|
---|
64 | $DbResult = $Database->select('sunrisechat_onlinelist','*','sender_id='.$SenderID.' AND sender_ip="'.$SenderIP.'"');
|
---|
65 | if($DbResult->num_rows() > 0)
|
---|
66 | {
|
---|
67 | $Row = $DbResult->fetch_array();
|
---|
68 | $Database->update('sunrisechat_onlinelist','sender_ip="'.$SenderIP.'" AND sender_id='.$SenderID,array('lasttime' => 'NOW()', 'status' => 'Away'));
|
---|
69 | } else $Database->insert('sunrisechat_onlinelist',array('lasttime' => 'NOW()', 'sender_ip' => $SenderIP, 'sender_id' => $SenderID, 'status' => 'Away'));
|
---|
70 | }
|
---|
71 | if($Command == 'UserInfo')
|
---|
72 | {
|
---|
73 | $Nick = $Parts[7];
|
---|
74 | echo('UserInfo: '.$Nick."\n");
|
---|
75 | $DbResult = $Database->select('sunrisechat_onlinelist','*','sender_id='.$SenderID.' AND sender_ip="'.$SenderIP.'"');
|
---|
76 | if($DbResult->num_rows > 0)
|
---|
77 | {
|
---|
78 | $Row = $DbResult->fetch_array();
|
---|
79 | $Database->update('sunrisechat_onlinelist','sender_ip="'.$SenderIP.'" AND sender_id='.$SenderID,array('lasttime' => 'NOW()', 'nick' => $Nick, 'operating_system' => $Parts[12], 'status' => $Parts[10]));
|
---|
80 | } else $Database->insert('sunrisechat_onlinelist',array('lasttime' => 'NOW()', 'nick' => $Nick, 'sender_ip' => $SenderIP, 'sender_id' => $SenderID, 'operating_system' => $Parts[12], 'status' => $Parts[10]));
|
---|
81 | }
|
---|
82 | if($Command == 'WhoIs') // for WebSunriseChat support
|
---|
83 | {
|
---|
84 | $DbResult = $Database->select('sunrisechat_onlinelist','*','sender_id='.$TargetID.' AND sender_ip="'.$TargetIP.'" AND operating_system="Fedora Core 2"');
|
---|
85 | if($DbResult->num_rows > 0)
|
---|
86 | {
|
---|
87 | $Row = $DbResult->fetch_array();
|
---|
88 | $_SESSION['DetailInfo'] = $Row['info'];
|
---|
89 | $Nick = $Row['nick'];
|
---|
90 | $_SESSION['nick'] = $Nick;
|
---|
91 | $_SESSION['IP'] = $Row['sender_ip'];
|
---|
92 | $_SESSION['ID'] = $Row['sender_id'];
|
---|
93 | $_SESSION['sequence'] = $Row['sequence'];
|
---|
94 | Send('UserInfo','');
|
---|
95 | if($Debug == 1) echo('UserInfo: '.$Nick."\n");
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | //DB_Select('sunrisechat_onlinelist','UNIX_TIMESTAMP(lasttime)');
|
---|
100 | //$Row = DB_Row();
|
---|
101 | //echo($Row[0]-(time()-200)."\n");
|
---|
102 | $Database->delete('sunrisechat_onlinelist','UNIX_TIMESTAMP(lasttime)<'.(time()-30));
|
---|
103 | }
|
---|
104 |
|
---|
105 | $Filename = '/tmp/sunrisechatout';
|
---|
106 | $Filename2 = '/tmp/sunrisechatin';
|
---|
107 | $File2 = fopen($Filename2,'w');
|
---|
108 | while(1)
|
---|
109 | {
|
---|
110 | if(file_exists($Filename))
|
---|
111 | {
|
---|
112 | $File = fopen($Filename,'r');
|
---|
113 | $Data = fread($File,65000);
|
---|
114 | fclose($File);
|
---|
115 | unlink($Filename);
|
---|
116 | //echo($Data);
|
---|
117 | $Rows = explode("\n",$Data);
|
---|
118 | array_pop($Rows);
|
---|
119 | foreach($Rows as $Item)
|
---|
120 | {
|
---|
121 | Packet($Item);
|
---|
122 | //echo($Item."\n");
|
---|
123 | }
|
---|
124 | }
|
---|
125 | sleep(5);
|
---|
126 | }
|
---|
127 |
|
---|
128 | ?>
|
---|