Skip to content

Client–Server_Initialization

Andrew McWatters edited this page Jun 26, 2019 · 17 revisions

Client–Server Initialization

HC SVNT DRACONES

This article outlines engine-level behavior. The following information is best suited for engine modders rather than game developers.

Client–Server initialization occurs in one or two Lua states depending on whether or not initialization takes place in a listen server context or in a dedicated server context, respectively.

Connecting to Listen Servers

Since Grid was written for Vertex Adventure, an MMORPG, and no server browser exists yet, connecting to a listen server is typically only done for debugging purposes by using the map console command.

engine.shared.map

concommand( "map", "Loads the specified map",
	function( _, _, _, _, argT )
		-- ...

		engine.connectToListenServer()
	end
)

Connecting to Dedicated Servers

In Grid, the engine connects to the server from the main menu.

game.client.gui.mainmenu

if ( not engine.isConnected() ) then
	if ( _DEBUG ) then
		engine.connect( "localhost" )
	end
else
	engine.disconnect()
end

Establishing a Connection

After making a call to either engine.connect() or engine.connectToListenServer(), Grid loads engine.client.network which then allows network.connect() or network.connectToListenServer() to be called.

Depending on which method is called, the engine will either use lua-enet to connect to the server or emulate the network procedures in-memory.

Stack Trace with console output

  1. Connect to server in:
  • Client game.client.gui.mainmenu or
  • Client engine.shared.map
  1. Client engine.connect() or engine.connectToListenServer()
  • Connecting to address:port...

  1. Server engine.onConnect()
  • peer has connected.

  1. Client engine.onConnect()
  • Connected to the server!

  1. Server engine.onPostConnect()
  2. Server engine.sendServerInfo()
  • Client
    • Received payload "serverInfo"

  1. Client engine.sendClientInfo()
  • Server
    • Received payload "clientInfo" from peer

  1. Shared player:initialSpawn()
Clone this wiki locally