Esempio n. 1
0
func (handler *HdlGdsSync) HandlePackage(buf []byte) {
	gdsSync := new(common.GdsSync)
	proto.Unmarshal(buf, gdsSync)
	fmt.Println(gdsSync.GetVersion())
	fmt.Println(gdsSync.GetWhat())
	buildingcsv := filepath.Join(handler.session.Server.Config.GdsPath, "buildings.csv")
	log.Println(buildingcsv)
	csvContent, _ := ioutil.ReadFile(buildingcsv)

	r2 := csv.NewReader(strings.NewReader(string(csvContent)))
	ss, _ := r2.ReadAll()
	sz := len(ss)
	buildingGds := new(gds.BuildingGds)
	buildingGds.Buildings = []*gds.Building{}
	for i := 0; i < sz; i++ {
		building := new(gds.Building)
		building.Name = &(ss[i][0])
		intVal, _ := strconv.Atoi(ss[i][1])
		v := uint32(intVal)
		building.Level = &v
		buildingGds.Buildings = append(buildingGds.Buildings, building)
	}

	bytes, _ := proto.Marshal(buildingGds)
	log.Println("xxxxx", len(bytes))
	handler.session.WriteToClient(ProtoBuildingsGds, bytes)
}
Esempio n. 2
0
func (c *Client) BeginLoop() *Client {
	buf := make([]byte, 4096)
	for {
		ByteRead, err := c.Conn.Read(buf)
		fmt.Println("ByteRead", ByteRead)
		if err != nil {
			log.Fatal("xx")
		}

		var size uint32
		var protoType monica.ProtoCode

		bufReader := bytes.NewReader(buf[:4])
		binary.Read(bufReader, binary.LittleEndian, &size)

		abufReader := bytes.NewReader(buf[4:8])
		binary.Read(abufReader, binary.LittleEndian, &protoType)

		switch protoType {
		case monica.ProtoPing:
			pingProto := new(common.Ping)
			proto.Unmarshal(buf[8:ByteRead], pingProto)
			fmt.Println("size", size)
			fmt.Println("protoType", protoType)
			fmt.Println("timeStamp", pingProto.GetTimestamp())
		case monica.ProtoBuildingsGds:
			gds := new(gds.BuildingGds)
			proto.Unmarshal(buf[8:ByteRead], gds)
			log.Println(len(gds.GetBuildings()))
			for _, building := range gds.GetBuildings() {
				fmt.Println("name ", building.GetName())
				fmt.Println("level ", building.GetLevel())
			}
		}

	}
	return c
}