diff --git a/d2networking/d2client/d2localclient/local_client_connection.go b/d2networking/d2client/d2localclient/local_client_connection.go index 3923d42b..7b521238 100644 --- a/d2networking/d2client/d2localclient/local_client_connection.go +++ b/d2networking/d2client/d2localclient/local_client_connection.go @@ -16,15 +16,14 @@ import ( // LocalClientConnection is the implementation of ClientConnection // for a local client. type LocalClientConnection struct { + clientListener d2networking.ClientListener asset *d2asset.AssetManager heroState *d2hero.HeroStateFactory - clientListener d2networking.ClientListener // The game client - uniqueID string // Unique ID generated on construction - openNetworkServer bool // True if this is a server - playerState *d2hero.HeroState // Local player state - gameServer *d2server.GameServer // Game Server - - logLevel d2util.LogLevel + playerState *d2hero.HeroState + gameServer *d2server.GameServer + uniqueID string + logLevel d2util.LogLevel + openNetworkServer bool } // GetUniqueID returns LocalClientConnection.uniqueID. diff --git a/d2networking/d2client/d2remoteclient/remote_client_connection.go b/d2networking/d2client/d2remoteclient/remote_client_connection.go index 57df11ef..d46813e6 100644 --- a/d2networking/d2client/d2remoteclient/remote_client_connection.go +++ b/d2networking/d2client/d2remoteclient/remote_client_connection.go @@ -23,14 +23,13 @@ const logPrefix = "Remote Client" // RemoteClientConnection is the implementation of ClientConnection // for a remote client. type RemoteClientConnection struct { + clientListener d2networking.ClientListener asset *d2asset.AssetManager heroState *d2hero.HeroStateFactory - clientListener d2networking.ClientListener // The GameClient - uniqueID string // Unique ID generated on construction - tcpConnection *net.TCPConn // UDP connection to the server - active bool // The connection is currently open - + tcpConnection *net.TCPConn *d2util.Logger + uniqueID string + active bool } // Create constructs a new RemoteClientConnection diff --git a/d2networking/d2client/game_client.go b/d2networking/d2client/game_client.go index 0737223d..6ca9fcd1 100644 --- a/d2networking/d2client/game_client.go +++ b/d2networking/d2client/game_client.go @@ -35,19 +35,18 @@ const ( // GameClient manages a connection to d2server.GameServer // and keeps a synchronized copy of the map and entities. type GameClient struct { - clientConnection ServerConnection // Abstract local/remote connection - connectionType d2clientconnectiontype.ClientConnectionType // Type of connection (local or remote) + clientConnection ServerConnection asset *d2asset.AssetManager scriptEngine *d2script.ScriptEngine - GameState *d2hero.HeroState // local player state - MapEngine *d2mapengine.MapEngine // Map and entities - mapGen *d2mapgen.MapGenerator // map generator - 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) - + GameState *d2hero.HeroState + MapEngine *d2mapengine.MapEngine + mapGen *d2mapgen.MapGenerator + Players map[string]*d2mapentity.Player *d2util.Logger + PlayerID string + connectionType d2clientconnectiontype.ClientConnectionType + Seed int64 + RegenMap bool } // Create constructs a new GameClient and returns a pointer to it. diff --git a/d2networking/d2netpacket/net_packet.go b/d2networking/d2netpacket/net_packet.go index 316e8a44..0f3bdc25 100644 --- a/d2networking/d2netpacket/net_packet.go +++ b/d2networking/d2netpacket/net_packet.go @@ -11,8 +11,8 @@ import ( // PacketData is unmarshalled to a struct of the type associated with // PacketType. type NetPacket struct { - PacketType d2netpackettype.NetPacketType `json:"packetType"` PacketData json.RawMessage `json:"packetData"` + PacketType d2netpackettype.NetPacketType `json:"packetType"` } // InspectPacketType determines the packet type from the given data diff --git a/d2networking/d2netpacket/packet_add_player.go b/d2networking/d2netpacket/packet_add_player.go index 795879a6..f8cf5ca3 100644 --- a/d2networking/d2netpacket/packet_add_player.go +++ b/d2networking/d2netpacket/packet_add_player.go @@ -13,14 +13,14 @@ import ( // It is sent by the server to create the entity for a newly connected // player on a client. type AddPlayerPacket struct { + Equipment d2inventory.CharacterEquipment `json:"equipment"` + Stats *d2hero.HeroStatsState `json:"heroStats"` + Skills map[int]*d2hero.HeroSkill `json:"heroSkills"` 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 diff --git a/d2networking/d2netpacket/packet_item_spawn.go b/d2networking/d2netpacket/packet_item_spawn.go index 1f16c0bb..14caf4f3 100644 --- a/d2networking/d2netpacket/packet_item_spawn.go +++ b/d2networking/d2netpacket/packet_item_spawn.go @@ -8,9 +8,9 @@ import ( // SpawnItemPacket contains the data required to create a Item entity type SpawnItemPacket struct { + Codes []string `json:"codes"` X int `json:"x"` Y int `json:"y"` - Codes []string `json:"codes"` } // CreateSpawnItemPacket returns a NetPacket which declares a diff --git a/d2networking/d2netpacket/packet_player_cast.go b/d2networking/d2netpacket/packet_player_cast.go index e0dfa3fb..0213460b 100644 --- a/d2networking/d2netpacket/packet_player_cast.go +++ b/d2networking/d2netpacket/packet_player_cast.go @@ -11,10 +11,10 @@ import ( // entity. type CastPacket struct { SourceEntityID string `json:"sourceEntityId"` + TargetEntityID string `json:"targetEntityId"` SkillID int `json:"skillId"` TargetX float64 `json:"targetX"` TargetY float64 `json:"targetY"` - TargetEntityID string `json:"targetEntityId"` } // CreateCastPacket returns a NetPacket which declares a CastPacket with the diff --git a/d2networking/d2netpacket/packet_player_connection_request.go b/d2networking/d2netpacket/packet_player_connection_request.go index 2617141d..986697fb 100644 --- a/d2networking/d2netpacket/packet_player_connection_request.go +++ b/d2networking/d2netpacket/packet_player_connection_request.go @@ -11,8 +11,8 @@ import ( // PlayerConnectionRequestPacket contains a player ID and game state. // It is sent by a remote client to initiate a connection (join a game). type PlayerConnectionRequestPacket struct { - ID string `json:"id"` PlayerState *d2hero.HeroState `json:"gameState"` + ID string `json:"id"` } // CreatePlayerConnectionRequestPacket returns a NetPacket which defines a diff --git a/d2networking/d2netpacket/packet_player_disconnect_request.go b/d2networking/d2netpacket/packet_player_disconnect_request.go index 456d4106..8683e43e 100644 --- a/d2networking/d2netpacket/packet_player_disconnect_request.go +++ b/d2networking/d2netpacket/packet_player_disconnect_request.go @@ -11,8 +11,8 @@ import ( // PlayerDisconnectRequestPacket contains a player ID and game state. // It is sent by a remote client to close the connection (leave a game). type PlayerDisconnectRequestPacket struct { - ID string `json:"id"` PlayerState *d2hero.HeroState `json:"gameState"` + ID string `json:"id"` } // CreatePlayerDisconnectRequestPacket returns a NetPacket which defines a diff --git a/d2networking/d2netpacket/packet_pong.go b/d2networking/d2netpacket/packet_pong.go index 7d98ac63..9fee500b 100644 --- a/d2networking/d2netpacket/packet_pong.go +++ b/d2networking/d2netpacket/packet_pong.go @@ -10,8 +10,8 @@ import ( // 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. type PongPacket struct { - ID string `json:"id"` TS time.Time `json:"ts"` + ID string `json:"id"` } // CreatePongPacket returns a NetPacket which declares a PongPacket with diff --git a/d2networking/d2netpacket/packet_update_server_info.go b/d2networking/d2netpacket/packet_update_server_info.go index 77c53e4a..683d3001 100644 --- a/d2networking/d2netpacket/packet_update_server_info.go +++ b/d2networking/d2netpacket/packet_update_server_info.go @@ -9,8 +9,8 @@ import ( // UpdateServerInfoPacket contains the ID for a player and the map seed. // It is sent by the server to synchronize these values on the client. type UpdateServerInfoPacket struct { - Seed int64 `json:"seed"` PlayerID string `json:"playerId"` + Seed int64 `json:"seed"` } // CreateUpdateServerInfoPacket returns a NetPacket which declares an diff --git a/d2networking/d2server/d2tcpclientconnection/tcp_client_connection.go b/d2networking/d2server/d2tcpclientconnection/tcp_client_connection.go index 7a457feb..eeb4efbc 100644 --- a/d2networking/d2server/d2tcpclientconnection/tcp_client_connection.go +++ b/d2networking/d2server/d2tcpclientconnection/tcp_client_connection.go @@ -13,9 +13,9 @@ import ( // TCPClientConnection represents a client connection over TCP type TCPClientConnection struct { - id string tcpConnection net.Conn playerState *d2hero.HeroState + id string } // CreateTCPClientConnection creates a new tcp client connection instance diff --git a/d2networking/d2server/d2udpclientconnection/udp_client_connection.go b/d2networking/d2server/d2udpclientconnection/udp_client_connection.go index 6dfa456f..a0ce0618 100644 --- a/d2networking/d2server/d2udpclientconnection/udp_client_connection.go +++ b/d2networking/d2server/d2udpclientconnection/udp_client_connection.go @@ -23,12 +23,11 @@ const logPrefix = "UDP Connection" // d2server.ClientConnection interface to represent remote client from the // server perspective. type UDPClientConnection struct { - id string // ID of the associated RemoteClientConnection - address *net.UDPAddr // IP address of the associated RemoteClientConnection - udpConnection *net.UDPConn // Server's UDP Connection - playerState *d2hero.HeroState // Client's game state - + address *net.UDPAddr + udpConnection *net.UDPConn + playerState *d2hero.HeroState *d2util.Logger + id string } // CreateUDPClientConnection constructs a new UDPClientConnection and diff --git a/d2networking/d2server/game_server.go b/d2networking/d2server/game_server.go index 8e349281..eb90a241 100644 --- a/d2networking/d2server/game_server.go +++ b/d2networking/d2server/game_server.go @@ -41,21 +41,20 @@ var ( // 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. type GameServer struct { - sync.RWMutex - connections map[string]ClientConnection listener net.Listener - networkServer bool ctx context.Context + packetManagerChan chan ReceivedPacket + connections map[string]ClientConnection + heroStateFactory *d2hero.HeroStateFactory cancel context.CancelFunc asset *d2asset.AssetManager - mapEngines []*d2mapengine.MapEngine - scriptEngine *d2script.ScriptEngine - seed int64 - maxConnections int - packetManagerChan chan ReceivedPacket - heroStateFactory *d2hero.HeroStateFactory - *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.