|
@@ -25,59 +25,48 @@
|
|
|
*/
|
|
|
//use \GatewayWorker\Lib\Gateway;
|
|
|
//use \GatewayWorker\Lib\DbConnection;
|
|
|
-use \think\Db;
|
|
|
+use think\Db;
|
|
|
+use think\App;
|
|
|
|
|
|
class Events
|
|
|
{
|
|
|
|
|
|
public static function onWorkerStart(){
|
|
|
|
|
|
- /*global $db;
|
|
|
- $my_config = array(
|
|
|
- 'host' => '127.0.0.1',
|
|
|
- 'port' => '3306',
|
|
|
- 'user' => 'youeryuan',
|
|
|
- 'password' => 'XwXXAFbp8kaYsLKF',
|
|
|
- 'dbname' => 'youeryuan',
|
|
|
- 'charset' => 'utf8',
|
|
|
- );
|
|
|
- $db = new DbConnection($my_config);*/
|
|
|
-
|
|
|
- echo 'onWorkerStart';
|
|
|
-
|
|
|
+ App::initCommon();
|
|
|
|
|
|
+ /*$info = Db::name('mt_admin')->find(1);
|
|
|
+ dump($info);*/
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 有消息时
|
|
|
- * @param int $client_id
|
|
|
- * @param mixed $message
|
|
|
- */
|
|
|
- public static function onMessage($client_id, $message)
|
|
|
- {
|
|
|
- dump($message);
|
|
|
- file_put_contents('1.json',$message.PHP_EOL,FILE_APPEND);
|
|
|
- return ;
|
|
|
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 有消息时
|
|
|
+ * @param int $client_id
|
|
|
+ * @param mixed $message
|
|
|
+ */
|
|
|
+ public static function onMessage($client_id, $message)
|
|
|
+ {
|
|
|
+ dump($message);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 当客户端断开连接时
|
|
|
- * @param integer $client_id 客户端id
|
|
|
- */
|
|
|
- public static function onClose($client_id)
|
|
|
- {
|
|
|
- // debug
|
|
|
- /* echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} client_id:$client_id onClose:''\n";
|
|
|
+ /**
|
|
|
+ * 当客户端断开连接时
|
|
|
+ * @param integer $client_id 客户端id
|
|
|
+ */
|
|
|
+ public static function onClose($client_id)
|
|
|
+ {
|
|
|
+ // debug
|
|
|
+ /* echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']} client_id:$client_id onClose:''\n";
|
|
|
|
|
|
- // 从房间的客户端列表中删除
|
|
|
- if(isset($_SESSION['room_id']))
|
|
|
- {
|
|
|
- $room_id = $_SESSION['room_id'];
|
|
|
- $new_message = array('type'=>'logout', 'from_client_id'=>$client_id, 'from_client_name'=>$_SESSION['client_name'], 'time'=>date('Y-m-d H:i:s'));
|
|
|
- Gateway::sendToGroup($room_id, json_encode($new_message));
|
|
|
- }*/
|
|
|
- }
|
|
|
+ // 从房间的客户端列表中删除
|
|
|
+ if(isset($_SESSION['room_id']))
|
|
|
+ {
|
|
|
+ $room_id = $_SESSION['room_id'];
|
|
|
+ $new_message = array('type'=>'logout', 'from_client_id'=>$client_id, 'from_client_name'=>$_SESSION['client_name'], 'time'=>date('Y-m-d H:i:s'));
|
|
|
+ Gateway::sendToGroup($room_id, json_encode($new_message));
|
|
|
+ }*/
|
|
|
+ }
|
|
|
|
|
|
}
|