majsoul_api

package module
v0.6.58 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

README

majsoul_api GoDoc

Documentation

Overview

Package majsoul_api provides access to majsoul's websocket server

Example
api, err := NewMajsoulAPI(MajsoulCN)
if err != nil {
	fmt.Println(err)
}

err = api.SendRegisterCode("t@ab.ef")
if err != nil {
	fmt.Println(err)
}

isLatest, latest, err := api.IsLatest()
fmt.Println("isLatest", isLatest, latest)
fmt.Println("resourceVersion", api.GetResourceVersion())
fmt.Println("codeVersion", api.GetCodeVersion())

//api.IgnoreVersionCheck(true)
//api.PanicOnVersionMismatch(false)
lobby, err := api.LobbyClient()
if err != nil {
	panic(err)
}

game, err := api.GameClient()
if err != nil {
	panic(err)
}

go lobby.Listen()

// Login
login := <-lobby.Login(&lq.ReqLogin{
	Account:   "jaymen.matthews@thtt.us",
	Password:  api.EncodePassword("jaymen.matthews@thtt"),
	Reconnect: false,
	Device: &lq.ClientDeviceInfo{
		DeviceType: "pc",
		Os:         "mac",
		OsVersion:  "",
		Browser:    "firefox",
	},
	RandomKey:      api.GenerateDeviceId(),
	ClientVersion:  api.GetResourceVersion(),
	GenAccessToken: true,
	CurrencyPlatforms: []uint32{
		// 1, // Google Play
		2, // China
	},
	Type: 0,
})
fmt.Println(login)

// after login
serverTime := <-lobby.FetchServerTime()
fmt.Println(serverTime.ServerTime)

settings := <-lobby.FetchServerSettings()
fmt.Println(settings)

info := <-lobby.FetchConnectionInfo()
fmt.Println(info.ClientEndpoint)

lobby.AddListener("NotifyAccountUpdate", func(wrapper lq.Wrapper) {
	fmt.Println(wrapper)
})

lobby.AddListener("NotifyAnotherLogin", func(wrapper lq.Wrapper) {
	fmt.Println(wrapper)
})

lobby.AddListener("NotifyAccountLogout", func(wrapper lq.Wrapper) {
	fmt.Println(wrapper)
})

lobby.AddListener("NotifyClientMessage", func(wrapper lq.Wrapper) {
	fmt.Println(wrapper)
})

lobby.AddListener("NotifyServerSetting", func(wrapper lq.Wrapper) {
	fmt.Println(wrapper)
})

lobby.AddListener("NotifyVipLevelChange", func(wrapper lq.Wrapper) {
	fmt.Println(wrapper)
})

lastHeartBeatTime := time.Now().Second()
go func() {
	time.AfterFunc(time.Minute*6, func() {
		// if game.LobbyNetMgr.Inst.isOK
		lobby.Heartbeat(&lq.ReqHeatBeat{
			NoOperationCounter: uint32(time.Now().Second() - lastHeartBeatTime),
		})
	})
}()

// client heartbeat
go func() {
	time.AfterFunc(time.Second, func() {
		if time.Now().Second()-lastHeartBeatTime > 2400 {
			// if game.LobbyNetMgr.Inst.isOK
			lobby.Heartbeat(&lq.ReqHeatBeat{
				NoOperationCounter: 0,
			})
			lastHeartBeatTime = time.Now().Second()
		}
	})
}()

//go func() {
//	time.AfterFunc(time.Second, func() {
//		// set localStorage.dolllt to time.Now()
//	})
//}()

announcement := <-lobby.FetchAnnouncement()
for _, j := range announcement.Announcements {
	fmt.Printf("[公告] %s\n%s\n\n", j.Title, j.Content)
}

record := <-lobby.FetchGameRecord(&lq.ReqGameRecord{
	GameUuid: "191006-9d228ebb-8d8c-48c0-9c13-bed0c1fbfd24",
})
fmt.Println("牌谱: 191006-9d228ebb-8d8c-48c0-9c13-bed0c1fbfd24")
players := map[uint32]string{}
for _, id := range record.Head.Accounts {
	players[id.Seat] = id.Nickname
}
for _, p := range record.Head.Result.Players {
	fmt.Printf("玩家:%s 位置:%d 点数:%d\n", players[p.Seat], p.Seat, p.TotalPoint)
}

i := <-lobby.FetchAccountInfo(&lq.ReqAccountInfo{AccountId: 114514})
fmt.Println(i.Room)

si := <-lobby.FetchAccountStatisticInfo(&lq.ReqAccountStatisticInfo{AccountId: 114514})
fmt.Printf("%+v", si)

_ = game
select {}
Output:

Index

Examples

Constants

View Source
const (
	ApiVersion          = "0.6.58.w"
	LatestTestedVersion = "0.6.73.w"

	MajsoulCN = "www.majsoul.com/1"
	MajsoulJP = "game.mahjongsoul.com"
	MajsoulEN = "mahjongsoul.game.yo-star.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MajsoulAPI

type MajsoulAPI struct {
	Base   string
	Region string
	Secret string
	// contains filtered or unexported fields
}

func NewMajsoulAPI

func NewMajsoulAPI(base string) (api *MajsoulAPI, err error)

Create a new majsoul api instance.

Example
api, err := NewMajsoulAPI(MajsoulJP)
if err != nil {
	fmt.Println(err)
}

// More operations here...
_ = api
Output:

func (*MajsoulAPI) EncodePassword

func (a *MajsoulAPI) EncodePassword(password string) string

Hash your clear password using the way majsoul uses.

func (*MajsoulAPI) GameClient

func (a *MajsoulAPI) GameClient() (*gameClient, error)

Create a new game(FastTest) client. A game client handles most in-game performances.

func (*MajsoulAPI) GenerateDeviceId

func (a *MajsoulAPI) GenerateDeviceId() string

Generate a uuid which majsoul uses as device id.

func (*MajsoulAPI) GetCodeVersion

func (a *MajsoulAPI) GetCodeVersion() string

Get code.js version now.

func (*MajsoulAPI) GetRegionUrl

func (a *MajsoulAPI) GetRegionUrl() string

Get region url current api.

func (*MajsoulAPI) GetResourceVersion

func (a *MajsoulAPI) GetResourceVersion() string

GetResourceVersion Get resource version now

func (*MajsoulAPI) GetWebSocketUrl

func (a *MajsoulAPI) GetWebSocketUrl() string

Pick up one websocket server from the slice.

func (*MajsoulAPI) IgnoreVersionCheck

func (a *MajsoulAPI) IgnoreVersionCheck(ignore bool)

Ignore version check when creating socket clients.

func (*MajsoulAPI) IsLatest

func (a *MajsoulAPI) IsLatest() (bool, string, error)

IsLatest Determine whether it's the latest lobby version. It returns a boolean and a detailed version string.

func (*MajsoulAPI) LobbyClient

func (a *MajsoulAPI) LobbyClient() (*lobbyClient, error)

Create a new lobby client. A lobby client handles most non-game performances.

func (*MajsoulAPI) PanicOnVersionMismatch

func (a *MajsoulAPI) PanicOnVersionMismatch(panic bool)

When ignoreVersionCheck is false, this controls whether panic(version_mismatch) works. Or just print out the warning information.

func (*MajsoulAPI) SendRegisterCode

func (a *MajsoulAPI) SendRegisterCode(email string) error

SendRegisterCode Send an email to the email you provide and determine whether it succeeds.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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