// GameClient project main.go
package main

import (
	pb "World/pb"
	"bytes"
	"encoding/binary"
	"fmt"
	"net"

	"github.com/golang/protobuf/proto"
)

const (
	addr = "192.168.31.168:50054"
	//	addr             = "139.196.215.75:50054"
	Min_Message_Size = 16
)

func main() {
	fmt.Println("Hello World!")
	//TestMarsh()
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		fmt.Println("connect failed:", err.Error())
		return
	}

	//conn = conn
	//	Login(conn)
	//	CreateClub(conn)
	//	ClubSnapshotList(conn)
	//JoinClub(conn)
	//	LeaveClub(conn)
	//	ClubCurrentBoard(conn)
	//	ClubMemberSnapshotList(conn)
	//	SearchClubInfo(conn)
	//	ModifyClubMember(conn)
	//	ModifyClubInfo(conn)
	//	RechargeClubFund(conn)
	//	GrantClubFund(conn)

	//	PurchaseClubLevel(conn)

	//	GetUserData(conn)
	HeartBeat(conn)

	//	SendMsg(conn)

	//	RechargeClubFund(conn)

}

func CreateClub(conn net.Conn) {
	var req pb.RequestCreateClub
	req.Param = new(pb.ClubParams)

	req.Param.ClubName = "阿明正俱乐部"
	req.Param.ClubArea = "上海"
	req.Param.ClubIcon = "阿明正.ico"

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + Min_Message_Size
	bys := new(bytes.Buffer)
	seq := 1
	uid := 42
	rid := 100
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_CreateClub_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	binary.Write(bys, binary.BigEndian, uint32(rid))
	fmt.Println("create club total:", total_len)
	fmt.Println("create club body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("create club len:", len(buf))

	conn.Write(buf)
}

//package main

//import (
//	//	"bytes"
//	//	"encoding/binary"
//	"fmt"
//	"net"

//	//	"github.com/golang/protobuf/proto"
//)

//const (
//	addr = "127.0.0.1:4321"
//)

//func main() {

//	//TestMarsh()
//	conn, err := net.Dial("tcp", addr)
//	if err != nil {
//		fmt.Println("connect failed:", err.Error())
//		return
//	}

//	//conn = conn
//	test.Login(conn)
////	CreateRoom(conn)
////	JoinRoom(conn)
////	LeaveRoom(conn)
////	SitDownRoom(conn)
////	select {}
//}

//func TestMarsh() {
//	var req main.RequestLogon

//	req.Version = "1.1.2"
//	req.Token = "this is token"

//	DoMarshal(&req)

//	var resp ResponseLogon
//	resp.Error = 5

//	DoMarshal(&resp)
//}

//func DoMarshal(msg interface{}) {
//	tmp, err := proto.Marshal(msg.(proto.Message))
//	if err != nil {
//		fmt.Println("err marshal")
//	}
//	fmt.Println("marshal len:", len(tmp))
//}

//func Login(conn net.Conn) {
//	var req test.RequestLogon

//	req.Version = "1.2.3"
//	req.Token = "284f3602f544637a2bf9092572152df2"

//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + 12
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 1
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_Logon_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	fmt.Println("login total:", total_len)
//	fmt.Println("login body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("login len:", len(buf))

//	conn.Write(buf)

//	read_buf := make([]byte, 1024)
//	reqLen, err := conn.Read(read_buf)
//	if err != nil {
//		fmt.Println("read conn error:", err)
//		return
//	}
//	fmt.Println("resp data len:", reqLen)
//	//todo: decode

//	rd := bytes.NewReader(read_buf[0:2])
//	var resp_total_len uint16
//	binary.Read(rd, binary.BigEndian, &resp_total_len)

//	rd = bytes.NewReader(read_buf[2:4])
//	var resp_msgid uint16
//	binary.Read(rd, binary.BigEndian, &resp_msgid)

//	rd = bytes.NewReader(read_buf[4:8])
//	var resp_seq uint32
//	binary.Read(rd, binary.BigEndian, &resp_seq)

//	rd = bytes.NewReader(read_buf[8:12])
//	var resp_uid uint32
//	binary.Read(rd, binary.BigEndian, &resp_uid)
//	fmt.Println("resp len:", resp_total_len, " msgid:", resp_msgid, " req:", resp_seq, " uid:", resp_uid)

//	var resp test.ResponseLogon
//	rd = bytes.NewReader(read_buf[12:reqLen])
//	binary.Read(rd, binary.BigEndian, &resp)

//	fmt.Println(" resp body error code:", resp.Error)
//}

//func CreateRoom(conn net.Conn) {
//	var req protocol.RequestCreateRoom
//	req.Param = new(protocol.RoomParams)

//	req.Param.OwnerType = 1
//	req.Param.GameMode = 1
//	req.Param.PlayerCountMax = 3
//	req.Param.RuleBlindEnum = 1
//	req.Param.RuleBuyinMinEnum = 1
//	req.Param.RuleBuyinFold = 2
//	req.Param.RuleTimeLimit = 1
//	req.Param.RuleSwitchBuyinControl = 1
//	req.Param.RuleSwitchInsurance = 0
//	req.Param.RuleSwitchAntiCheat = 0
//	req.Param.RuleSwitchForceStraddle = 1
//	req.Param.RuleSwitchRandomSeat = 1
//	req.Param.RuleAnteAmount = 20
//	req.Param.GameName = "test room"
//	req.Param.ClubId = 12

//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + 12
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 1
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_CreateRoom_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	fmt.Println("create room total:", total_len)
//	fmt.Println("create room body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("create room len:", len(buf))

//	conn.Write(buf)
//}

func ClubSnapshotList(conn net.Conn) {
	var req pb.RequestClubSnapshotList
	req.Uid = 123456

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 12
	bys := new(bytes.Buffer)
	seq := 1
	uid := 1
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_ClubSnapshotList_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	fmt.Println("ClubSnapshotList total:", total_len)
	fmt.Println("ClubSnapshotList body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("ClubSnapshotList:", len(buf))

	conn.Write(buf)
}

//func JoinClub(conn net.Conn) {
//	var req pb.RequestJoinClub

//	req.Param = new(pb.JoinClubParams)

//	req.Param.ClubId = 34
//	req.Param.ClubUid = 222222
//	req.Param.ClubMessage = "test ClubIcon"

//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + 12
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 1
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_JoinClub_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	fmt.Println("join club total:", total_len)
//	fmt.Println("join club body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("join club len:", len(buf))

//	n, err := conn.Write(buf)
//	fmt.Println("write ", n, " bytes, with err:", err)
//}

//func JoinRoom(conn net.Conn) {
//	var req RequestJoinRoom

//	req.Roomid = 123

//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + 12
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 1
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(MSGID_MsgID_JoinRoom_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	fmt.Println("join room total:", total_len)
//	fmt.Println("join room body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("join room len:", len(buf))

//	n, err := conn.Write(buf)
//	fmt.Println("write ", n, " bytes, with err:", err)
//}

func LeaveClub(conn net.Conn) {
	var req pb.RequestLeaveClub

	req.Param = new(pb.LeaveClubParams)

	req.Param.ClubId = 123
	req.Param.ClubDid = 123
	req.Param.ClubAmount = 123

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 12
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_LeaveClub_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	fmt.Println("leave club total:", total_len)
	fmt.Println("leave club body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("leave club len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}

func ClubCurrentBoard(conn net.Conn) {
	var req pb.RequestClubCurrentBoard

	req.Param = new(pb.ClubCurrentBoardParams)

	req.Param.ClubId = 123
	req.Param.ClubUid = 123

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 12
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_ClubCurrentBoard_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	fmt.Println("CurrentBoard total:", total_len)
	fmt.Println("CurrentBoard body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("CurrentBoard len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}

func ClubMemberSnapshotList(conn net.Conn) {
	var req pb.RequestClubMemberSnapshotList

	req.Param = new(pb.ClubMemberSnapshotListParams)

	req.Param.ClubId = 100035
	req.Param.ClubUid = 29

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 12
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_ClubMemberSnapshotList_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	fmt.Println("ClubMemberSnapshotList total:", total_len)
	fmt.Println("ClubMemberSnapshotList body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("ClubMemberSnapshotList len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}

func SearchClubInfo(conn net.Conn) {
	req := new(pb.RequestSearchClubInfo)

	req.ClubId = 100035

	tmp, err := proto.Marshal(req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 12
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_SearchClubInfo_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	fmt.Println("SearchClubInfo total:", total_len)
	fmt.Println("SearchClubInfo body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("SearchClubInfo len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}

func ClubCreaterInfo(conn net.Conn) {
	req := new(pb.RequestSearchClubInfo)

	req.ClubId = 100035

	tmp, err := proto.Marshal(req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 12
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_SearchClubInfo_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	fmt.Println("SearchClubInfo total:", total_len)
	fmt.Println("SearchClubInfo body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("SearchClubInfo len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}

func ModifyClubMember(conn net.Conn) {
	var req pb.RequestModifyClubMember

	req.Param = new(pb.ModifyClubMemberParams)

	req.Param.ClubId = 31
	req.Param.ClubUid = 14
	req.Param.TargetId = 15
	req.Param.ActionType = 123

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 12
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_ModifyClubMember_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	fmt.Println("ModifyClubMember total:", total_len)
	fmt.Println("ModifyClubMember body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("ModifyClubMember len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}

//func ModifyClubInfo(conn net.Conn) {
//	var req pb.RequestModifyClubInfo

//	req.Param = new(pb.ModifyClubInfoParams)
//	req.Param.ClubId = 123
//	req.Param.ClubUid = 123
//	req.Param.ClubName = "123"
//	req.Param.ClubDescrption = "123"
//	req.Param.ClubIcon = "123"
//	req.Param.ActionType = 123

//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + 12
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 3
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_ModifyClubInfo_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	fmt.Println("ModifyClubInfo total:", total_len)
//	fmt.Println("ModifyClubInfo body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("ModifyClubInfo len:", len(buf))

//	n, err := conn.Write(buf)
//	fmt.Println("write ", n, " bytes, with err:", err)
//}

func GrantClubFund(conn net.Conn) {
	var req pb.RequestGrantClubFund

	req.Param = new(pb.GrantClubFundParams)
	req.Param.ClubId = 123
	req.Param.ClubUid = 123
	req.Param.TargetId = 123
	req.Param.Amount = 123

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + Min_Message_Size
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	rid := 100
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_GrantClubFund_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	binary.Write(bys, binary.BigEndian, uint32(rid))
	fmt.Println("GrantClubFund total:", total_len)
	fmt.Println("GrantClubFund body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("GrantClubFund len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}

//func ClubCurrentClub(conn net.Conn) {
//	var req protocol.RequestClubCurrentClub

//	req.Param = new(protocol.ClubCurrentClubParams)

//	req.Param.ClubId = 123
//	req.Param.ClubUid = 123

//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + 12
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 3
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(protocol.MSGID_MsgID_LeaveClub_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	fmt.Println("leave room total:", total_len)
//	fmt.Println("leave room body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("leave room len:", len(buf))

//	n, err := conn.Write(buf)
//	fmt.Println("write ", n, " bytes, with err:", err)
//}

//func SitDownRoom(conn net.Conn) {
//	var req RequestSitDown

//	req.Roomid = 123
//	req.Seatid = 1

//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + 12
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 3
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(MSGID_MsgID_SitDown_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	fmt.Println("sitdown total:", total_len)
//	fmt.Println("sitdown body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("sitdown room len:", len(buf))

//	n, err := conn.Write(buf)
//	fmt.Println("write ", n, " bytes, with err:", err)
//}

func PurchaseClubLevel(conn net.Conn) {
	req := new(pb.RequestPurchaseClubLevel)
	req.ClubId = 100064
	req.TypeId = 2

	tmp, err := proto.Marshal(req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + Min_Message_Size
	bys := new(bytes.Buffer)
	seq := 1
	uid := 42
	rid := 100
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_PurchaseClubLevel_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	binary.Write(bys, binary.BigEndian, uint32(rid))
	log.Println("GrantClubFund total:", total_len)
	log.Println("GrantClubFund body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	log.Println("GrantClubFund len:", len(buf))

	n, err := conn.Write(buf)
	log.Println("write ", n, " bytes, with err:", err)
}

func SendMsg(conn net.Conn) {
	req := new(pb.RequestSendMsg)
	req.ClubId = 100064
	req.Msg = "My Msg"

	tmp, err := proto.Marshal(req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + Min_Message_Size
	bys := new(bytes.Buffer)
	seq := 1
	uid := 42
	rid := 100
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_SendMsg_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	binary.Write(bys, binary.BigEndian, uint32(rid))
	log.Println("SendMsg total:", total_len)
	log.Println("SendMsg body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	log.Println("SendMsg len:", len(buf))

	n, err := conn.Write(buf)
	log.Println("write ", n, " bytes, with err:", err)
}

func RechargeClubFund(conn net.Conn) {
	var req pb.RequestRechargeClubFund

	req.Param = new(pb.RechargeClubFundParams)
	req.Param.ClubId = 100064
	req.Param.BuyCount = 1

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + Min_Message_Size
	bys := new(bytes.Buffer)
	seq := 1
	uid := 42
	rid := 100
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_RechargeClubFund_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	binary.Write(bys, binary.BigEndian, uint32(rid))
	buf := append(bys.Bytes(), tmp...)
	log.Println("RechargeClubFund len:", len(buf))

	n, err := conn.Write(buf)
	log.Println("write ", n, " bytes, with err:", err)
}

//func GetUserData(conn net.Conn) {
//	var req pb.RequestGetUserData
//	req.UserId = 3
//	tmp, err := proto.Marshal(&req)
//	if err != nil {
//		fmt.Println("marshal proto failed:", err.Error())
//		return
//	}

//	body_len := len(tmp)
//	total_len := body_len + Min_Message_Size
//	bys := new(bytes.Buffer)
//	seq := 1
//	uid := 3
//	rid := 100
//	binary.Write(bys, binary.BigEndian, uint16(total_len))
//	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_GetUserData_Request))
//	binary.Write(bys, binary.BigEndian, uint32(seq))
//	binary.Write(bys, binary.BigEndian, uint32(uid))
//	binary.Write(bys, binary.BigEndian, uint32(rid))
//	fmt.Println("GetUserData total:", total_len)
//	fmt.Println("GetUserData body total:", body_len)
//	buf := append(bys.Bytes(), tmp...)
//	fmt.Println("GetUserData len:", len(buf))

//	conn.Write(buf)
//}

func HeartBeat(conn net.Conn) {
	//		req := msg.(*pb.RequestHeartBeat)

	//	var resp pb.ResponseHeartBeat
	//	resp.Uid = req.Uid
	//	SendMessage(conn, header, pb.MSGID_MsgID_HeartBeat_Response, &resp)
	var req pb.RequestHeartBeat

	tmp, err := proto.Marshal(&req)
	if err != nil {
		fmt.Println("marshal proto failed:", err.Error())
		log.Println("marshal proto failed:", err.Error())
		return
	}

	body_len := len(tmp)
	total_len := body_len + 16
	bys := new(bytes.Buffer)
	seq := 1
	uid := 3
	rid := 100
	binary.Write(bys, binary.BigEndian, uint16(total_len))
	binary.Write(bys, binary.BigEndian, uint16(pb.MSGID_MsgID_HeartBeat_Request))
	binary.Write(bys, binary.BigEndian, uint32(seq))
	binary.Write(bys, binary.BigEndian, uint32(uid))
	binary.Write(bys, binary.BigEndian, uint32(rid))
	log.Println("leave room total:", total_len)
	log.Println("leave room body total:", body_len)
	buf := append(bys.Bytes(), tmp...)
	fmt.Println("HeartBeat len:", len(buf))

	n, err := conn.Write(buf)
	fmt.Println("write ", n, " bytes, with err:", err)
}
