### Compiling the Server Source: https://github.com/sniper00/moondemo/blob/master/README.md Instructions for compiling the Moon server, including cloning the repository with submodules and referencing the Moon build documentation. ```shell git clone --recursive https://github.com/sniper00/MoonDemo.git ``` -------------------------------- ### Running the Server Source: https://github.com/sniper00/moondemo/blob/master/README.md Steps to run the game server, including prerequisites like Redis, configuration options for databases (Redis/PostgreSQL), startup scripts for different OS, and accessing the management backend. ```shell # Windows: start_server.bat # Linux/macOS: start_hub.sh start_game.sh # Access management backend: # Web: http://127.0.0.1:8003/ # Telnet: telnet 127.0.0.1 8003 (then 'S1 help') ``` -------------------------------- ### Server Structure Overview Source: https://github.com/sniper00/moondemo/blob/master/README.md Directory structure of the game server, detailing the organization of common modules, service-specific logic, configuration files, and tools. ```shell . ├── common/ #逻辑公共模块目录 │   ├── CmdCode.lua #自动生成的和客户端通信的协议定义文件 │   ├── Database.lua #数据库操作 │   ├── ErrorCode.lua #逻辑错误码定义 │   ├── GameCfg.lua #游戏配表 │   ├── GameDef.lua #游戏内部相关配置 │   ├── LuaPanda.lua #LuaPanda调试库 │   ├── init.lua #common目录初始化脚本 │   ├── protocol.lua │   ├── protocol_pb.lua #protobuf消息编码和解码逻辑 │   ├── setup.lua #All In One包装: 消息注册,服务内模块注册,配表更新,代码热更 │   ├── vector2.lua │   └── verify_proto.lua #开发环境下,Lua数据结构严格验证库 ├── game │   ├── auth #每个服务对应的逻辑脚本目录 │   ├── center │   ├── gate │   ├── node │   ├── room │   ├── service_auth.lua │   ├── service_center.lua │   ├── service_gate.lua │   ├── service_hub.lua │   ├── service_node.lua │   ├── service_room.lua │   ├── service_user.lua │   └── user ├── log # 运行日志目录 ├── main_game.lua # game 进程启动文件 ├── main_hub.lua # hub 进程启动文件 ├── moon # moon源码 ├── node.json # 节点配置文件,用于集群通信 ├── protocol # protobuf协议定义目录 │   ├── annotations.proto # 只用于生成Lua代码注解 │   ├── center.proto # 定义自动转发到Center服务的消息 │   ├── common.proto # 公共protobuf定义 │   ├── json_verify.json # 用于verify_proto │   ├── proto.pb │   ├── room.proto # 定义自动转发到Room服务的消息 │   └── user.proto # 定义自动转发到User服务的消息 ├── robot │   └── robot.lua # 机器人脚本 ├── serverconf.lua # 数据库相关配置 ├── start_game.sh ├── start_hub.sh ├── start_server.bat ├── static │   ├── table # 游戏配表目录 │   └── www # GM后台目录 └── tools ├── Annotations.lua # 自动生成的代码注解文件 ├── ProtoEnum.lua ├── __pycache__ ├── make_annotations.py ├── moonfly.bat ├── moonfly.py # 代码注解生成脚本 └── protoc3.exe ``` -------------------------------- ### Debugging with VS Code LuaPanda Source: https://github.com/sniper00/moondemo/blob/master/README.md Guide to setting up and using the VS Code LuaPanda extension for debugging the game server. It involves adding a require statement to the service code, configuring the debugger, and setting breakpoints. ```lua require("common.LuaPanda").start("127.0.0.1", 8818) ``` -------------------------------- ### Unity Web Player Initialization and Configuration Source: https://github.com/sniper00/moondemo/blob/master/BallAction/001/index.html This snippet configures the Unity Web Player for the BallAction project. It sets up the canvas element, defines build URLs, and configures project-specific settings like data, framework, and code URLs. It also includes logic for handling mobile and desktop display styles and initializes the Unity instance. ```javascript var canvas = document.querySelector("#unity-canvas"); function unityShowBanner(msg, type) { var warningBanner = document.querySelector("#unity-warning"); function updateBannerVisibility() { warningBanner.style.display = warningBanner.children.length ? 'block' : 'none'; } var div = document.createElement('div'); div.innerHTML = msg; warningBanner.appendChild(div); if (type == 'error') div.style = 'background: red; padding: 10px;'; else { if (type == 'warning') div.style = 'background: yellow; padding: 10px;'; setTimeout(function() { warningBanner.removeChild(div); updateBannerVisibility(); }, 5000); } updateBannerVisibility(); } var buildUrl = "Build"; var loaderUrl = buildUrl + "/001.loader.js"; var config = { arguments: [], dataUrl: buildUrl + "/001.data.gz", frameworkUrl: buildUrl + "/001.framework.js.gz", codeUrl: buildUrl + "/001.wasm.gz", streamingAssetsUrl: "StreamingAssets", companyName: "DefaultCompany", productName: "BallAction", productVersion: "0.1", showBanner: unityShowBanner, }; if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) { var meta = document.createElement('meta'); meta.name = 'viewport'; meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes'; document.getElementsByTagName('head')[0].appendChild(meta); document.querySelector("#unity-container").className = "unity-mobile"; canvas.className = "unity-mobile"; // config.devicePixelRatio = 1; } else { canvas.style.width = "960px"; canvas.style.height = "600px"; } document.querySelector("#unity-loading-bar").style.display = "block"; var script = document.createElement("script"); script.src = loaderUrl; script.onload = () => { createUnityInstance(canvas, config, (progress) => { document.querySelector("#unity-progress-bar-full").style.width = 100 * progress + "%" }).then((unityInstance) => { document.querySelector("#unity-loading-bar").style.display = "none"; document.querySelector("#unity-fullscreen-button").onclick = () => { unityInstance.SetFullscreen(1); }; }).catch((message) => { alert(message); }); }; document.body.appendChild(script); ``` -------------------------------- ### Protobuf Annotation Generation Script Source: https://github.com/sniper00/moondemo/blob/master/README.md Python script used for generating code annotations from protobuf definitions, facilitating better code understanding and tooling integration. ```python # tools/make_annotations.py (example usage) # This script processes .proto files to generate Lua annotations. ```