Commit 86e9f109 authored by Chunchi Che's avatar Chunchi Che

add transformJoinGame_

parent 8669b58a
// todo: use interface
package darkneos
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"log"
"unicode/utf16"
"github.com/sktt1ryze/ygopro-proxy/DarkNeos/ygopropb"
......@@ -23,7 +26,8 @@ const (
CtosProtoPlayerInfo = 16
CtosProtoJoinGame = 18
StocChat = 25
StocJoinGame = 18
StocChat = 25
)
type YgoPacket struct {
......@@ -32,6 +36,19 @@ type YgoPacket struct {
Exdata []byte
}
type HostInfo struct {
Lflist uint32
Rule uint8
Mode uint8
DuelRule uint8
NoCheckDeck bool
NoShuffleDeck bool
StartLp uint32
StartHand uint8
DrawCount uint8
TimeLimit uint16
}
func packetToBuffer(pkt YgoPacket) []byte {
buf := make([]byte, 0)
......@@ -97,6 +114,11 @@ func Transform(src []byte, tranformType int) ([]byte, error) {
pb = ygopropb.YgoStocMsg{
Msg: &msg,
}
case StocJoinGame:
msg := transformJoinGame_(packet)
pb = ygopropb.YgoStocMsg{
Msg: &msg,
}
default:
return nil, errors.New("Unhandled YgoStocMsg type")
}
......@@ -107,8 +129,6 @@ func Transform(src []byte, tranformType int) ([]byte, error) {
}
}
// todo: use interface
// +++++ Client To Server +++++
// @Name: [20]uint16
......@@ -161,6 +181,40 @@ func transformChat(pkt YgoPacket) ygopropb.YgoStocMsg_StocChat {
}
}
// @lflist: uint32
// @rule: uint8
// @mode: uint8
// @duel_rule: uint8
// @no_check_deck: bool
// @no_shuffle_deck: bool
// @start_lp: uint32
// @start_hand: uint8
// @draw_count: uint8
// @time_limit: uint16
func transformJoinGame_(pkt YgoPacket) ygopropb.YgoStocMsg_StocJoinGame {
hostInfo := HostInfo{}
exData := bytes.NewBuffer(pkt.Exdata)
if err := binary.Read(exData, binary.LittleEndian, &hostInfo); err != nil {
log.Fatal(err)
}
return ygopropb.YgoStocMsg_StocJoinGame{
StocJoinGame: &ygopropb.StocJoinGame{
Lflist: int32(hostInfo.Lflist),
Rule: int32(hostInfo.Rule),
Mode: int32(hostInfo.Mode),
DuelRule: int32(hostInfo.DuelRule),
NoCheckDeck: hostInfo.NoCheckDeck,
NoShuffleDeck: hostInfo.NoShuffleDeck,
StartLp: int32(hostInfo.StartLp),
StartHand: int32(hostInfo.StartHand),
DrawCount: int32(hostInfo.DrawCount),
TimeLimit: int32(hostInfo.TimeLimit),
},
}
}
// +++++ Util Functions +++++
func strToUtf16Buffer(s string) []uint16 {
......
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