Пример #1
0
func RegisterModule() {
	gw := new(gateway)
	gw.addr = ":" + strconv.Itoa(config.DataSetting.GatewayPort)
	gw.maxConnNum = config.DataSetting.MaxOnlineNum
	gw.headLen = config.DataSetting.HeadLen
	gw.msgIDLen = config.DataSetting.MsgIDLen
	gw.maxDataLen = config.DataSetting.MaxDataLen
	gw.agants = concurrent.NewConcurrentMap(config.DataSetting.MaxOnlineNum)
	module.Register(gw)
	globalGW = gw
}
Пример #2
0
//加载所有名字
func InitAllRoleName() {
	allNames = concurrent.NewConcurrentMap(100000)
	logger.Info("===========>>开启缓存所有名字")
	allRoleNames, err := db.FindAllName()
	if err != nil {
		panic(err)
	}
	for _, RN := range allRoleNames {
		allNames.Put(RN.RoleName, RN.RoleID)
	}
	logger.Info("===========>>缓存所有名字成功")
}
Пример #3
0
func (this *db_table_role_info) init() error {
	session, collection := c(_DB_ROLE_INFO)
	this.collection = collection
	this.session = session
	this.cmap = concurrent.NewConcurrentMap(1000)
	err := this.ensureIndexs("roleid", "roleid_", true, true)
	if err != nil {
		return err
	}
	err = this.ensureIndexs("rolename", "rolename_", true, true)
	if err != nil {
		return err
	}
	err = this.ensureIndexs("level", "level_", false, false)
	if err != nil {
		return err
	}
	go this.loop_dump()
	return nil
}
Пример #4
0
// gateway.go
package gateway

import (
	"github.com/gbember/gt/util/concurrent"
	"github.com/gbember/gtserver/proto"
)

type Gateway interface {
	Send(msg proto.Messager)
	RealSend(msg proto.Messager)
	Close(int8)
}

var (
	gateways *concurrent.ConcurrentMap = concurrent.NewConcurrentMap(10000)
)

func GetGW(roleID int32) Gateway {
	if v := gateways.Get(roleID); v != nil {
		return v.(Gateway)
	}
	return nil
}

func SetGW(roleID int32, gw Gateway) {
	gateways.Put(roleID, gw)
}
func DeleteGW(roleID int32) {
	gateways.Delete(roleID)
}
Пример #5
0
package role

import (
	"github.com/gbember/gt/util/concurrent"
	"github.com/gbember/gtserver/proto"
)

var (
	allRoles       = concurrent.NewConcurrentMap(1000)
	resgisterFuncs = make(map[uint16]handleFunc)
)

type handleFunc func(*RoleData, proto.Messager)

func GetRoleClient(roleID int32) *RoleData {
	rd := allRoles.Get(roleID)
	if rd != nil {
		return rd.(*RoleData)
	}
	return nil
}
func SetRoleClient(rd *RoleData) {
	allRoles.Put(rd.RoleID, rd)
}

//注册处理函数
func RegisterHandle(msgID uint16, f handleFunc) {
	resgisterFuncs[msgID] = f
}

//查找处理函数(没有返回nil)