func P_forward_req(hostid int32, pkt *packet.Packet) []byte {
	tbl, _ := PKT_FORWARDIPC(pkt)

	object := &IPCObject{}
	err := json.Unmarshal(tbl.F_IPC, object)

	if err != nil {
		log.Println("decode forward IPCObject error")
		return nil
	}

	// if user is online, send to the server, or else send to database
	state := core.State(object.DestID)

	//fmt.Println(tbl.F_dest_id, tbl.F_IPC)
	switch state {
	case core.ON_PROT, core.ON_FREE:
		host := core.Host(object.DestID)

		ch := ForwardChan(host)

		if ch != nil {
			ch <- tbl.F_IPC
		} else {
			forward_tbl.Push(object)
		}
	default:
		forward_tbl.Push(object)
	}

	ret := INT{F_v: 1}
	return packet.Pack(-1, &ret, nil)
}
Beispiel #2
0
func _unicast(hostid int32, obj *IPCObject) {
	// if user is online, send to the server, or else send to database
	state := core.State(obj.DestID)

	switch state {
	case ON_PROT, ON_FREE:
		host := core.Host(obj.DestID)
		ch := ForwardChan(host)

		if ch != nil {
			ch <- *obj
		} else {
			forward_tbl.Push(obj)
		}
	default:
		forward_tbl.Push(obj)
	}
}
func P_forwardgroup_req(hostid int32, pkt *packet.Packet) (r []byte) {
	tbl, _ := PKT_FORWARDIPC(pkt)
	ret := INT{F_v: 1}

	defer func() {
		r = packet.Pack(-1, &ret, nil)
	}()

	object := &IPCObject{}
	err := json.Unmarshal(tbl.F_IPC, object)
	if err != nil {
		ret.F_v = 0
		log.Println("decode group IPCObject error")
		return
	}

	group := core.Group(object.DestID)
	if group == nil {
		ret.F_v = 0
		log.Println("forward ipc: no such group")
		return
	}
	group.Push(object)

	// send to online users directly
	members := group.Members()
	for _, user_id := range members {
		state := core.State(user_id)
		switch state {
		case core.ON_PROT, core.ON_FREE:
			host := core.Host(user_id)

			ch := ForwardChan(host)
			if ch != nil {
				ch <- tbl.F_IPC
			}
		}
	}

	return
}