d2client

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: 19 Imported by: 0

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

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

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.

Jump to

Keyboard shortcuts

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