Commit Graph

41 Commits

Author SHA1 Message Date
Houmgaor
bf983966a0 refactor(channelserver): migrate inline queries to helpers and define named constants
Migrate 6 character data handlers to use the existing loadCharacterData
and saveCharacterData helpers, eliminating duplicate inline SQL:
- LoadFavoriteQuest, SaveFavoriteQuest, LoadDecoMyset, LoadMezfesData,
  LoadHunterNavi, GetEquipSkinHist

Define named constants replacing magic numbers across handlers:
- Achievement trophy tiers, broadcast/message types, diva phase
  durations, RP accrual rates, kill log layout, semaphore bases,
  quest stage/loading screen IDs

Update anti-patterns doc with accurate line counts, evidence-based
softlock analysis, and revised refactoring priorities.
2026-02-20 19:46:57 +01:00
Houmgaor
d32e77efba refactor: replace panic calls with structured error handling
Replace ~25 panic() calls in non-fatal code paths with proper
s.logger.Error + return patterns. Panics in handler code crashed
goroutines (caught by defer/recover but still disruptive) instead
of failing gracefully.

Key changes:
- SJISToUTF8 now returns (string, error); all 30+ callers updated
- Handler DB/IO panics replaced with log + return/ack fail
- Unhandled switch-case panics replaced with logger.Error
- Sign server Accept() panic replaced with log + continue
- Dead unreachable panic in guild_model.go removed
- deltacomp patch error logs and returns partial data

Panics intentionally kept: ByteFrame sentinel, unimplemented
packet stubs, os.Exit in main.go.
2026-02-20 19:11:41 +01:00
Houmgaor
c2eba51b29 fix(channelserver): add max-size guards to binary blob save handlers
A malicious or buggy client could send arbitrarily large payloads
that get written directly to PostgreSQL, wasting disk and memory.
Each save handler now rejects payloads exceeding a generous upper
bound derived from the known data format sizes.

Covers all remaining items from #158: partner, hunternavi,
savemercenary, scenariodata, platedata, platebox, platemyset,
rengokudata, mezfes, savefavoritequest, house_furniture, mission.

Closes #158
2026-02-19 00:28:28 +01:00
Houmgaor
604d53d6d7 fix(channelserver): validate packet fields before use in handlers
Several handlers used packet fields as array indices or SQL column
names without bounds checking, allowing crafted packets to panic the
server or produce malformed SQL.

Panic fixes (high severity):
- handlers_mail: bounds check AccIndex against mailList length
- handlers_misc: validate ArmourID >= 10000 and MogType <= 4
- handlers_mercenary: check RawDataPayload length before slicing
- handlers_house: check RawDataPayload length in SaveDecoMyset
- handlers_register: guard empty RawDataPayload in OperateRegister

SQL column name fixes (medium severity):
- handlers_misc: early return on unknown PointType
- handlers_items: reject unknown StampType in weekly stamp handlers
- handlers_achievement: cap AchievementID at 32
- handlers_goocoo: skip goocoo.Index > 4
- handlers_house: cap BoxIndex for warehouse operations
- handlers_tower: fix MissionIndex=0 bypassing normalization guard
2026-02-19 00:23:04 +01:00
Houmgaor
b2b1c426a5 fix(channelserver): validate client binary blobs before saving
- Reject BinaryType outside 1-5 in SetUserBinary to prevent
  dynamic column name with unchecked client input
- Check rengoku payload length before DB write and fixed-offset
  reads to prevent panic on short payloads
- Require MercData >= 4 bytes before ReadUint32 to prevent panic

Ref: Mezeporta/Erupe#158
2026-02-18 23:39:29 +01:00
Houmgaor
0d07a1f698 refactor(mhfpacket): rename 15 Unk fields with identified meanings
Replace unknown field names with descriptive names based on handler
logic analysis, switch dispatch patterns, DB query context, and
inline comments:

- ObjectHandleID, IsQuest, ItemIDCount, MaxCount, TokenLength,
  FormatVersion, LogoutType (high confidence from comments/constants)
- QueryType, DataType, MissionIndex, CheckOnly, RequestType,
  ExchangeType, TournamentID (confirmed by handler switch/if usage)

Also fix MsgSysLogout.Build calling ReadUint8 instead of WriteUint8.
2026-02-18 21:48:08 +01:00
Houmgaor
2bd5f98f32 docs: add doc.go files and godoc comments to all packages
Add package-level documentation (doc.go) to all 22 first-party
packages and godoc comments to ~150 previously undocumented
exported symbols across common/, network/, and server/.
2026-02-18 21:39:13 +01:00
Houmgaor
c64dabc3ba fix: check all Close() return values for errcheck lint
Add explicit error discards (_ =) for Close() calls on network
connections, SQL rows, and file handles across 28 files. Also add
.golangci.yml with standard linter defaults to match CI configuration.
2026-02-17 23:57:14 +01:00
Houmgaor
47f7a1f636 fix(channelserver): handle bare Exec errors and filter expected ErrNoRows
138 bare db.Exec calls across 22 handler files silently dropped write
errors. Each is now wrapped with error check and zap logging.

4 QueryRow sites that legitimately return sql.ErrNoRows during normal
operation (new player mezfes, festa rankings, empty guild item box)
now filter it out to reduce log noise.
2026-02-17 23:33:44 +01:00
Houmgaor
46bbb6adf9 fix: resolve all remaining lint errors (errcheck) across 49 files
Fix unchecked error returns on bf.Seek(), db.Exec(), QueryRow().Scan(),
pkt.Build(), logger.Sync(), and binary.Write() calls. The linter now
passes with 0 errors, build compiles, and all tests pass with -race.
2026-02-17 18:07:38 +01:00
Houmgaor
2a0e3e2c84 fix: re-enable CI lint job and fix ~65 lint errors (partial)
Re-enable the golangci-lint job in CI (disabled Oct 2025), update to
Go 1.25 and golangci-lint-action v7. Fix errcheck, gosimple S1009,
staticcheck SA4031 and SA2001 errors across 54 files. Remaining ~39
lint errors will be addressed in follow-up commits.
2026-02-17 17:59:00 +01:00
Houmgaor
fb3e86f429 fix: handle Query/QueryRow/transaction errors in channel server handlers
Add error checking and logging for ~25 database call sites that were
silently dropping errors, preventing resource leaks (unclosed rows),
nil pointer panics, and silent data corruption in festa transactions.
2026-02-17 17:44:35 +01:00
Houmgaor
3da54fade8 chore: adds remaining logging for Hunter Navi and Plate data. 2025-11-01 17:14:05 +01:00
wish
69a2a7ca3b MhfReadMercenaryW changes 2025-03-16 15:51:10 +11:00
wish
4348aa02a8 temporarily fix rasta expiration 2024-10-09 00:51:51 +11:00
wish
edd357fe50 concatenate packets during send 2024-10-08 20:42:42 +11:00
wish
04008fceb8 rewrite ReadMercenaryW handler 2024-08-08 22:16:09 +10:00
wish
2f8d09b09e more GuildTresure optimisation 2023-10-24 21:21:21 +11:00
wish
94f9174afa change Airou struct definition & remove airoulist.bin 2023-10-12 23:27:54 +11:00
wish
1f93419cb7 add support for more versions 2023-07-03 00:30:44 +10:00
wish
758bd90ab3 fix the last two bytes of HunterNavi savedata being clipped off 2023-07-02 17:06:28 +10:00
wish
b60bf4979b fix ContractMercenary 2023-06-19 22:44:20 +10:00
wish
7d884da938 replace deprecated code 2023-03-31 00:04:51 +11:00
wish
e811dd1274 initial time fix 2023-03-04 21:43:10 +11:00
wish
c718e9a5a7 fix various packet responses 2023-02-12 14:04:16 +11:00
wish
29d62634fa clean up various save handlers 2023-01-29 22:32:52 +11:00
wish
068b7ba72d clean up various save handlers 2023-01-29 21:35:01 +11:00
wish
9f7a065971 Merge branch 'main' into feature/rasta
# Conflicts:
#	server/channelserver/handlers_mercenary.go
2023-01-29 21:01:10 +11:00
wish
de20a0668b clean up various mercenary handlers 2023-01-29 20:59:16 +11:00
wish
c37755f7c3 further decode merc packets 2023-01-29 14:40:27 +11:00
wish
1382e99fc6 further decode merc packets 2023-01-29 12:22:07 +11:00
wish
753d215211 fix reading and cancelling rasta contracts 2023-01-29 02:18:23 +11:00
wish
bd42b5d0c2 various changes 2023-01-29 01:27:46 +11:00
wish
616d58e70e dump other savedata types 2022-09-05 15:29:24 +10:00
wish
65d35a5188 dump navi savedata 2022-09-05 14:34:48 +10:00
wish
df1a4834ba fix airou dismissal 2022-09-02 20:28:58 +10:00
wish
6e7259a068 dump more save data types to backup 2022-08-19 19:46:55 +10:00
wish
12ac12ff3f stub mercenary data 2022-08-14 09:49:35 +10:00
wish
265dc25800 fix merc saving/loading 2022-08-08 21:02:07 +10:00
wish
4968252491 initial mercenaries build 2022-08-08 18:21:54 +10:00
wish
2c0e7a5267 repository cleanup 2022-07-29 03:25:23 +10:00