walkor пре 12 година
родитељ
комит
7c54ddbe5c
3 измењених фајлова са 24 додато и 5 уклоњено
  1. 6 1
      Applications/Event.php
  2. 6 4
      Applications/GameBuffer.php
  3. 12 0
      Workers/GameGateway.php

+ 6 - 1
Applications/Event.php

@@ -58,7 +58,12 @@ class Event
    
    protected static function notifyConnectionSuccess($address, $socket_id, $uid)
    {
-       
+       $buf = new GameBuffer();
+       $buf->header['cmd'] = GameBuffer::CMD_GATEWAY;
+       $buf->header['sub_cmd'] = GameBuffer::SCMD_CONNECT_SUCCESS;
+       $buf->header['from_uid'] = $socket_id;
+       $buf->header['to_uid'] = $uid;
+       GameBuffer::sendToGateway($address, $buf->getBuffer());
    }
    
    protected static function getUidBySid($sid)

+ 6 - 4
Applications/GameBuffer.php

@@ -6,12 +6,12 @@
 * 
  */
 require_once WORKERMAN_ROOT_DIR . 'Protocols/Buffer.php';
-require_once WORKERMAN_ROOT_DIR . 'Applications/System.php';
+require_once WORKERMAN_ROOT_DIR . 'Applications/Event.php';
 
 class GameBuffer extends WORKERMAN\Protocols\Buffer
 {
     // 系统命令
-    const CMD_SYSTEM = 128;
+    const CMD_Event = 128;
     // 连接事件 
     const SCMD_ON_CONNECT = 1;
     // 关闭事件
@@ -27,6 +27,8 @@ class GameBuffer extends WORKERMAN\Protocols\Buffer
     const SCMD_KICK_ADDRESS = 3;
     // 广播内容
     const SCMD_BROADCAST = 4;
+    // 通知连接成功
+    const SCMD_CONNECT_SUCCESS = 5;
     
     // 用户中心
     const CMD_USER = 1;
@@ -42,7 +44,7 @@ class GameBuffer extends WORKERMAN\Protocols\Buffer
             self::CMD_USER  => 'User',
             self::CMD_MAP => 'Map',
             self::CMD_GATEWAY => 'GateWay',
-            self::CMD_SYSTEM => 'System',
+            self::CMD_Event => 'Event',
      );
     
     public static $scmdMap = array(
@@ -62,7 +64,7 @@ class GameBuffer extends WORKERMAN\Protocols\Buffer
     
     public static function sendToUid($uid, $buffer)
     {
-        $address = System::getAddressByUid($uid);
+        $address = Event::getAddressByUid($uid);
         if($address)
         {
             return self::sendToGateway($address, $buffer);

+ 12 - 0
Workers/GameGateway.php

@@ -153,6 +153,18 @@ class GameGateway extends WORKERMAN\Core\SocketWorker
                 return;
             case GameBuffer::SCMD_BROADCAST:
                 return $this->broadCast($recv_str);
+            case GameBuffer::SCMD_CONNECT_SUCCESS:
+                $socket_id = $data['from_uid'];
+                $uid = $data['to_uid'];
+                // 查看是否已经绑定uid
+                $binded_uid = $this->getUidByFd($socket_id);
+                if($binded_uid)
+                {
+                    $this->notice('notify connection success fail ' . $socket_id . ' already binded data:'.serialize($data));
+                    return;
+                }
+                $this->uidConnMap[$uid] = $socket_id;
+                $this->connections[$socket_id] = $uid;
         }
     }