1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-02 22:57:04 -05:00

d2networking: fix all fieldalignments

This commit is contained in:
gucio321 2021-06-13 17:52:16 +02:00
parent cbfd8efce8
commit 9c87bd775e
14 changed files with 43 additions and 48 deletions

View File

@ -16,15 +16,14 @@ import (
// LocalClientConnection is the implementation of ClientConnection // LocalClientConnection is the implementation of ClientConnection
// for a local client. // for a local client.
type LocalClientConnection struct { type LocalClientConnection struct {
clientListener d2networking.ClientListener
asset *d2asset.AssetManager asset *d2asset.AssetManager
heroState *d2hero.HeroStateFactory heroState *d2hero.HeroStateFactory
clientListener d2networking.ClientListener // The game client playerState *d2hero.HeroState
uniqueID string // Unique ID generated on construction gameServer *d2server.GameServer
openNetworkServer bool // True if this is a server uniqueID string
playerState *d2hero.HeroState // Local player state logLevel d2util.LogLevel
gameServer *d2server.GameServer // Game Server openNetworkServer bool
logLevel d2util.LogLevel
} }
// GetUniqueID returns LocalClientConnection.uniqueID. // GetUniqueID returns LocalClientConnection.uniqueID.

View File

@ -23,14 +23,13 @@ const logPrefix = "Remote Client"
// RemoteClientConnection is the implementation of ClientConnection // RemoteClientConnection is the implementation of ClientConnection
// for a remote client. // for a remote client.
type RemoteClientConnection struct { type RemoteClientConnection struct {
clientListener d2networking.ClientListener
asset *d2asset.AssetManager asset *d2asset.AssetManager
heroState *d2hero.HeroStateFactory heroState *d2hero.HeroStateFactory
clientListener d2networking.ClientListener // The GameClient tcpConnection *net.TCPConn
uniqueID string // Unique ID generated on construction
tcpConnection *net.TCPConn // UDP connection to the server
active bool // The connection is currently open
*d2util.Logger *d2util.Logger
uniqueID string
active bool
} }
// Create constructs a new RemoteClientConnection // Create constructs a new RemoteClientConnection

View File

@ -35,19 +35,18 @@ const (
// GameClient manages a connection to d2server.GameServer // GameClient manages a connection to d2server.GameServer
// and keeps a synchronized copy of the map and entities. // and keeps a synchronized copy of the map and entities.
type GameClient struct { type GameClient struct {
clientConnection ServerConnection // Abstract local/remote connection clientConnection ServerConnection
connectionType d2clientconnectiontype.ClientConnectionType // Type of connection (local or remote)
asset *d2asset.AssetManager asset *d2asset.AssetManager
scriptEngine *d2script.ScriptEngine scriptEngine *d2script.ScriptEngine
GameState *d2hero.HeroState // local player state GameState *d2hero.HeroState
MapEngine *d2mapengine.MapEngine // Map and entities MapEngine *d2mapengine.MapEngine
mapGen *d2mapgen.MapGenerator // map generator mapGen *d2mapgen.MapGenerator
PlayerID string // ID of the local player Players map[string]*d2mapentity.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 *d2util.Logger
PlayerID string
connectionType d2clientconnectiontype.ClientConnectionType
Seed int64
RegenMap bool
} }
// Create constructs a new GameClient and returns a pointer to it. // Create constructs a new GameClient and returns a pointer to it.

View File

@ -11,8 +11,8 @@ import (
// PacketData is unmarshalled to a struct of the type associated with // PacketData is unmarshalled to a struct of the type associated with
// PacketType. // PacketType.
type NetPacket struct { type NetPacket struct {
PacketType d2netpackettype.NetPacketType `json:"packetType"`
PacketData json.RawMessage `json:"packetData"` PacketData json.RawMessage `json:"packetData"`
PacketType d2netpackettype.NetPacketType `json:"packetType"`
} }
// InspectPacketType determines the packet type from the given data // InspectPacketType determines the packet type from the given data

View File

@ -13,14 +13,14 @@ import (
// It is sent by the server to create the entity for a newly connected // It is sent by the server to create the entity for a newly connected
// player on a client. // player on a client.
type AddPlayerPacket struct { type AddPlayerPacket struct {
Equipment d2inventory.CharacterEquipment `json:"equipment"`
Stats *d2hero.HeroStatsState `json:"heroStats"`
Skills map[int]*d2hero.HeroSkill `json:"heroSkills"`
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
X int `json:"x"` X int `json:"x"`
Y int `json:"y"` Y int `json:"y"`
HeroType d2enum.Hero `json:"hero"` 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"` LeftSkill int `json:"leftSkill"`
RightSkill int `json:"rightSkill"` RightSkill int `json:"rightSkill"`
Gold int Gold int

View File

@ -8,9 +8,9 @@ import (
// SpawnItemPacket contains the data required to create a Item entity // SpawnItemPacket contains the data required to create a Item entity
type SpawnItemPacket struct { type SpawnItemPacket struct {
Codes []string `json:"codes"`
X int `json:"x"` X int `json:"x"`
Y int `json:"y"` Y int `json:"y"`
Codes []string `json:"codes"`
} }
// CreateSpawnItemPacket returns a NetPacket which declares a // CreateSpawnItemPacket returns a NetPacket which declares a

View File

@ -11,10 +11,10 @@ import (
// entity. // entity.
type CastPacket struct { type CastPacket struct {
SourceEntityID string `json:"sourceEntityId"` SourceEntityID string `json:"sourceEntityId"`
TargetEntityID string `json:"targetEntityId"`
SkillID int `json:"skillId"` SkillID int `json:"skillId"`
TargetX float64 `json:"targetX"` TargetX float64 `json:"targetX"`
TargetY float64 `json:"targetY"` TargetY float64 `json:"targetY"`
TargetEntityID string `json:"targetEntityId"`
} }
// CreateCastPacket returns a NetPacket which declares a CastPacket with the // CreateCastPacket returns a NetPacket which declares a CastPacket with the

View File

@ -11,8 +11,8 @@ import (
// PlayerConnectionRequestPacket contains a player ID and game state. // PlayerConnectionRequestPacket contains a player ID and game state.
// It is sent by a remote client to initiate a connection (join a game). // It is sent by a remote client to initiate a connection (join a game).
type PlayerConnectionRequestPacket struct { type PlayerConnectionRequestPacket struct {
ID string `json:"id"`
PlayerState *d2hero.HeroState `json:"gameState"` PlayerState *d2hero.HeroState `json:"gameState"`
ID string `json:"id"`
} }
// CreatePlayerConnectionRequestPacket returns a NetPacket which defines a // CreatePlayerConnectionRequestPacket returns a NetPacket which defines a

View File

@ -11,8 +11,8 @@ import (
// PlayerDisconnectRequestPacket contains a player ID and game state. // PlayerDisconnectRequestPacket contains a player ID and game state.
// It is sent by a remote client to close the connection (leave a game). // It is sent by a remote client to close the connection (leave a game).
type PlayerDisconnectRequestPacket struct { type PlayerDisconnectRequestPacket struct {
ID string `json:"id"`
PlayerState *d2hero.HeroState `json:"gameState"` PlayerState *d2hero.HeroState `json:"gameState"`
ID string `json:"id"`
} }
// CreatePlayerDisconnectRequestPacket returns a NetPacket which defines a // CreatePlayerDisconnectRequestPacket returns a NetPacket which defines a

View File

@ -10,8 +10,8 @@ import (
// PongPacket contains the time at which it was sent and the ID of the // 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. // client. It is sent by the client in response to a Pong packet.
type PongPacket struct { type PongPacket struct {
ID string `json:"id"`
TS time.Time `json:"ts"` TS time.Time `json:"ts"`
ID string `json:"id"`
} }
// CreatePongPacket returns a NetPacket which declares a PongPacket with // CreatePongPacket returns a NetPacket which declares a PongPacket with

View File

@ -9,8 +9,8 @@ import (
// UpdateServerInfoPacket contains the ID for a player and the map seed. // UpdateServerInfoPacket contains the ID for a player and the map seed.
// It is sent by the server to synchronize these values on the client. // It is sent by the server to synchronize these values on the client.
type UpdateServerInfoPacket struct { type UpdateServerInfoPacket struct {
Seed int64 `json:"seed"`
PlayerID string `json:"playerId"` PlayerID string `json:"playerId"`
Seed int64 `json:"seed"`
} }
// CreateUpdateServerInfoPacket returns a NetPacket which declares an // CreateUpdateServerInfoPacket returns a NetPacket which declares an

View File

@ -13,9 +13,9 @@ import (
// TCPClientConnection represents a client connection over TCP // TCPClientConnection represents a client connection over TCP
type TCPClientConnection struct { type TCPClientConnection struct {
id string
tcpConnection net.Conn tcpConnection net.Conn
playerState *d2hero.HeroState playerState *d2hero.HeroState
id string
} }
// CreateTCPClientConnection creates a new tcp client connection instance // CreateTCPClientConnection creates a new tcp client connection instance

View File

@ -23,12 +23,11 @@ const logPrefix = "UDP Connection"
// d2server.ClientConnection interface to represent remote client from the // d2server.ClientConnection interface to represent remote client from the
// server perspective. // server perspective.
type UDPClientConnection struct { type UDPClientConnection struct {
id string // ID of the associated RemoteClientConnection address *net.UDPAddr
address *net.UDPAddr // IP address of the associated RemoteClientConnection udpConnection *net.UDPConn
udpConnection *net.UDPConn // Server's UDP Connection playerState *d2hero.HeroState
playerState *d2hero.HeroState // Client's game state
*d2util.Logger *d2util.Logger
id string
} }
// CreateUDPClientConnection constructs a new UDPClientConnection and // CreateUDPClientConnection constructs a new UDPClientConnection and

View File

@ -41,21 +41,20 @@ var (
// GameServer manages a copy of the map and entities as well as manages packet routing and connections. // 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. // It can accept connections from localhost as well remote clients. It can also be started in a standalone mode.
type GameServer struct { type GameServer struct {
sync.RWMutex
connections map[string]ClientConnection
listener net.Listener listener net.Listener
networkServer bool
ctx context.Context ctx context.Context
packetManagerChan chan ReceivedPacket
connections map[string]ClientConnection
heroStateFactory *d2hero.HeroStateFactory
cancel context.CancelFunc cancel context.CancelFunc
asset *d2asset.AssetManager asset *d2asset.AssetManager
mapEngines []*d2mapengine.MapEngine
scriptEngine *d2script.ScriptEngine
seed int64
maxConnections int
packetManagerChan chan ReceivedPacket
heroStateFactory *d2hero.HeroStateFactory
*d2util.Logger *d2util.Logger
scriptEngine *d2script.ScriptEngine
mapEngines []*d2mapengine.MapEngine
maxConnections int
seed int64
sync.RWMutex
networkServer bool
} }
// ReceivedPacket encapsulates the data necessary for the packet manager goroutine to process data from clients. // ReceivedPacket encapsulates the data necessary for the packet manager goroutine to process data from clients.