Exemple #1
0
func (user *ChatUser) sendMsgReq_Handle(req *chat.SendmsgReq) {
	if !user.verify() {
		user.Close("not login")
		return
	}

	fmt.Println("user:"******" msg:", req.GetMsg())

	if !user.userMgr.SendMsg(user.getAcc(), req.GetMsg()) {
		//发送数据失败
		user.Close("SendMsg Fail")
		return
	}

	protoRsp := &chat.SendmsgRsp{
		State: proto.Int32(0),
	}

	rspData, err := proto.Marshal(protoRsp)
	util.CheckError(err, "proto.Marshal SendmsgRsp: ")

	packetData := user.encodePacket(rspData, cmd_sendmsg_rsp)

	user.sendPacket(packetData)
}
Exemple #2
0
func (user *ChatUser) loginReq_Handle(req *chat.LoginReq) {
	fmt.Println("user:"******" pwd:", req.GetPwd())

	var rsp *chat.LoginRsp
	if !user.verify() {
		fmt.Println("setVerify")
		selfAcc := req.GetAcc()

		joinState, userAarray := user.userMgr.Join(selfAcc, user)
		if !joinState {
			//进入失败了,关闭连接
			user.Close("join fail")
			return
		}

		user.setAcc(selfAcc)

		rsp = &chat.LoginRsp{
			State:    proto.Int32(0),
			AccArray: userAarray,
		}

	} else {
		rsp = &chat.LoginRsp{
			State: proto.Int32(1),
		}
	}

	rspData, err := proto.Marshal(rsp)
	//编码失败了
	util.CheckError(err, "proto.Marshal LoginRsp: ")

	packetData := user.encodePacket(rspData, cmd_login_rsp)

	user.sendPacket(packetData)
}