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