bnet

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2018 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package bnet implements a mocked BNCS client that can be used to interact with BNCS servers.

Index

Constants

This section is empty.

Variables

View Source
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")
	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)")
	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

View Source
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: func() string {
		var paths = []string{
			"./war3",
			"C:/Program Files/Warcraft III/",
			"C:/Program Files (x86)/Warcraft III/",
			path.Join(os.Getenv("HOME"), ".wine/drive_c/Program Files/Warcraft III/"),
			path.Join(os.Getenv("HOME"), ".wine/drive_c/Program Files (x86)/Warcraft III/"),
		}

		for i := 0; i < len(paths); i++ {
			if _, err := os.Stat(paths[i]); err == nil {
				return paths[i]
			}
		}

		return "."
	}(),
}

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

func CheckRevision(valueString string, fileNames []string, mpqNumber int) (uint32, error)

CheckRevision runs CheckRevision part of BNCS authentication for mpqNumber First fileName must be the executable file

func CreateBNCSKeyInfo

func CreateBNCSKeyInfo(cdkey string, clientToken uint32, serverToken uint32) (*bncs.CDKey, error)

CreateBNCSKeyInfo decodes a CD-key, retrieves its relevant values, and calculates a hash suitable for SID_AUTH_CHECK (0x51)

func ExtractMPQNumber

func ExtractMPQNumber(mpqName string) int

ExtractMPQNumber reads an MPQ filename (e.g. IX86ver#.mpq) and returns the int value of that number Returns -1 on failure

func GetExeInfo

func GetExeInfo(fileName string) (uint32, string, error)

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 Channel

type Channel struct {
	Name  string
	Flags bncs.ChatChannelFlags
}

Channel joined event

type Chat

type Chat struct {
	User
	Content string
	Type    bncs.ChatEventType
}

Chat event

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 NewClient

func NewClient(conf *Config) (*Client, error)

NewClient initializes a Client struct

func (*Client) ChangePassword added in v1.2.0

func (b *Client) ChangePassword(newPassword string) error

ChangePassword of an existing account

ChangePassword sequence:

  1. Client starts with Dial sequence
  2. Client waits for user to enter account information and new password:
  3. C > S [0x55] SID_AUTH_ACCOUNTCHANGE
  4. S > C [0x55] SID_AUTH_ACCOUNTCHANGE
  5. C > S [0x56] SID_AUTH_ACCOUNTCHANGEPROOF
  6. S > C [0x56] SID_AUTH_ACCOUNTCHANGEPROOF
  7. Client can continue with logon ([0x53] SID_AUTH_ACCOUNTLOGON)

func (*Client) Channel

func (b *Client) Channel() string

Channel currently chatting in

func (*Client) CreateAccount

func (b *Client) CreateAccount() error

CreateAccount registers a new account

CreateAccount sequence:

  1. Client starts with Dial sequence
  2. Client waits for user to enter new account information:
  3. C > S [0x52] SID_AUTH_ACCOUNTCREATE
  4. S > C [0x52] SID_AUTH_ACCOUNTCREATE
  5. Client can continue with logon ([0x53] SID_AUTH_ACCOUNTLOGON)

func (*Client) Dial

func (b *Client) Dial() (*network.BNCSConn, error)

Dial opens a new connection to server, verifies game version, and authenticates with CD keys

Dial sequence:

  1. C > S [0x50] SID_AUTH_INFO
  2. S > C [0x25] SID_PING
  3. C > S [0x25] SID_PING (optional)
  4. S > C [0x50] SID_AUTH_INFO
  5. C > S [0x51] SID_AUTH_CHECK
  6. S > C [0x51] SID_AUTH_CHECK
  7. Client gets icons file, TOS file, and server list file:
  8. C > S [0x2D] SID_GETICONDATA (optional)
  9. S > C [0x2D] SID_GETICONDATA (optional response)
  10. C > S [0x33] SID_GETFILETIME (returned icons file name) (optional)
  11. C > S [0x33] SID_GETFILETIME ("tos_USA.txt") (optional)
  12. C > S [0x33] SID_GETFILETIME ("bnserver.ini") (optional)
  13. S > C [0x33] SID_GETFILETIME (one for each request)
  14. 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

func (b *Client) Logon() error

Logon opens a new connection to server, logs on, and joins chat

Logon sequence:

  1. Client starts with Dial sequence ([0x50] SID_AUTH_INFO and [0x51] SID_AUTH_CHECK)
  2. Client waits for user to enter account information (standard logon shown, uses NLS):
  3. C > S [0x53] SID_AUTH_ACCOUNTLOGON
  4. S > C [0x53] SID_AUTH_ACCOUNTLOGON
  5. C > S [0x54] SID_AUTH_ACCOUNTLOGONPROOF
  6. S > C [0x54] SID_AUTH_ACCOUNTLOGONPROOF
  7. C > S [0x45] SID_NETGAMEPORT (optional)
  8. C > S [0x0A] SID_ENTERCHAT
  9. S > C [0x0A] SID_ENTERCHAT
  10. C > S [0x44] SID_WARCRAFTGENERAL (WID_TOURNAMENT) (optional)
  11. S > C [0x44] SID_WARCRAFTGENERAL (WID_TOURNAMENT) (optional response)
  12. C > S [0x46] SID_NEWS_INFO (optional)
  13. S > C [0x46] SID_NEWS_INFO (optional response)
  14. Client waits until user wants to Enter Chat.
  15. C > S [0x0C] SID_JOINCHANNEL (First Join, "W3")
  16. S > C [0x0F] SID_CHATEVENT
  17. A sequence of chat events for entering chat follow.

func (*Client) Run

func (b *Client) Run() error

Run reads packets and emits an event for each received packet Not safe for concurrent invocation

func (*Client) Say

func (b *Client) Say(s string) error

Say sends a chat message May block while rate-limiting packets

func (*Client) User added in v1.2.0

func (b *Client) User(name string) (*User, bool)

User in channel by name

func (*Client) Users

func (b *Client) Users() map[string]User

Users in channel

type Config added in v1.1.0

type Config struct {
	Platform          bncs.AuthInfoReq
	ServerAddr        string
	KeepAliveInterval time.Duration
	BinPath           string
	Username          string
	Password          string
	CDKeyOwner        string
	CDKeys            []string
	GamePort          uint16
}

Config for bnet.Client

type JoinError

type JoinError struct {
	Channel string
	Error   bncs.ChatEventType
}

JoinError event

type NLS

type NLS struct {
	// contains filtered or unexported fields
}

NLS password hashing helper

func NewNLS

func NewNLS(username string, password string) (*NLS, error)

NewNLS initializes a new NLS struct

func (*NLS) AccountCreate

func (n *NLS) AccountCreate() ([]byte, []byte, error)

AccountCreate generates the content for an SID_AUTH_ACCOUNTCREATE packet

func (*NLS) ClientKey

func (n *NLS) ClientKey() (res [32]byte)

ClientKey for NLS exchange

func (*NLS) Free

func (n *NLS) Free()

Free NLS struct

func (*NLS) SessionKey

func (n *NLS) SessionKey(serverKey *[32]byte, salt *[32]byte) (res [20]byte)

SessionKey for NLS exchange

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) Operator added in v1.1.0

func (u *User) Operator() bool

Operator in channel

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)

type UserJoined

type UserJoined struct {
	User
	AlreadyInChannel bool
}

UserJoined event

type UserLeft

type UserLeft struct {
	User
}

UserLeft event

type UserUpdate

type UserUpdate struct {
	User
}

UserUpdate event

type Whisper

type Whisper struct {
	Username string
	Content  string
	Flags    bncs.ChatUserFlags
	Ping     uint32
}

Whisper event

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL