2020-06-23 00:31:42 +00:00
|
|
|
package d2netpacket
|
|
|
|
|
|
|
|
import (
|
2020-08-10 00:32:47 +00:00
|
|
|
"encoding/json"
|
2020-09-23 17:30:54 +00:00
|
|
|
"log"
|
2020-06-23 00:31:42 +00:00
|
|
|
"time"
|
2020-06-29 21:01:26 +00:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
2020-06-23 00:31:42 +00:00
|
|
|
)
|
|
|
|
|
2020-06-29 21:01:26 +00:00
|
|
|
// PingPacket contains the time at which it was sent. It is sent by the
|
|
|
|
// server and instructs the client to respond with a Pong packet.
|
2020-06-23 00:31:42 +00:00
|
|
|
type PingPacket struct {
|
|
|
|
TS time.Time `json:"ts"`
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:01:26 +00:00
|
|
|
// CreatePingPacket returns a NetPacket which declares a GenerateMapPacket
|
|
|
|
// with the the current time.
|
2020-06-23 00:31:42 +00:00
|
|
|
func CreatePingPacket() NetPacket {
|
2020-08-10 00:32:47 +00:00
|
|
|
ping := PingPacket{
|
|
|
|
TS: time.Now(),
|
|
|
|
}
|
2020-10-22 05:12:06 +00:00
|
|
|
|
2020-09-23 17:30:54 +00:00
|
|
|
b, err := json.Marshal(ping)
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
2020-08-10 00:32:47 +00:00
|
|
|
|
2020-06-23 00:31:42 +00:00
|
|
|
return NetPacket{
|
|
|
|
PacketType: d2netpackettype.Ping,
|
2020-08-10 00:32:47 +00:00
|
|
|
PacketData: b,
|
2020-06-23 00:31:42 +00:00
|
|
|
}
|
|
|
|
}
|