Menu

Game_API

Sven James

API for game clients and game servers.

Suggestion for name: libglou

Client API

### initialization

// NOTE: maybe we should wrap the xoup calls into glou calls

// setup a XMPP connection
XoupXmppConnection *xmpp_con = xoup_xmpp_connection_new(jid, pw);

// register XMPP connection event handlers
xoup_xmpp_connection_add_handler(xmpp_con, "connected", connected, NULL);
xoup_xmpp_connection_add_handler(xmpp_con, "disconnected", disconnected, NULL);
xoup_xmpp_connection_add_handler(xmpp_con, "error", error, NULL);

// connect
xoup_xmpp_connection_connect(xmpp_con);

// setup a game client connection to "wormux.org"
GlouClient *client = glou_client_new("wormux.org", xmpp_con);

// register client event handlers
glou_client_add_handler(client, "subscribed_to_matches", subscribed_to_matches, NULL);
glou_client_add_handler(client, "subscribed_to_match_info", subscribed_to_match_info, NULL);
glou_client_add_handler(client, "queried_community_info", queried_community_info, NULL);
glou_client_add_handler(client, "queried_news", queried_news, NULL);
// ... match_added, match_removed, match_updated, match_info_updated, ...

// mainloop
while (TRUE) {
    glou_handle_events();
}

### list matches

// setup filters if desired
GlouList *filters = glou_list_new();
glou_list_add(filters, glou_filter_new("map", "mountain*"));

// subscribe to the list of matches
// the list will contain basic match information
// emitted events: subscribed, added, removed, updated
glou_client_subscribe_to_matches(client, filters);

// handle events
void match_added(GlouClient *client, GlouMatch *match, void *userdata) {
    printf(" * %s (%s/%s)\n", match->name, match->player_count, match->max_player_count);
}

void subscribed_to_matches(GlouClient *client, void *userdata) {
    printf("received complete list of matches\n");
}

void match_removed(GlouClient *client, GlouMatch *match, void *userdata) {...}
void match_updated(GlouClient *client, GlouMatch *match, void *userdata) {...}

### detailed match info

// subscribe to detailed information of a match
// this will contain information like player-lists, map-lists etc.
// emitted events: subscribed, updated
glou_client_subscribe_to_match_info(client, match);

// handle events
void subscribed_to_match_info(GlouClient *client, Match *match, void *userdata) {
    printf("received detailed match info for %s\n", match->name);
}

### query community information

// query information about this and that...
// emitted events: queried_*
glou_client_query_community_info(client);
glou_client_query_news(client);

// handle events
void queried_community_info(GlouClient *client, GlouCommunityInfo *info, void *userdata) {
    printf("motd: %s\n", info->motd);
}

void queried_news(GlouClient *client, GlouList *news_items, void *userdata) {
    printf("news:\n");
    for (int i = 0; i

Server API

### initialization

// setup a XMPP connection
XoupXmppConnection *xmpp_con = xoup_xmpp_connection_new(jid, pw);

// register XMPP connection event handlers
xoup_xmpp_connection_add_handler(xmpp_con, "connected", connected, NULL);
xoup_xmpp_connection_add_handler(xmpp_con, "disconnected", disconnected, NULL);
xoup_xmpp_connection_add_handler(xmpp_con, "error", error, NULL);

// connect
xoup_xmpp_connection_connect(xmpp_con);

// setup a game server connection to "wormux.org"
GlouServer *server = glou_server_new("wormux.org", xmpp_con);

// mainloop
while (TRUE) {
    glou_handle_events();
}

### enlist a match on the community server

GlouMatch *match = glou_match_new(id);
match->map = ...

glou_server_add_match(server, match);

### update a match

glou_match_add_player(match, player);
glou_server_update_match(server, match);

### close a match

GlouMatchResult *result = glou_match_result_new(match);
result->winner = ...
glou_server_close_match(server, match, result);

// the server may instantly start a new match
GlouMatch *new_match = glou_match_copy(match, new_id);
new_match->map = ...
glou_server_add_match(server, new_match);
// ...

[Category:Ideas]


Related

Wiki: Components

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.