コード例 #1
0
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)
}
コード例 #2
0
func P_getinfo_req(hostid int32, pkt *packet.Packet) []byte {
	tbl, _ := PKT_ID(pkt)
	ret := INFO{}
	ret.F_id = tbl.F_id
	ret.F_state = core.State(tbl.F_id)
	ret.F_score = core.Score(tbl.F_id)
	ret.F_protecttime = core.ProtectTimeout(tbl.F_id)
	if ret.F_state == 0 {
		ret.F_flag = false
	} else {
		ret.F_flag = true
	}

	return packet.Pack(-1, &ret, nil)
}
コード例 #3
0
ファイル: handle.go プロジェクト: chenbk85/gonet
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)
	}
}
コード例 #4
0
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
}