예제 #1
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
}
예제 #2
0
func P_login_req(hostid int32, pkt *packet.Packet) []byte {
	tbl, _ := PKT_LOGIN_REQ(pkt)
	ret := LOGIN_ACK{F_success: false}

	if core.Login(tbl.F_id, hostid) {
		ret.F_success = true

		// 登陆后,将联盟消息push给玩家
		group := core.Group(tbl.F_group)
		if group != nil {
			ch := ForwardChan(hostid)
			objs := group.Recv(tbl.F_groupmsgmax + 1)
			for _, v := range objs {
				ch <- v.Json()
			}

			ret.F_groupmsgmax = group.MaxMsgId
		}
	}

	return packet.Pack(-1, &ret, nil)
}