Commit d51ac1c0 authored by Chunchi Che's avatar Chunchi Che

add MsgStartAdapter impl

parent ea97b52a
Pipeline #17779 passed with stages
in 4 minutes and 3 seconds
Subproject commit 6ecf0f70f5ba7917191907e7730ccac2a59d28e9 Subproject commit 867be3cee1dfe449735e81a85aa887724e8067cb
...@@ -458,7 +458,7 @@ export namespace ygopro { ...@@ -458,7 +458,7 @@ export namespace ygopro {
} }
} }
export class YgoStocMsg extends pb_1.Message { export class YgoStocMsg extends pb_1.Message {
#one_of_decls: number[][] = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]; #one_of_decls: number[][] = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]];
constructor( constructor(
data?: data?:
| any[] | any[]
...@@ -475,6 +475,7 @@ export namespace ygopro { ...@@ -475,6 +475,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -488,6 +489,7 @@ export namespace ygopro { ...@@ -488,6 +489,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -501,6 +503,7 @@ export namespace ygopro { ...@@ -501,6 +503,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -514,6 +517,7 @@ export namespace ygopro { ...@@ -514,6 +517,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -527,6 +531,7 @@ export namespace ygopro { ...@@ -527,6 +531,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -540,6 +545,7 @@ export namespace ygopro { ...@@ -540,6 +545,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -553,6 +559,7 @@ export namespace ygopro { ...@@ -553,6 +559,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -566,6 +573,7 @@ export namespace ygopro { ...@@ -566,6 +573,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -579,6 +587,7 @@ export namespace ygopro { ...@@ -579,6 +587,7 @@ export namespace ygopro {
stoc_select_tp?: StocSelectTp; stoc_select_tp?: StocSelectTp;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -592,6 +601,7 @@ export namespace ygopro { ...@@ -592,6 +601,7 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: StocDeckCount; stoc_deck_count?: StocDeckCount;
stoc_duel_start?: never; stoc_duel_start?: never;
stoc_game_msg?: never;
} }
| { | {
stoc_join_game?: never; stoc_join_game?: never;
...@@ -605,6 +615,21 @@ export namespace ygopro { ...@@ -605,6 +615,21 @@ export namespace ygopro {
stoc_select_tp?: never; stoc_select_tp?: never;
stoc_deck_count?: never; stoc_deck_count?: never;
stoc_duel_start?: StocDuelStart; stoc_duel_start?: StocDuelStart;
stoc_game_msg?: never;
}
| {
stoc_join_game?: never;
stoc_chat?: never;
stoc_hs_player_enter?: never;
stoc_type_change?: never;
stoc_hs_player_change?: never;
stoc_hs_watch_change?: never;
stoc_select_hand?: never;
stoc_hand_result?: never;
stoc_select_tp?: never;
stoc_deck_count?: never;
stoc_duel_start?: never;
stoc_game_msg?: StocGameMessage;
} }
)) ))
) { ) {
...@@ -660,6 +685,9 @@ export namespace ygopro { ...@@ -660,6 +685,9 @@ export namespace ygopro {
if ("stoc_duel_start" in data && data.stoc_duel_start != undefined) { if ("stoc_duel_start" in data && data.stoc_duel_start != undefined) {
this.stoc_duel_start = data.stoc_duel_start; this.stoc_duel_start = data.stoc_duel_start;
} }
if ("stoc_game_msg" in data && data.stoc_game_msg != undefined) {
this.stoc_game_msg = data.stoc_game_msg;
}
} }
} }
get stoc_join_game() { get stoc_join_game() {
...@@ -801,6 +829,19 @@ export namespace ygopro { ...@@ -801,6 +829,19 @@ export namespace ygopro {
get has_stoc_duel_start() { get has_stoc_duel_start() {
return pb_1.Message.getField(this, 11) != null; return pb_1.Message.getField(this, 11) != null;
} }
get stoc_game_msg() {
return pb_1.Message.getWrapperField(
this,
StocGameMessage,
12
) as StocGameMessage;
}
set stoc_game_msg(value: StocGameMessage) {
pb_1.Message.setOneofWrapperField(this, 12, this.#one_of_decls[0], value);
}
get has_stoc_game_msg() {
return pb_1.Message.getField(this, 12) != null;
}
get msg() { get msg() {
const cases: { const cases: {
[index: number]: [index: number]:
...@@ -815,7 +856,8 @@ export namespace ygopro { ...@@ -815,7 +856,8 @@ export namespace ygopro {
| "stoc_hand_result" | "stoc_hand_result"
| "stoc_select_tp" | "stoc_select_tp"
| "stoc_deck_count" | "stoc_deck_count"
| "stoc_duel_start"; | "stoc_duel_start"
| "stoc_game_msg";
} = { } = {
0: "none", 0: "none",
1: "stoc_join_game", 1: "stoc_join_game",
...@@ -829,9 +871,13 @@ export namespace ygopro { ...@@ -829,9 +871,13 @@ export namespace ygopro {
9: "stoc_select_tp", 9: "stoc_select_tp",
10: "stoc_deck_count", 10: "stoc_deck_count",
11: "stoc_duel_start", 11: "stoc_duel_start",
12: "stoc_game_msg",
}; };
return cases[ return cases[
pb_1.Message.computeOneofCase(this, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) pb_1.Message.computeOneofCase(
this,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
)
]; ];
} }
static fromObject(data: { static fromObject(data: {
...@@ -852,6 +898,7 @@ export namespace ygopro { ...@@ -852,6 +898,7 @@ export namespace ygopro {
stoc_select_tp?: ReturnType<typeof StocSelectTp.prototype.toObject>; stoc_select_tp?: ReturnType<typeof StocSelectTp.prototype.toObject>;
stoc_deck_count?: ReturnType<typeof StocDeckCount.prototype.toObject>; stoc_deck_count?: ReturnType<typeof StocDeckCount.prototype.toObject>;
stoc_duel_start?: ReturnType<typeof StocDuelStart.prototype.toObject>; stoc_duel_start?: ReturnType<typeof StocDuelStart.prototype.toObject>;
stoc_game_msg?: ReturnType<typeof StocGameMessage.prototype.toObject>;
}): YgoStocMsg { }): YgoStocMsg {
const message = new YgoStocMsg({}); const message = new YgoStocMsg({});
if (data.stoc_join_game != null) { if (data.stoc_join_game != null) {
...@@ -903,6 +950,9 @@ export namespace ygopro { ...@@ -903,6 +950,9 @@ export namespace ygopro {
data.stoc_duel_start data.stoc_duel_start
); );
} }
if (data.stoc_game_msg != null) {
message.stoc_game_msg = StocGameMessage.fromObject(data.stoc_game_msg);
}
return message; return message;
} }
toObject() { toObject() {
...@@ -924,6 +974,7 @@ export namespace ygopro { ...@@ -924,6 +974,7 @@ export namespace ygopro {
stoc_select_tp?: ReturnType<typeof StocSelectTp.prototype.toObject>; stoc_select_tp?: ReturnType<typeof StocSelectTp.prototype.toObject>;
stoc_deck_count?: ReturnType<typeof StocDeckCount.prototype.toObject>; stoc_deck_count?: ReturnType<typeof StocDeckCount.prototype.toObject>;
stoc_duel_start?: ReturnType<typeof StocDuelStart.prototype.toObject>; stoc_duel_start?: ReturnType<typeof StocDuelStart.prototype.toObject>;
stoc_game_msg?: ReturnType<typeof StocGameMessage.prototype.toObject>;
} = {}; } = {};
if (this.stoc_join_game != null) { if (this.stoc_join_game != null) {
data.stoc_join_game = this.stoc_join_game.toObject(); data.stoc_join_game = this.stoc_join_game.toObject();
...@@ -958,6 +1009,9 @@ export namespace ygopro { ...@@ -958,6 +1009,9 @@ export namespace ygopro {
if (this.stoc_duel_start != null) { if (this.stoc_duel_start != null) {
data.stoc_duel_start = this.stoc_duel_start.toObject(); data.stoc_duel_start = this.stoc_duel_start.toObject();
} }
if (this.stoc_game_msg != null) {
data.stoc_game_msg = this.stoc_game_msg.toObject();
}
return data; return data;
} }
serialize(): Uint8Array; serialize(): Uint8Array;
...@@ -1008,6 +1062,10 @@ export namespace ygopro { ...@@ -1008,6 +1062,10 @@ export namespace ygopro {
writer.writeMessage(11, this.stoc_duel_start, () => writer.writeMessage(11, this.stoc_duel_start, () =>
this.stoc_duel_start.serialize(writer) this.stoc_duel_start.serialize(writer)
); );
if (this.has_stoc_game_msg)
writer.writeMessage(12, this.stoc_game_msg, () =>
this.stoc_game_msg.serialize(writer)
);
if (!w) return writer.getResultBuffer(); if (!w) return writer.getResultBuffer();
} }
static deserialize(bytes: Uint8Array | pb_1.BinaryReader): YgoStocMsg { static deserialize(bytes: Uint8Array | pb_1.BinaryReader): YgoStocMsg {
...@@ -1096,6 +1154,13 @@ export namespace ygopro { ...@@ -1096,6 +1154,13 @@ export namespace ygopro {
(message.stoc_duel_start = StocDuelStart.deserialize(reader)) (message.stoc_duel_start = StocDuelStart.deserialize(reader))
); );
break; break;
case 12:
reader.readMessage(
message.stoc_game_msg,
() =>
(message.stoc_game_msg = StocGameMessage.deserialize(reader))
);
break;
default: default:
reader.skipField(); reader.skipField();
} }
......
...@@ -21,3 +21,5 @@ export const STOC_SELECT_TP = 4; ...@@ -21,3 +21,5 @@ export const STOC_SELECT_TP = 4;
export const STOC_HAND_RESULT = 5; export const STOC_HAND_RESULT = 5;
export const STOC_DECK_COUNT = 9; export const STOC_DECK_COUNT = 9;
export const STOC_DUEL_START = 21; export const STOC_DUEL_START = 21;
export const MSG_START = 4;
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import { ygopro } from "../../../idl/ocgcore"; import { ygopro } from "../../../idl/ocgcore";
import { YgoProPacket, StocAdapter } from "../../packet"; import { YgoProPacket, StocAdapter } from "../../packet";
import { MSG_START } from "../../protoDecl";
import MsgStartAdapter from "./start";
/* /*
* STOC GameMsg * STOC GameMsg
...@@ -22,7 +24,28 @@ export default class GameMsgAdapter implements StocAdapter { ...@@ -22,7 +24,28 @@ export default class GameMsgAdapter implements StocAdapter {
} }
upcast(): ygopro.YgoStocMsg { upcast(): ygopro.YgoStocMsg {
// TODO const exData = this.packet.exData;
return new ygopro.YgoStocMsg({}); const dataView = new DataView(exData.buffer);
const func = dataView.getUint8(0);
const gameData = exData.slice(1);
const gameMsg = new ygopro.StocGameMessage({});
switch (func) {
case MSG_START: {
gameMsg.start = MsgStartAdapter(gameData);
break;
}
default: {
console.log("Unhandled GameMessage function=", func);
break;
}
}
return new ygopro.YgoStocMsg({
stoc_game_msg: gameMsg,
});
} }
} }
import { ygopro } from "../../../idl/ocgcore";
const LITTLE_ENDIAN = true;
const INT16_BYTE_OFFSET = 2;
const INT32_BYTE_OFFSET = 4;
/*
* MSG Start
*
* @param todo
*
* @usage - 服务端在决斗开始时告诉前端/客户端双方的基础信息
* */
export default (data: Uint8Array) => {
const dataView = new DataView(data.buffer);
// TODO: 对DataView包装下实现一个BufferIO类,便于解析二进制数据
const pT = dataView.getUint8(0);
const playerType =
(pT & 0xf) <= 0
? ygopro.StocGameMessage.MsgStart.PlayerType.FirstStrike
: (pT & 0xf0) > 0
? ygopro.StocGameMessage.MsgStart.PlayerType.Observer
: ygopro.StocGameMessage.MsgStart.PlayerType.SecondStrike;
let offset = 1;
if (dataView.byteLength > 17) {
// data长度大于17,会多传一个大师规则字段
const masterRule = dataView.getUint8(offset); // TODO
offset += 1;
}
const life1 = dataView.getInt32(offset, LITTLE_ENDIAN);
offset += INT32_BYTE_OFFSET;
const life2 = dataView.getInt32(offset, LITTLE_ENDIAN);
offset += INT32_BYTE_OFFSET;
const deckSize1 = dataView.getInt16(offset, LITTLE_ENDIAN);
offset += INT16_BYTE_OFFSET;
const extraSize1 = dataView.getInt16(offset, LITTLE_ENDIAN);
offset += INT16_BYTE_OFFSET;
const deckSize2 = dataView.getInt16(offset, LITTLE_ENDIAN);
offset += INT16_BYTE_OFFSET;
const extraSize2 = dataView.getInt16(offset, LITTLE_ENDIAN);
offset += INT16_BYTE_OFFSET;
return new ygopro.StocGameMessage.MsgStart({
playerType,
life1,
life2,
deckSize1,
deckSize2,
extraSize1,
extraSize2,
});
};
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