Ejemplo n.º 1
0
func P_rank_list_req(sess *Session, reader *packet.Packet) (ret []byte, err error) {
	ids, scores, err := ipc.GetList(1, -1)

	if err != nil {
		return nil, err
	}

	out := rank_list{}
	out.F_items = make([]rank_list_item, len(ids))

	for k, v := range ids {
		info, _ := ipc.GetInfo(v)
		out.F_items[k].F_id = v
		out.F_items[k].F_name = info.Name
		out.F_items[k].F_rank = scores[k]
		out.F_items[k].F_state = info.State

		t := int32(info.ProtectTime - time.Now().Unix())
		if t > 0 {
			out.F_items[k].F_protect_time = int32(t)
		} else {
			out.F_items[k].F_protect_time = 0
		}
	}

	writer := packet.Writer()
	return packet.Pack(Code["rank_list_ack"], out, writer), nil
}
Ejemplo n.º 2
0
func _fill_user_snapshot(user *User, snapshot *user_snapshot) {
	snapshot.F_id = user.Id
	snapshot.F_name = user.Name
	snapshot.F_rank = user.Score

	info, _ := ipc.GetInfo(user.Id)
	pt := info.ProtectTime - time.Now().Unix()
	if pt > 0 {
		snapshot.F_protect_time = int32(pt)
	} else {
		snapshot.F_protect_time = 0
	}

	snapshot.F_last_save_time = int32(user.LastSaveTime.Unix())
	snapshot.F_server_time = int32(time.Now().Unix())
}
Ejemplo n.º 3
0
func P_atk_player_req(sess *Session, reader *packet.Packet) (ret []byte, err error) {
	tbl, _ := PKT_command_id_pack(reader)
	writer := packet.Writer()
	success := user_snapshot{}
	failed := command_result_pack{}

	if ipc.Raid(tbl.F_id) {
		opponent, e := user_tbl.Load(tbl.F_id)
		if e == nil {
			_fill_user_snapshot(&opponent, &success)
			ret = packet.Pack(Code["atk_player_succeed_ack"], success, writer)
			return
		}
	}

	//
	info, err := ipc.GetInfo(tbl.F_id)
	failed.F_rst = info.Id
	ret = packet.Pack(Code["atk_player_faild_ack"], failed, writer)
	return
}