base

package
v0.0.0-...-cd1bf01 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PlayerstatuOffline     int32 = -1
	PlayerstatuInitial     int32 = 0
	PlayerstatuWaitAuthen  int32 = 1
	PlayerstatuWaitSitDown int32 = 2
	PlayerstatuHaveSitDown int32 = 3
	PlayerstatuWatching    int32 = 4
	PlayerstatuHandUp      int32 = 5
	PlayerstatuBeginGame   int32 = 6
)
View Source
const (
	Playertimer_checkhandup = iota //入座举手定时器
	Playertimer_checkplay          //游戏对局定时器
)
View Source
const (
	Tabletimer_checkbegin = iota
)

Variables

View Source
var (
	Skeleton   *module.Skeleton
	PlayerList *PlayerNodeList
	//Curgamenum   int64 //当前牌局计数,初始化为时间戳
	//GameTables   []ITable
	NetGate *gate.Gate
	//GameLogic    IGameLogic
	GameChanRPC  *chanrpc.Server
	RobotChanRPC *chanrpc.Server
	GameLogic    IGameLogic
)
View Source
var GPlayerNodeID uint64 = 1

Functions

func CheckDateDiff

func CheckDateDiff(srcTime time.Time, destime time.Time, compType string, cmpValue int) bool

CheckDateDiff srcTime:比较时间 destime:被比较时间 compType:day,month,year cmpValue:差值最大

func ClosePlayer

func ClosePlayer(player IPlayerNode)
func GetTable(tableid int) (ITable, error) {
	if tableid < 1 || tableid > conf.RoomInfo.MaxTableNum {
		return nil, errors.New("table index out of range")
	}
	return GameTables[tableid-1], nil
}

func GameHandler

func GameHandler(m interface{}, h interface{})

GameHandler 消息回调注入信道

func GernateToken

func GernateToken(account string, password string, userID int64) string

func GetTntervalDay

func GetTntervalDay(t1 time.Time, t2 time.Time) int

获得间隔天数

func NewSkeleton

func NewSkeleton() *module.Skeleton

func SendAutoReqMsg

func SendAutoReqMsg(player IPlayerNode, route string, reqID uint64, m interface{}) error

SendAutoReqMsg 自动包装消息内容

func SendFailMsg

func SendFailMsg(player IPlayerNode, code int32, message string, m interface{})

func SendFailMsgWithID

func SendFailMsgWithID(player IPlayerNode, rspID uint64, code int32, message string, m interface{})

func SendFullRspMsg

func SendFullRspMsg(toclient gate.Agent, m interface{}) error

func SendReqMsg

func SendReqMsg(player IPlayerNode, m *msg.RequestData) error

func SendRobotMsg2Game

func SendRobotMsg2Game(route string, userID int64, robotmsg interface{}) error

SendMsg2GameLogic AI区与玩法区通信

func SendRspMsg

func SendRspMsg(player IPlayerNode, m interface{}) error

func SendRspMsgWithID

func SendRspMsgWithID(player IPlayerNode, rspID uint64, m interface{})

Types

type ClientNode

type ClientNode struct {
	This IPlayerNode //业务层对象
	PlayerNode
	Usernodeinfo          msg.LoginRes
	Useraccountdbw        Userplaygamedata //可更新入用户库数据
	Userlogindeviceid     string
	Userprodname          string //用户来源产品
	Userlogindevicetype   int32
	Userloginchannellong  string
	Userloginchannelshort int32
	Userloginfrom         string
	Userloginsiteid       int32
	Usergamestatus        int32     //游戏状态
	Useroffline           bool      //是否掉线
	Userisrobot           bool      //是否机器人
	Userlastopertime      time.Time //上次操作时间,只针对登录,入座,准备,打牌,离桌做记录
	Userlogintime         time.Time //登录时间点
	Usersitdowntime       time.Time //入座时间
	Userhanduptime        time.Time //举手时间
	LastUpateTokenTime    time.Time //
	Usertableid           int32     //座位号
	Userchairid           int32     //椅子号
	ProxyClientID         uint64    //代理客户端ID
	LoginIP               string    //客户端IP
	ClientVersion         string    //客户端版本
	LastRecvTime          time.Time //
	TableCurLevel         int32     //当前所在的桌子等级
	TableLastLevel        int32     //上次所在的桌子等级
	ActiveReqMapMsg       []msg.RouteMsg
	VipRechargeTimes      map[int32]int32

	//广告使用
	GameendData        []GameEndData //游戏结束数据
	LookAdType         int32         //看广告类型 -1未达到开放局数  1开启 -2 每日看广告到达上限
	SkyRedPack         int32         //天降红包金额
	BaoPeiCur          bool          //看广告当局包赔,和下局包赔没有关系,是另外一种广告
	LookChaAdSucTimes  int32         //看插屏广告成功次数
	LookADSucTimes     int32         //成功看激励广告次数不包括banner,插屏,开屏
	LookExcAdPlayTimes int32         //看完激励广告后,N局内不再显示激励广告,大于0,不显示激励广告
	GetPowerTimes      int32         //获取体力次数,刺激场一天只能N次看广告得体力
	UpdateLookAdTime   int64         //看广告的时间
}

func (*ClientNode) ClearActiveReqMap

func (p *ClientNode) ClearActiveReqMap()

func (*ClientNode) GetAbleServerLevel

func (player *ClientNode) GetAbleServerLevel() int32

func (*ClientNode) GetAbleTableLevel

func (player *ClientNode) GetAbleTableLevel() int32

GetAbleTableLevel 获取玩家当前可参与的桌子等级,应用层可重写计算逻辑

func (*ClientNode) Initialize

func (player *ClientNode) Initialize()

func (*ClientNode) IsProxyedNode

func (player *ClientNode) IsProxyedNode() bool

IsProxyedNode 本身是否被代理节点

func (*ClientNode) OnTimer

func (player *ClientNode) OnTimer()

func (*ClientNode) SetTimer

func (player *ClientNode) SetTimer(timerid int, d time.Duration) (*timer.Timer, error)

func (*ClientNode) SyncOldPlayerData

func (player *ClientNode) SyncOldPlayerData(playerold IPlayerNode)

type GameEndData

type GameEndData struct {
	GoldBean int32 //结算奖券值
	SourceID int32 //来源id
}

单个玩家

type GameTable

type GameTable struct {
	GameRoundNum   int64 //游戏对局编号
	SitdownPlayers int32
	ReadyPlayers   int32
	TimeGameBegin  time.Time
	TableStatus    int32
	TablePlayers   []IPlayerNode
	WatchPlayers   []IPlayerNode
	Tabletimemap   map[int32]*TableTimer //定时器
	TableID        int32                 //桌子号
	TableCurLevel  int32                 //桌子当前等级
	TableBasePoint int32                 //桌子底注
	BLock          bool                  //桌子是否被锁住
	// contains filtered or unexported fields
}

func (*GameTable) CustomData

func (table *GameTable) CustomData() interface{}

func (*GameTable) GameBegin

func (table *GameTable) GameBegin(gamenum int64)

func (*GameTable) GameEnd

func (table *GameTable) GameEnd()

func (*GameTable) GetLock

func (table *GameTable) GetLock() bool

func (*GameTable) Init

func (table *GameTable) Init(tableid int32, chairnum int32, flogic IGameLogic)

func (*GameTable) KillTimer

func (table *GameTable) KillTimer(timerid int32)

func (*GameTable) OnTimerCheckBegin

func (table *GameTable) OnTimerCheckBegin()

func (*GameTable) RecoverTable

func (table *GameTable) RecoverTable()

RecoverTable 用户完全离开后,还原桌子某些动态属性到初始状态

func (*GameTable) ResetGameTable

func (table *GameTable) ResetGameTable()

func (*GameTable) ResetTable

func (table *GameTable) ResetTable()

func (*GameTable) SetCustomData

func (table *GameTable) SetCustomData(data interface{})

func (*GameTable) SetLock

func (table *GameTable) SetLock()

func (*GameTable) SetTimer

func (table *GameTable) SetTimer(timerid int32, d time.Duration, cb func()) error

func (*GameTable) UnLock

func (table *GameTable) UnLock()

解锁

type IAppMain

type IAppMain interface {
	InitEngine(logicEngine IGameLogic)
	CreateClientPlayer() IPlayerNode
	OnCreateTable() ITable
	GameStart(table ITable)
	OnPlayerConnect(player IPlayerNode)
	OnPlayerClose(player IPlayerNode)
	//可大量重写接口
	AppMsgCallBackInit(map[string]MsgHandler)
	CallBackEtcdConf(action string, key string, value string)
	CallBackSendRoomInfo(player IPlayerNode)
	//RecoverRobot(userid int64, gameCoin int64)
	RecoverRobot(userid int64, player IPlayerNode)
	CallBackSitDown(player IPlayerNode, table ITable)
	CallLoginSuccess(player IPlayerNode)
	CallBackLeaveTable(player IPlayerNode, table ITable)
	CallBackOffline(player IPlayerNode)
	CallBackLogOut(player IPlayerNode)
	CallBackHandUp(player IPlayerNode, table ITable)
	CallBackGameStart(table ITable)
	CallBackLoginAgain(player IPlayerNode)
	AutoPlay(player IPlayerNode)
	OnDestroy()
	CheckNeedPeiPai(player IPlayerNode, TableLevel int32) bool
}

app层逻辑接口

type IAppRobot

type IAppRobot interface {
	HandleRobotMsg(args []interface{})
	OnCreateRobot() IPlayerNode
	RegisteRobotMsg()
	OnRobotLoginIn(player IPlayerNode, loginmsg interface{})
	OnRobotLoginOut(player IPlayerNode)
	CloseRobot(player IPlayerNode)
	OnDestroy()
}

app层机器人接口

type IGameLogic

type IGameLogic interface {
	//可重写频率低接口
	InitAppMain(appMain IGameLogic)
	InitBoot(appMain IGameLogic)
	Start(netgate *gate.Gate) error
	Gamestart(table ITable)
	OnCreateTable() ITable
	OnCreatePlayer(addr string) IPlayerNode
	RegisteGameMsgCallback(skeleton *module.Skeleton)
	RegisteLoginMsgCallback(skeleton *module.Skeleton)
	OnPlayerConnect(player IPlayerNode)
	OnPlayerClose(player IPlayerNode)
	ClosePlayer(player IPlayerNode)
	//SavePlayerGameCoin(player IPlayerNode, gamecoin int64, writesource int32)
	//SavePlayerGoldBean(player IPlayerNode, goldbean int32, writesource int32)
	SavePlayerProp(player IPlayerNode, propinfo msg.UserPropChange, writesource int32, bwritedb bool)
	SavePlayerGameEnd(player IPlayerNode, datachanged Userplaygamedata)
	SaveTableGameEnd(table ITable)

	//可大量重写接口
	SyncOldPlayerData(oldplayer IPlayerNode, newplayer IPlayerNode)
	CreateClientPlayer(IPlayerNode) //用来设置上层业务用户数据
	CreateTable(ITable)             //用来设置上层业务桌子数据
	AppMsgCallBackInit(map[string]MsgHandler)
	CallBackEtcdConf(action string, key string, value string)
	CallBackSendRoomInfo(player IPlayerNode)
	//RecoverRobot(userid int64, gameCoin int64)
	RecoverRobot(userid int64, player IPlayerNode)
	CallBackSitDown(player IPlayerNode, table ITable)
	CallLoginSuccess(player IPlayerNode)
	CallBackLeaveTable(player IPlayerNode, table ITable)
	CallBackOffline(player IPlayerNode)
	CallBackLogOut(player IPlayerNode)
	CallBackHandUp(player IPlayerNode, table ITable)
	CallBackGameStart(table ITable)
	CallBackLoginAgain(player IPlayerNode)
	AutoPlay(player IPlayerNode)
	OnDestroy()
	CallBackRechargeBulletinNotice(args []interface{})
	CallLoginSuccessExtInfo(player IPlayerNode, clientLoginRsp *msg.ClientUserRes)  //登录信息扩展
	CallBackSitDownExtInfo(player IPlayerNode, sitdownres *msg.SitDownRes)          //入座信息扩展
	CallBackPlayerJoinExtInfo(player IPlayerNode, joinres *msg.TableJoinPlayer)     //加入玩家信息扩展
	CallBackLoginAgainExtInfo(player IPlayerNode, loginAgainres *msg.LoginAgainRes) //掉线重入玩家信息扩展
	CheckNeedPeiPai(player IPlayerNode, TableLevel int32) bool

	CheckIsNewPlayer(player IPlayerNode) bool
	GetDailyRedPacket(player IPlayerNode) [2]int32
}
func Sendmsg(player IPlayerNode, args ...interface{}) error {
	if msg.Processor.Type() == json.Processor_Type {
		netagent := player.(*PlayerNode).Netagent
		rspBody := &msg.Responsedata{}
		rspBody.Rspname = reflect.TypeOf(args[0]).Name()
		log.Debug("rspBody.Rspname %v", rspBody.Rspname)
		rspBody.Rspdata = args[0]
		netagent.WriteMsg(rspBody)
	} else if msg.Processor.Type() == protobuf.Processor_Type {
		netagent := player.(*PlayerNode).Netagent
		if len(args) < 2 {
			log.Error("arguments must have msg, msgtype")
			return errors.New("arguments must have msg, msgtype")
		}
		netagent.Write8HeaderMsg(args[1].(uint16), args[0])
	} else {
		log.Error("Sendmsg msg.Processor is invalid:%v", reflect.TypeOf(msg.Processor))
		return errors.New("Sendmsg msg.Processor is invalid")
	}
	return nil
}

type IPlayerNode

type IPlayerNode interface {
	Initialize()
	IsProxyNode() bool
	IsMiddlePlatNode() bool
	IsProxyedNode() bool
	GetNodeID() uint64
	Resetgamedata()
	GameBegin()
	GameEnd()
	HandleAutoGame()
	SetUserData(data interface{})
	UserData() interface{}
}

type IRobot

type IRobot interface {
	InitAppMain(appMain IRobot)
	HandleRobotMsg(args []interface{})
	OnCreateRobot() IPlayerNode
	RegisteRobotMsg()
	OnRobotLoginIn(player IPlayerNode, loginmsg interface{})
	OnRobotLoginOut(player IPlayerNode)
	CloseRobot(player IPlayerNode)
	OnDestroy()

	//业务层重写
	CallBackCreateRobot(IPlayerNode)
}

type ITable

type ITable interface {
	Init(tableid int32, chairnum int32, flogic IGameLogic)
	ResetTable()
	GameBegin(gamenum int64)
	GameEnd()
	SetCustomData(data interface{})
	CustomData() interface{}
}

type MiddlePlatNode

type MiddlePlatNode struct {
	PlayerNode
}

中台节点

func (*MiddlePlatNode) IsMiddlePlatNode

func (player *MiddlePlatNode) IsMiddlePlatNode() bool

type MsgHandler

type MsgHandler func(agrs []interface{})

type PlayerNode

type PlayerNode struct {
	Netagent    gate.Agent //socket链接点
	Usertimemap sync.Map   //定时器
	PlayerID    uint64     //节点序列号
	// contains filtered or unexported fields
}

func (*PlayerNode) GameBegin

func (player *PlayerNode) GameBegin()

func (*PlayerNode) GameEnd

func (player *PlayerNode) GameEnd()

func (*PlayerNode) GetNodeID

func (player *PlayerNode) GetNodeID() uint64

func (*PlayerNode) HandleAutoGame

func (player *PlayerNode) HandleAutoGame()

func (*PlayerNode) Initialize

func (player *PlayerNode) Initialize()

func (*PlayerNode) IsMiddlePlatNode

func (player *PlayerNode) IsMiddlePlatNode() bool

func (*PlayerNode) IsProxyNode

func (player *PlayerNode) IsProxyNode() bool

IsProxyNode 本身是否为代理节点

func (*PlayerNode) IsProxyedNode

func (player *PlayerNode) IsProxyedNode() bool

IsProxyedNode 本身是否被代理节点

func (*PlayerNode) KillTimer

func (player *PlayerNode) KillTimer(timerid int)

func (*PlayerNode) OnTimer

func (player *PlayerNode) OnTimer()

func (*PlayerNode) Resetgamedata

func (player *PlayerNode) Resetgamedata()

func (*PlayerNode) SetTimer

func (player *PlayerNode) SetTimer(timerid int, d time.Duration) (*timer.Timer, error)

func (*PlayerNode) SetUserData

func (player *PlayerNode) SetUserData(data interface{})

func (*PlayerNode) UserData

func (player *PlayerNode) UserData() interface{}

type PlayerNodeList

type PlayerNodeList struct {
	//onlinelist map[int64]IPlayerNode
	Onlinelist sync.Map
	LockPlayer sync.RWMutex
}

func (*PlayerNodeList) AddPlayer

func (playerlist *PlayerNodeList) AddPlayer(userid int64, player IPlayerNode)

func (*PlayerNodeList) DeletePlayer

func (playerlist *PlayerNodeList) DeletePlayer(userid int64)

func (*PlayerNodeList) GetAllPlayers

func (playerlist *PlayerNodeList) GetAllPlayers() map[int64]IPlayerNode

func (*PlayerNodeList) GetOnlineNum

func (playerlist *PlayerNodeList) GetOnlineNum() int

func (*PlayerNodeList) GetPlayer

func (playerlist *PlayerNodeList) GetPlayer(userid int64) (IPlayerNode, bool)

func (*PlayerNodeList) Init

func (playerlist *PlayerNodeList) Init()

type ProxyNode

type ProxyNode struct {
	PlayerNode
	MapClient map[uint64]*ClientNode
	// contains filtered or unexported fields
}

func (*ProxyNode) DelProxyedNode

func (player *ProxyNode) DelProxyedNode(proxyedID uint64)

func (*ProxyNode) GetClients

func (player *ProxyNode) GetClients() map[uint64]*ClientNode

func (*ProxyNode) GetLock

func (player *ProxyNode) GetLock()

func (*ProxyNode) GetProxyedNode

func (player *ProxyNode) GetProxyedNode(proxyedID uint64) (*ClientNode, bool)

func (*ProxyNode) Initialize

func (player *ProxyNode) Initialize()

func (*ProxyNode) IsProxyNode

func (player *ProxyNode) IsProxyNode() bool

IsProxyNode 本身是否为代理节点

func (*ProxyNode) SetProxyedNode

func (player *ProxyNode) SetProxyedNode(proxyedID uint64, proxyedPlayer *ClientNode)

func (*ProxyNode) UnLock

func (player *ProxyNode) UnLock()

type RobotHandler

type RobotHandler func(userID int64, robotmsg interface{})

type TableTimer

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

type Userplaygamedata

type Userplaygamedata struct {
	Gametax           uint64 //税收
	Gamecoin          int64  //key:srcid 增量
	Playcoin          int64  //游戏玩分
	Goldbean          int32  //key:srcid增量
	Diamond           int64
	Proplist          map[int32]map[int32]msg.UserPropChange //key:srcid道具列表增量
	Gameplaytime      int32                                  //
	Gameonlinetime    int32                                  //
	Gamewintimes      int32                                  //
	Gamelosetimes     int32                                  //
	Gamewinstktimes   int32                                  //
	Gamelosestktimes  int32                                  //
	Gamewinmstktimes  int32                                  //最大连胜局
	Gamelosemstktimes int32                                  //最大连输局
	Gamecoinwin       int64                                  //
	Gamecoinlose      int64                                  //
	WinOrLose         int8                                   //0 输,1赢
}

Jump to

Keyboard shortcuts

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