You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.6 KiB
Go

package internal
import (
"app/internal/iniconfig"
"app/internal/msg_util"
"app/servers/internal/app_tools"
"core/log"
"core/network"
"google.golang.org/protobuf/proto"
)
func NewClient(conf *iniconfig.Config, account string, parser *msg_util.ProtoParser, initState IState, isCycle bool) *Client {
c := &Client{
conf: conf,
paymentAddr: conf.String("payment"),
loginAddr: conf.String("login"),
goatLoginKey: conf.String("goat_key"),
account: account,
passport_type: conf.MustString("passport_type", app_tools.PassportTypeUUID),
msgCh: make(chan proto.Message, 64),
parser: parser,
isCycle: isCycle,
}
c.fsm = NewFsm(c, initState)
log.KV("account", account).Info("robot start")
return c
}
type Client struct {
conf *iniconfig.Config
fsm *Fsm
parser *msg_util.ProtoParser
msgCh chan proto.Message
gameConn network.INetClient
chatConn network.INetClient
paymentAddr string
loginAddr string
gameAddr string
goatLoginKey string
account string
passport_type string
sid int32
uid int64
rid int64
isCycle bool
}
func (this *Client) Config() *iniconfig.Config { return this.conf }
func (this *Client) GoatKey() string { return this.goatLoginKey }
func (this *Client) FixState() string { return this.conf.MustString("state_mode", "") }
func (this *Client) Parser() *msg_util.ProtoParser { return this.parser }
func (this *Client) PaymentAddr() string { return this.paymentAddr }
func (this *Client) LoginAddr() string { return this.loginAddr }
func (this *Client) GameAddr() string { return this.gameAddr }
func (this *Client) Account() string { return this.account }
func (this *Client) PassportType() string { return this.passport_type }
func (this *Client) SID() int32 { return this.sid }
func (this *Client) UpdateLoginInfo(gameAddr string, gameConn network.INetClient, sid int32, uid int64, rid int64) {
this.gameAddr = gameAddr
this.rid = rid
this.uid = uid
this.sid = sid
this.gameConn = gameConn
}
func (this *Client) recvMsg(pbmsg proto.Message) { this.msgCh <- pbmsg }
func (this *Client) Send2Game(msg proto.Message) {
if conn := this.gameConn; conn != nil {
conn.SendMsg(msg)
}
}
func (this *Client) Send2Chat(msg proto.Message) {
if conn := this.chatConn; conn != nil {
conn.SendMsg(msg)
}
}
func (this *Client) Stop() {
if conn := this.gameConn; conn != nil {
this.gameConn = nil
conn.Stop()
}
if conn := this.chatConn; conn != nil {
this.chatConn = nil
conn.Stop()
}
this.fsm.Stop()
}