mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
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).
This commit is contained in:
52
cmd/protbot/conn/conn.go
Normal file
52
cmd/protbot/conn/conn.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package conn
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
// MHFConn wraps a CryptConn and provides convenience methods for MHF connections.
|
||||
type MHFConn struct {
|
||||
*CryptConn
|
||||
RawConn net.Conn
|
||||
}
|
||||
|
||||
// DialWithInit connects to addr and sends the 8 NULL byte initialization
|
||||
// required by sign and entrance servers.
|
||||
func DialWithInit(addr string) (*MHFConn, error) {
|
||||
conn, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dial %s: %w", addr, err)
|
||||
}
|
||||
|
||||
// Sign and entrance servers expect 8 NULL bytes to initialize the connection.
|
||||
_, err = conn.Write(make([]byte, 8))
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("write init bytes to %s: %w", addr, err)
|
||||
}
|
||||
|
||||
return &MHFConn{
|
||||
CryptConn: NewCryptConn(conn),
|
||||
RawConn: conn,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DialDirect connects to addr without sending initialization bytes.
|
||||
// Used for channel server connections.
|
||||
func DialDirect(addr string) (*MHFConn, error) {
|
||||
conn, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("dial %s: %w", addr, err)
|
||||
}
|
||||
|
||||
return &MHFConn{
|
||||
CryptConn: NewCryptConn(conn),
|
||||
RawConn: conn,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Close closes the underlying connection.
|
||||
func (c *MHFConn) Close() error {
|
||||
return c.RawConn.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user