d2netpacket

package
v0.0.0-...-7f92c57 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2021 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package d2netpacket provides all of the different types of packets

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InspectPacketType

func InspectPacketType(b []byte) (d2netpackettype.NetPacketType, error)

InspectPacketType determines the packet type from the given data

func MarshalPacket

func MarshalPacket(packet interface{}) ([]byte, error)

MarshalPacket is a quick helper function to Marshal very anything UNSAFELY, meaning the error is not checked before sending.

Types

type AddPlayerPacket

type AddPlayerPacket struct {
	ID         string                         `json:"id"`
	Name       string                         `json:"name"`
	X          int                            `json:"x"`
	Y          int                            `json:"y"`
	HeroType   d2enum.Hero                    `json:"hero"`
	Equipment  d2inventory.CharacterEquipment `json:"equipment"`
	Stats      *d2hero.HeroStatsState         `json:"heroStats"`
	Skills     map[int]*d2hero.HeroSkill      `json:"heroSkills"`
	LeftSkill  int                            `json:"leftSkill"`
	RightSkill int                            `json:"rightSkill"`
	Gold       int
}

AddPlayerPacket contains the data required to create a Player entity. It is sent by the server to create the entity for a newly connected player on a client.

func UnmarshalAddPlayer

func UnmarshalAddPlayer(packet []byte) (AddPlayerPacket, error)

UnmarshalAddPlayer unmarshals the packet data into an AddPlayerPacket struct

type CastPacket

type CastPacket struct {
	SourceEntityID string  `json:"sourceEntityId"`
	SkillID        int     `json:"skillId"`
	TargetX        float64 `json:"targetX"`
	TargetY        float64 `json:"targetY"`
	TargetEntityID string  `json:"targetEntityId"`
}

CastPacket contains a cast command for an entity. It is sent by the server and instructs the client to trigger the use of the given skill on the given entity.

func UnmarshalCast

func UnmarshalCast(packet []byte) (CastPacket, error)

UnmarshalCast unmarshals the given data to a CastPacket struct

type GenerateMapPacket

type GenerateMapPacket struct {
	RegionType d2enum.RegionIdType `json:"regionType"`
}

GenerateMapPacket contains an enumerable representing a region. It is sent by the server to generate the map for the given region on a client.

func UnmarshalGenerateMap

func UnmarshalGenerateMap(packet []byte) (GenerateMapPacket, error)

UnmarshalGenerateMap unmarshals the given packet data into a GenerateMapPacket struct

type MovePlayerPacket

type MovePlayerPacket struct {
	PlayerID string  `json:"playerId"`
	StartX   float64 `json:"startX"`
	StartY   float64 `json:"startY"`
	DestX    float64 `json:"destX"`
	DestY    float64 `json:"destY"`
}

MovePlayerPacket contains a movement command for a specific player entity. It is sent by the server to move a player entity on a client. https://github.com/OpenDiablo2/OpenDiablo2/issues/825

func UnmarshalMovePlayer

func UnmarshalMovePlayer(packet []byte) (MovePlayerPacket, error)

UnmarshalMovePlayer unmarshals the given data to a MovePlayerPacket struct

type NetPacket

type NetPacket struct {
	PacketType d2netpackettype.NetPacketType `json:"packetType"`
	PacketData json.RawMessage               `json:"packetData"`
}

NetPacket is used to wrap and send all packet types under d2netpacket. When decoding a packet: First the PacketType byte is read, then the PacketData is unmarshalled to a struct of the type associated with PacketType.

func CreateAddPlayerPacket

func CreateAddPlayerPacket(
	id, name string,
	x, y int,
	heroType d2enum.Hero,
	stats *d2hero.HeroStatsState,
	skills map[int]*d2hero.HeroSkill,
	equipment d2inventory.CharacterEquipment,
	leftSkill, rightSkill, gold int) (NetPacket, error)

CreateAddPlayerPacket returns a NetPacket which declares an AddPlayerPacket with the data in given parameters.

func CreateCastPacket

func CreateCastPacket(entityID string, skillID int, targetX, targetY float64) (NetPacket, error)

CreateCastPacket returns a NetPacket which declares a CastPacket with the given skill command.

func CreateGenerateMapPacket

func CreateGenerateMapPacket(regionType d2enum.RegionIdType) (NetPacket, error)

CreateGenerateMapPacket returns a NetPacket which declares a GenerateMapPacket with the given regionType.

func CreateMovePlayerPacket

func CreateMovePlayerPacket(playerID string, startX, startY, destX, destY float64) (NetPacket, error)

CreateMovePlayerPacket returns a NetPacket which declares a MovePlayerPacket with the given ID and movement command.

func CreatePingPacket

func CreatePingPacket() (NetPacket, error)

CreatePingPacket returns a NetPacket which declares a GenerateMapPacket with the the current time.

func CreatePlayerConnectionRequestPacket

func CreatePlayerConnectionRequestPacket(id string, playerState *d2hero.HeroState) (NetPacket, error)

CreatePlayerConnectionRequestPacket returns a NetPacket which defines a PlayerConnectionRequestPacket with the given ID and game state.

func CreatePlayerDisconnectRequestPacket

func CreatePlayerDisconnectRequestPacket(id string) (NetPacket, error)

CreatePlayerDisconnectRequestPacket returns a NetPacket which defines a PlayerDisconnectRequestPacket with the given ID.

func CreatePongPacket

func CreatePongPacket(id string) (NetPacket, error)

CreatePongPacket returns a NetPacket which declares a PongPacket with the current time and given ID.

func CreateSavePlayerPacket

func CreateSavePlayerPacket(playerState *d2mapentity.Player, difficulty d2enum.DifficultyType) (NetPacket, error)

CreateSavePlayerPacket sends a packet which instructs the server to save the Player

func CreateServerClosedPacket

func CreateServerClosedPacket() (NetPacket, error)

CreateServerClosedPacket returns a NetPacket which declares a ServerClosedPacket with the current time.

func CreateServerFullPacket

func CreateServerFullPacket() (NetPacket, error)

CreateServerFullPacket returns a NetPacket which declares a ServerFullPacket.

func CreateSpawnItemPacket

func CreateSpawnItemPacket(x, y int, codes ...string) (NetPacket, error)

CreateSpawnItemPacket returns a NetPacket which declares a SpawnItemPacket with the data in given parameters.

func CreateUpdateServerInfoPacket

func CreateUpdateServerInfoPacket(seed int64, playerID string) (NetPacket, error)

CreateUpdateServerInfoPacket returns a NetPacket which declares an UpdateServerInfoPacket with the given player ID and map seed.

func UnmarshalNetPacket

func UnmarshalNetPacket(packet []byte) (NetPacket, error)

UnmarshalNetPacket unmarshals the byte slice into a NetPacket struct

type PingPacket

type PingPacket struct {
	TS time.Time `json:"ts"`
}

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.

func UnmarshalPing

func UnmarshalPing(packet []byte) (PingPacket, error)

UnmarshalPing unmarshals the given data to a PingPacket struct

type PlayerConnectionRequestPacket

type PlayerConnectionRequestPacket struct {
	ID          string            `json:"id"`
	PlayerState *d2hero.HeroState `json:"gameState"`
}

PlayerConnectionRequestPacket contains a player ID and game state. It is sent by a remote client to initiate a connection (join a game).

func UnmarshalPlayerConnectionRequest

func UnmarshalPlayerConnectionRequest(packet []byte) (PlayerConnectionRequestPacket, error)

UnmarshalPlayerConnectionRequest unmarshals the given data to a PlayerConnectionRequestPacket struct

type PlayerDisconnectRequestPacket

type PlayerDisconnectRequestPacket struct {
	ID          string            `json:"id"`
	PlayerState *d2hero.HeroState `json:"gameState"`
}

PlayerDisconnectRequestPacket contains a player ID and game state. It is sent by a remote client to close the connection (leave a game).

func UnmarshalPlayerDisconnectionRequest

func UnmarshalPlayerDisconnectionRequest(packet []byte) (PlayerDisconnectRequestPacket, error)

UnmarshalPlayerDisconnectionRequest unmarshals the given data to a PlayerDisconnectRequestPacket struct

type PongPacket

type PongPacket struct {
	ID string    `json:"id"`
	TS time.Time `json:"ts"`
}

PongPacket contains the time at which it was sent and the ID of the client. It is sent by the client in response to a Pong packet.

func UnmarshalPong

func UnmarshalPong(packet []byte) (PongPacket, error)

UnmarshalPong unmarshals the given data to a PongPacket struct

type SavePlayerPacket

type SavePlayerPacket struct {
	Player     *d2mapentity.Player   `json:"Player"`
	Difficulty d2enum.DifficultyType `json:"Difficulty"`
}

SavePlayerPacket has the actual selected left and right skill the Server has to check if these skills are actually allowed for the Player

func UnmarshalSavePlayer

func UnmarshalSavePlayer(packet []byte) (SavePlayerPacket, error)

UnmarshalSavePlayer unmarshalls the given data to a SavePlayerPacket struct

type ServerClosedPacket

type ServerClosedPacket struct {
	TS time.Time `json:"ts"`
}

ServerClosedPacket contains the current time. It is sent by the server to inform a client that the server has shut down.

func UnmarshalServerClosed

func UnmarshalServerClosed(packet []byte) (ServerClosedPacket, error)

UnmarshalServerClosed unmarshals the given data to a ServerClosedPacket struct

type ServerFullPacket

type ServerFullPacket struct{}

ServerFullPacket is sent by the server to inform a client that the server has reached the max number of allowed connections.

func UnmarshalServerFull

func UnmarshalServerFull(packet []byte) (ServerFullPacket, error)

UnmarshalServerFull unmarshalls the given data to a ServerFullPacket struct

type SpawnItemPacket

type SpawnItemPacket struct {
	X     int      `json:"x"`
	Y     int      `json:"y"`
	Codes []string `json:"codes"`
}

SpawnItemPacket contains the data required to create a Item entity

func UnmarshalSpawnItem

func UnmarshalSpawnItem(packet []byte) (SpawnItemPacket, error)

UnmarshalSpawnItem unmarshals the given data to a SpawnItemPacket struct

type UpdateServerInfoPacket

type UpdateServerInfoPacket struct {
	Seed     int64  `json:"seed"`
	PlayerID string `json:"playerId"`
}

UpdateServerInfoPacket contains the ID for a player and the map seed. It is sent by the server to synchronize these values on the client.

func UnmarshalUpdateServerInfo

func UnmarshalUpdateServerInfo(packet []byte) (UpdateServerInfoPacket, error)

UnmarshalUpdateServerInfo unmarshals the data to a UpdateServerInfoPacket struct

Directories

Path Synopsis
Package d2netpackettype defines types which are encoded to JSON and sent in network packet payloads.
Package d2netpackettype defines types which are encoded to JSON and sent in network packet payloads.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL