API_DOCS: Non Player Connection Handling

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5193
Joined: Fri Dec 13, 2002 4:11 am
Location: https://github.com/OmniTanks
Contact:

API_DOCS: Non Player Connection Handling

Post by JeffM » Thu Apr 05, 2007 7:39 am

For 2.1.x we now have an interface to allow a plug-in to hook into network connections that are not from BZFLAG clients. This can allow the game server to also be a server for other protocols, such as HTTP.

a new event

Code: Select all

bz_eNewNonPlayerConnection
will be called each time a network connection is opened by a non bzflag client ( any time we get a connection that dosn't start with the BZFLAG connection string ).

The data for this event will have a connection ID, and the data that was sent.

If a plug-in wishes to service this connection it can then call the function

Code: Select all

BZF_API bool bz_registerNonPlayerConnectionHandler ( int connectionID, bz_NonPlayerConnectionHandler* handler );
With the connection ID, and a derived handler. This handler has 2 methods.

Code: Select all

	virtual void pending ( int connectionID, void *data, unsigned int size ); 
	virtual void disconnect( int connectionID ); 
the pending method is called any time new data is received by the connection. the disconnect method is called when the connection is closed.

the plug-in can send data to the connection by calling

Code: Select all

BZF_API bool bz_sendNonPlayerData ( int connectionID, const void *data, unsigned int size );
With the connection ID and some data.

When the plug-in is done with a connection it can remove itself as a handler by calling

Code: Select all

BZF_API bool bz_removeNonPlayerConnectionHandler ( int connectionID, bz_NonPlayerConnectionHandler* handler );
This will remove the handler from the connection. When a connection has no handlers, it is closed and deleted.

This goes along with the changes to the bzflag connection protocol to make the client start the handshake and be more like HTTP.

There will be more API changes to let a plug-in use a protocol that needs a server side handshake, as well as listen on another port, but one thing at a time.[/code]
ImageJeffM

User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5193
Joined: Fri Dec 13, 2002 4:11 am
Location: https://github.com/OmniTanks
Contact:

Post by JeffM » Fri Apr 06, 2007 5:43 am

a new event has been added

Code: Select all

bz_eIdleNewNonPlayerConnection
this event will be called for non player connections that are idle for over 6 seconds ( configurable by the _tcpTimeout var ). The data with the event is the same as the new connection, but will have no data, and a 0 size.

If a plug-in wishes to send out data to the connection it may install a handler for it and do so.

connections that are idle with out any pending send data, or installed handlers, will be closed.
ImageJeffM

Post Reply