代码拉取完成,页面将自动刷新
实时服务器集成游戏联机对战引擎云开发,开发者可以在实时服务器上直接调用 游戏联机对战引擎云开发 中的云函数、云数据库、云存储等服务。
下面以云函数为例介绍如何在实时服务器中使用云开发,云开发中其它服务调用过程类似。
'use strict';
exports.main = (event, context, callback) => {
console.log("Hello World")
console.log(event)
console.log(event["non-exist"])
console.log(context)
callback(null, event);
};
import { mgobexsInterface } from './mgobexsInterface';
const gameServer: mgobexsInterface.GameServer.IGameServer = {
mode: 'sync',
onInitGameData: function (): mgobexsInterface.GameData {
return {};
},
onRecvFromClient: function onRecvFromClient({ actionData, gameData, SDK, room, exports }) {
// 收到客户端消息就调用云函数
tcbApp.callFunction({
name: "mgobe_test",
data: { a: 1 },
}).then((res: any) => {
// 返回成功结果
SDK.logger.debug({ res });
SDK.sendData({ playerIdList: [], data: { res } });
SDK.exitAction();
}).catch((err: any) => {
// 返回失败结果
SDK.logger.debug({ err });
SDK.sendData({ playerIdList: [], data: { err } });
SDK.exitAction();
});
}
};
let tcbApp: any;
// 服务器初始化时调用
function onInitGameServer(tcb: any) {
// 初始化 TCB
tcbApp = tcb.init({
secretId: "请填写腾讯云API密钥SecretId",
secretKey: "请填写腾讯云API密钥SecretKey",
env: "请填写云开发环境",
serviceUrl: 'http://tcb-admin.tencentyun.com/admin',
timeout: 5000,
});
}
export const mgobexsCode: mgobexsInterface.mgobexsCode = {
logLevel: 'debug+',
logLevelSDK: 'debug+',
gameInfo: {
gameId: "请填写游戏ID",
serverKey: "请填写后端密钥",
},
onInitGameServer,
gameServer
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。