Documentation ¶
Overview ¶
Code generated by proto_code_gen. DO NOT EDIT. https://github.com/fish-tennis/proto_code_gen
Index ¶
- Constants
- func AutoRegisterPlayerComponentProto(packetHandlerRegister PacketHandlerRegister)
- func CreateNewActivity(activityCfgId int32, activities ActivityMgr, t time.Time) Activity
- func GetComponentIndex(componentName string) int
- func GetPlayerComponentMap() map[string]int
- func GetPlayerMgr() gentity.PlayerMgr
- func InitGlobalEntityStructAndHandler()
- func InitPlayerComponentMap()
- func OfflinePlayerProcess(playerId int64, data interface{}, ...) bool
- func OnCoinReq(this *Money, req *pb.CoinReq)
- func RegisterConditionCheckers() *internal.ConditionMgr
- func RegisterPlayerHandler(cmd PacketCommand, handler func(player *Player, packet Packet))
- func RegisterProgressCheckers() *internal.ProgressMgr
- func RoutePlayerPacket(playerId int64, cmd PacketCommand, message proto.Message, ...) bool
- func SetPlayerMgr(mgr gentity.PlayerMgr)
- type Activities
- func (this *Activities) AddAllActivities(t time.Time)
- func (this *Activities) AddNewActivity(activityCfg *cfg.ActivityCfg, t time.Time) Activity
- func (this *Activities) CanJoin(activityCfg *cfg.ActivityCfg, t time.Time) bool
- func (this *Activities) CheckEnd(t time.Time)
- func (this *Activities) CheckEndTime(activityCfg *cfg.ActivityCfg, t time.Time) bool
- func (this *Activities) CheckJoinTime(activityCfg *cfg.ActivityCfg, t time.Time) bool
- func (this *Activities) GetActivity(activityId int32) Activity
- func (this *Activities) LoadData(sourceData map[int32][]byte)
- func (this *Activities) OnEvent(event interface{})
- func (this *Activities) RemoveActivity(activityId int32)
- type ActivityConditionArg
- type ActivityDefault
- func (this *ActivityDefault) Exchange(exchangeCfgId int32)
- func (this *ActivityDefault) GetPropertyInt32(propertyName string) int32
- func (this *ActivityDefault) OnDateChange(oldDate time.Time, curDate time.Time)
- func (this *ActivityDefault) OnEnd(t time.Time)
- func (this *ActivityDefault) OnEvent(event interface{})
- func (this *ActivityDefault) ReceiveReward(cfgId int32)
- func (this *ActivityDefault) Reset()
- type Bag
- type BagCountItem
- type BagUniqueItem
- type BaseInfo
- type BasePlayerComponent
- func (this *BasePlayerComponent) GetCacheKey() string
- func (this *BasePlayerComponent) GetEntity() gentity.Entity
- func (this *BasePlayerComponent) GetName() string
- func (this *BasePlayerComponent) GetNameLower() string
- func (this *BasePlayerComponent) GetPlayer() *Player
- func (this *BasePlayerComponent) GetPlayerId() int64
- func (this *BasePlayerComponent) SetEntity(entity gentity.Entity)
- type ChildActivity
- type ClientConnectionHandler
- type CurQuests
- type FinishedQuests
- type GlobalEntity
- func (this *GlobalEntity) GetProcessStatInfo() *ProcessStatInfo
- func (this *GlobalEntity) LoadData(data interface{}) error
- func (this *GlobalEntity) RunRoutine() bool
- func (this *GlobalEntity) SaveCache(kvCache gentity.KvCache) error
- func (this *GlobalEntity) SaveDb(removeCacheAfterSaveDb bool) error
- type Guild
- type Hook
- type Money
- type PendingMessages
- type Player
- func (this *Player) FireConditionEvent(event interface{})
- func (this *Player) FireEvent(event interface{})
- func (this *Player) GetAccountId() int64
- func (this *Player) GetActivities() *Activities
- func (this *Player) GetBag() *Bag
- func (this *Player) GetBaseInfo() *BaseInfo
- func (this *Player) GetComponent(componentName string) gentity.Component
- func (this *Player) GetConnection() Connection
- func (this *Player) GetGuild() *Guild
- func (this *Player) GetLevel() int32
- func (this *Player) GetName() string
- func (this *Player) GetPropertyInt32(propertyName string) int32
- func (this *Player) GetQuest() *Quest
- func (this *Player) GetRegionId() int32
- func (this *Player) OnDisconnect(connection Connection)
- func (this *Player) OnRecvPacket(packet *ProtoPacket)
- func (this *Player) ResetConnection()
- func (this *Player) RunRoutine() bool
- func (this *Player) SaveCache(kvCache gentity.KvCache) error
- func (this *Player) SaveDb(removeCacheAfterSaveDb bool) error
- func (this *Player) Send(command PacketCommand, message proto.Message) bool
- func (this *Player) SendErrorRes(errorReqCmd PacketCommand, errorMsg string) bool
- func (this *Player) SetConnection(connection Connection, useGate bool)
- type PlayerComponent
- type PlayerDataComponent
- type PlayerMapDataComponent
- type ProcessStatInfo
- type Quest
- type RouteOptions
Constants ¶
const ( // mongo表名 GlobalEntityCollectionName = "global" // global表的key GlobalEntityCollectionKeyName = "key" // GlobalEntity在redis里的前缀 GlobalEntityCachePrefix = GlobalEntityCollectionName // GlobalEntity在mongo表里的key GlobalEntityCollectionKey = "GlobalEntity" )
const (
// Player在redis里的前缀
PlayerCachePrefix = "p"
)
Variables ¶
This section is empty.
Functions ¶
func AutoRegisterPlayerComponentProto ¶
func AutoRegisterPlayerComponentProto(packetHandlerRegister PacketHandlerRegister)
根据proto的命名规则和玩家组件里消息回调的格式,通过反射自动生成消息的注册 类似Java的注解功能
func CreateNewActivity ¶
根据模板创建活动对象
func GetComponentIndex ¶
func GetPlayerComponentMap ¶
func GetPlayerMgr ¶
func InitGlobalEntityStructAndHandler ¶
func InitGlobalEntityStructAndHandler()
注册GlobalEntity的结构体和消息回调
func InitPlayerComponentMap ¶
func InitPlayerComponentMap()
func OfflinePlayerProcess ¶
func OfflinePlayerProcess(playerId int64, data interface{}, f func(offlinePlayerId int64, offlineData interface{}) bool) bool
对离线玩家的数据处理
func RegisterConditionCheckers ¶
func RegisterConditionCheckers() *internal.ConditionMgr
func RegisterPlayerHandler ¶
func RegisterPlayerHandler(cmd PacketCommand, handler func(player *Player, packet Packet))
func RegisterProgressCheckers ¶
func RegisterProgressCheckers() *internal.ProgressMgr
func RoutePlayerPacket ¶
func RoutePlayerPacket(playerId int64, cmd PacketCommand, message proto.Message, opts ...*RouteOptions) bool
路由玩家消息 如果目标玩家在本服务器,则直接路由到本服务器上的玩家 如果目标玩家在另一个服务器上,则转发到目标服务器 ServerA -> ServerB -> Player
DirectSendClientRouteOptions(): 消息直接转发给客户端,不做逻辑处理 ServerA -> ServerB -> Client
举例: 有人申请加入公会,公会广播该消息给公会成员,ServerB收到消息后,直接把消息发给客户端(Player.Send),而不需要放入玩家的逻辑消息队列(Player.OnRecvPacket)
SaveDbRouteOptions(): 消息先保存数据库再转发,防止丢失 举例: 公会会长同意了玩家A的入会申请,此时玩家A可能不在线,就把该消息存入玩家的数据库,待玩家下次上线时,从数据库取出该消息,并进行相应的逻辑处理
func SetPlayerMgr ¶
Types ¶
type Activities ¶
type Activities struct { PlayerMapDataComponent Data map[int32]Activity `db:"Data"` }
活动模块
func NewActivities ¶
func NewActivities(player *Player) *Activities
func (*Activities) AddAllActivities ¶
func (this *Activities) AddAllActivities(t time.Time)
func (*Activities) AddNewActivity ¶
func (this *Activities) AddNewActivity(activityCfg *cfg.ActivityCfg, t time.Time) Activity
func (*Activities) CanJoin ¶
func (this *Activities) CanJoin(activityCfg *cfg.ActivityCfg, t time.Time) bool
检查活动是否能参加
func (*Activities) CheckEndTime ¶
func (this *Activities) CheckEndTime(activityCfg *cfg.ActivityCfg, t time.Time) bool
检查活动时间是否结束
func (*Activities) CheckJoinTime ¶
func (this *Activities) CheckJoinTime(activityCfg *cfg.ActivityCfg, t time.Time) bool
检查活动时间能否参加
func (*Activities) GetActivity ¶
func (this *Activities) GetActivity(activityId int32) Activity
func (*Activities) LoadData ¶
func (this *Activities) LoadData(sourceData map[int32][]byte)
func (*Activities) RemoveActivity ¶
func (this *Activities) RemoveActivity(activityId int32)
type ActivityConditionArg ¶
type ActivityConditionArg struct { Activities *Activities Activity Activity }
type ActivityDefault ¶
type ActivityDefault struct { ChildActivity // 基础数据 Base *pb.ActivityDefaultBaseData `db:"Base"` }
默认活动模板,支持常见的简单活动
func (*ActivityDefault) Exchange ¶
func (this *ActivityDefault) Exchange(exchangeCfgId int32)
兑换物品
商店也是一种兑换功能
func (*ActivityDefault) GetPropertyInt32 ¶
func (this *ActivityDefault) GetPropertyInt32(propertyName string) int32
func (*ActivityDefault) OnDateChange ¶
func (this *ActivityDefault) OnDateChange(oldDate time.Time, curDate time.Time)
func (*ActivityDefault) OnEnd ¶
func (this *ActivityDefault) OnEnd(t time.Time)
func (*ActivityDefault) OnEvent ¶
func (this *ActivityDefault) OnEvent(event interface{})
func (*ActivityDefault) ReceiveReward ¶
func (this *ActivityDefault) ReceiveReward(cfgId int32)
领取活动任务奖励
type Bag ¶
type Bag struct { BasePlayerComponent BagCountItem *BagCountItem `child:"CountItem"` BagUniqueItem *BagUniqueItem `child:"UniqueItem"` }
背包模块 演示通过组合模式,整合多个不同的子背包模块,提供更高一级的背包接口
type BagCountItem ¶
type BagCountItem struct { gentity.BaseMapDirtyMark Items map[int32]int32 `db:"CountItem;plain"` }
有数量的物品背包
func NewBagCountItem ¶
func NewBagCountItem() *BagCountItem
func (*BagCountItem) AddItem ¶
func (this *BagCountItem) AddItem(itemCfgId, addCount int32) int32
func (*BagCountItem) DelItem ¶
func (this *BagCountItem) DelItem(itemCfgId, delCount int32) int32
func (*BagCountItem) GetItemCount ¶
func (this *BagCountItem) GetItemCount(itemCfgId int32) int32
type BagUniqueItem ¶
type BagUniqueItem struct { gentity.BaseMapDirtyMark Items map[int64]*pb.UniqueItem `db:"UniqueItem"` }
不可叠加的物品背包
func NewBagUniqueItem ¶
func NewBagUniqueItem() *BagUniqueItem
func (*BagUniqueItem) AddUniqueItem ¶
func (this *BagUniqueItem) AddUniqueItem(uniqueItem *pb.UniqueItem) int32
func (*BagUniqueItem) DelItem ¶
func (this *BagUniqueItem) DelItem(itemCfgId, delCount int32) int32
func (*BagUniqueItem) DelUniqueItem ¶
func (this *BagUniqueItem) DelUniqueItem(uniqueId int64) int32
func (*BagUniqueItem) GetItemCount ¶
func (this *BagUniqueItem) GetItemCount(itemCfgId int32) int32
type BaseInfo ¶
type BaseInfo struct { PlayerDataComponent // plain表示明文存储,在保存到mongo时,不会进行proto序列化 Data *pb.BaseInfo `db:"BaseInfo;plain"` }
玩家基础信息组件
func (*BaseInfo) GetOnlineSecondsThisTime ¶
本次登录在线时长
func (*BaseInfo) HandlePlayerEntryGameOk ¶
func (this *BaseInfo) HandlePlayerEntryGameOk(_ gnet.PacketCommand, msg *pb.PlayerEntryGameOk)
玩家进游戏服成功,非客户端消息 这种格式写的函数可以自动注册非客户端的消息回调
type BasePlayerComponent ¶
type BasePlayerComponent struct {
// contains filtered or unexported fields
}
玩家组件
func (*BasePlayerComponent) GetCacheKey ¶
func (this *BasePlayerComponent) GetCacheKey() string
组件缓存key
func (*BasePlayerComponent) GetEntity ¶
func (this *BasePlayerComponent) GetEntity() gentity.Entity
func (*BasePlayerComponent) GetNameLower ¶
func (this *BasePlayerComponent) GetNameLower() string
func (*BasePlayerComponent) GetPlayer ¶
func (this *BasePlayerComponent) GetPlayer() *Player
关联的玩家对象
func (*BasePlayerComponent) GetPlayerId ¶
func (this *BasePlayerComponent) GetPlayerId() int64
关联的玩家id
func (*BasePlayerComponent) SetEntity ¶
func (this *BasePlayerComponent) SetEntity(entity gentity.Entity)
type ChildActivity ¶
type ChildActivity struct { gentity.BaseDirtyMark BaseActivity Activities *Activities }
子活动
func (*ChildActivity) GetActivityCfg ¶
func (this *ChildActivity) GetActivityCfg() *cfg.ActivityCfg
活动配置数据
type ClientConnectionHandler ¶
type ClientConnectionHandler struct {
DefaultConnectionHandler
}
客户端连接的handler
func NewClientConnectionHandler ¶
func NewClientConnectionHandler(protoCodec *ProtoCodec) *ClientConnectionHandler
func (*ClientConnectionHandler) OnRecvPacket ¶
func (this *ClientConnectionHandler) OnRecvPacket(connection Connection, packet Packet)
type CurQuests ¶
type CurQuests struct { gentity.BaseMapDirtyMark // struct tag里面没有设置保存字段名,会默认使用字段名的全小写形式 Quests map[int32]*pb.QuestData `db:""` // contains filtered or unexported fields }
当前任务列表
type FinishedQuests ¶
type FinishedQuests struct { gentity.BaseDirtyMark // struct tag里面没有设置保存字段名,会默认使用字段名的全小写形式 Finished []int32 `db:"plain"` // 基础类型,设置明文存储 // contains filtered or unexported fields }
已完成的任务
func (*FinishedQuests) Add ¶
func (f *FinishedQuests) Add(finishedQuestId int32)
type GlobalEntity ¶
type GlobalEntity struct { gentity.BaseRoutineEntity // contains filtered or unexported fields }
演示全局类的非玩家实体 这里演示的GlobalEntity,每个game进程一个实例
func CreateGlobalEntityFromDb ¶
func CreateGlobalEntityFromDb() *GlobalEntity
从数据库加载的数据构造出GlobalEntity对象
func CreateTempGlobalEntity ¶
func CreateTempGlobalEntity() *GlobalEntity
func GetGlobalEntity ¶
func GetGlobalEntity() *GlobalEntity
func NewGlobalEntity ¶
func NewGlobalEntity() *GlobalEntity
func (*GlobalEntity) GetProcessStatInfo ¶
func (this *GlobalEntity) GetProcessStatInfo() *ProcessStatInfo
func (*GlobalEntity) LoadData ¶
func (this *GlobalEntity) LoadData(data interface{}) error
func (*GlobalEntity) RunRoutine ¶
func (this *GlobalEntity) RunRoutine() bool
func (*GlobalEntity) SaveDb ¶
func (this *GlobalEntity) SaveDb(removeCacheAfterSaveDb bool) error
type Guild ¶
type Guild struct { PlayerDataComponent Data *pb.PlayerGuildData `db:"Guild"` }
玩家的公会模块
func (*Guild) GetGuildData ¶
func (this *Guild) GetGuildData() *pb.PlayerGuildData
func (*Guild) HandleGuildJoinAgreeRes ¶
func (this *Guild) HandleGuildJoinAgreeRes(cmd gnet.PacketCommand, msg *pb.GuildJoinAgreeRes)
玩家进游戏服成功,非客户端消息 这种格式写的函数可以自动注册非客户端的消息回调
func (*Guild) SetGuildId ¶
type Money ¶
type Money struct { PlayerDataComponent // 该字段必须导出(首字母大写) // 使用struct tag来标记该字段需要存数据库,可以设置存储字段名 Data *pb.Money `db:"Money"` }
玩家的钱财组件
func (*Money) IncDiamond ¶
type PendingMessages ¶
type PendingMessages struct { BasePlayerComponent Messages map[int64]*pb.RoutePlayerMessage `db:""` }
待处理消息 该组件不会在玩家下线时保存数据库,也不保存缓存
func NewPendingMessages ¶
func NewPendingMessages(player *Player) *PendingMessages
type Player ¶
type Player struct { gentity.BaseRoutineEntity // contains filtered or unexported fields }
玩家对象
func CreatePlayerFromData ¶
func CreatePlayerFromData(playerData *pb.PlayerData) *Player
从加载的数据构造出玩家对象
func CreateTempPlayer ¶
func NewEmptyPlayer ¶
func (*Player) FireConditionEvent ¶
func (this *Player) FireConditionEvent(event interface{})
分发条件相关事件
func (*Player) GetActivities ¶
func (this *Player) GetActivities() *Activities
func (*Player) GetBaseInfo ¶
func (*Player) GetComponent ¶
获取组件
func (*Player) GetConnection ¶
func (this *Player) GetConnection() Connection
func (*Player) GetPropertyInt32 ¶
提供一个统一的属性值查询接口
func (*Player) OnDisconnect ¶
func (this *Player) OnDisconnect(connection Connection)
func (*Player) ResetConnection ¶
func (this *Player) ResetConnection()
func (*Player) RunRoutine ¶
开启消息处理协程 每个玩家一个独立的消息处理协程 除了登录消息,其他消息都在玩家自己的协程里处理,因此这里对本玩家的操作不需要加锁
func (*Player) SendErrorRes ¶
通用的错误返回消息
func (*Player) SetConnection ¶
设置关联的连接,支持客户端直连模式和网关模式
type PlayerComponent ¶
玩家组件接口
type PlayerDataComponent ¶
type PlayerDataComponent struct { BasePlayerComponent gentity.BaseDirtyMark }
保存数据作为一个整体的玩家组件 当保存数据的任何一个字段更新时,作为一个整体进行缓存更新
func NewPlayerDataComponent ¶
func NewPlayerDataComponent(player *Player, componentName string) *PlayerDataComponent
type PlayerMapDataComponent ¶
type PlayerMapDataComponent struct { BasePlayerComponent gentity.BaseMapDirtyMark }
保存数据为map格式的玩家组件 当对map的某一项增删改时,只对那一项进行缓存更新
func NewPlayerMapDataComponent ¶
func NewPlayerMapDataComponent(player *Player, componentName string) *PlayerMapDataComponent
type ProcessStatInfo ¶
type ProcessStatInfo struct { gentity.DataComponent // plain表示明文存储,在保存到mongo时,不会进行proto序列化 Data *pb.ProcessStatInfo `db:"ProcessStatInfo;plain"` }
进程统计信息组件
func NewProcessStatInfo ¶
func NewProcessStatInfo(globalEntity *GlobalEntity, data *pb.ProcessStatInfo) *ProcessStatInfo
func (*ProcessStatInfo) HandleShutdownReq ¶
func (this *ProcessStatInfo) HandleShutdownReq(cmd PacketCommand, req *pb.ShutdownReq)
func (*ProcessStatInfo) HandleStartupReq ¶
func (this *ProcessStatInfo) HandleStartupReq(cmd PacketCommand, req *pb.StartupReq)
type Quest ¶
type Quest struct { BasePlayerComponent // 保存数据的子模块:已完成的任务 // 保存数据的子模块必须是导出字段(字段名大写开头) Finished *FinishedQuests `child:""` // 保存数据的子模块:当前任务列表 Quests *CurQuests `child:""` }
任务模块 有多个子模块
func (*Quest) OnFinishQuestReq ¶
func (this *Quest) OnFinishQuestReq(reqCmd gnet.PacketCommand, req *pb.FinishQuestReq)
完成任务的消息回调 这种格式写的函数可以自动注册客户端消息回调
type RouteOptions ¶
type RouteOptions struct { // true:消息直接发给客户端 // false:放入玩家消息队列,消息将在玩家协程中被处理 DirectSendClient bool // 路由到指定的服务器 ToServerId int32 // 先保存到数据库(player.pendingmessages),防止路由失败造成消息丢失 SaveDb bool }
路由参数
func DirectSendClientRouteOptions ¶
func DirectSendClientRouteOptions() *RouteOptions
func NewRouteOptions ¶
func NewRouteOptions() *RouteOptions
func SaveDbRouteOptions ¶
func SaveDbRouteOptions() *RouteOptions
func (*RouteOptions) SetDirectSendClient ¶
func (this *RouteOptions) SetDirectSendClient(directSendClient bool) *RouteOptions
set DirectSendClient
func (*RouteOptions) SetToServerId ¶
func (this *RouteOptions) SetToServerId(toServerId int32) *RouteOptions
set ToServerId
Source Files ¶
- activities.go
- activity_default.go
- bag.go
- bag_countitem.go
- bag_uniqueitem.go
- base_info.go
- client_connection_handler.go
- component_map.go
- condition_checker.go
- global_entity.go
- guild.go
- money.go
- offline_process.go
- pending_messages.go
- player.go
- player_component.go
- player_component_handler_auto_register.go
- player_component_handler_gen.go
- player_handler.go
- player_mgr.go
- player_property.go
- process_stat_info.go
- progress_checker.go
- quest.go
- route.go
- server_hook.go