All articles
Article 2 min read

A specific, useful title: Building a Game Server Tracker: Insights from Exposing Public Data

This blog explores lessons learned from developing a public JSON API for tracking Lineage 2 server status, covering MySQL quirks, CORS issues, and the value of sharing data.

Introduction

Building a game server tracker can be an engaging project that combines web development with database management. The article discusses one developer's experience in creating such a system to track the availability of servers for the MMORPG Lineage 2. It covers various aspects including MySQL configuration issues, CORS settings, and strategies for handling public data exposure effectively.

MySQL Configuration Challenges

One of the initial hurdles was dealing with date fields in MySQL that returned incorrect formats. The API users expected Unix timestamps (seconds since January 1, 1970) but were receiving dates instead. This issue was resolved by altering the SQL query to explicitly cast the timestamp columns as integers using CONVERT(TIME(0), UNSIGNED) before selecting them.

Corrected Query Example

sql
SELECT server_id, CONVERT(TIME(server_last_online, 'unixepoch'), UNSIGNED) AS last_online FROM servers;

CORS and Security Considerations

Another challenge encountered was handling Cross-Origin Resource Sharing (CORS). The public API had to serve data without security constraints, but this exposed users to cross-origin attacks. The solution involved configuring the server with appropriate headers for allowing requests from any origin:

javascript
app.use((req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
});

Valuing Public Data Exposure

Despite the technical hurdles, exposing Lineage 2 server status data publicly was worthwhile. It offered developers a wealth of information that could be used to improve game servers and support communities. By sharing this data, the developer created a resource that helped players find active servers more easily, thereby enhancing overall satisfaction with the game.

Conclusion

Through navigating issues such as MySQL date formatting and managing CORS security settings, the article concludes by emphasizing the value of making useful data freely available to improve player experiences and support game communities.