Documentation ¶
Overview ¶
Package bnet implements a mocked BNCS client that can be used to interact with BNCS servers.
Example ¶
package main import ( "fmt" "github.com/nielsAD/gowarcraft3/network" "github.com/nielsAD/gowarcraft3/network/bnet" ) func main() { client, err := bnet.NewClient(&bnet.Config{ ServerAddr: "europe.battle.net.example", Username: "gowarcraft3", Password: "gowarcraft3", }) if err != nil { fmt.Println(err) return } defer client.Close() // Log on if err = client.Logon(); err != nil { fmt.Println(err) return } // Print incoming chat messages client.On(&bnet.Chat{}, func(ev *network.Event) { var msg = ev.Arg.(*bnet.Chat) fmt.Printf("[%s] %s\n", msg.User.Name, msg.Content) }) // Run() blocks until the connection is closed client.Run() }
Output:
Index ¶
- Variables
- func AccountCreateResultToError(r bncs.AccountCreateResult) error
- func AuthResultToError(r bncs.AuthResult) error
- func CheckRevision(valueString string, fileNames []string, mpqNumber int) (uint32, error)
- func CreateBNCSKeyInfo(cdkey string, clientToken uint32, serverToken uint32) (*bncs.CDKey, error)
- func ExtractMPQNumber(mpqName string) int
- func FilterChat(s string) string
- func GetExeInfo(fileName string) (uint32, string, error)
- func LogonProofResultToError(r bncs.LogonProofResult) error
- func LogonResultToError(r bncs.LogonResult) error
- func VerifyServerSignature(ip net.IP, sig *[128]byte) bool
- type Channel
- type Chat
- type Client
- func (b *Client) ChangePassword(newPassword string) error
- func (b *Client) Channel() string
- func (b *Client) CreateAccount() error
- func (b *Client) Dial() (*network.BNCSConn, error)
- func (b *Client) DialWithConn(conn net.Conn) (*network.BNCSConn, error)
- func (b *Client) Encoding() bncs.Encoding
- func (b *Client) InitDefaultHandlers()
- func (b *Client) Logon() error
- func (b *Client) Run() error
- func (b *Client) Say(s string) error
- func (b *Client) User(name string) (*User, bool)
- func (b *Client) Users() map[string]User
- type Config
- type JoinError
- type NLS
- type SHA1
- type SRP
- type SystemMessage
- type User
- type UserJoined
- type UserLeft
- type UserUpdate
- type Whisper
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrCheckRevision = errors.New("bnet: BNCSUtil call to checkRevision failed") ErrExeInfo = errors.New("bnet: BNCSUtil call to getExeInfo failed") ErrKeyDecoder = errors.New("bnet: BNCSUtil call to keyDecoder failed") ErrNLS = errors.New("bnet: BNCSUtil call to NLS failed") ErrUnexpectedPacket = errors.New("bnet: Received unexpected packet") ErrAuthFail = errors.New("bnet: Authentication failed") ErrInvalidServerSig = errors.New("bnet: Authentication failed (invalid server signature)") ErrInvalidGameVersion = errors.New("bnet: Authentication failed (game version invalid)") ErrCDKeyInvalid = errors.New("bnet: Authentication failed (CD key invalid)") ErrCDKeyInUse = errors.New("bnet: Authentication failed (CD key in use)") ErrCDKeyBanned = errors.New("bnet: Authentication failed (CD key banned)") ErrUnknownAccount = errors.New("bnet: Authentication failed (account does not exist)") ErrInvalidAccount = errors.New("bnet: Authentication failed (account invalid)") ErrPasswordVerification = errors.New("bnet: Authentication failed (server cannot verify password)") ErrIncorrectPassword = errors.New("bnet: Authentication failed (password incorrect)") ErrAccountCreate = errors.New("bnet: Account creation failed") ErrAccountNameTaken = errors.New("bnet: Account creation failed (account name taken)") ErrAccountNameIllegal = errors.New("bnet: Account creation failed (illegal account name)") )
Errors
var DefaultConfig = Config{ Platform: bncs.AuthInfoReq{ PlatformCode: protocol.DString("IX86"), GameVersion: w3gs.GameVersion{Product: w3gs.ProductROC, Version: w3gs.CurrentGameVersion}, LanguageCode: protocol.DString("enUS"), TimeZoneBias: 4294967176, MpqLocaleID: 1033, UserLanguageID: 1033, CountryAbbreviation: "USA", Country: "United States", }, KeepAliveInterval: 30 * time.Second, CDKeyOwner: "gowarcraft3", GamePort: 6112, BinPath: dir.InstallDir(), }
DefaultConfig for bnet.Client
Functions ¶
func AccountCreateResultToError ¶
func AccountCreateResultToError(r bncs.AccountCreateResult) error
AccountCreateResultToError converts bncs.AccountCreateResult to an appropriate error
func AuthResultToError ¶
func AuthResultToError(r bncs.AuthResult) error
AuthResultToError converts bncs.AuthResult to an appropriate error
func CheckRevision ¶
CheckRevision runs CheckRevision part of BNCS authentication for mpqNumber First fileName must be the executable file
func CreateBNCSKeyInfo ¶
CreateBNCSKeyInfo decodes a CD-key, retrieves its relevant values, and calculates a hash suitable for SID_AUTH_CHECK (0x51)
func ExtractMPQNumber ¶
ExtractMPQNumber reads an MPQ filename (e.g. IX86ver#.mpq) and returns the int value of that number Returns -1 on failure
func FilterChat ¶ added in v1.2.1
FilterChat makes the chat message suitable for bnet. It filters out control characters, replaces emoji with text, and truncates length.
func GetExeInfo ¶
GetExeInfo retrieves version and date/size information from executable file
func LogonProofResultToError ¶
func LogonProofResultToError(r bncs.LogonProofResult) error
LogonProofResultToError converts bncs.LogonProofResult to an appropriate error
func LogonResultToError ¶
func LogonResultToError(r bncs.LogonResult) error
LogonResultToError converts bncs.LogonProofResult to an appropriate error
Types ¶
type Client ¶
type Client struct { network.EventEmitter network.BNCSConn // Read-only UniqueName string // Set once before Dial(), read-only after that Config // contains filtered or unexported fields }
Client represents a mocked BNCS client Public methods/fields are thread-safe unless explicitly stated otherwise
func (*Client) ChangePassword ¶ added in v1.2.0
ChangePassword of an existing account
ChangePassword sequence:
- Client starts with Dial sequence
- Client waits for user to enter account information and new password:
- C > S [0x55] SID_AUTH_ACCOUNTCHANGE
- S > C [0x55] SID_AUTH_ACCOUNTCHANGE
- C > S [0x56] SID_AUTH_ACCOUNTCHANGEPROOF
- S > C [0x56] SID_AUTH_ACCOUNTCHANGEPROOF
- Client can continue with logon ([0x53] SID_AUTH_ACCOUNTLOGON)
func (*Client) CreateAccount ¶
CreateAccount registers a new account
CreateAccount sequence:
- Client starts with Dial sequence
- Client waits for user to enter new account information:
- C > S [0x52] SID_AUTH_ACCOUNTCREATE
- S > C [0x52] SID_AUTH_ACCOUNTCREATE
- Client can continue with logon ([0x53] SID_AUTH_ACCOUNTLOGON)
func (*Client) Dial ¶
Dial opens a new connection to server, verifies game version, and authenticates with CD keys
func (*Client) DialWithConn ¶ added in v1.6.0
DialWithConn initializes a connection to server, verifies game version, and authenticates with CD keys
Dial sequence:
- C > S [0x50] SID_AUTH_INFO
- S > C [0x25] SID_PING
- C > S [0x25] SID_PING (optional)
- S > C [0x50] SID_AUTH_INFO
- C > S [0x51] SID_AUTH_CHECK
- S > C [0x51] SID_AUTH_CHECK
- Client gets icons file, TOS file, and server list file:
- C > S [0x2D] SID_GETICONDATA (optional)
- S > C [0x2D] SID_GETICONDATA (optional response)
- C > S [0x33] SID_GETFILETIME (returned icons file name) (optional)
- C > S [0x33] SID_GETFILETIME ("tos_USA.txt") (optional)
- C > S [0x33] SID_GETFILETIME ("bnserver.ini") (optional)
- S > C [0x33] SID_GETFILETIME (one for each request)
- Connection to BNFTPv2 to do file downloads
func (*Client) InitDefaultHandlers ¶
func (b *Client) InitDefaultHandlers()
InitDefaultHandlers adds the default callbacks for relevant packets
func (*Client) Logon ¶
Logon opens a new connection to server, logs on, and joins chat
Logon sequence:
- Client starts with Dial sequence ([0x50] SID_AUTH_INFO and [0x51] SID_AUTH_CHECK)
- Client waits for user to enter account information (standard logon shown, uses SRP):
- C > S [0x53] SID_AUTH_ACCOUNTLOGON
- S > C [0x53] SID_AUTH_ACCOUNTLOGON
- C > S [0x54] SID_AUTH_ACCOUNTLOGONPROOF
- S > C [0x54] SID_AUTH_ACCOUNTLOGONPROOF
- C > S [0x45] SID_NETGAMEPORT (optional)
- C > S [0x0A] SID_ENTERCHAT
- S > C [0x0A] SID_ENTERCHAT
- C > S [0x44] SID_WARCRAFTGENERAL (WID_TOURNAMENT) (optional)
- S > C [0x44] SID_WARCRAFTGENERAL (WID_TOURNAMENT) (optional response)
- C > S [0x46] SID_NEWS_INFO (optional)
- S > C [0x46] SID_NEWS_INFO (optional response)
- Client waits until user wants to Enter Chat.
- C > S [0x0C] SID_JOINCHANNEL (First Join, "W3")
- S > C [0x0F] SID_CHATEVENT
- A sequence of chat events for entering chat follow.
func (*Client) Run ¶
Run reads packets and emits an event for each received packet Not safe for concurrent invocation
type Config ¶ added in v1.1.0
type Config struct { ServerAddr string KeepAliveInterval time.Duration Platform bncs.AuthInfoReq BinPath string ExeInfo string ExeVersion uint32 ExeHash uint32 VerifySignature bool SHA1Auth bool Username string Password string CDKeyOwner string CDKeys []string GamePort uint16 }
Config for bnet.Client
type NLS ¶
type NLS struct {
// contains filtered or unexported fields
}
NLS provider for SRP
func (*NLS) AccountCreate ¶
AccountCreate generates the content for an SID_AUTH_ACCOUNTCREATE packet
func (*NLS) PasswordProof ¶ added in v1.4.0
PasswordProof for SRP exchange
func (*NLS) VerifyPassword ¶ added in v1.4.0
VerifyPassword after SRP exchange
type SHA1 ¶ added in v1.4.0
type SHA1 struct {
// contains filtered or unexported fields
}
SHA1 provider for SRP
func (*SHA1) AccountCreate ¶ added in v1.4.0
AccountCreate generates the content for an SID_AUTH_ACCOUNTCREATE packet
func (*SHA1) PasswordProof ¶ added in v1.4.0
PasswordProof for SRP exchange
func (*SHA1) VerifyPassword ¶ added in v1.4.0
VerifyPassword after SRP exchange
type SRP ¶ added in v1.4.0
type SRP interface { AccountCreate() ([]byte, []byte, error) ClientKey() [32]byte PasswordProof(serverKey *[32]byte, salt *[32]byte) [20]byte VerifyPassword(proof *[20]byte) bool Free() }
SRP password helper
type SystemMessage ¶
type SystemMessage struct { Content string Type bncs.ChatEventType }
SystemMessage event
type User ¶
type User struct { Name string StatString string Flags bncs.ChatUserFlags Ping uint32 Joined time.Time LastSeen time.Time }
User in chat
func (User) Stat ¶ added in v1.1.0
func (u User) Stat() (product protocol.DWordString, icon protocol.DWordString, lvl int, tag protocol.DWordString)
Stat split into (icon, level, clan)