Commit Graph

51 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
e5133e5dcf refactor(channelserver): replace init() handler registration with explicit construction
The handler table was a package-level global populated by init(), making
registration implicit and untestable. Move it to buildHandlerTable()
which returns the map, store it as a Server struct field initialized in
NewServer(), and add a missing-handler guard in handlePacketGroup to log
a warning instead of panicking on unknown opcodes.
2026-02-20 18:58:32 +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
eab7d1fc4f fix(channelserver): eliminate data races in shutdown and session lifecycle
The channel server had several concurrency issues found by the race
detector during isolation testing:

- acceptClients could send on a closed acceptConns channel during
  shutdown, causing a panic. Replace close(acceptConns) with a done
  channel and select-based shutdown signaling in both acceptClients
  and manageSessions.
- invalidateSessions read isShuttingDown and iterated sessions without
  holding the lock. Rewrite with ticker + done channel select and
  snapshot sessions under lock before processing timeouts.
- sendLoop/recvLoop accessed global _config.ErupeConfig.LoopDelay
  which races with tests modifying the global. Use the per-server
  erupeConfig instead.
- logoutPlayer panicked on DB errors and crashed on nil DB (no-db
  test scenarios). Guard with nil check and log errors instead.
- Shutdown was not idempotent, double-calling caused double-close
  panic on done channel.

Add 5 channel isolation tests verifying independent shutdown,
listener failure, session panic recovery, cross-channel registry
after shutdown, and stage isolation.
2026-02-20 14:36:37 +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
7dfc3e6049 Merge upstream/main into main
Resolve conflict in handlers_stage.go: keep lock-free packet
building pattern (copy session list, release lock, then build)
over upstream's in-lock QueueSendMHF approach.

Fix test compilation: remove objectIDs field references after
upstream removed it from Server struct.

Resync vendor directory with updated go.mod dependencies.
2026-02-16 11:31:42 +01:00
Houmgaor
afc554f1ec fix(save): avoid double-save.
feat(logging): more complete logging data.
2025-11-01 00:37:59 +01:00
Houmgaor
e1a461e892 fix(stage): fix deadlock that was preventing stage change. 2025-10-27 01:13:43 +01:00
Houmgaor
1c32be98cc fix(session): race condition. 2025-10-19 23:49:23 +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
dd36f367a9 alpelo object system backport test commit 2025-10-05 16:10:47 +11:00
wish
d86f50bd29 Merge branch 'main' into fix/packet-queue 2025-02-18 03:16:41 +11:00
wish
7c61f70590 add invalidateSessions 2025-02-18 03:16:18 +11:00
wish
d1dfc3fbb1 packet queue fix proposal 2025-02-18 03:12:09 +11:00
wish
4eed6a9738 add playtime chat command 2024-11-09 18:20:49 +11:00
wish
ab7bb0d004 revert packet concatenation 2024-11-09 17:39:14 +11:00
wish
7bf2fd5b8f revert packet concatenation 2024-11-09 17:22:43 +11:00
wish
8191994acb add LoopDelay config option 2024-10-08 22:26:00 +11:00
wish
34e84f31df ignore empty packet buffer 2024-10-08 21:06:52 +11:00
wish
1432e8f2b8 Merge remote-tracking branch 'origin/main' 2024-10-08 20:43:20 +11:00
wish
edd357fe50 concatenate packets during send 2024-10-08 20:42:42 +11:00
stratic-dev
ae32951671 Add troubleshooting for setup on docker and add opcode dec and hex to logger 2024-10-05 22:56:53 +01:00
wish
b20969ddc6 emulate retail semaphore logic 2024-10-03 21:56:06 +10:00
wish
4fbfd569df Merge pull request #111 from ZeruLight/feature/moderation
feature/moderation
2024-01-11 23:04:29 +11:00
wish
af29ee637e minor session optimisations 2024-01-11 23:03:53 +11:00
wish
e0615dcd0c add support for operator accounts & bans 2024-01-03 19:08:45 +11:00
wish
0ea0dc217b simplify config 2023-12-31 12:51:24 +11:00
wish
3c6067c8a6 port partial fix/mutex-rework 2023-11-26 23:22:56 +11:00
wish
405e65346b add LogMessageData DevModeOption & disable Logging by default 2023-11-20 00:58:24 +11:00
wish
e9fa4e5261 fix LogOutboundMessages not working 2023-11-20 00:49:50 +11:00
wish
e5fa0501b7 add packet time profiling 2023-11-19 20:17:03 +11:00
wish
9642787631 rework Stage Object IDs 2023-07-29 22:35:08 +10:00
wish
bcb71536ec initial rights v4 concept 2023-03-11 23:17:14 +11:00
wish
c110082ab5 test session timeout 2023-03-11 01:08:21 +11:00
wish
ab4669acc9 unhide EnumerateQuest packet logs 2023-03-11 00:57:14 +11:00
wish
0caf610d33 rework logging code 2023-03-09 22:11:55 +11:00
wish
e811dd1274 initial time fix 2023-03-04 21:43:10 +11:00
wish
b73ddb8866 support printing non-blocking packets 2022-11-12 13:36:27 +11:00
wish
4a7cde77ea fix nil StrConv on save 2022-11-01 10:49:28 +11:00
wish
676bb736bf lockable courses via config 2022-10-30 16:43:58 +11:00
wish
31bac7bd68 initial course command 2022-10-30 15:03:12 +11:00
wish
bac4e70be4 course enumeration concept 2022-10-30 11:44:22 +11:00
wish
0bbb90a927 address packet queueing issues 2022-10-12 01:41:29 +11:00
wish
e90e3da142 add KQF command 2022-09-30 03:47:59 +10:00
wish
ba927f877d fix guild enumeration and applications 2022-08-04 06:43:41 +10:00
wish
ab51588e9e objects v3 2022-08-02 04:37:19 +10:00