xy hace 3 semanas
commit
b093e6a151
Se han modificado 6 ficheros con 580 adiciones y 0 borrados
  1. BIN
      .DS_Store
  2. 97 0
      compile_protos.php
  3. 0 0
      main.php
  4. 12 0
      proto/bag.proto
  5. 432 0
      proto/common.proto
  6. 39 0
      proto/mail.proto

BIN
.DS_Store


+ 97 - 0
compile_protos.php

@@ -0,0 +1,97 @@
+#!/usr/bin/env php
+<?php
+/**
+ * 自动编译 protos 目录下所有 .proto 文件
+ * 使用方法:php compile_protos.php [输出目录]
+ */
+
+// 参数检查
+if ($argc < 2) {
+    echo "Usage: php compile_protos.php <output_dir>\n";
+    exit(1);
+}
+
+$protoDir = __DIR__ . '/protos';
+$outputDir = rtrim($argv[1], '/');
+
+// 检查 protoc 是否可用
+exec('protoc --version 2>&1', $output, $retval);
+if ($retval !== 0) {
+    echo "Error: protoc compiler not found. Please install it first.\n";
+    echo "On macOS: brew install protobuf\n";
+    echo "On Linux: sudo apt-get install protobuf-compiler\n";
+    echo "On Windows: choco install protoc\n";
+    exit(1);
+}
+
+// 创建输出目录
+if (!file_exists($outputDir)) {
+    mkdir($outputDir, 0755, true);
+}
+
+// 递归查找所有 .proto 文件
+$files = new RecursiveIteratorIterator(
+    new RecursiveDirectoryIterator($protoDir),
+    RecursiveIteratorIterator::LEAVES_ONLY
+);
+
+$protoFiles = [];
+foreach ($files as $file) {
+    if ($file->getExtension() === 'proto') {
+        $protoFiles[] = $file->getRealPath();
+    }
+}
+
+if (empty($protoFiles)) {
+    echo "No .proto files found in {$protoDir}\n";
+    exit(0);
+}
+
+// 编译每个文件
+$successCount = 0;
+foreach ($protoFiles as $protoFile) {
+    $relativePath = substr($protoFile, strlen($protoDir) + 1);
+    echo "Compiling {$relativePath}... ";
+    
+    $command = sprintf(
+        'protoc --php_out=%s --proto_path=%s %s 2>&1',
+        escapeshellarg($outputDir),
+        escapeshellarg(dirname($protoFile)),
+        escapeshellarg($protoFile)
+    );
+    
+    exec($command, $output, $retval);
+    
+    if ($retval === 0) {
+        echo "OK\n";
+        $successCount++;
+    } else {
+        echo "FAILED\n";
+        echo "Error output:\n" . implode("\n", $output) . "\n";
+    }
+}
+
+echo "\nResult: {$successCount}/" . count($protoFiles) . " files compiled successfully\n";
+
+// 生成自动加载文件
+generateAutoload($outputDir);
+
+/**
+ * 生成 composer 自动加载配置
+ */
+function generateAutoload(string $outputDir) {
+    $autoloadFile = $outputDir . '/composer.json';
+    
+    if (!file_exists($autoloadFile)) {
+        file_put_contents($autoloadFile, json_encode([
+            'name' => 'generated/protobuf-messages',
+            'autoload' => [
+                'psr-4' => [
+                    '' => './'
+                ]
+            ]
+        ], JSON_PRETTY_PRINT));
+        
+        echo "\nGenerated composer.json for autoloading. Run 'composer dump-autoload' if needed.\n";
+    }
+}

+ 0 - 0
main.php


+ 12 - 0
proto/bag.proto

@@ -0,0 +1,12 @@
+syntax = "proto3";
+
+option go_package = "./msg";
+
+import "common.proto";          // 直接引入
+
+
+message ItemRequest {
+    int32 ItemID = 1;
+    int32 Quantity = 2; 
+}
+

+ 432 - 0
proto/common.proto

@@ -0,0 +1,432 @@
+syntax = "proto3";
+
+package common_pack;
+
+option go_package = "./msg";
+
+enum roleType {
+    ROLE_TYPE_UNKNOWN = 0;
+    RED        = 1;  // 无操作
+    BLUE   = 4;
+    YELLOW   = 3;
+    GREEN   = 2;
+}
+
+enum OptType {
+    OPT_TYPE_UNKNOWN = 0;
+    ZHI_SHAI_ZI     = 1;  
+    SELECT_ROLE   = 2;
+}
+
+enum roomType {
+  ROOM_TYPE_UNKNOWN = 0;
+  SHUANG_REN = 1;
+  SIREN_REN = 2;
+}
+
+enum roomMode {
+  ROOM_MODE_UNKNOWN = 0;
+  REN_JI = 1;
+  WAN_JIA = 2;
+}
+
+enum roadType {
+  ROAD_TYPE_UNKNOWN = 0;
+  HOME =1;
+}
+
+enum playerStatus {
+  PLAYER_STATUS_UNKNOWN = 0;
+  SZ_ANIMATION =1;
+  COLOR_FINISH = 2;
+  COLOR_KICK = 3;
+  COLOR_TIME_OUT = 4;
+}
+
+enum roomStatus {
+  AWAIT = 0;
+  START = 1;
+  END = 2;
+}
+
+message round {
+  roleType m_color = 1; 
+  string m_road = 2;
+  OptType opt = 3;
+  int32 szNumber = 4;
+}
+
+message RoomInfo {
+  repeated RoleData roles = 1;
+  repeated ColorData colors = 2;
+  roomType room_type = 3;
+  roomMode room_mode = 4;
+  roleType cur_round_color = 5; //当前那个阵营的回合
+  repeated round rounds = 6;
+  repeated ColorData finish_colors = 7;
+  repeated ColorData kict_colors = 8;
+  int32 id = 9;
+  int32 room_level = 10; //房间的每个等级都对应着不同的奖励和消耗
+  roomStatus room_status = 11;
+  NotifyPlayerOpt cur_color_opt_data = 12; //当前阵营操作的类型
+  int32 opt_time = 13; //玩家当前剩余操作时间
+}
+
+message RoleData {
+  roleType m_color = 1;
+  int32 m_seat = 2;
+  string m_id = 3;
+  roadType m_cur_road = 4;
+  int32 step = 5;
+  int32 old_setp = 6;
+}
+
+message ColorData {
+  string m_id = 1;
+  roleType m_color = 2;
+  bool is_kick = 3;
+  bool is_finish = 4;
+  int32 time_out_num = 5;
+  string m_name = 6;
+  string m_head = 7;
+  int32 rank_num = 8;
+  int32 m_coin = 9;
+  int32 m_reward_coin = 10;
+}
+
+message MoveStepData {
+  string m_id = 1;
+  int32 step = 2;
+  int32 old_setp = 3;
+}
+
+message SendColorSz {
+  roleType color = 1;  // 
+}
+
+message SendRoleMove {
+  roleType color = 1;  // 
+  string roleId = 2;
+}
+
+message SendQuitRoom {
+  roleType color = 1;  // 
+}
+
+message NotifyPlayerSzNumber {
+  roleType color = 1;  // 
+  int32 szNumber = 2;   // 
+  MsgError err_msg = 3;
+}
+
+message NotifyPlayerMove {
+  roleType color = 1;  // 
+  MoveStepData step = 2;   // 
+  repeated RoleData kick = 3;
+}
+
+message NotifyPlayerOpt {
+  roleType color = 1;  // 
+  OptType opt = 2;   // 
+  repeated RoleData canMoveRoles = 3;
+  int32 opt_time = 4;
+}
+
+message NotifyPlayerStatus {
+  roleType color = 1;  // 
+  playerStatus status = 2;
+  repeated ColorData colors = 3;
+  ColorData time_out_color = 4;
+}
+
+
+message NotifySettlement {
+  roleType color = 1;  // 
+  repeated ColorData finish_colors = 2;
+}
+
+
+message NotifyUpdateRoomInfo {
+  RoomInfo room_info = 1;  // 
+}
+//----------------------------------
+
+
+//用户信息
+message UserInfo {
+  string UserId = 1;
+  string m_head = 2;
+  int32 m_coin = 3;
+  string name = 4;
+  int32 room_id = 5; //如果用户在某一个房间玩,他的id就一直存在,
+  int32 online_status = 6;//在线=1 离线等0
+  
+}
+//登录 请求
+message ReqLogin {
+  string account = 1;
+  string password = 2;
+}
+
+//登录 响应
+message ResLogin {
+  string userId = 1;
+  string nikeName = 2;
+  UserInfo userInfo = 3;
+  MsgError err_msg = 4;
+}
+//注册 请求
+message ReqRegister {
+  string nikeName = 1;
+  string account = 2;
+  string password = 3;
+  string m_head = 4;
+}
+//注册 响应
+message ResRegister {
+  bool success = 1;
+  MsgError err_msg = 2;
+}
+
+
+
+//进入大厅
+message EnterHall {
+  string userId = 1;
+}
+//进入大厅响应
+message ResEnterHall {
+  bool success = 1;
+  MsgError err_msg = 2;
+  RoomInfo reconnect_room_info = 3;
+}
+
+//离开大厅
+message LeaveHall {
+  string userId = 1;
+}
+
+//匹配ludo
+message MatchLudo {
+  roomType select_room_type = 1;
+  int32 room_level = 2;
+  roleType select_color = 3;
+}
+//匹配ludo 响应
+message ResMatchLudo {
+  bool success = 1;
+  MsgError err_msg = 2;
+  RoomInfo room = 3;
+}
+
+//error
+message MsgError {
+  int32 error_code = 1;
+  string error_msg = 2;
+}
+
+
+// 更新用户信息
+message UpdateUserInfo {
+  UserInfo info = 1;
+}
+message ResHeartBeat {
+  string msg = 1;
+}
+
+message ReqHeartBeat {
+  string msg = 1;
+}
+
+message ShopItem{
+  string name = 1;
+  string id = 2;
+  int32 price = 3;
+  int32 num = 4;
+}
+
+//被踢登陆
+message BeKickLogin {
+  MsgError err_msg = 1;
+}
+
+// 请求商城
+message ReqShop {
+  int32 shopType = 1;
+}
+
+// 响应商城
+message ResShop {
+  bool success = 1;
+  MsgError err_msg = 2;
+  repeated ShopItem list = 3;
+}
+
+
+message HistoryRecord{
+  int32 id = 1;
+  int32 room_id = 2;
+  string user_id = 3;
+  string time = 4;
+}
+
+message ReqLudoHistory{
+  string user_id = 1;
+}
+
+message ResLudoHistory{
+  bool success = 1;
+  MsgError err_msg = 2;
+  repeated HistoryRecord list = 3;
+}
+
+message ReqLudoRoomInfo{
+  int64 room_id = 1;
+}
+
+message ResLudoRoomInfo{
+  bool success = 1;
+  MsgError err_msg = 2;
+  RoomInfo info = 3;
+}
+
+message BuyShopItem{
+  string id = 1;
+}
+
+//好友请求的结构
+message RequestAddFriendItem{
+  int32 id = 1;
+  string RequestID = 2; //请求id
+  string FromUserID = 3;
+  string ToUserID = 4;
+  int32 Status = 5; //状态
+  string Message = 6;
+}
+
+//请求好友列表
+message ReqFriendList{
+  string user_id = 1;
+}
+
+//响应好友列表请求,暂时没做分页
+message ResFriendList{
+  bool success = 1;
+  MsgError err_msg = 2;
+  repeated UserInfo list = 3;
+}
+
+//请求好友申请单个数据
+message FriendRequestItem{
+  UserInfo info = 1;
+  string request_msg = 2;
+  string create_time = 3;
+  int32 status = 4;
+}
+
+//请求好友申请列表
+message ReqFriendRequestList{
+  string user_id = 1;
+}
+
+//响应好友申请列表请求,暂时没做分页
+message ResFriendRequestList{
+  bool success = 1;
+  MsgError err_msg = 2;
+  repeated FriendRequestItem list = 3;
+ 
+}
+
+//请求添加好友
+message ReqAddFriend{
+  string ToUserID = 1;
+  string msg = 2;
+}
+
+//客户端接收到请求消息
+message RecvAddFriendRequest{
+  UserInfo info = 1;
+}
+
+//接收到的玩家对消息进行操作
+message OptAddFriendRequest{
+  RequestAddFriendItem info = 1;
+}
+
+
+//通知请求的玩家,对方的操作结果
+message NotifyOptFriend{
+  RequestAddFriendItem info = 1;
+}
+
+
+//根据玩家id搜索玩家
+message SearchUser{
+  string user_id = 1;
+}
+
+//响应搜索结果
+message ResSearchUser{
+  bool success = 1;
+  MsgError err_msg = 2;
+  UserInfo info = 3;
+}
+
+//删除好友
+message ReqDeleteFriend{
+  string ToUserID = 1;
+}
+
+//删除好友响应
+message ResDeleteFriend{
+  bool success = 1;
+  MsgError err_msg = 2;
+}
+
+
+
+//好友上线/下线响应
+message ResFriendOnLineStatus{
+  bool success = 1;
+  MsgError err_msg = 2;
+  UserInfo info = 3;
+}
+
+
+//聊天消息
+message ChatMessage{
+  int32 id = 1;
+  string session_id = 2;
+  string sender_id = 3;
+  string content = 4;
+  string created_at = 5;
+  string content_type = 6;
+}
+
+//发送聊天内容
+message ReqSendChatMsg{
+  string content_type = 1; //消息类型
+  string to_userid = 2; //发送给谁
+  string content = 3; //消息内容
+}
+
+message ResSendChatMsg{
+  bool success = 1;
+  MsgError err_msg = 2;
+}
+//接收聊天内容
+message RecvChatMsg{
+  ChatMessage info = 1;
+}
+//请求获取聊天历史
+message ReqChatHistory{
+  string to_userid = 1;
+  int32 last_msgid = 2; 
+}
+//响应获取聊天历史
+message ResChatHistory{
+  bool success = 1;
+  MsgError err_msg = 2;
+  repeated ChatMessage list = 3;
+}
+

+ 39 - 0
proto/mail.proto

@@ -0,0 +1,39 @@
+syntax = "proto3";
+
+option go_package = "./msg";
+
+import "common.proto";          // 直接引入
+
+
+enum OptMailType {
+  ROLE_TYPE_UNKNOWN = 0;
+  CHECK        = 1;  // 查看
+  RECEIVE   = 2; //领取
+  DELETE   = 3; //删除
+}
+
+//邮箱信息
+message MailInfo{
+  string mail_json_info = 1;
+  int32 mail_type = 2;
+  int32 check_status = 3;
+  int32 receive_status = 4;
+  string create_time = 5;
+}
+
+//请求获取邮箱
+message ReqMail{
+  string userid = 1;
+  int32 mail_type = 2;
+}
+//响应获取邮箱列表
+message ResMail{
+  bool success = 1;
+  common_pack.MsgError err_msg = 2;
+  repeated MailInfo list = 3;
+}
+//操作邮箱
+message OptMail{
+  int32 mail_id =1;
+  OptMailType opt =2;
+}