Files
Erupe/cmd/protbot/scenario/session.go
Houmgaor 0e84377e21 feat(protbot): add headless MHF protocol bot as cmd/protbot
Copy MHBridge into the Erupe module as cmd/protbot/ so it can be
built, tested, and maintained alongside the server. The bot
implements the full sign → entrance → channel login flow and
supports lobby entry, chat, session setup, and quest enumeration.

The conn/ package keeps its own Blowfish crypto primitives to avoid
importing erupe-ce/config (which requires a config file at init).
2026-02-20 02:49:23 +01:00

51 lines
1.7 KiB
Go

package scenario
import (
"fmt"
"time"
"erupe-ce/cmd/protbot/protocol"
)
// SetupSession performs the post-login session setup: ISSUE_LOGKEY, RIGHTS_RELOAD, LOADDATA.
// Returns the loaddata response blob for inspection.
func SetupSession(ch *protocol.ChannelConn, charID uint32) ([]byte, error) {
// Step 1: Issue logkey.
ack := ch.NextAckHandle()
fmt.Printf("[session] Sending MSG_SYS_ISSUE_LOGKEY (ackHandle=%d)...\n", ack)
if err := ch.SendPacket(protocol.BuildIssueLogkeyPacket(ack)); err != nil {
return nil, fmt.Errorf("issue logkey send: %w", err)
}
resp, err := ch.WaitForAck(ack, 10*time.Second)
if err != nil {
return nil, fmt.Errorf("issue logkey ack: %w", err)
}
fmt.Printf("[session] ISSUE_LOGKEY ACK (error=%d, %d bytes)\n", resp.ErrorCode, len(resp.Data))
// Step 2: Rights reload.
ack = ch.NextAckHandle()
fmt.Printf("[session] Sending MSG_SYS_RIGHTS_RELOAD (ackHandle=%d)...\n", ack)
if err := ch.SendPacket(protocol.BuildRightsReloadPacket(ack)); err != nil {
return nil, fmt.Errorf("rights reload send: %w", err)
}
resp, err = ch.WaitForAck(ack, 10*time.Second)
if err != nil {
return nil, fmt.Errorf("rights reload ack: %w", err)
}
fmt.Printf("[session] RIGHTS_RELOAD ACK (error=%d, %d bytes)\n", resp.ErrorCode, len(resp.Data))
// Step 3: Load save data.
ack = ch.NextAckHandle()
fmt.Printf("[session] Sending MSG_MHF_LOADDATA (ackHandle=%d)...\n", ack)
if err := ch.SendPacket(protocol.BuildLoaddataPacket(ack)); err != nil {
return nil, fmt.Errorf("loaddata send: %w", err)
}
resp, err = ch.WaitForAck(ack, 30*time.Second)
if err != nil {
return nil, fmt.Errorf("loaddata ack: %w", err)
}
fmt.Printf("[session] LOADDATA ACK (error=%d, %d bytes)\n", resp.ErrorCode, len(resp.Data))
return resp.Data, nil
}