Exemple #1
0
// 客户端申请加入讨论组
func HandleClientJoinGroup(conn *net.TCPConn, recPacket *packet.Packet) {
	// read
	readMsg := &pb.PbClientJoinGroup{}
	packet.Unpack(recPacket, readMsg)

	from_uuid := readMsg.GetFromUuid()
	group_id := readMsg.GetGroupId()
	// note_msg := readMsg.GetNoteMsg()
	// timestamp := readMsg.GetTimestamp()

	// 加入讨论组
	if ret := groupinfo.JoinGroup(from_uuid, group_id); !ret {
		return
	}

	group_name, _ := groupinfo.GetGroupNameAndOwner(group_id)

	// write
	writeMsg := pb.PbServerNotifyJoinGroup{
		ApplicantUuid: proto.String(from_uuid),
		GroupId:       proto.String(group_id),
		GroupName:     proto.String(group_name),
		Timestamp:     proto.Int64(time.Now().Unix()),
	}

	// 通知所有组员,这个消息不离线存储
	group_members := groupinfo.GetAllUuid(group_id)
	for i := 1; i < len(group_members); i++ {
		SendPbData(UuidMapConn.Get(group_members[i]).(*net.TCPConn), packet.PK_ServerNotifyJoinGroup, writeMsg)
	}
}
Exemple #2
0
// 客户端(群主)申请解散讨论组
func HandleClientDisbandGroup(conn *net.TCPConn, recPacket *packet.Packet) {
	// read
	readMsg := &pb.PbClientDisbandGroup{}
	packet.Unpack(recPacket, readMsg)
	from_id := readMsg.GetFromUuid()
	group_id := readMsg.GetGroupId()
	// timestamp := readMsg.GetTimestamp()

	// 验证from_id确实是该conn,并且是group_id的群主
	group_name, group_owner := groupinfo.GetGroupNameAndOwner(group_id)
	if from_id != ConnMapUuid.Get(conn).(string) || group_owner != from_id {
		CloseConn(conn)
		return
	}

	// 解散讨论组
	ret := groupinfo.DisbandGroup(from_id, group_id)
	tips_msg := "解散讨论组[" + group_name + "]成功"
	if ret {
		tips_msg = "解散讨论组[" + group_name + "]失败"
	}

	// write
	writeMsg := &pb.PbServerNotifyDisbandGroup{
		Disband:   proto.Bool(ret),
		GroupId:   proto.String(group_id),
		GroupName: proto.String(group_name),
		TipsMsg:   proto.String(tips_msg),
		Timestamp: proto.Int64(time.Now().Unix()),
	}
	SendPbData(conn, packet.PK_ServerNotifyDisbandGroup, writeMsg)
}