Commit abd64650 authored by liujiangnan's avatar liujiangnan

feat: 添加MGOBE

parent 629f2a1a
This diff is collapsed.
This diff is collapsed.
{
"ver": "1.0.1",
"uuid": "fd279805-6e95-474f-ac26-e19034f2b093",
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "a5f635d9-92ca-41fe-ba2a-e6fee035993e",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"ver": "1.0.8",
"uuid": "771c13cf-dd4a-4c25-9dca-413a319550cf",
"isPlugin": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
## MGOBE 游戏 Server 示例代码
### 说明
- 自定义游戏 Server 必要文件是 index.js,上传代码时需要打包为 zip 文件,并且 zip 文件根目录包含 mgobexs 文件夹,index.js 位于 mgobexs 文件夹下。
- 该示例代码可以同时使用 JavaScript、TypeScript 开发,TypeScript 需要编译为 JavaScript 后才能使用。
- 开发者可以在此基础上修改 index.ts 或 index.js 文件进行开发。
- 源码文件位于 src/mgobexs 目录下,请在此目录下进行修改
### 使用
- 安装 TypeScript、gulp
```
npm install -g typescript
npm install -g gulp
```
- 命令行进入 mgobexs 后执行
```
npm install
```
- 根据自己的业务逻辑修改 index.ts
- 将 TypeScript 编译为 JavaScript,在 mgobexs 目录执行
```
npm run gulp
```
- 该命令会将代码编译,并生成 zip 文件,开发者将该 zip 文件上传即可
### npm 命令
- npm run gulp :编译 TypeScript 并打包为 zip
- npm run gulp-watch :监听 .ts 发生变化时编译 TypeScript, 并打包为 zip
const gulp = require("gulp");
const clean = require("gulp-clean");
const ts = require('gulp-typescript');
const zip = require('gulp-zip');
const watch = require('gulp-watch');
const tsProject = ts.createProject("./tsconfig.json", {
declaration: false
});
const DEST_PATH = "./dist/mgobexs.zip";
const SRC_PATH = "./src/mgobexs";
const TSC_PATH = ["./src/mgobexs/*.ts"];
gulp.task("clean", () => {
return gulp.src(DEST_PATH, {
read: false,
allowEmpty: true
}).pipe(clean({
force: true
}));
});
gulp.task("tsc", () => {
return gulp.src(TSC_PATH)
.pipe(tsProject()).js
.pipe(gulp.dest(SRC_PATH));
});
gulp.task("zip", () => {
return gulp.src([
'./src/**/*.*',
'./src/**/*.*',
'!./src/mgobexs/*.ts',
'!./**/__MACOSX',
'!./**/.DS_Store'
]).pipe(zip(DEST_PATH))
.pipe(gulp.dest("./"));
});
gulp.task("default", gulp.series("clean", "tsc", "zip"));
gulp.task("watch", () => {
return watch('./src/mgobexs/*.ts', gulp.series("default"));
});
{
"name": "server",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"gulp": "gulp",
"gulp-watch": "gulp watch"
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^11.13.5"
},
"description": "",
"devDependencies": {
"gulp": "^4.0.1",
"gulp-clean": "^0.4.0",
"gulp-typescript": "^5.0.1",
"gulp-watch": "^5.0.1",
"gulp-zip": "^4.2.0",
"typescript": "^3.4.5"
}
}
import { mgobexsInterface } from './mgobexsInterface';
const gameServer: mgobexsInterface.GameServer.IGameServer = {
// 消息模式
mode: 'sync',
// 初始化游戏数据
onInitGameData: function (): mgobexsInterface.GameData {
return {};
},
// 监听客户端数据
onRecvFromClient: function onRecvFromClient({ actionData, gameData, SDK, room, exports }: mgobexsInterface.ActionArgs<mgobexsInterface.UserDefinedData>) {
gameData.pos = Math.floor(Math.random() * 2000);
SDK.logger.debug('onRecvFromClient', gameData, actionData);
setTimeout(() => {
SDK.sendData({ playerIdList: [], data: { data: gameData, ts: new Date().toISOString() } }, { timeout: 2000, maxTry: 3 });
SDK.exitAction();
}, gameData.pos);
},
// 监听加房广播
onJoinRoom: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onJoinRoom',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听创建房间广播
onCreateRoom: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onCreateRoom',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听退房广播
onLeaveRoom: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onLeaveRoom',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听玩家被移除广播
onRemovePlayer: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onRemovePlayer',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听房间销毁广播
onDestroyRoom: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onDestroyRoom',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听修改房间属性广播
onChangeRoom: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onChangeRoom',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听修改玩家自定义状态广播
onChangeCustomPlayerStatus: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onChangeCustomPlayerStatus',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听玩家网络状态变化广播
onChangePlayerNetworkState: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onChangePlayerNetworkState',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听开始帧同步广播
onStartFrameSync: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onStartFrameSync',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
},
// 监听停止帧同步广播
onStopFrameSync: function ({ actionData, gameData, SDK, room, exports }) {
SDK.logger.debug(
'onStopFrameSync',
'actionData:', actionData,
'gameData:', gameData,
'room:', room
);
}
};
// 服务器初始化时调用
function onInitGameServer(tcb: any) {
// 如需要,可以在此初始化 TCB
const tcbApp = tcb.init({
secretId: '请填写腾讯云API密钥ID',
secretKey: '请填写腾讯云API密钥KEY',
env: '请填写云开发环境ID',
serviceUrl: 'http://tcb-admin.tencentyun.com/admin',
timeout: 5000
});
// ...
}
export const mgobexsCode: mgobexsInterface.mgobexsCode = {
logLevel: 'error+',
logLevelSDK: 'error+',
gameInfo: {
gameId: '请填写游戏ID',
serverKey: '请填写后端密钥'
},
onInitGameServer,
gameServer
}
export namespace mgobexsInterface {
//PROTO-STRUCT-BEGIN
export interface ICreateRoomBst {
roomInfo?: (IRoomInfo|null);
}
export interface IJoinRoomBst {
roomInfo?: (IRoomInfo|null);
joinPlayerId?: (string|null);
}
export interface ILeaveRoomBst {
roomInfo?: (IRoomInfo|null);
leavePlayerId?: (string|null);
}
export interface IRemovePlayerBst {
roomInfo?: (IRoomInfo|null);
removePlayerId?: (string|null);
}
export interface IChangeRoomBst {
roomInfo?: (IRoomInfo|null);
}
export interface IChangeCustomPlayerStatusBst {
changePlayerId?: (string|null);
customPlayerStatus?: (number|null);
roomInfo?: (IRoomInfo|null);
}
export interface IChangePlayerNetworkStateBst {
changePlayerId?: (string|null);
networkState?: (NetworkState|null);
roomInfo?: (IRoomInfo|null);
}
export interface IStartFrameSyncBst {
roomInfo?: (IRoomInfo|null);
}
export interface IStopFrameSyncBst {
roomInfo?: (IRoomInfo|null);
}
export interface IDestroyRoomBst {
roomInfo?: (IRoomInfo|null);
}
export interface IRoomInfo {
id?: (string|null);
name?: (string|null);
type?: (string|null);
createType?: (CreateRoomType|null);
maxPlayers?: (number|null);
owner?: (string|null);
isPrivate?: (boolean|null);
customProperties?: (string|null);
playerList?: (IPlayerInfo[]|null);
teamList?: (ITeamInfo[]|null);
frameSyncState?: (FrameSyncState|null);
frameRate?: (number|null);
routeId?: (string|null);
createTime?: (number|null);
startGameTime?: (number|null);
isForbidJoin?: (boolean|null);
}
export enum CreateRoomType {
COMMON_CREATE = 0,
MATCH_CREATE = 1
}
export interface IPlayerInfo {
id?: (string|null);
name?: (string|null);
teamId?: (string|null);
customPlayerStatus?: (number|null);
customProfile?: (string|null);
commonNetworkState?: (NetworkState|null);
relayNetworkState?: (NetworkState|null);
isRobot?: (boolean|null);
matchAttributes?: (IMatchAttribute[]|null);
}
export interface ITeamInfo {
id?: (string|null);
name?: (string|null);
minPlayers?: (number|null);
maxPlayers?: (number|null);
}
export enum FrameSyncState {
STOP = 0,
START = 1
}
export enum NetworkState {
COMMON_OFFLINE = 0,
COMMON_ONLINE = 1,
RELAY_OFFLINE = 2,
RELAY_ONLINE = 3
}
export interface IMatchAttribute {
name?: (string|null);
value?: (number|null);
}
//PROTO-STRUCT-END
export interface IGameInfo {
gameId: string;
serverKey: string;
}
export interface ResponseEvent<T> {
code: number;
msg: string;
seq: string;
data?: T;
}
export type ReqCallback<T> = (event: ResponseEvent<T>) => any;
export interface IGetRoomByRoomIdPara {
roomId: string;
}
export interface IGetRoomByRoomIdRsp {
roomInfo?: mgobexsInterface.IRoomInfo;
}
export interface IChangeRoomPara {
roomId: string;
roomName?: string;
owner?: string;
isPrivate?: boolean;
isForbidJoin?: boolean;
customProperties?: string;
}
export interface IChangeRoomRsp {
roomInfo?: mgobexsInterface.IRoomInfo;
}
export interface IChangeCustomPlayerStatusPara {
roomId: string;
playerId: string;
customPlayerStatus: number;
}
export interface IChangeCustomPlayerStatusRsp {
roomInfo?: mgobexsInterface.IRoomInfo;
}
export interface IRemovePlayerPara {
roomId: string;
removePlayerId: string;
}
export interface IRemovePlayerRsp {
roomInfo?: mgobexsInterface.IRoomInfo;
}
export interface GameData {
[key: string]: any;
}
export interface UserDefinedData {
[key: string]: any;
}
export interface ActionArgs<T> {
sender: string;
actionData: T;
gameData: GameData;
room: IRoomInfo;
exports: { data: GameData; };
SDK: {
sendData: (data: { playerIdList: string[]; data: UserDefinedData; }, resendConf?: { timeout: number; maxTry: number; }) => void;
dispatchAction: (actionData: UserDefinedData) => void;
clearAction: () => void;
exitAction: () => void;
getRoomByRoomId: (getRoomByRoomIdPara: IGetRoomByRoomIdPara, callback?: ReqCallback<IGetRoomByRoomIdRsp>) => void;
changeRoom: (changeRoomPara: IChangeRoomPara, callback?: ReqCallback<IChangeRoomRsp>) => void;
changeCustomPlayerStatus: (changeCustomPlayerStatusPara: IChangeCustomPlayerStatusPara, callback?: ReqCallback<IChangeCustomPlayerStatusRsp>) => void;
removePlayer: (removePlayerPara: IRemovePlayerPara, callback?: ReqCallback<IRemovePlayerRsp>) => void;
logger: {
debug: (...args: any[]) => void;
info: (...args: any[]) => void;
error: (...args: any[]) => void;
};
};
}
export namespace GameServer {
export type Receiver<T> = (data: ActionArgs<T>) => void;
export type onRecvFromClient = Receiver<UserDefinedData>;
export type onCreateRoom = Receiver<ICreateRoomBst>;
export type onJoinRoom = Receiver<IJoinRoomBst>;
export type onLeaveRoom = Receiver<ILeaveRoomBst>;
export type onRemovePlayer = Receiver<IRemovePlayerBst>;
export type onChangeRoom = Receiver<IChangeRoomBst>;
export type onChangeCustomPlayerStatus = Receiver<IChangeCustomPlayerStatusBst>;
export type onChangePlayerNetworkState = Receiver<IChangePlayerNetworkStateBst>;
export type onStartFrameSync = Receiver<IStartFrameSyncBst>;
export type onStopFrameSync = Receiver<IStopFrameSyncBst>;
export type onDestroyRoom = Receiver<IDestroyRoomBst>;
export interface IGameServer {
mode?: 'async' | 'sync';
onInitGameData: (args: { room: IRoomInfo; }) => GameData;
onRecvFromClient: onRecvFromClient;
onCreateRoom?: onCreateRoom;
onJoinRoom?: onJoinRoom;
onLeaveRoom?: onLeaveRoom;
onRemovePlayer?: onRemovePlayer;
onChangeRoom?: onChangeRoom;
onChangeCustomPlayerStatus?: onChangeCustomPlayerStatus;
onChangePlayerNetworkState?: onChangePlayerNetworkState;
onStartFrameSync?: onStartFrameSync;
onStopFrameSync?: onStopFrameSync;
onDestroyRoom?: onDestroyRoom;
}
}
export interface mgobexsCode {
logLevelSDK?: 'debug+' | 'info+' | 'error+';
logLevel?: 'debug+' | 'info+' | 'error+';
onInitGameServer?: (tcb: any) => any;
gameInfo: IGameInfo;
gameServer: GameServer.IGameServer;
}
}
\ No newline at end of file
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
//"outDir": "./", /* Redirect output structure to the directory. */
//"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "incremental": true, /* Enable incremental compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
"strictNullChecks": false, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"resolveJsonModule": true
}
}
{
"title": "play",
"title": "iDebugABC",
"packageName": "org.cocos2d.demo",
"startScene": "57ea7c61-9b8b-498a-b024-c98ee9124beb",
"startScene": "06cd8565-a4c1-447d-9d22-f34a4efe1390",
"excludeScenes": [],
"includeSDKBox": false,
"orientation": {
......@@ -19,16 +19,17 @@
"md5Cache": false,
"nativeMd5Cache": true,
"encryptJs": true,
"xxteaKey": "af95a0f7-a8da-4f",
"xxteaKey": "6bbfce23-28b4-4a",
"zipCompressJs": true,
"fb-instant-games": {},
"android": {
"REMOTE_SERVER_ROOT": "",
"packageName": "org.cocos2d.demo"
"packageName": "org.cocos2d.idebugabc"
},
"ios": {
"REMOTE_SERVER_ROOT": "",
"packageName": "org.cocos2d.demo"
"packageName": "org.cocos2d.demo",
"ios_enable_jit": true
},
"mac": {
"REMOTE_SERVER_ROOT": "",
......@@ -50,5 +51,6 @@
"scheme": "https",
"skipRecord": false
},
"appBundle": false
"appBundle": false,
"agreements": {}
}
{
"last-module-event-record-time": 1600677246969,
"last-module-event-record-time": 1637828733469,
"migrate-history": [
"cloud-function"
]
......
{
"game": {
"name": "未知游戏",
"appid": "UNKNOW"
}
"name": "oxford",
"appid": "682526339",
"cid": "14699"
},
"configs": [
{
"appid": "682526339",
"services": [
{
"service_id": "269",
"enable": true
}
]
}
],
"needExecNative": true
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment