Documentation ¶
Overview ¶
Package d2server provides connection management and client synchronization.
Data is encoded to JSON and compressed using gzip. Transport is over UDP. The server is authoritative for both local and remote clients.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientConnection ¶
type ClientConnection interface { GetUniqueID() string GetConnectionType() d2clientconnectiontype.ClientConnectionType SendPacketToClient(packet d2netpacket.NetPacket) error GetPlayerState() *d2hero.HeroState SetPlayerState(playerState *d2hero.HeroState) }
ClientConnection is an interface for abstracting local and remote clients.
type GameServer ¶
GameServer manages a copy of the map and entities as well as manages packet routing and connections. It can accept connections from localhost as well remote clients. It can also be started in a standalone mode.
func NewGameServer ¶
func NewGameServer(asset *d2asset.AssetManager, networkServer bool, l d2util.LogLevel, maxConnections ...int) (*GameServer, error)
NewGameServer builds a new GameServer that can be started
ctx: required context item networkServer: true = 0.0.0.0 | false = 127.0.0.1 maxConnections (default: 8): maximum number of TCP connections allowed open
func (*GameServer) OnClientConnected ¶
func (g *GameServer) OnClientConnected(client ClientConnection)
OnClientConnected initializes the given ClientConnection. It sends the following packets to the newly connected client: UpdateServerInfoPacket, GenerateMapPacket, AddPlayerPacket.
It also sends AddPlayerPackets for each other player entity to the new player and vice versa, so all player entities exist on all clients.
For more information, see d2networking.d2netpacket.
func (*GameServer) OnClientDisconnected ¶
func (g *GameServer) OnClientDisconnected(client ClientConnection)
OnClientDisconnected removes the given client from the list of client connections. If this client was the host, disconnects all clients and kills GameServer.
func (*GameServer) OnPacketReceived ¶
func (g *GameServer) OnPacketReceived(client ClientConnection, packet d2netpacket.NetPacket) error
OnPacketReceived is called when a packet has been received from a remote client, and by the local client to 'send' a packet to the server, nolint:gocyclo // switch statement on packet type makes sense, no need to change
func (*GameServer) Start ¶
func (g *GameServer) Start() error
Start essentially starts all of the game server go routines as well as begins listening for connection. This will return an error if it is unable to bind to a socket.
type ReceivedPacket ¶
type ReceivedPacket struct { Client ClientConnection Packet d2netpacket.NetPacket }
ReceivedPacket encapsulates the data necessary for the packet manager goroutine to process data from clients. The packet manager needs to know who sent the data, in addition to the data itself.
Directories ¶
Path | Synopsis |
---|---|
Package d2tcpclientconnection provides a TCP protocol implementation of a client connection
|
Package d2tcpclientconnection provides a TCP protocol implementation of a client connection |
Package d2udpclientconnection provides an implementation of a UDP client connection with a game state.
|
Package d2udpclientconnection provides an implementation of a UDP client connection with a game state. |