From 677e76179ca055669c4c987a5be1ff99d9e04587 Mon Sep 17 00:00:00 2001 From: genxium Date: Sun, 29 Jan 2023 22:38:12 +0800 Subject: [PATCH] Minor fix. --- battle_srv/models/room.go | 1 + battle_srv/protos/room_downsync_frame.pb.go | 40 +++++++------- .../pbfiles/room_downsync_frame.proto | 6 +-- frontend/assets/scripts/OfflineMap.js | 2 +- frontend/assets/scripts/WsSessionMgr.js | 5 +- ...om_downsync_frame_proto_bundle.forcemsg.js | 52 +++++++++---------- .../Classes/udp_session_bridge.cpp | 6 +-- 7 files changed, 57 insertions(+), 55 deletions(-) diff --git a/battle_srv/models/room.go b/battle_srv/models/room.go index b688bd3..0168cad 100644 --- a/battle_srv/models/room.go +++ b/battle_srv/models/room.go @@ -1732,6 +1732,7 @@ func (pR *Room) startBattleUdpTunnel() { continue } playerId := pReq.PlayerId + Logger.Info(fmt.Sprintf("`BattleUdpTunnel` for roomId=%d received decoded WsReq:", pR.Id), zap.Any("pReq", pReq)) if player, exists1 := pR.Players[playerId]; exists1 { authKey := pReq.AuthKey if authKey != player.BattleUdpTunnelAuthKey { diff --git a/battle_srv/protos/room_downsync_frame.pb.go b/battle_srv/protos/room_downsync_frame.pb.go index 07ab68e..8893d07 100644 --- a/battle_srv/protos/room_downsync_frame.pb.go +++ b/battle_srv/protos/room_downsync_frame.pb.go @@ -571,9 +571,9 @@ type WsReq struct { JoinIndex int32 `protobuf:"varint,4,opt,name=joinIndex,proto3" json:"joinIndex,omitempty"` AckingFrameId int32 `protobuf:"varint,5,opt,name=ackingFrameId,proto3" json:"ackingFrameId,omitempty"` AckingInputFrameId int32 `protobuf:"varint,6,opt,name=ackingInputFrameId,proto3" json:"ackingInputFrameId,omitempty"` - InputFrameUpsyncBatch []*InputFrameUpsync `protobuf:"bytes,7,rep,name=inputFrameUpsyncBatch,proto3" json:"inputFrameUpsyncBatch,omitempty"` - Hb *HeartbeatUpsync `protobuf:"bytes,8,opt,name=hb,proto3" json:"hb,omitempty"` - AuthKey int32 `protobuf:"varint,9,opt,name=authKey,proto3" json:"authKey,omitempty"` + AuthKey int32 `protobuf:"varint,7,opt,name=authKey,proto3" json:"authKey,omitempty"` + InputFrameUpsyncBatch []*InputFrameUpsync `protobuf:"bytes,8,rep,name=inputFrameUpsyncBatch,proto3" json:"inputFrameUpsyncBatch,omitempty"` + Hb *HeartbeatUpsync `protobuf:"bytes,9,opt,name=hb,proto3" json:"hb,omitempty"` } func (x *WsReq) Reset() { @@ -650,6 +650,13 @@ func (x *WsReq) GetAckingInputFrameId() int32 { return 0 } +func (x *WsReq) GetAuthKey() int32 { + if x != nil { + return x.AuthKey + } + return 0 +} + func (x *WsReq) GetInputFrameUpsyncBatch() []*InputFrameUpsync { if x != nil { return x.InputFrameUpsyncBatch @@ -664,13 +671,6 @@ func (x *WsReq) GetHb() *HeartbeatUpsync { return nil } -func (x *WsReq) GetAuthKey() int32 { - if x != nil { - return x.AuthKey - } - return 0 -} - type InputsBufferSnapshot struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1883,16 +1883,16 @@ var file_room_downsync_frame_proto_rawDesc = []byte{ 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x2e, 0x0a, 0x12, 0x61, 0x63, 0x6b, 0x69, 0x6e, 0x67, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x12, 0x61, 0x63, 0x6b, 0x69, 0x6e, 0x67, 0x49, 0x6e, 0x70, 0x75, 0x74, - 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x4e, 0x0a, 0x15, 0x69, 0x6e, 0x70, 0x75, 0x74, - 0x46, 0x72, 0x61, 0x6d, 0x65, 0x55, 0x70, 0x73, 0x79, 0x6e, 0x63, 0x42, 0x61, 0x74, 0x63, 0x68, - 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x55, 0x70, 0x73, 0x79, 0x6e, 0x63, - 0x52, 0x15, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x55, 0x70, 0x73, 0x79, - 0x6e, 0x63, 0x42, 0x61, 0x74, 0x63, 0x68, 0x12, 0x27, 0x0a, 0x02, 0x68, 0x62, 0x18, 0x08, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x48, 0x65, 0x61, - 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x55, 0x70, 0x73, 0x79, 0x6e, 0x63, 0x52, 0x02, 0x68, 0x62, - 0x12, 0x18, 0x0a, 0x07, 0x61, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x18, 0x09, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x07, 0x61, 0x75, 0x74, 0x68, 0x4b, 0x65, 0x79, 0x22, 0x9a, 0x02, 0x0a, 0x14, 0x49, + 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x75, 0x74, 0x68, 0x4b, + 0x65, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x61, 0x75, 0x74, 0x68, 0x4b, 0x65, + 0x79, 0x12, 0x4e, 0x0a, 0x15, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x55, + 0x70, 0x73, 0x79, 0x6e, 0x63, 0x42, 0x61, 0x74, 0x63, 0x68, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x46, + 0x72, 0x61, 0x6d, 0x65, 0x55, 0x70, 0x73, 0x79, 0x6e, 0x63, 0x52, 0x15, 0x69, 0x6e, 0x70, 0x75, + 0x74, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x55, 0x70, 0x73, 0x79, 0x6e, 0x63, 0x42, 0x61, 0x74, 0x63, + 0x68, 0x12, 0x27, 0x0a, 0x02, 0x68, 0x62, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, + 0x55, 0x70, 0x73, 0x79, 0x6e, 0x63, 0x52, 0x02, 0x68, 0x62, 0x22, 0x9a, 0x02, 0x0a, 0x14, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x73, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x53, 0x6e, 0x61, 0x70, 0x73, 0x68, 0x6f, 0x74, 0x12, 0x2a, 0x0a, 0x10, 0x72, 0x65, 0x66, 0x52, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x72, diff --git a/frontend/assets/resources/pbfiles/room_downsync_frame.proto b/frontend/assets/resources/pbfiles/room_downsync_frame.proto index 4606d0f..e5effaa 100644 --- a/frontend/assets/resources/pbfiles/room_downsync_frame.proto +++ b/frontend/assets/resources/pbfiles/room_downsync_frame.proto @@ -73,9 +73,9 @@ message WsReq { int32 joinIndex = 4; int32 ackingFrameId = 5; int32 ackingInputFrameId = 6; - repeated InputFrameUpsync inputFrameUpsyncBatch = 7; - HeartbeatUpsync hb = 8; - int32 authKey = 9; + int32 authKey = 7; + repeated InputFrameUpsync inputFrameUpsyncBatch = 8; + HeartbeatUpsync hb = 9; } message InputsBufferSnapshot { diff --git a/frontend/assets/scripts/OfflineMap.js b/frontend/assets/scripts/OfflineMap.js index 4118d0b..7105c67 100644 --- a/frontend/assets/scripts/OfflineMap.js +++ b/frontend/assets/scripts/OfflineMap.js @@ -161,7 +161,7 @@ cc.Class({ intAuthToken: "foobar", authKey: Math.floor(Math.random() * 65535), }).finish() - const res2 = DelayNoMore.UdpSession.punchToServer("127.0.0.1", 3000, holePunchData); + //const res2 = DelayNoMore.UdpSession.punchToServer("127.0.0.1", 3000, holePunchData, 19999, holePunchData); const res3 = DelayNoMore.UdpSession.upsertPeerUdpAddr([window.pb.protos.PeerUdpAddr.create({ ip: "192.168.31.194", port: 6789, diff --git a/frontend/assets/scripts/WsSessionMgr.js b/frontend/assets/scripts/WsSessionMgr.js index c0c6e20..45e1f2f 100644 --- a/frontend/assets/scripts/WsSessionMgr.js +++ b/frontend/assets/scripts/WsSessionMgr.js @@ -107,8 +107,9 @@ window.handleHbRequirements = function(resp) { authKey: authKey, }).finish(); const udpTunnelHolePunchData = window.pb.protos.WsReq.encode({ - playerId: window.mapIns.selfPlayerInfo.playerId, - joinIndex: window.mapIns.selfPlayerInfo.JoinIndex, + msgId: Date.now(), + playerId: window.mapIns.selfPlayerInfo.Id, + act: window.UPSYNC_MSG_ACT_PLAYER_CMD, authKey: resp.bciFrame.battleUdpTunnel.authKey, }).finish(); const res2 = DelayNoMore.UdpSession.punchToServer(backendAddress.HOST, 3000, holePunchData, resp.bciFrame.battleUdpTunnel.port, udpTunnelHolePunchData); diff --git a/frontend/assets/scripts/modules/room_downsync_frame_proto_bundle.forcemsg.js b/frontend/assets/scripts/modules/room_downsync_frame_proto_bundle.forcemsg.js index 7604806..69ff8f4 100644 --- a/frontend/assets/scripts/modules/room_downsync_frame_proto_bundle.forcemsg.js +++ b/frontend/assets/scripts/modules/room_downsync_frame_proto_bundle.forcemsg.js @@ -3167,9 +3167,9 @@ $root.protos = (function() { * @property {number|null} [joinIndex] WsReq joinIndex * @property {number|null} [ackingFrameId] WsReq ackingFrameId * @property {number|null} [ackingInputFrameId] WsReq ackingInputFrameId + * @property {number|null} [authKey] WsReq authKey * @property {Array.|null} [inputFrameUpsyncBatch] WsReq inputFrameUpsyncBatch * @property {protos.HeartbeatUpsync|null} [hb] WsReq hb - * @property {number|null} [authKey] WsReq authKey */ /** @@ -3236,6 +3236,14 @@ $root.protos = (function() { */ WsReq.prototype.ackingInputFrameId = 0; + /** + * WsReq authKey. + * @member {number} authKey + * @memberof protos.WsReq + * @instance + */ + WsReq.prototype.authKey = 0; + /** * WsReq inputFrameUpsyncBatch. * @member {Array.} inputFrameUpsyncBatch @@ -3252,14 +3260,6 @@ $root.protos = (function() { */ WsReq.prototype.hb = null; - /** - * WsReq authKey. - * @member {number} authKey - * @memberof protos.WsReq - * @instance - */ - WsReq.prototype.authKey = 0; - /** * Creates a new WsReq instance using the specified properties. * @function create @@ -3296,13 +3296,13 @@ $root.protos = (function() { writer.uint32(/* id 5, wireType 0 =*/40).int32(message.ackingFrameId); if (message.ackingInputFrameId != null && Object.hasOwnProperty.call(message, "ackingInputFrameId")) writer.uint32(/* id 6, wireType 0 =*/48).int32(message.ackingInputFrameId); + if (message.authKey != null && Object.hasOwnProperty.call(message, "authKey")) + writer.uint32(/* id 7, wireType 0 =*/56).int32(message.authKey); if (message.inputFrameUpsyncBatch != null && message.inputFrameUpsyncBatch.length) for (var i = 0; i < message.inputFrameUpsyncBatch.length; ++i) - $root.protos.InputFrameUpsync.encode(message.inputFrameUpsyncBatch[i], writer.uint32(/* id 7, wireType 2 =*/58).fork()).ldelim(); + $root.protos.InputFrameUpsync.encode(message.inputFrameUpsyncBatch[i], writer.uint32(/* id 8, wireType 2 =*/66).fork()).ldelim(); if (message.hb != null && Object.hasOwnProperty.call(message, "hb")) - $root.protos.HeartbeatUpsync.encode(message.hb, writer.uint32(/* id 8, wireType 2 =*/66).fork()).ldelim(); - if (message.authKey != null && Object.hasOwnProperty.call(message, "authKey")) - writer.uint32(/* id 9, wireType 0 =*/72).int32(message.authKey); + $root.protos.HeartbeatUpsync.encode(message.hb, writer.uint32(/* id 9, wireType 2 =*/74).fork()).ldelim(); return writer; }; @@ -3362,17 +3362,17 @@ $root.protos = (function() { break; } case 7: { + message.authKey = reader.int32(); + break; + } + case 8: { if (!(message.inputFrameUpsyncBatch && message.inputFrameUpsyncBatch.length)) message.inputFrameUpsyncBatch = []; message.inputFrameUpsyncBatch.push($root.protos.InputFrameUpsync.decode(reader, reader.uint32())); break; } - case 8: { - message.hb = $root.protos.HeartbeatUpsync.decode(reader, reader.uint32()); - break; - } case 9: { - message.authKey = reader.int32(); + message.hb = $root.protos.HeartbeatUpsync.decode(reader, reader.uint32()); break; } default: @@ -3428,6 +3428,9 @@ $root.protos = (function() { if (message.ackingInputFrameId != null && message.hasOwnProperty("ackingInputFrameId")) if (!$util.isInteger(message.ackingInputFrameId)) return "ackingInputFrameId: integer expected"; + if (message.authKey != null && message.hasOwnProperty("authKey")) + if (!$util.isInteger(message.authKey)) + return "authKey: integer expected"; if (message.inputFrameUpsyncBatch != null && message.hasOwnProperty("inputFrameUpsyncBatch")) { if (!Array.isArray(message.inputFrameUpsyncBatch)) return "inputFrameUpsyncBatch: array expected"; @@ -3442,9 +3445,6 @@ $root.protos = (function() { if (error) return "hb." + error; } - if (message.authKey != null && message.hasOwnProperty("authKey")) - if (!$util.isInteger(message.authKey)) - return "authKey: integer expected"; return null; }; @@ -3472,6 +3472,8 @@ $root.protos = (function() { message.ackingFrameId = object.ackingFrameId | 0; if (object.ackingInputFrameId != null) message.ackingInputFrameId = object.ackingInputFrameId | 0; + if (object.authKey != null) + message.authKey = object.authKey | 0; if (object.inputFrameUpsyncBatch) { if (!Array.isArray(object.inputFrameUpsyncBatch)) throw TypeError(".protos.WsReq.inputFrameUpsyncBatch: array expected"); @@ -3487,8 +3489,6 @@ $root.protos = (function() { throw TypeError(".protos.WsReq.hb: object expected"); message.hb = $root.protos.HeartbeatUpsync.fromObject(object.hb); } - if (object.authKey != null) - message.authKey = object.authKey | 0; return message; }; @@ -3514,8 +3514,8 @@ $root.protos = (function() { object.joinIndex = 0; object.ackingFrameId = 0; object.ackingInputFrameId = 0; - object.hb = null; object.authKey = 0; + object.hb = null; } if (message.msgId != null && message.hasOwnProperty("msgId")) object.msgId = message.msgId; @@ -3529,6 +3529,8 @@ $root.protos = (function() { object.ackingFrameId = message.ackingFrameId; if (message.ackingInputFrameId != null && message.hasOwnProperty("ackingInputFrameId")) object.ackingInputFrameId = message.ackingInputFrameId; + if (message.authKey != null && message.hasOwnProperty("authKey")) + object.authKey = message.authKey; if (message.inputFrameUpsyncBatch && message.inputFrameUpsyncBatch.length) { object.inputFrameUpsyncBatch = []; for (var j = 0; j < message.inputFrameUpsyncBatch.length; ++j) @@ -3536,8 +3538,6 @@ $root.protos = (function() { } if (message.hb != null && message.hasOwnProperty("hb")) object.hb = $root.protos.HeartbeatUpsync.toObject(message.hb, options); - if (message.authKey != null && message.hasOwnProperty("authKey")) - object.authKey = message.authKey; return object; }; diff --git a/frontend/build-templates/jsb-link/frameworks/runtime-src/Classes/udp_session_bridge.cpp b/frontend/build-templates/jsb-link/frameworks/runtime-src/Classes/udp_session_bridge.cpp index 57adc7e..da214da 100644 --- a/frontend/build-templates/jsb-link/frameworks/runtime-src/Classes/udp_session_bridge.cpp +++ b/frontend/build-templates/jsb-link/frameworks/runtime-src/Classes/udp_session_bridge.cpp @@ -28,7 +28,7 @@ bool punchToServer(se::State& s) { SE_PRECONDITION2(ok, false, "punchToServer: Error processing arguments"); CHARC* srvIp = args[0].toString().c_str(); int srvPort = args[1].toInt32(); - BYTEC bytes[1024]; + BYTEC bytes[maxUdpPayloadBytes]; memset(bytes, 0, sizeof bytes); se::Object* obj = args[2].toObject(); size_t sz = 0; @@ -39,12 +39,12 @@ bool punchToServer(se::State& s) { } int udpTunnelSrvPort = args[3].toInt32(); - BYTEC udpTunnelBytes[1024]; + BYTEC udpTunnelBytes[maxUdpPayloadBytes]; memset(udpTunnelBytes, 0, sizeof udpTunnelBytes); se::Object* udpTunnelObj = args[4].toObject(); size_t udpTunnelSz = 0; uint8_t* udpTunnelPtr = NULL; - obj->getTypedArrayData(&udpTunnelPtr, &udpTunnelSz); + udpTunnelObj->getTypedArrayData(&udpTunnelPtr, &udpTunnelSz); for (size_t i = 0; i < udpTunnelSz; i++) { udpTunnelBytes[i] = (char)(*(udpTunnelPtr + i)); }