Commit Graph

169 Commits

Author SHA1 Message Date
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
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
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
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
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
wish
be6f55b5a8 initial distributions rework 2023-11-05 00:31:16 +11:00
wish
f9280f483f simplify & handle Mail better 2023-10-31 00:21:05 +11:00
wish
431b3bbeff Merge branch 'main' of github.com:ZeruLight/Erupe 2023-10-24 21:25:34 +11:00
wish
ba50dc419a fix parsing and handling of DistItem packets 2023-10-24 21:24:35 +11:00
wish
e688fdf3c5 more GuildTresure optimisation 2023-10-17 00:35:06 +11:00
wish
0de15e8440 rewrite ReadMercenaryW parser 2023-10-12 23:26:12 +11:00
wish
641032f862 implement hunt data logging (partial #82) 2023-10-08 19:25:48 +11:00
wish
aa98e89d77 cover more versions with Hiden savedata 2023-10-02 01:19:56 +11:00
Samboge
aecb6af9e5 My Mission Fix for MHF-F5
Client only sent 322 byte (32 header + 290 byte of data)
2023-10-01 08:03:14 +07:00