Browse Source

AO msgs: simplify readers + writers

master
HimbeerserverDE 1 year ago
parent
commit
0877c5e4f6
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
  1. 19
      active_object.go

19
active_object.go

@ -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)
msglenBytes := make([]byte, 2)
r.Read(msglenBytes)
msglen := binary.BigEndian.Uint16(msglenBytes)
msg := make([]byte, msglen)
r.Read(msg)
id := ReadUint16(r)
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()

Loading…
Cancel
Save