Documentation ¶
Overview ¶
Package d2client provides client side connection, map and entity management.
GameClient declares the ServerConnection interface to interact with local and remote servers. LocalClientConnection is the host and creates the game server (see d2server).
Index ¶
- type GameClient
- func (g *GameClient) Close() error
- func (g *GameClient) Destroy() error
- func (g *GameClient) IsSinglePlayer() bool
- func (g *GameClient) OnPacketReceived(packet d2netpacket.NetPacket) error
- func (g *GameClient) Open(connectionString, saveFilePath string) error
- func (g *GameClient) SendPacketToServer(packet d2netpacket.NetPacket) error
- type ServerConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GameClient ¶
type GameClient struct { GameState *d2hero.HeroState // local player state MapEngine *d2mapengine.MapEngine // Map and entities PlayerID string // ID of the local player Players map[string]*d2mapentity.Player // IDs of the other players Seed int64 // Map seed RegenMap bool // Regenerate tile cache on render (map has changed) *d2util.Logger // contains filtered or unexported fields }
GameClient manages a connection to d2server.GameServer and keeps a synchronized copy of the map and entities.
func Create ¶
func Create(connectionType d2clientconnectiontype.ClientConnectionType, asset *d2asset.AssetManager, l d2util.LogLevel, scriptEngine *d2script.ScriptEngine) (*GameClient, error)
Create constructs a new GameClient and returns a pointer to it.
func (*GameClient) Close ¶
func (g *GameClient) Close() error
Close destroys the server if the client is local. For remote clients it sends a DisconnectRequestPacket (see d2netpacket).
func (*GameClient) Destroy ¶
func (g *GameClient) Destroy() error
Destroy does the same thing as Close.
func (*GameClient) IsSinglePlayer ¶
func (g *GameClient) IsSinglePlayer() bool
IsSinglePlayer returns a bool for whether the game is a single-player game
func (*GameClient) OnPacketReceived ¶
func (g *GameClient) OnPacketReceived(packet d2netpacket.NetPacket) error
OnPacketReceived is called by the ClientConection and processes incoming packets. nolint:gocyclo // switch statement on packet type makes sense, no need to change
func (*GameClient) Open ¶
func (g *GameClient) Open(connectionString, saveFilePath string) error
Open creates the server and connects to it if the client is local. If the client is remote it sends a PlayerConnectionRequestPacket to the server (see d2netpacket).
func (*GameClient) SendPacketToServer ¶
func (g *GameClient) SendPacketToServer(packet d2netpacket.NetPacket) error
SendPacketToServer calls server.OnPacketReceived if the client is local. If it is remote the NetPacket sent over a UDP connection to the server.
type ServerConnection ¶
type ServerConnection interface { Open(connectionString string, saveFilePath string) error Close() error SendPacketToServer(packet d2netpacket.NetPacket) error SetClientListener(listener d2networking.ClientListener) }
ServerConnection is an interface for abstracting local and remote server connections.
Directories ¶
Path | Synopsis |
---|---|
Package d2clientconnectiontype provides types for client connections
|
Package d2clientconnectiontype provides types for client connections |
Package d2localclient facilitates communication between a local client and server.
|
Package d2localclient facilitates communication between a local client and server. |
Package d2remoteclient facilitates communication between a remote client and server.
|
Package d2remoteclient facilitates communication between a remote client and server. |