function welive_call($data, $accept, $index) { $data = string_to_array($data); switch ($data['x']) { case 4: if (!$this->checkGuest($accept, $index)) { return false; } $msg = decodeChar($data['i']); if (strlen($msg) > 1024) { $msg = "... too long ..."; } $aix = $this->guest[$index]['aix']; $this->send(array('x' => 4, 'g' => $this->guest[$index]['gid'], 'i' => $msg), $this->accept[$aix], $aix); break; case 1: if (!$this->checkAdmin($accept, $index)) { return false; } $msg = decodeChar($data['i']); if (strlen($msg) > 2048) { $msg = "... too long ..."; } if ($this->admin[$index]['type']) { $spec = 0; switch ($msg) { case 'system die': die; break; case 'all': $spec = 1; $msg = 'Total connections = ' . count($this->accept) . '<br>Total admins = ' . count($this->admin) . '<br>Total guests = ' . count($this->guest); break; case 'admin': $spec = 1; $msg = 'Total admins = ' . count($this->admin); foreach ($this->admin as $a) { $msg .= "<br>{$a['fullname']} = {$a['guests']}"; } break; case 'guest': $spec = 1; $msg = 'Total guests = ' . count($this->guest); break; } if ($spec) { $this->send(array('x' => 1, 'u' => $this->admin[$index]['fullname'] . ' (' . $this->admin[$index]['post'] . ')', 't' => $this->admin[$index]['type'], 'i' => $msg), $accept, $index); return true; } } $this->ws_send_all(array('x' => 1, 'u' => $this->admin[$index]['fullname'] . ' (' . $this->admin[$index]['post'] . ')', 't' => $this->admin[$index]['type'], 'i' => $msg), $index); break; case 2: if ($data['a'] != 8 and !$this->checkAdmin($accept, $index)) { return false; } switch ($data['a']) { case 3: if (isset($this->admin[$index])) { $this->admin[$index]['busy'] = 1; } $this->ws_send_all(array('x' => 2, 'a' => 3, 'ix' => $index)); break; case 4: if (isset($this->admin[$index])) { $this->admin[$index]['busy'] = 0; } $this->ws_send_all(array('x' => 2, 'a' => 4, 'ix' => $index)); break; case 5: $gid = ForceInt($data['g']); if ($gid) { $guest = APP::$DB->getOne("SELECT ipzone, fromurl, grade, fullname, address, phone, email, remark FROM " . TABLE_PREFIX . "guest WHERE gid = '{$gid}'"); if (!empty($guest)) { $this->send(array('x' => 2, 'a' => 5, 'g' => $gid, 'd' => $guest), $accept, $index); } } break; case 6: $gid = ForceInt($data['g']); if ($gid) { $grade = ForceInt($data['grade']); $fullname = ForceData($data['fullname']); $address = ForceData($data['address']); $phone = ForceData($data['phone']); $email = ForceData($data['email']); $remark = ForceData($data['remark']); APP::$DB->exe("UPDATE " . TABLE_PREFIX . "guest SET grade = '{$grade}', fullname = '{$fullname}', address = '{$address}', phone = '{$phone}', email = '{$email}', remark = '{$remark}' WHERE gid = '{$gid}'"); $this->send(array('x' => 2, 'a' => 6, 'g' => $gid, 'n' => $fullname), $accept, $index); } break; case 8: $aid = ForceInt($data['id']); $sid = $data['s']; $agent = $data['ag']; if (!$aid or !IsAlnum($sid) or !IsAlnum($agent)) { $this->close($accept, $index, 0); return false; } $sql = "SELECT a.aid, a.type, a.username, a.fullname, a.fullname_en, a.post, a.post_en, a.lastip AS ip FROM " . TABLE_PREFIX . "session s LEFT JOIN " . TABLE_PREFIX . "admin a ON a.aid = s.aid WHERE s.sid = '{$sid}' AND s.aid = '{$aid}' AND s.agent = '{$agent}' AND a.activated = 1"; $admin = APP::$DB->getOne($sql); if (!$admin or !$admin['aid']) { $this->close($accept, $index, 0); return false; } $avatar = GetAvatar($admin['aid'], 1); $this->ws_send_all(array('x' => 2, 'a' => 1, 'ix' => $index, 'id' => $admin['aid'], 't' => $admin['type'], 'n' => $admin['fullname'], 'p' => $admin['post'], 'av' => $avatar)); $this->admin[$index] = $admin; $this->admin[$index]['busy'] = 0; $this->admin[$index]['avatar'] = $avatar; $guest_list = array(); foreach ($this->guest as $k => $g) { if ($g['aid'] == $aid) { $this->guest[$k]['aix'] = $index; $this->send(array('x' => 6, 'a' => 1), $this->accept[$k], $k); $guest_list[] = array('g' => $g['gid'], 'n' => $g['n'], 'l' => $g['l']); } } $this->admin[$index]['guests'] = count($guest_list); $admin_list = array(); foreach ($this->admin as $k => $a) { $admin_list[] = array('ix' => $k, 'id' => $a['aid'], 't' => $a['type'], 'n' => $a['fullname'], 'p' => $a['post'], 'av' => $a['avatar'], 'b' => $a['busy'], 'gs' => $a['guests']); } $this->send(array('x' => 2, 'a' => 8, 'ix' => $index, 'al' => $admin_list, 'gl' => $guest_list), $accept, $index); break; case 9: if ($this->admin[$index]['type'] == 1) { die; } break; } break; case 5: $msg = decodeChar($data['i']); if (strlen($msg) > 2048) { $msg = "... too long ..."; } if (array_key_exists($index, $this->guest)) { $aix = $this->guest[$index]['aix']; $this->send(array('x' => 5, 'a' => 2, 'g' => $this->guest[$index]['gid'], 'i' => $msg), $this->accept[$aix], $aix); $this->send(array('x' => 5, 'a' => 2), $accept, $index); if (APP::$_CFG['History']) { $fromid = $this->guest[$index]['gid']; $fromname = Iif($this->guest[$index]['fullname'], ForceData($this->guest[$index]['fullname']), Iif($this->guest[$index]['l'], '客人', 'Guest') . $fromid); $toid = $this->admin[$aix]['aid']; $toname = $this->admin[$aix]['fullname']; $msg = ForceData($msg); APP::$DB->exe("INSERT INTO " . TABLE_PREFIX . "msg (type, fromid, fromname, toid, toname, msg, time)\r\nVALUES (0, '{$fromid}', '{$fromname}', '{$toid}', '{$toname}', '{$msg}', '" . time() . "')"); } } elseif (array_key_exists($index, $this->admin)) { $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { $this->send(array('x' => 5, 'a' => 1, 'i' => $msg), $this->accept[$gix], $gix); $this->send(array('x' => 5, 'a' => 1, 'g' => $gid, 'i' => $msg), $accept, $index); if (APP::$_CFG['History']) { $fromid = $this->admin[$index]['aid']; $fromname = $this->admin[$index]['fullname']; $toname = Iif($this->guest[$gix]['fullname'], ForceData($this->guest[$gix]['fullname']), Iif($this->guest[$gix]['l'], '客人', 'Guest') . $gid); $msg = ForceData($msg); APP::$DB->exe("INSERT INTO " . TABLE_PREFIX . "msg (type, fromid, fromname, toid, toname, msg, time)\r\nVALUES (1, '{$fromid}', '{$fromname}', '{$gid}', '{$toname}', '{$msg}', '" . time() . "')"); } } } else { $this->close($accept, $index, 0); } break; case 6: switch ($data['a']) { case 8: $key = $data['k']; $code = decodeChar($data['c']); $decode = authcode($code, 'DECODE', $key); if ($decode != md5(WEBSITE_KEY . APP::$_CFG['KillRobotCode']) or md5($data['i']) != "164718d6efb3650e0cf5e5f40ef7a96a") { $this->close($accept, $index, 0); return false; } $gid = ForceInt($data['gid']); $aid = ForceInt($data['aid']); $fullname = decodeChar($data['fn']); $first = Iif($aid, 0, 1); $hasRecord = 0; if ($gid and $first) { $guest = APP::$DB->getOne("SELECT aid, fullname FROM " . TABLE_PREFIX . "guest WHERE gid = '{$gid}'"); if ($guest and $guest['aid']) { $aid = $guest['aid']; $fullname = $guest['fullname']; $hasRecord = 1; } } $admin_index = $this->select_admin($aid); if ($admin_index === false) { $this->send(array('x' => 6, 'a' => 9), $accept, $index); $this->close($accept, $index, 0); return false; } if (isset($this->admin[$admin_index])) { $this->admin[$admin_index]['guests'] += 1; } $aid = $this->admin[$admin_index]['aid']; $lang = ForceInt($data['l']); $fromurl = ForceData($data['fr']); $browser = ForceData($data['ag']); $lastip = $this->ip($accept); $ipzone = convertip($lastip); $timenow = time(); if ($gid) { $this->clearGuest($gid); } $recs = array(); if ($first and $gid and $hasRecord) { APP::$DB->exe("UPDATE " . TABLE_PREFIX . "guest SET aid = '{$aid}', lang ='{$lang}', logins = (logins + 1), last = '{$timenow}', lastip = '{$lastip}', ipzone = '{$ipzone}', browser = '{$browser}', fromurl = '{$fromurl}' WHERE gid = '{$gid}'"); $limit = ForceInt(APP::$_CFG['Record']); if (APP::$_CFG['History'] and $limit) { $records = APP::$DB->query("SELECT type, msg, time FROM " . TABLE_PREFIX . "msg WHERE (type = 0 AND fromid = '{$gid}') OR (type = 1 AND toid = '{$gid}') ORDER BY mid DESC LIMIT {$limit}"); while ($r = APP::$DB->fetch($records)) { $recs[] = array('t' => $r['type'], 'm' => $r['msg'], 'd' => DisplayDate($r['time'], 'H:i:s', 1)); } $recs = array_reverse($recs); } } elseif ($first) { APP::$DB->exe("INSERT INTO " . TABLE_PREFIX . "guest (aid, lang, last, lastip, ipzone, browser, fromurl)\r\nVALUES ('{$aid}', '{$lang}', '{$timenow}', '{$lastip}', '{$ipzone}', '{$browser}', '{$fromurl}')"); $gid = APP::$DB->insert_id; } $this->guest[$index] = array('gid' => $gid, 'aid' => $aid, 'aix' => $admin_index, 'n' => $fullname, 'l' => $lang); $this->send(array('x' => 6, 'a' => 8, 'g' => $gid, 'n' => $fullname, 'l' => $lang, 're' => $recs), $this->accept[$admin_index], $admin_index); if ($lang) { $a_n = $this->admin[$admin_index]['fullname']; $a_p = $this->admin[$admin_index]['post']; } else { $a_n = $this->admin[$admin_index]['fullname_en']; $a_p = $this->admin[$admin_index]['post_en']; } $this->send(array('x' => 6, 'a' => 8, 'gid' => $gid, 'fn' => $fullname, 'aid' => $aid, 'an' => $a_n, 'p' => $a_p, 'av' => $this->admin[$admin_index]['avatar'], 're' => $recs), $accept, $index); break; case 5: if (!$this->checkGuest($accept, $index)) { return false; } $this->send(array('x' => 6, 'a' => 5), $accept, $index); $this->close($accept, $index); break; case 6: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { if (isset($this->admin[$index])) { $this->admin[$index]['guests'] -= 1; } $this->send(array('x' => 6, 'a' => 6), $this->accept[$gix], $gix); unset($this->guest[$gix]); $this->close($this->accept[$gix], $gix, 0); } if ($gid) { APP::$DB->exe("UPDATE " . TABLE_PREFIX . "guest SET banned = (banned + 1) WHERE gid = '{$gid}'"); } break; case 7: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { $this->send(array('x' => 6, 'a' => 7), $this->accept[$gix], $gix); } break; case 10: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { $this->send(array('x' => 6, 'a' => 10), $this->accept[$gix], $gix); } break; case 11: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $aix = ForceInt($data['aix']); $gix = $this->guestIndex($gid); if ($gid and $gix !== false and isset($this->admin[$aix])) { $aid = $this->admin[$aix]['aid']; if (isset($this->guest[$gix])) { $this->guest[$gix]['aid'] = $aid; $this->guest[$gix]['aix'] = $aix; } if ($this->guest[$gix]['l']) { $a_n = $this->admin[$aix]['fullname']; $a_p = $this->admin[$aix]['post']; } else { $a_n = $this->admin[$aix]['fullname_en']; $a_p = $this->admin[$aix]['post_en']; } $recs = array(); $limit = ForceInt(APP::$_CFG['Record']); if (APP::$_CFG['History'] and $limit) { $records = APP::$DB->query("SELECT type, msg, time FROM " . TABLE_PREFIX . "msg WHERE (type = 0 AND fromid = '{$gid}') OR (type = 1 AND toid = '{$gid}') ORDER BY mid DESC LIMIT {$limit}"); while ($r = APP::$DB->fetch($records)) { $recs[] = array('t' => $r['type'], 'm' => $r['msg'], 'd' => DisplayDate($r['time'], 'H:i:s', 1)); } $recs = array_reverse($recs); } $this->send(array('x' => 6, 'a' => 8, 'g' => $gid, 'n' => $this->guest[$gix]['n'], 'l' => $this->guest[$gix]['l'], 're' => $recs), $this->accept[$aix], $aix); $this->send(array('x' => 6, 'a' => 11, 'aid' => $aid, 'an' => $a_n, 'p' => $a_p, 'av' => $this->admin[$aix]['avatar']), $this->accept[$gix], $gix); $this->send(array('x' => 6, 'a' => 11, 'g' => $gid, 'i' => 1), $accept, $index); if (isset($this->admin[$index])) { $this->admin[$index]['guests'] -= 1; } if (isset($this->admin[$aix])) { $this->admin[$aix]['guests'] += 1; } APP::$DB->exe("UPDATE " . TABLE_PREFIX . "guest SET aid = '{$aid}' WHERE gid = '{$gid}'"); } else { $this->send(array('x' => 6, 'a' => 11, 'g' => $gid, 'i' => 0), $accept, $index); } break; } break; default: $this->close($accept, $index, 0); break; } }
function welive_call($data, $accept, $index) { $data = string_to_array($data); switch ($data['x']) { case 4: if (!$this->checkGuest($accept, $index)) { return false; } $msg = decodeChar($data['i']); if (strlen($msg) > 1024) { $msg = "... too long ..."; } $aix = $this->guest[$index]['aix']; $this->send(array('x' => 4, 'g' => $this->guest[$index]['gid'], 'i' => $msg), $this->accept[$aix], $aix); break; case 2: if ($data['a'] != 8 and !$this->checkAdmin($accept, $index)) { return false; } switch ($data['a']) { case 3: if (isset($this->admin[$index])) { $this->admin[$index]['busy'] = 1; } $this->ws_send_all(array('x' => 2, 'a' => 3, 'ix' => $index)); break; case 4: if (isset($this->admin[$index])) { $this->admin[$index]['busy'] = 0; } $this->ws_send_all(array('x' => 2, 'a' => 4, 'ix' => $index)); break; case 8: $aid = ForceInt($data['id']); $sid = $data['s']; $agent = $data['ag']; if (!$aid or !IsAlnum($sid) or !IsAlnum($agent)) { $this->close($accept, $index, 0); return false; } $sql = "SELECT a.aid, a.type, a.username, a.fullname, a.fullname_en, a.post, a.post_en, a.lastip AS ip\nFROM " . TABLE_PREFIX . "session s\nLEFT JOIN " . TABLE_PREFIX . "admin a ON a.aid = s.aid\nWHERE s.sid = '{$sid}'\nAND s.aid = '{$aid}'\nAND s.agent = '{$agent}'\nAND a.activated = 1"; $admin = APP::$DB->getOne($sql); if (!$admin or !$admin['aid']) { $this->close($accept, $index, 0); return false; } $avatar = GetAvatar($admin['aid'], 1); $this->ws_send_all(array('x' => 2, 'a' => 1, 'ix' => $index, 'id' => $admin['aid'], 't' => $admin['type'], 'n' => $admin['fullname'], 'p' => $admin['post'], 'av' => $avatar)); $this->admin[$index] = $admin; $this->admin[$index]['busy'] = 0; $this->admin[$index]['avatar'] = $avatar; $guest_list = array(); foreach ($this->guest as $k => $g) { if ($g['aid'] == $aid) { $this->guest[$k]['aix'] = $index; $this->send(array('x' => 6, 'a' => 1), $this->accept[$k], $k); $guest_list[] = array('g' => $g['gid'], 'n' => $g['n'], 'l' => $g['l']); } } $this->admin[$index]['guests'] = count($guest_list); $admin_list = array(); foreach ($this->admin as $k => $a) { $admin_list[] = array('ix' => $k, 'id' => $a['aid'], 't' => $a['type'], 'n' => $a['fullname'], 'p' => $a['post'], 'av' => $a['avatar'], 'b' => $a['busy'], 'gs' => $a['guests']); } $this->send(array('x' => 2, 'a' => 8, 'ix' => $index, 'al' => $admin_list, 'gl' => $guest_list), $accept, $index); break; case 9: if ($this->admin[$index]['type'] == 1) { die; } break; } break; case 5: $msg = decodeChar($data['i']); if (strlen($msg) > 2048) { $msg = "... too long ..."; } if (array_key_exists($index, $this->guest)) { $aix = $this->guest[$index]['aix']; $this->send(array('x' => 5, 'a' => 2, 'g' => $this->guest[$index]['gid'], 'i' => $msg), $this->accept[$aix], $aix); $this->send(array('x' => 5, 'a' => 2), $accept, $index); } elseif (array_key_exists($index, $this->admin)) { $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { $this->send(array('x' => 5, 'a' => 1, 'i' => $msg), $this->accept[$gix], $gix); $this->send(array('x' => 5, 'a' => 1, 'g' => $gid, 'i' => $msg), $accept, $index); } } else { $this->close($accept, $index, 0); } break; case 6: switch ($data['a']) { case 8: $key = $data['k']; $code = decodeChar($data['c']); $decode = authcode($code, 'DECODE', $key); if ($decode != md5(WEBSITE_KEY . APP::$_CFG['KillRobotCode']) or md5($data['i']) != "164718d6efb3650e0cf5e5f40ef7a96a") { $this->close($accept, $index, 0); return false; } $gid = ForceInt($data['gid']); $aid = ForceInt($data['aid']); $fullname = decodeChar($data['fn']); $first = Iif($aid, 0, 1); $hasRecord = 0; if ($gid and $first) { $guest = APP::$DB->getOne("SELECT aid, fullname FROM " . TABLE_PREFIX . "guest WHERE gid = '{$gid}'"); if ($guest and $guest['aid']) { $aid = $guest['aid']; $fullname = $guest['fullname']; $hasRecord = 1; } } $admin_index = $this->select_admin($aid); if ($admin_index === false) { $this->send(array('x' => 6, 'a' => 9), $accept, $index); $this->close($accept, $index, 0); return false; } if (isset($this->admin[$admin_index])) { $this->admin[$admin_index]['guests'] += 1; } $aid = $this->admin[$admin_index]['aid']; $lang = ForceInt($data['l']); $fromurl = ForceData($data['fr']); $browser = ForceData($data['ag']); $lastip = $this->ip($accept); $ipzone = convertip($lastip); $timenow = time(); if ($gid) { $this->clearGuest($gid); } $recs = array(); if ($first and $gid and $hasRecord) { APP::$DB->exe("UPDATE " . TABLE_PREFIX . "guest SET aid = '{$aid}', lang ='{$lang}', logins = (logins + 1), last = '{$timenow}', lastip = '{$lastip}', ipzone = '{$ipzone}', browser = '{$browser}', fromurl = '{$fromurl}' WHERE gid = '{$gid}'"); } elseif ($first) { APP::$DB->exe("INSERT INTO " . TABLE_PREFIX . "guest (aid, lang, last, lastip, ipzone, browser, fromurl)\nVALUES ('{$aid}', '{$lang}', '{$timenow}', '{$lastip}', '{$ipzone}', '{$browser}', '{$fromurl}')"); $gid = APP::$DB->insert_id; } $this->guest[$index] = array('gid' => $gid, 'aid' => $aid, 'aix' => $admin_index, 'n' => $fullname, 'l' => $lang); $this->send(array('x' => 6, 'a' => 8, 'g' => $gid, 'n' => $fullname, 'l' => $lang, 're' => $recs), $this->accept[$admin_index], $admin_index); if ($lang) { $a_n = $this->admin[$admin_index]['fullname']; $a_p = $this->admin[$admin_index]['post']; } else { $a_n = $this->admin[$admin_index]['fullname_en']; $a_p = $this->admin[$admin_index]['post_en']; } $this->send(array('x' => 6, 'a' => 8, 'gid' => $gid, 'fn' => $fullname, 'aid' => $aid, 'an' => $a_n, 'p' => $a_p, 'av' => $this->admin[$admin_index]['avatar'], 're' => $recs), $accept, $index); break; case 5: if (!$this->checkGuest($accept, $index)) { return false; } $this->send(array('x' => 6, 'a' => 5), $accept, $index); $this->close($accept, $index); break; case 6: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { if (isset($this->admin[$index])) { $this->admin[$index]['guests'] -= 1; } $this->send(array('x' => 6, 'a' => 6), $this->accept[$gix], $gix); unset($this->guest[$gix]); $this->close($this->accept[$gix], $gix, 0); } if ($gid) { APP::$DB->exe("UPDATE " . TABLE_PREFIX . "guest SET banned = (banned + 1) WHERE gid = '{$gid}'"); } break; case 7: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { $this->send(array('x' => 6, 'a' => 7), $this->accept[$gix], $gix); } break; case 10: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $gix = $this->guestIndex($gid); if ($gix !== false) { $this->send(array('x' => 6, 'a' => 10), $this->accept[$gix], $gix); } break; case 11: if (!$this->checkAdmin($accept, $index)) { return false; } $gid = ForceInt($data['g']); $aix = ForceInt($data['aix']); $gix = $this->guestIndex($gid); if ($gid and $gix !== false and isset($this->admin[$aix])) { $aid = $this->admin[$aix]['aid']; if (isset($this->guest[$gix])) { $this->guest[$gix]['aid'] = $aid; $this->guest[$gix]['aix'] = $aix; } if ($this->guest[$gix]['l']) { $a_n = $this->admin[$aix]['fullname']; $a_p = $this->admin[$aix]['post']; } else { $a_n = $this->admin[$aix]['fullname_en']; $a_p = $this->admin[$aix]['post_en']; } $recs = array(); $this->send(array('x' => 6, 'a' => 8, 'g' => $gid, 'n' => $this->guest[$gix]['n'], 'l' => $this->guest[$gix]['l'], 're' => $recs), $this->accept[$aix], $aix); $this->send(array('x' => 6, 'a' => 11, 'aid' => $aid, 'an' => $a_n, 'p' => $a_p, 'av' => $this->admin[$aix]['avatar']), $this->accept[$gix], $gix); $this->send(array('x' => 6, 'a' => 11, 'g' => $gid, 'i' => 1), $accept, $index); if (isset($this->admin[$index])) { $this->admin[$index]['guests'] -= 1; } if (isset($this->admin[$aix])) { $this->admin[$aix]['guests'] += 1; } APP::$DB->exe("UPDATE " . TABLE_PREFIX . "guest SET aid = '{$aid}' WHERE gid = '{$gid}'"); } else { $this->send(array('x' => 6, 'a' => 11, 'g' => $gid, 'i' => 0), $accept, $index); } break; } break; default: $this->close($accept, $index, 0); break; } }