Home Games Projects Blog Contact Private
Network

Archive for June 11th, 2008

Pitfalls Of RakNet’s Lightweight Database

As described yesterday, I’ve used RakNet’s Lightweight Database to keep a server list on a master server. Overall it isn’t that difficult, but there were a few things I had problems with. I think that it’s mainly due to the poor documentation of the Lightweight Database plugin. The documentation can be found here (manual), here (Doxygen for the server) and here (Doxygen for the client).

Column Numbers

My first problem was finding the proper cells in the table on the client. I connected to the server and got an object of type DataStructures::Table (documentation here) through deserializing the incoming stream. But when I then tried to use the member function GetCellValueByIndex of the Table class I got mostly garbage or data that didn’t make any sense. I then got the idea to simply dump the whole table to the console and was able to see that the table had more columns than I had specified when creating the table.

The LightweightDatabaseServer::AddTable member function silently adds columns to the table which it needs to work. I understand that those columns are necessary, but the function’s documentation should mention this because when you otherwise get strange results when using GetCellValueByIndex with an index you think is right though it’s not right.

Additionally, the number of columns added depends on the parameters given to AddTable. So you should make your choice about the parameters you want to hand AddTable and then check what columns the table really contains.

Pings

RakNet offers the possibility to ping a remote host, but RakNet doesn’t do normal pings, just its own pings which need a RakNet peer on the other side. I stumbled across this when I tried to use the removeRowOnPingFailure option of LightweightDatabaseServer::AddTable. After adding my server to the table I closed the connection to the server and destroyed the instance of RakPeerInterface.

If removeRowOnPingFailure was set at the master server the newly added server would only show up for a few seconds or minutes and vanish again. As it turns out RakNet pings the other side by trying to connect to the port the lightweight database request came from. Because I had already destroyed the peer which had used that port, the ping failed and my server was removed from the list.

I fixed this problem by making the local peer, that connected to the master server, use the port number that would later be used to accept connections from player clients. This actually worked and I’ve learned that, although RakNet doesn’t need to have the connection kept open, it needs to find a RakNet peer on the exact same port that was used to connect to the server when adding something to the table.