Пример #1
0
func TestMsgHeaderGateClient(t *testing.T) {
	byMsg := make([]byte, 4)
	msgHeader := NewMsgHeaderGateClient(1, 2, bsn_common.TMsgLen(len(byMsg)))

	vUserId := bsn_common.MakeGateUserId(1, 2)
	if msgHeader.UserId() != vUserId {
		t.Error(msgHeader.UserId())
	}
	if msgHeader.Len() != 4 {
		t.Error(msgHeader.Len())
	}

	if bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)) != CSMsgHeaderGateClient_Size {
		t.Errorf("bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader))=%v != CSMsgHeaderGateClient_Size=%v", bsn_common.TMsgLen(unsafe.Sizeof(*msgHeader)), CSMsgHeaderGateClient_Size)
	}

	byDatas := msgHeader.Serialize()
	GSLog.Mustln(byDatas)

	msgHeader = NewMsgHeaderGateClientFromBytes(byDatas)

	if msgHeader.UserId() != vUserId {
		t.Error(msgHeader.UserId())
	}
	if msgHeader.Len() != 4 {
		t.Error(msgHeader.Len())
	}
}
Пример #2
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
}
Пример #3
0
func NewMsgHeaderGateClient(vu8ServerType, vu8ServerId uint8, vTMsgLen bsn_common.TMsgLen) *SMsgHeaderGateClient {
	this := &SMsgHeaderGateClient{}
	vUserId := bsn_common.MakeGateUserId(vu8ServerType, vu8ServerId)
	this.SMsgHeader.Fill(bsn_common.TMsgType(vUserId), vTMsgLen)
	return this
}