xy 3 săptămâni în urmă
părinte
comite
36326a1065
2 a modificat fișierele cu 20 adăugiri și 0 ștergeri
  1. 17 0
      src/GameClient.php
  2. 3 0
      src/main.php

+ 17 - 0
src/GameClient.php

@@ -6,8 +6,10 @@ require_once './msg.php';
 
 use App\WebSocketClient;
 use Common_pack\EnterHall;
+use Common_pack\ReqFriendList;
 use Common_pack\ReqLogin;
 use Common_pack\ResEnterHall;
+use Common_pack\ResFriendList;
 use Common_pack\ResHeartBeat;
 use Common_pack\ResLogin;
 use Exception;
@@ -27,6 +29,14 @@ class GameClient {
     public function close() {
         echo "命令调用了 close \n";
     }
+
+    public function getFriends(){
+        $userResponse = new ReqFriendList(); 
+        $userResponse->setUserId($this->userId);
+        $binaryData = $userResponse->serializeToString();
+        $this->client->sendBinary(MsgID::REQFRIENDLIST, $binaryData);
+        echo "已发送获取好友列表请求\n";
+    }
     public function outGame(){
         echo "命令调用了 outGame \n";
     }
@@ -122,6 +132,13 @@ class GameClient {
             // echo "心跳:".$response->getMsg();
             // echo "\n";
         });
+
+        $this->client->on(MsgID::RESFRIENDLIST, function($binaryData) {
+            $response = new ResFriendList();
+            $response->mergeFromString($binaryData);
+            echo "获取好友列表:".$response->getList();
+            echo "\n";
+        });
     }
 
     private function startListening() {

+ 3 - 0
src/main.php

@@ -42,6 +42,9 @@ class ProgramMain {
                 case 'outGame':
                     $client->outGame();
                     break;
+                case 'getFriens':
+                    $client->getFriends();
+                    break;
                 case 'exit':
                     $client->close();
                     exit(0);