Esempio n. 1
0
func GetUser(ses *netdef.Session) *User {
	v := ses.GetTag(gameUserTag)
	if v != nil {
		return v.(*User)
	}
	return nil
}
Esempio n. 2
0
func (self *relayComponent) SendRaw(relaySession *netdef.Session, sessionid int64, pkt *netdef.Packet) error {

	if relaySession == nil {
		return nil
	}

	// 整合调用封包
	relaySession.Send(&coredef.RelayMessageACK{
		UserMsgID: proto.Uint32(pkt.MsgID),
		UserMsg:   pkt.Data,
		SessionID: proto.Int64(sessionid),
	})

	return nil

}
Esempio n. 3
0
func (self *binaryAcceptor) addSession(ses *netdef.Session) {

	ses.SessionID = atomic.AddInt64(&self.sesIDAcc, 1)

	self.sesMapGuard.Lock()
	self.sesMap[self.sesIDAcc] = ses
	self.sesMapGuard.Unlock()

}
Esempio n. 4
0
// 流包到Chan队列
func RecvPacketLoop(ses *netdef.Session) {

	var err error
	var pkt *netdef.Packet
	// 循环读取封包
	for {

		pkt, err = ses.PStream.Read()

		if err != nil {
			break
		}

		// 封包变事件
		ses.PostEvent(&netdef.NetEvent{Method: netdef.EventRecvPacket, Pkt: pkt, Ses: ses, Tag: nil})
	}

	ses.InternalStop(err)

}
Esempio n. 5
0
// 移除ses上的绑定
func RemoveUser(ses *netdef.Session) *User {

	tag := ses.GetTag(gameUserTag)

	if tag == nil {
		return nil
	}

	u := tag.(*User)

	userGuard.Lock()

	ses.SetTag(gameUserTag, nil)

	userCount = userCount - 1

	userGuard.Unlock()

	return u

}