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.
Returns:
0 if the new connection could not be established, otherwise nonzero.
Parameters:
session |
Name of the session
(STRING* or char*). |
hostname |
Domain or IP Address
(STRING* or char*)
, or NULL for a session on
the same machine. |
Edition
A8 C
Speed:
Very slow (up to
5 seconds)
Remarks:
- 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
after connection.
-
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.
Example:
if (session_connect("office","127.0.0.1"))
{
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
}
See also:
session_open, session_close, connection, dplay_status,
ftp, http
► latest
version online