refactor(channelserver): add numeric column helpers and extract protocol constants

Add readCharacterInt/adjustCharacterInt helpers for single-column
integer operations on the characters table. Eliminates fmt.Sprintf
SQL construction in handlers_misc.go and replaces inline queries
across cafe, kouryou, and mercenary handlers.

Second round of protocol constant extraction: adds constants_time.go
(secsPerDay, secsPerWeek), constants_raviente.go (register IDs,
semaphore constants), and named constants across 14 handler files
replacing raw hex/numeric literals. Updates anti-patterns doc to
mark #4 (magic numbers) as substantially fixed.
This commit is contained in:
Houmgaor
2026-02-20 21:18:40 +01:00
parent 28bf6e93fb
commit 458d8c9397
20 changed files with 182 additions and 124 deletions

View File

@@ -17,8 +17,7 @@ func handleMsgMhfAddKouryouPoint(s *Session, p mhfpacket.MHFPacket) {
zap.Uint32("points_to_add", pkt.KouryouPoints),
)
var points int
err := s.server.db.QueryRow("UPDATE characters SET kouryou_point=COALESCE(kouryou_point + $1, $1) WHERE id=$2 RETURNING kouryou_point", pkt.KouryouPoints, s.charID).Scan(&points)
points, err := adjustCharacterInt(s, "kouryou_point", int(pkt.KouryouPoints))
if err != nil {
s.logger.Error("Failed to update KouryouPoint in db",
zap.Error(err),
@@ -42,8 +41,7 @@ func handleMsgMhfAddKouryouPoint(s *Session, p mhfpacket.MHFPacket) {
func handleMsgMhfGetKouryouPoint(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfGetKouryouPoint)
var points int
err := s.server.db.QueryRow("SELECT COALESCE(kouryou_point, 0) FROM characters WHERE id = $1", s.charID).Scan(&points)
points, err := readCharacterInt(s, "kouryou_point")
if err != nil {
s.logger.Error("Failed to get kouryou_point from db",
zap.Error(err),
@@ -70,8 +68,7 @@ func handleMsgMhfExchangeKouryouPoint(s *Session, p mhfpacket.MHFPacket) {
zap.Uint32("points_to_spend", pkt.KouryouPoints),
)
var points int
err := s.server.db.QueryRow("UPDATE characters SET kouryou_point=kouryou_point - $1 WHERE id=$2 RETURNING kouryou_point", pkt.KouryouPoints, s.charID).Scan(&points)
points, err := adjustCharacterInt(s, "kouryou_point", -int(pkt.KouryouPoints))
if err != nil {
s.logger.Error("Failed to exchange Koryo points",
zap.Error(err),