Merge pull request #23 from ZeruLight/bug/user-binary-db-leak

clean up user binary querying
This commit is contained in:
wish
2022-08-11 15:02:25 +10:00
committed by GitHub

View File

@@ -3,7 +3,6 @@ package channelserver
import ( import (
"fmt" "fmt"
"erupe-ce/common/byteframe"
"erupe-ce/network/mhfpacket" "erupe-ce/network/mhfpacket"
) )
@@ -39,25 +38,18 @@ func handleMsgSysGetUserBinary(s *Session, p mhfpacket.MHFPacket) {
s.server.userBinaryPartsLock.RLock() s.server.userBinaryPartsLock.RLock()
defer s.server.userBinaryPartsLock.RUnlock() defer s.server.userBinaryPartsLock.RUnlock()
data, ok := s.server.userBinaryParts[userBinaryPartID{charID: pkt.CharID, index: pkt.BinaryType}] data, ok := s.server.userBinaryParts[userBinaryPartID{charID: pkt.CharID, index: pkt.BinaryType}]
resp := byteframe.NewByteFrame()
// If we can't get the real data, try to get it from the database. // If we can't get the real data, try to get it from the database.
if !ok { if !ok {
var data []byte err := s.server.db.QueryRow(fmt.Sprintf("SELECT type%d FROM user_binaries WHERE id=$1", pkt.BinaryType), pkt.CharID).Scan(&data)
rows, _ := s.server.db.Queryx(fmt.Sprintf("SELECT type%d FROM user_binaries WHERE id=$1", pkt.BinaryType), pkt.CharID) if err != nil {
for rows.Next() { doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
rows.Scan(&data) } else {
resp.WriteBytes(data) doAckBufSucceed(s, pkt.AckHandle, data)
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
return
} }
doAckBufFail(s, pkt.AckHandle, make([]byte, 4))
return
} else { } else {
resp.WriteBytes(data) doAckBufSucceed(s, pkt.AckHandle, data)
} }
doAckBufSucceed(s, pkt.AckHandle, resp.Data())
} }
func handleMsgSysNotifyUserBinary(s *Session, p mhfpacket.MHFPacket) {} func handleMsgSysNotifyUserBinary(s *Session, p mhfpacket.MHFPacket) {}