代码拉取完成,页面将自动刷新
package main
import (
"github.com/xiaonanln/goworld/engine/common"
"github.com/xiaonanln/goworld/engine/entity"
"github.com/xiaonanln/goworld/engine/gwlog"
)
type avatarInfo struct {
name string
level int
}
// OnlineService is the service entity for maintain total online avatar infos
type OnlineService struct {
entity.Entity
avatars map[common.EntityID]*avatarInfo
maxlevel int
}
func (s *OnlineService) DefineAttrs(desc *entity.EntityTypeDesc) {
}
// OnInit initialize OnlineService fields
func (s *OnlineService) OnInit() {
s.avatars = map[common.EntityID]*avatarInfo{}
}
// OnCreated is called when OnlineService is created
func (s *OnlineService) OnCreated() {
gwlog.Infof("Registering OnlineService ...")
s.DeclareService("OnlineService")
}
// CheckIn is called when Avatars login
func (s *OnlineService) CheckIn(avatarID common.EntityID, name string, level int) {
s.avatars[avatarID] = &avatarInfo{
name: name,
level: level,
}
if level > s.maxlevel {
s.maxlevel = level
}
gwlog.Infof("%s CHECK IN: %s %s %d, total online %d", s, avatarID, name, level, len(s.avatars))
}
// CheckOut is called when Avatars logout
func (s *OnlineService) CheckOut(avatarID common.EntityID) {
delete(s.avatars, avatarID)
gwlog.Infof("%s CHECK OUT: %s, total online %d", s, avatarID, len(s.avatars))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。