From db550ce86fda38f42cedacec9244fb5f340e1f6f Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 21 Jun 2024 09:50:46 +0800 Subject: [PATCH] Store chunk header when unpacking --- messages7/cl_start_info.go | 6 +++--- messages7/enter_game.go | 6 +++--- messages7/info.go | 6 +++--- messages7/net_message.go | 2 +- messages7/ready.go | 6 +++--- messages7/ready_to_enter.go | 6 +++--- messages7/sv_chat.go | 6 +++--- messages7/sv_client_info.go | 6 +++--- protocol7/connection.go | 4 ++-- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/messages7/cl_start_info.go b/messages7/cl_start_info.go index 9a8e0db..23c28fe 100644 --- a/messages7/cl_start_info.go +++ b/messages7/cl_start_info.go @@ -9,7 +9,7 @@ import ( ) type ClStartInfo struct { - header *chunk7.ChunkHeader + ChunkHeader *chunk7.ChunkHeader Name string Clan string @@ -101,9 +101,9 @@ func (info *ClStartInfo) Unpack(u *packer.Unpacker) { } func (msg *ClStartInfo) Header() *chunk7.ChunkHeader { - return msg.header + return msg.ChunkHeader } func (msg *ClStartInfo) SetHeader(header *chunk7.ChunkHeader) { - msg.header = header + msg.ChunkHeader = header } diff --git a/messages7/enter_game.go b/messages7/enter_game.go index 84b3fb8..9e70176 100644 --- a/messages7/enter_game.go +++ b/messages7/enter_game.go @@ -7,7 +7,7 @@ import ( ) type EnterGame struct { - header *chunk7.ChunkHeader + ChunkHeader *chunk7.ChunkHeader } func (msg EnterGame) MsgId() int { @@ -34,9 +34,9 @@ func (msg *EnterGame) Unpack(u *packer.Unpacker) { } func (msg *EnterGame) Header() *chunk7.ChunkHeader { - return msg.header + return msg.ChunkHeader } func (msg *EnterGame) SetHeader(header *chunk7.ChunkHeader) { - msg.header = header + msg.ChunkHeader = header } diff --git a/messages7/info.go b/messages7/info.go index db51233..f97009c 100644 --- a/messages7/info.go +++ b/messages7/info.go @@ -7,7 +7,7 @@ import ( ) type Info struct { - header *chunk7.ChunkHeader + ChunkHeader *chunk7.ChunkHeader } func (msg Info) MsgId() int { @@ -41,9 +41,9 @@ func (msg *Info) Unpack(u *packer.Unpacker) { } func (msg *Info) Header() *chunk7.ChunkHeader { - return msg.header + return msg.ChunkHeader } func (msg *Info) SetHeader(header *chunk7.ChunkHeader) { - msg.header = header + msg.ChunkHeader = header } diff --git a/messages7/net_message.go b/messages7/net_message.go index 0d26307..eb69b83 100644 --- a/messages7/net_message.go +++ b/messages7/net_message.go @@ -15,5 +15,5 @@ type NetMessage interface { Unpack(u *packer.Unpacker) Header() *chunk7.ChunkHeader - SetHeader(chunkHeader *chunk7.ChunkHeader) + SetHeader(header *chunk7.ChunkHeader) } diff --git a/messages7/ready.go b/messages7/ready.go index d0e6916..9384b7c 100644 --- a/messages7/ready.go +++ b/messages7/ready.go @@ -7,7 +7,7 @@ import ( ) type Ready struct { - header *chunk7.ChunkHeader + ChunkHeader *chunk7.ChunkHeader } func (msg Ready) MsgId() int { @@ -34,9 +34,9 @@ func (msg *Ready) Unpack(u *packer.Unpacker) { } func (msg *Ready) Header() *chunk7.ChunkHeader { - return msg.header + return msg.ChunkHeader } func (msg *Ready) SetHeader(header *chunk7.ChunkHeader) { - msg.header = header + msg.ChunkHeader = header } diff --git a/messages7/ready_to_enter.go b/messages7/ready_to_enter.go index b1a7ccb..45d88bc 100644 --- a/messages7/ready_to_enter.go +++ b/messages7/ready_to_enter.go @@ -7,7 +7,7 @@ import ( ) type ReadyToEnter struct { - header *chunk7.ChunkHeader + ChunkHeader *chunk7.ChunkHeader } func (msg ReadyToEnter) MsgId() int { @@ -34,9 +34,9 @@ func (msg *ReadyToEnter) Unpack(u *packer.Unpacker) { } func (msg *ReadyToEnter) Header() *chunk7.ChunkHeader { - return msg.header + return msg.ChunkHeader } func (msg *ReadyToEnter) SetHeader(header *chunk7.ChunkHeader) { - msg.header = header + msg.ChunkHeader = header } diff --git a/messages7/sv_chat.go b/messages7/sv_chat.go index 66a1bb7..e5da51e 100644 --- a/messages7/sv_chat.go +++ b/messages7/sv_chat.go @@ -9,7 +9,7 @@ import ( ) type SvChat struct { - header *chunk7.ChunkHeader + ChunkHeader *chunk7.ChunkHeader Mode int ClientId int @@ -50,9 +50,9 @@ func (msg *SvChat) Unpack(u *packer.Unpacker) { } func (msg *SvChat) Header() *chunk7.ChunkHeader { - return msg.header + return msg.ChunkHeader } func (msg *SvChat) SetHeader(header *chunk7.ChunkHeader) { - msg.header = header + msg.ChunkHeader = header } diff --git a/messages7/sv_client_info.go b/messages7/sv_client_info.go index 4bc754c..b5dde22 100644 --- a/messages7/sv_client_info.go +++ b/messages7/sv_client_info.go @@ -7,7 +7,7 @@ import ( ) type SvClientInfo struct { - header *chunk7.ChunkHeader + ChunkHeader *chunk7.ChunkHeader ClientId int Local bool @@ -79,9 +79,9 @@ func (info *SvClientInfo) Unpack(u *packer.Unpacker) { } func (msg *SvClientInfo) Header() *chunk7.ChunkHeader { - return msg.header + return msg.ChunkHeader } func (msg *SvClientInfo) SetHeader(header *chunk7.ChunkHeader) { - msg.header = header + msg.ChunkHeader = header } diff --git a/protocol7/connection.go b/protocol7/connection.go index 7f7132e..0a0e586 100644 --- a/protocol7/connection.go +++ b/protocol7/connection.go @@ -123,7 +123,7 @@ func (client *Connection) OnMotd(motd string) { func (client *Connection) OnGameMsg(msg int, chunk chunk7.Chunk, u *packer.Unpacker, result *PacketResult) { if msg == network7.MsgGameReadyToEnter { fmt.Println("got ready to enter") - result.Packet.Messages = append(result.Packet.Messages, &messages7.Ready{}) + result.Packet.Messages = append(result.Packet.Messages, &messages7.Ready{ChunkHeader: &chunk.Header}) result.Response.Messages = append(result.Response.Messages, &messages7.EnterGame{}) } else if msg == network7.MsgGameSvMotd { motd := u.GetString() @@ -131,7 +131,7 @@ func (client *Connection) OnGameMsg(msg int, chunk chunk7.Chunk, u *packer.Unpac client.OnMotd(motd) } } else if msg == network7.MsgGameSvChat { - chat := &messages7.SvChat{} + chat := &messages7.SvChat{ChunkHeader: &chunk.Header} chat.Unpack(u) client.OnChatMessage(chat) result.Packet.Messages = append(result.Packet.Messages, chat)