49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package maincity
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"sync"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelComp struct {
|
|
modules.MCompModel
|
|
module *MainCity
|
|
lock sync.RWMutex
|
|
onlines map[string][]*pb.BaseUserInfo //关联用户信息
|
|
}
|
|
|
|
func (this *modelComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.TableName = comm.Tablekftask
|
|
this.module = module.(*MainCity)
|
|
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelComp) setplayerPos(uid string, friends []*pb.BaseUserInfo) {
|
|
this.lock.Lock()
|
|
this.onlines[uid] = friends
|
|
this.lock.Unlock()
|
|
}
|
|
func (this *modelComp) getplayerPos(uid string) (friends []*pb.BaseUserInfo) {
|
|
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()
|
|
}
|