package maincity import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "sync" ) type modelComp struct { cbase.ModuleCompBase module *MainCity lock sync.RWMutex ulock sync.RWMutex onlines map[string][]string //关联用户信息 } func (this *modelComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.ModuleCompBase.Init(service, module, comp, options) this.module = module.(*MainCity) this.onlines = make(map[string][]string) return } func (this *modelComp) setplayerPos(uid string, friends []string) { this.lock.Lock() this.onlines[uid] = append(this.onlines[uid], friends...) this.lock.Unlock() } func (this *modelComp) addplayerPos(uid string, friend string) { this.lock.Lock() if _, ok := this.onlines[uid]; ok { this.onlines[uid] = append(this.onlines[uid], friend) } this.lock.Unlock() } func (this *modelComp) getplayerPos(uid string) (friends []string) { this.lock.RLock() friends = this.onlines[uid] this.lock.RUnlock() return } func (this *modelComp) removelayerPos(uid string) { this.lock.Lock() delete(this.onlines, uid) this.lock.Unlock() }