AO msgs: simplify readers + writers

master
HimbeerserverDE 2021-04-01 16:27:05 +02:00
parent 360468d3d8
commit 0877c5e4f6
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
1 changed files with 4 additions and 15 deletions

View File

@ -139,18 +139,9 @@ func processAoMsgs(c *Conn, r *bytes.Reader) []byte {
w := &bytes.Buffer{}
for r.Len() >= 4 {
idBytes := make([]byte, 2)
r.Read(idBytes)
id := binary.BigEndian.Uint16(idBytes)
id := ReadUint16(r)
msglenBytes := make([]byte, 2)
r.Read(msglenBytes)
msglen := binary.BigEndian.Uint16(msglenBytes)
msg := make([]byte, msglen)
r.Read(msg)
msg = aoMsgReplaceIDs(c, msg)
msg := aoMsgReplaceIDs(c, ReadBytes16(r))
if id == c.currentPlayerCao {
id = c.localPlayerCao
@ -158,10 +149,8 @@ func processAoMsgs(c *Conn, r *bytes.Reader) []byte {
id = c.currentPlayerCao
}
binary.BigEndian.PutUint16(idBytes, id)
w.Write(idBytes)
w.Write(msglenBytes)
w.Write(msg)
WriteUint16(w, id)
WriteBytes16(w, msg)
}
return w.Bytes()