2020-06-13 18:32:09 -04:00
|
|
|
package d2netpacket
|
|
|
|
|
|
|
|
import (
|
2020-08-09 20:32:47 -04:00
|
|
|
"encoding/json"
|
2020-09-12 16:25:09 -04:00
|
|
|
|
2020-06-26 17:12:19 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-06-13 18:32:09 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
|
|
|
)
|
|
|
|
|
2020-06-29 17:01:26 -04:00
|
|
|
// GenerateMapPacket contains an enumerable representing a region. It
|
|
|
|
// is sent by the server to generate the map for the given region on
|
|
|
|
// a client.
|
2020-06-13 18:32:09 -04:00
|
|
|
type GenerateMapPacket struct {
|
2020-06-26 17:12:19 -04:00
|
|
|
RegionType d2enum.RegionIdType `json:"regionType"`
|
2020-06-13 18:32:09 -04:00
|
|
|
}
|
|
|
|
|
2020-06-29 17:01:26 -04:00
|
|
|
// CreateGenerateMapPacket returns a NetPacket which declares a
|
|
|
|
// GenerateMapPacket with the given regionType.
|
2020-11-23 08:18:30 -05:00
|
|
|
func CreateGenerateMapPacket(regionType d2enum.RegionIdType) (NetPacket, error) {
|
2020-08-09 20:32:47 -04:00
|
|
|
generateMapPacket := GenerateMapPacket{
|
|
|
|
RegionType: regionType,
|
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
b, err := json.Marshal(generateMapPacket)
|
|
|
|
if err != nil {
|
2020-11-23 08:18:30 -05:00
|
|
|
return NetPacket{PacketType: d2netpackettype.GenerateMap}, err
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-08-09 20:32:47 -04:00
|
|
|
|
2020-06-13 18:32:09 -04:00
|
|
|
return NetPacket{
|
|
|
|
PacketType: d2netpackettype.GenerateMap,
|
2020-08-09 20:32:47 -04:00
|
|
|
PacketData: b,
|
2020-11-23 08:18:30 -05:00
|
|
|
}, nil
|
2020-08-09 20:32:47 -04:00
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// UnmarshalGenerateMap unmarshals the given packet data into a GenerateMapPacket struct
|
2020-08-09 20:32:47 -04:00
|
|
|
func UnmarshalGenerateMap(packet []byte) (GenerateMapPacket, error) {
|
|
|
|
var p GenerateMapPacket
|
|
|
|
if err := json.Unmarshal(packet, &p); err != nil {
|
|
|
|
return p, err
|
2020-06-13 18:32:09 -04:00
|
|
|
}
|
2020-08-09 20:32:47 -04:00
|
|
|
|
|
|
|
return p, nil
|
2020-06-13 18:32:09 -04:00
|
|
|
}
|