Skip to content

Client–Server_Initialization

Andrew McWatters edited this page Oct 22, 2016 · 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 two or one Lua states depending on whether or not initialization takes place in a dedicated server context or in a listen server context, respectively.

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

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 region console command.

engine.shared.region

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

		engine.connectToListenServer()
	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.region
  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