Commit Graph

181 Commits

Author SHA1 Message Date
Houmgaor
7f13ee6a51 chore(mhfpacket): remove orphaned commented-out panics in stub parsers
Replace dead `//panic("Not implemented")` after return statements with
TODO comments indicating these are stub parsers with unknown fields.
2026-02-23 17:11:19 +01:00
Houmgaor
f640cfee27 fix: log SJIS decoding errors instead of silently discarding them
Add SJISToUTF8Lossy() that wraps SJISToUTF8() and logs decode errors at
slog.Debug level. Replace all 31 call sites across 17 files that previously
discarded the error with `_, _ =`. This makes garbled text from malformed
SJIS client data debuggable without adding noise at default log levels.
2026-02-22 17:01:22 +01:00
Houmgaor
f17cb96b52 refactor(config): rename package _config to config with cfg alias
The config package used `package _config` with a leading underscore,
which is unconventional in Go. Rename to `package config` (matching the
directory name) and use `cfg` as the standard import alias across all
93 importing files.
2026-02-21 13:20:15 +01:00
Houmgaor
a752c5187e fix(channelserver): send ACK on empty Raviente register payload
handleMsgSysOperateRegister returned without sending an ACK when the
payload was empty, causing the client to softlock waiting for a response.
Send doAckBufSucceed with nil data on the early-return path to match
the success-path ACK type.

Also update tests to expect error returns instead of panics from
unimplemented Build/Parse stubs (matching prior panic→error refactor),
and mark resolved anti-patterns in docs.
2026-02-20 20:05:52 +01:00
Houmgaor
ac59188488 refactor(byteframe): replace read-overflow panic with sticky error
ByteFrame previously panicked on out-of-bounds reads, which crashed
the server when parsing malformed client packets. Now sets a sticky
error (checked via Err()) and returns zero values, matching the
encoding/binary scanner pattern. The session recv loop checks Err()
after parsing to reject malformed packets gracefully.

Also replaces remaining panic("Not implemented") stubs in network
packet Build/Parse methods with proper error returns.
2026-02-20 20:00:54 +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
06cb3afa57 refactor: standardize logging on zap across all packages
Replace all fmt.Printf/Println and log.Printf/Fatal with structured
zap.Logger calls to eliminate inconsistent logging (anti-pattern #12).

- network/crypt_conn: inject logger via NewCryptConn, replace 6 fmt calls
- signserver/session: use existing s.logger for debug packet dumps
- entranceserver: use s.logger for inbound/outbound debug logging
- api/utils: accept logger param in verifyPath, replace fmt.Println
- api/endpoints: use s.logger for screenshot path diagnostics
- config: replace log.Fatal with error return in getOutboundIP4
- deltacomp: replace log.Printf with zap.L() global logger
2026-02-20 18:59:12 +01:00
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
ba9fce153d refactor(mhfpacket): rename MsgSysCreateStage.Unk0 to CreateType
Wii U decompilation of all 6 callers of snj_stage_create confirms
the field distinguishes new stage creation (1) from entering an
existing stage (2): lobby/myhouse/quest pass 1, guild room and
move operations pass 2.
2026-02-19 00:46:57 +01:00
Houmgaor
151af1a202 refactor(mhfpacket): rename MsgMhfUpdateHouse.Unk1 to HasPassword
Verified via Wii U decompilation of putUpdate_house: the field is set
to 0 when no password is provided, and 1 when a password string is
present. The previous comment "Always 0x01" was inaccurate.
2026-02-18 22:57:18 +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
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
d2b5bb72f8 refactor: extract gametime package, replace fmt.Printf with zap logging
Move time utilities (TimeAdjusted, TimeMidnight, TimeWeekStart, TimeWeekNext,
TimeGameAbsolute) from channelserver into common/gametime to break the
inappropriate dependency where signserver, entranceserver, and api imported
the 38K-line channelserver package just for time functions.

Replace all fmt.Printf debug logging in sys_session.go and handlers_object.go
with structured zap logging for consistent observability.
2026-02-17 17:54:51 +01:00
Houmgaor
645c4ddd38 test: increase code coverage from 45.1% to 48.3%
Add unit tests across multiple packages:
- byteframe: SetBE/SetLE byte order switching
- config: Mode.String() for all safe version ranges
- mhfpacket: 28 Parse methods, 5 Build methods, empty packet builds,
  variable-length packets, NOT IMPLEMENTED error paths, UpdateWarehouse
- network: PacketID.String() for known IDs, out-of-range, and all valid
- channelserver: handleMsgMhfGetPaperData (6 switch cases), grpToGR
  (11 input values), gacha handlers, TimeGameAbsolute, equipSkinHistSize
  (4 config branches), guild mission handlers, dumpSaveData disabled path
- entranceserver: makeHeader with various inputs
2026-02-17 17:32:54 +01:00
Houmgaor
0bd724f74e test: backport remaining test files from v9.2.x-stable
Import 18 network packet test files and 5 server infrastructure test
files, adapted for main branch APIs: fix config import alias (_config),
remove non-existent DevMode field, use global handlerTable instead of
per-server handlers map, and correct validateToken mock expectations
to include both token and tokenID arguments.

Adds go-sqlmock dependency for database mocking in signserver tests.
2026-02-17 00:09:41 +01:00
Houmgaor
127d3af167 tests(network): adds tests for network features (except mhfpacket). 2025-10-27 12:18:41 +01:00
Houmgaor
1398383a8d fix(lint): automated linting, with simple formatter. 2025-10-19 22:43:05 +02:00
Houmgaor
0e7bc553d7 test: fix issues in tests with cryptography 2025-10-19 21:18:55 +02:00
Houmgaor
8a92a7957e fix(crashes): trying to investigate the causes of crash.
New unit tests to that end.
2025-10-19 19:02:29 +02:00
wish
3d0114ce22 fix MhfAcquireCafeItem cost in G1-G5.2 2025-04-01 20:58:33 +11:00
wish
459f382dd7 simplify 2024-07-24 23:41:05 +10:00
wish
4204ab1ecb Merge branch 'refs/heads/main' into fix/quest-stamps 2024-07-24 23:28:13 +10:00
wish
dd13713bc1 fix parsing SysTerminalLog 2024-06-25 22:50:58 +10:00
wish
843b6a9dff fix quest stampcard 2024-03-17 16:39:06 +11:00
wish
d26ae4563e fix G1 compatibility 2024-03-17 16:35:16 +11:00
wish
fac68a2b4b fix UpdateGuacot 2024-03-06 22:17:27 +11:00
wish
40d4aba3c4 convert other Warehouse types to new system 2024-02-25 14:12:37 +11:00
wish
b969c53f3a fix Warehouse packet parsing 2024-02-21 02:09:42 +11:00
wish
db364110eb Merge branch 'main' into feature/warehouse-v2 2024-02-20 17:50:04 +11:00
wish
5bcfe25ede implement Festa Bonus Categories & Guild Character optimisations 2024-02-20 04:18:16 +11:00
wish
4ccb3af5ac simplify cryptography 2024-01-11 23:00:44 +11:00
wish
f73bdd7445 rewrite CastBinary payload handling 2024-01-05 02:39:25 +11:00
wish
7e34862e25 Merge remote-tracking branch 'origin/main' into feature/warehouse-v2
# Conflicts:
#	server/channelserver/handlers.go
2023-12-13 11:38:05 +11:00
wish
ef7d46ba2e revert UpdateGuacot parsing 2023-12-04 22:29:58 +11:00
wish
7717f2f12a fix Enumerate/UpdateGuacot 2023-12-04 22:06:43 +11:00
wish
9d54a9746c remove unused variable 2023-12-02 21:16:26 +11:00
wish
11bac4ecf3 handle UnreserveSrg 2023-12-02 21:10:52 +11:00
wish
67e791be2b parse & stub PostSeibattle 2023-11-30 00:31:09 +11:00
wish
e914cf406b limit EnumerateShop responses 2023-11-29 21:37:41 +11:00
wish
3c6067c8a6 port partial fix/mutex-rework 2023-11-26 23:22:56 +11:00
wish
0550fb21b5 parse & handle PlayFreeGacha 2023-11-22 22:59:36 +11:00
wish
d4ddf7bc25 initial legacy support for DistItem 2023-11-21 23:46:33 +11:00
wish
d7d3e7c61f update parsing of CastBinary & EnterStage 2023-11-19 23:12:58 +11:00
wish
85fc76edd5 update parsing of many packets 2023-11-19 02:34:02 +11:00
wish
fc57d63689 update parsing of many packets 2023-11-19 00:35:22 +11:00
wish
4a83b68725 Merge pull request #97 from ZeruLight/fix/rework-distributions
fix/rework-distributions
2023-11-11 19:42:08 +11:00
wish
317daef04b rewrite EnumerateDistItem handler 2023-11-07 21:26:45 +11:00
wish
6ff20858ed rewrite EnumerateStage & parse ReserveStage 2023-11-07 16:50:39 +11:00