Example #1
0
func (this *SServerUser) msg_reg(vMsg *bsn_msg.SMsgHeaderGateServer) error {
	vServerType := uint8(vMsg.GroupId())
	vServerId := uint8(vMsg.UserId())
	vUserId := bsn_common.MakeGateUserId(vServerType, vServerId)
	GSLog.Debugf("reg server vServerType=%v vServerId=%v vUserId=%v this.Id()=%v \n", vServerType, vServerId, vUserId, this.Id())

	if this.Id() != 0 {
		return errors.New("had reg with id " + strconv.Itoa(int(this.Id())))
	}

	this.SetId(vUserId)
	this.UserMgr().AddUser(this)

	return nil
}
Example #2
0
func (this *SServerUser) runImp() {
	defer bsn_common.FuncGuard()
	defer func() {
		this.Close()
		this.UserMgr().DelUser(this)
	}()

	vSClientUserMgr := this.UserMgr().Gate().GetClientMgr()
	var vMsg bsn_msg.SMsgHeaderGateServer
	for !this.M_bClose {
		err := this.ReadMsgHeader()
		if err != nil {
			GSLog.Errorln(err)
			return
		}
		vMsg.DeSerialize(this.M_byMsgHeader)

		vLen := vMsg.Len()
		this.M_byMsgBody = make([]byte, vLen)
		if vLen > 0 {
			err = this.ReadMsgBody()
			if err != nil {
				GSLog.Errorln(err)
				return
			}
		}

		switch vMsg.ServerMsgType() {
		case bsn_msg.CServerMsgType_Reg:
			err = this.msg_reg(&vMsg)
		case bsn_msg.CServerMsgType_ToUser:
			err = vSClientUserMgr.SendMsgToUser(vMsg.UserId(), this.M_byMsgBody)
		default:
			err = errors.New("unknown msg type " + strconv.Itoa(int(vMsg.Type())))
		}

		if err != nil {
			GSLog.Errorln("process msg err: ", vMsg.Type(), err)
		}
	}
}