session_connect(STRING* session,STRING* hostname)
Connects a client to a running multiplayer session.
The first parameter
contains the name of the session, the second parameter gives the name, domain
or IP address of the server. This way, level or zone changing in a multiplayer
environment can easily be performed.
0 if the new connection could not be established, otherwise nonzero.
||Name of the session
(STRING* or char*).
||Domain or IP Address
(STRING* or char*)
, or NULL for a session on
the same machine.
Very slow (up to
- This function can be used to switch the engine to client mode even if it wasn't
started with the -cl command line option. After switching from
single player mode
to client mode the first time with a loaded level, the level must be loaded anew.
After successfully joining a session, dplay_id is set to the unique identification number of the client.
All client dependent functions or initializations must run after connecting
to a session. For instance, creating a client player in the main function
won't work when the engine was not in client mode when running main().
A good place for creating the client player is after reloading the level
Use dplay_status for determining when the session is connected and the level is up to date.
Use dplay_port for switching to a different server that uses a different port address.
Connection to a server will fail when the IP or port number is wrong, when the session name does not match, when dplay_encrypt has a different value on the server, or when the client script is different to the server script in a protected session. When the connection fails, the on_client event is triggered with EVENT_LEAVE.
level_load("office.wmb"); // load level anew
while (dplay_status < 6) wait(1); // wait until the level state is received from the server
player_create(); // user function to place the player into the level
session_open, session_close, connection, dplay_status,