mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-03 15:17:04 -05:00
2254e4b2a6
* Networking refactor * Networking refactor * Networking refactor * Networking refactor * Refactor netpacket for json.Rawmessages as the data type and client side JSON decoder. * Move game server connection handler to json decoder. * Move game server connection handler to json decoder.
38 lines
1019 B
Go
38 lines
1019 B
Go
package d2netpacket
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2netpacket/d2netpackettype"
|
|
)
|
|
|
|
// UpdateServerInfoPacket contains the ID for a player and the map seed.
|
|
// It is sent by the server to synchronize these values on the client.
|
|
type UpdateServerInfoPacket struct {
|
|
Seed int64 `json:"seed"`
|
|
PlayerID string `json:"playerId"`
|
|
}
|
|
|
|
// CreateUpdateServerInfoPacket returns a NetPacket which declares an
|
|
// UpdateServerInfoPacket with the given player ID and map seed.
|
|
func CreateUpdateServerInfoPacket(seed int64, playerID string) NetPacket {
|
|
updateServerInfo := UpdateServerInfoPacket{
|
|
Seed: seed,
|
|
PlayerID: playerID,
|
|
}
|
|
b, _ := json.Marshal(updateServerInfo)
|
|
|
|
return NetPacket{
|
|
PacketType: d2netpackettype.UpdateServerInfo,
|
|
PacketData: b,
|
|
}
|
|
}
|
|
|
|
func UnmarshalUpdateServerInfo(packet []byte) (UpdateServerInfoPacket, error) {
|
|
var resp UpdateServerInfoPacket
|
|
|
|
if err := json.Unmarshal(packet, &resp); err != nil {
|
|
return resp, err
|
|
}
|
|
return resp, nil
|
|
}
|