Commit Graph

36 Commits

Author SHA1 Message Date
Houmgaor
5f3c843082 refactor(config): eliminate ErupeConfig global variable
Replace the mutable global `_config.ErupeConfig` with dependency
injection across 79 files. Config is now threaded through existing
paths: `ClientContext.RealClientMode` for packet encoding, `s.server.
erupeConfig` for channel handlers, and explicit parameters for utility
functions. This removes hidden coupling, enables test parallelism
without global save/restore, and prevents low-level packages from
reaching up to the config layer.

Key changes:
- Enrich ClientContext with RealClientMode for packet files
- Add mode parameter to CryptConn, mhfitem, mhfcourse functions
- Convert handlers_commands init() to lazy sync.Once initialization
- Delete global var, init(), and helper functions from config.go
- Update all tests to pass config explicitly
2026-02-20 17:07:42 +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
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
b1c8b2848f security: fix CodeQL warnings for integer overflow and workflow permissions
- handlers_tower.go: add bounds checks before int-to-int16 and int-to-uint16
  conversions to prevent overflow/wraparound (CodeQL #7, #8)
- go-improved.yml, go.yml: add top-level `permissions: contents: read` to
  restrict workflow token scope (CodeQL #15, #16, #17)
2026-02-16 19:14:14 +01:00
wish
79cdc28a01 simplify Gem math 2024-02-14 18:36:06 +11:00
wish
685f51ecb3 clean up Tower responses 2024-02-14 18:03:56 +11:00
wish
5f370896df clean up Tower responses 2024-02-14 17:28:01 +11:00
wish
0ea0dc217b simplify config 2023-12-31 12:51:24 +11:00
wish
617d600f9a test TSP accumulation 2023-11-30 00:07:09 +11:00
wish
15739ad0d2 fix PostTowerInfo not incrementing 2023-11-29 23:15:32 +11:00
wish
fb5294e705 decode Get/PostNotice and GemHistory 2023-06-25 12:24:20 +10:00
wish
cdf7b09c48 partial Tenrouirai progression automation 2023-06-25 02:47:40 +10:00
wish
fa5b5bb774 fix variable mistake 2023-06-25 00:19:44 +10:00
wish
36cdc77321 fix contribution sorting 2023-06-25 00:18:08 +10:00
wish
4a21272c42 partial Tenrouirai automation and Gem fix 2023-06-25 00:11:47 +10:00
wish
6865e2d530 rename Zone to Block 2023-06-19 22:43:32 +10:00
wish
5464594c98 rename Zone to Block 2023-06-18 20:38:04 +10:00
wish
0b4108fb85 various Conquest changes 2023-06-12 23:23:53 +10:00
wish
d269d5f777 various Tower changes 2023-06-12 19:56:00 +10:00
wish
03dde7d60d various Tower changes 2023-06-12 00:05:51 +10:00
wish
75d5ceed4f various Tower changes 2023-06-12 00:01:20 +10:00
wish
2c8391b5a4 various Tower changes 2023-06-11 18:51:56 +10:00
wish
fbecbfa571 rewrite Earth packet handlers 2023-06-10 23:09:50 +10:00
wish
0703577571 fix errors 2023-05-28 14:57:32 +10:00
wish
64344ee2ee parse and stub various packets 2023-05-28 14:41:35 +10:00
wish
e98259a11a move various packet handlers 2023-02-13 22:27:07 +11:00
wish
6dbb702665 fix GetGemInfo response 2022-11-18 21:17:41 +11:00
wish
128f375cd2 dump savedata without name 2022-09-10 22:43:23 +10:00
wish
d81e55cab4 stub GetGemInfo 2022-09-08 15:16:44 +10:00
wish
2c0e7a5267 repository cleanup 2022-07-29 03:25:23 +10:00