Crossfire Server, Branch 1.12  R12190
Login, player creation

The core connection structure is socket_struct.

The init_sockets array, length contained in ::socket_info.allocated_sockets, contains at indice 0 the listening socket for the server, initialized through init_server(). This socket is always in use.

When a client connects, a socket from init_sockets is reused or reallocated in do_server(). During the first connection phase, the client can issue any command in the client_commands array - mostly, commands to negociate the connection, request faces and various game-related information -, 'add_me' and 'reply' commands, processed by add_me_cmd() and reply_cmd() respectively.

When the client sends the 'add_me' command (handled through add_me_cmd()), the socket is copied from the init_sockets array to the player.socket field, in add_player(), and the socket in init_sockets is marked as reusable.

The function add_player() is responsible from initializing the player structure, and putting the player in the first map.

The player then enters the ST_GET_NAME mode (as defined in player.state field), to get the name, then password and such.

The main socket handling function is do_server(), which is responsible for reading data from sockets, both init_sockets and players's, and also accepting new connections. It will also close connection to dropped clients, and check for banned hosts trying to connect.

The life-cycle of a connection is thus:

The main player creation routine is reply_cmd(), one of the few the player can issue while not playing. Creation cycle is:

Function responsibilities: