00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __GGZCORE_H__
00029 #define __GGZCORE_H__
00030
00031 #define GGZCORE_VERSION_MAJOR 0
00032 #define GGZCORE_VERSION_MINOR 0
00033 #define GGZCORE_VERSION_MICRO 14
00034 #define GGZCORE_VERSION_IFACE "9:0:0"
00035
00036 #include <stdarg.h>
00037 #include <sys/types.h>
00038
00039 #include <ggz_common.h>
00040
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048
00049
00050
00051
00053 #define GGZCORE_DBG_CONF "GGZCORE:CONF"
00054
00056 #define GGZCORE_DBG_GAME "GGZCORE:GAME"
00057
00059 #define GGZCORE_DBG_HOOK "GGZCORE:HOOK"
00060
00062 #define GGZCORE_DBG_MODULE "GGZCORE:MODULE"
00063
00065 #define GGZCORE_DBG_NET "GGZCORE:NET"
00066
00068 #define GGZCORE_DBG_POLL "GGZCORE:POLL"
00069
00071 #define GGZCORE_DBG_ROOM "GGZCORE:ROOM"
00072
00074 #define GGZCORE_DBG_SERVER "GGZCORE:SERVER"
00075
00077 #define GGZCORE_DBG_STATE "GGZCORE:STATE"
00078
00080 #define GGZCORE_DBG_TABLE "GGZCORE:TABLE"
00081
00083 #define GGZCORE_DBG_XML "GGZCORE:XML"
00084
00085
00086 typedef enum {
00087 GGZ_OPT_PARSER = 0x0001,
00088 GGZ_OPT_MODULES = 0x0002,
00089 GGZ_OPT_THREADED_IO = 0x0004,
00090 GGZ_OPT_EMBEDDED = 0x0008,
00091 GGZ_OPT_RECONNECT = 0x0010
00092 } GGZOptionFlags;
00093
00094
00096 typedef struct _GGZOptions {
00097
00099 GGZOptionFlags flags;
00100
00101 } GGZOptions;
00102
00103
00110 int ggzcore_init(GGZOptions options);
00111
00112
00115 void ggzcore_reload(void);
00116
00119 void ggzcore_destroy(void);
00120
00121
00122
00123
00125 typedef struct _GGZServer GGZServer;
00126
00128 typedef struct _GGZRoom GGZRoom;
00129
00131 typedef struct _GGZPlayer GGZPlayer;
00132
00134 typedef struct _GGZTable GGZTable;
00135
00139 typedef struct _GGZGameType GGZGameType;
00140
00145 typedef struct _GGZModule GGZModule;
00146
00151 typedef struct _GGZGame GGZGame;
00152
00154 typedef enum {
00155 GGZ_HOOK_OK,
00156 GGZ_HOOK_REMOVE,
00157 GGZ_HOOK_ERROR,
00158 GGZ_HOOK_CRISIS
00159 } GGZHookReturn;
00160
00162 typedef GGZHookReturn (*GGZHookFunc)(unsigned int id,
00163 const void* event_data,
00164 const void* user_data);
00165
00170 typedef void (*GGZDestroyFunc)(void* data);
00171
00172
00178 typedef enum {
00180 GGZ_LOGIN,
00181
00183 GGZ_LOGIN_GUEST,
00184
00187 GGZ_LOGIN_NEW
00188 } GGZLoginType;
00189
00190
00196 typedef struct {
00200 GGZClientReqError status;
00201
00204 const char *message;
00205 } GGZErrorEventData;
00206
00208 typedef struct {
00209 const char *motd;
00210 const char *url;
00211 } GGZMotdEventData;
00212
00220 typedef enum {
00228 GGZ_CONNECTED,
00229
00235 GGZ_CONNECT_FAIL,
00236
00243 GGZ_NEGOTIATED,
00244
00250 GGZ_NEGOTIATE_FAIL,
00251
00258 GGZ_LOGGED_IN,
00259
00266 GGZ_LOGIN_FAIL,
00267
00277 GGZ_MOTD_LOADED,
00278
00286 GGZ_ROOM_LIST,
00287
00295 GGZ_TYPE_LIST,
00296
00302 GGZ_SERVER_PLAYERS_CHANGED,
00303
00309 GGZ_ENTERED,
00310
00317 GGZ_ENTER_FAIL,
00318
00324 GGZ_LOGOUT,
00325
00330 GGZ_NET_ERROR,
00331
00338 GGZ_PROTOCOL_ERROR,
00339
00345 GGZ_CHAT_FAIL,
00346
00352 GGZ_STATE_CHANGE,
00353
00364 GGZ_CHANNEL_CONNECTED,
00365
00373 GGZ_CHANNEL_READY,
00374
00382 GGZ_CHANNEL_FAIL,
00383
00388 GGZ_SERVER_ROOMS_CHANGED,
00389
00391 GGZ_NUM_SERVER_EVENTS
00392 } GGZServerEvent;
00393
00395 typedef struct {
00396 GGZChatType type;
00397 const char *sender;
00398 const char *message;
00399 } GGZChatEventData;
00400
00402 typedef struct {
00404 GGZLeaveType reason;
00405
00408 const char *player;
00409 } GGZTableLeaveEventData;
00410
00412 typedef struct {
00414 const char *player_name;
00415
00416
00417
00418
00419 int rooms_known;
00420
00425 GGZRoom *to_room;
00426
00431 GGZRoom *from_room;
00432 } GGZRoomChangeEventData;
00433
00443 typedef enum {
00448 GGZ_PLAYER_LIST,
00449
00453 GGZ_TABLE_LIST,
00454
00459 GGZ_CHAT_EVENT,
00460
00463 GGZ_ROOM_ENTER,
00464
00467 GGZ_ROOM_LEAVE,
00468
00472 GGZ_TABLE_UPDATE,
00473
00477 GGZ_TABLE_LAUNCHED,
00478
00482 GGZ_TABLE_LAUNCH_FAIL,
00483
00487 GGZ_TABLE_JOINED,
00488
00492 GGZ_TABLE_JOIN_FAIL,
00493
00498 GGZ_TABLE_LEFT,
00499
00503 GGZ_TABLE_LEAVE_FAIL,
00504
00508 GGZ_PLAYER_LAG,
00509
00517 GGZ_PLAYER_STATS,
00518
00521 GGZ_PLAYER_COUNT,
00522
00526 GGZ_PLAYER_PERMS
00527 } GGZRoomEvent;
00528
00529
00539 typedef enum {
00547 GGZ_GAME_LAUNCHED,
00548
00553 GGZ_GAME_LAUNCH_FAIL,
00554
00559 GGZ_GAME_NEGOTIATED,
00560
00563 GGZ_GAME_NEGOTIATE_FAIL,
00564
00569 GGZ_GAME_PLAYING
00570 } GGZGameEvent;
00571
00572
00579 typedef enum {
00580 GGZ_STATE_OFFLINE,
00581 GGZ_STATE_CONNECTING,
00582 GGZ_STATE_RECONNECTING,
00583 GGZ_STATE_ONLINE,
00584 GGZ_STATE_LOGGING_IN,
00585 GGZ_STATE_LOGGED_IN,
00586 GGZ_STATE_ENTERING_ROOM,
00587 GGZ_STATE_IN_ROOM,
00588 GGZ_STATE_BETWEEN_ROOMS,
00589 GGZ_STATE_LAUNCHING_TABLE,
00590 GGZ_STATE_JOINING_TABLE,
00591 GGZ_STATE_AT_TABLE,
00592 GGZ_STATE_LEAVING_TABLE,
00593 GGZ_STATE_LOGGING_OUT
00594 } GGZStateID;
00595
00596
00602 typedef enum {
00603 GGZ_ENVIRONMENT_PASSIVE,
00604 GGZ_ENVIRONMENT_CONSOLE,
00605 GGZ_ENVIRONMENT_FRAMEBUFFER,
00606 GGZ_ENVIRONMENT_XWINDOW,
00607 GGZ_ENVIRONMENT_XFULLSCREEN
00608 } GGZModuleEnvironment;
00609
00610
00611
00612
00619 GGZServer* ggzcore_server_new(void);
00620
00628 int ggzcore_server_reset(GGZServer *server);
00629
00630
00631
00632
00633
00646 int ggzcore_server_add_event_hook(GGZServer *server,
00647 const GGZServerEvent event,
00648 const GGZHookFunc func);
00649
00654 int ggzcore_server_add_event_hook_full(GGZServer *server,
00655 const GGZServerEvent event,
00656 const GGZHookFunc func,
00657 const void *data);
00658
00668 int ggzcore_server_remove_event_hook(GGZServer *server,
00669 const GGZServerEvent event,
00670 const GGZHookFunc func);
00671
00680 int ggzcore_server_remove_event_hook_id(GGZServer *server,
00681 const GGZServerEvent event,
00682 const unsigned int hook_id);
00683
00684
00685
00686
00687
00701 int ggzcore_server_set_hostinfo(GGZServer *server,
00702 const char *host,
00703 const unsigned int port,
00704 const unsigned int use_tls);
00705
00719 int ggzcore_server_set_logininfo(GGZServer *server,
00720 const GGZLoginType type,
00721 const char *handle,
00722 const char *password,
00723 const char *email);
00724
00735 int ggzcore_server_log_session(GGZServer *server, const char *filename);
00736
00737
00738
00739
00740
00747 const char* ggzcore_server_get_host(const GGZServer *server);
00748
00755 int ggzcore_server_get_port(const GGZServer *server);
00756
00763 GGZLoginType ggzcore_server_get_type(const GGZServer *server);
00764
00771 const char* ggzcore_server_get_handle(const GGZServer *server);
00772
00779 const char* ggzcore_server_get_password(const GGZServer *server);
00780
00791 int ggzcore_server_get_fd(const GGZServer *server);
00792
00804 int ggzcore_server_get_channel(GGZServer *server);
00805
00811 GGZStateID ggzcore_server_get_state(const GGZServer *server);
00812
00818 int ggzcore_server_get_tls(const GGZServer *server);
00819
00824 int ggzcore_server_get_num_players(const GGZServer *server);
00825
00829 int ggzcore_server_get_num_rooms(const GGZServer *server);
00830
00832 GGZRoom* ggzcore_server_get_nth_room(const GGZServer *server,
00833 const unsigned int num);
00834
00837 int ggzcore_server_get_room_num(const GGZServer *server,
00838 const GGZRoom *room);
00839
00841 GGZRoom* ggzcore_server_get_cur_room(const GGZServer *server);
00842
00846 GGZPlayer* ggzcore_server_get_player(GGZServer *server, const char *name);
00847
00854 int ggzcore_server_get_num_gametypes(const GGZServer *server);
00855
00857 GGZGameType* ggzcore_server_get_nth_gametype(const GGZServer *server,
00858 const unsigned int num);
00859
00861 GGZGame* ggzcore_server_get_cur_game(const GGZServer *server);
00862
00864 int ggzcore_server_is_online(const GGZServer *server);
00865
00867 int ggzcore_server_is_logged_in(const GGZServer *server);
00868
00870 int ggzcore_server_is_in_room(const GGZServer *server);
00871
00873 int ggzcore_server_is_at_table(const GGZServer *server);
00874
00875
00876
00877
00895 int ggzcore_server_connect(GGZServer *server);
00896
00907 int ggzcore_server_create_channel(GGZServer *server);
00908
00925 int ggzcore_server_login(GGZServer *server);
00926
00928 int ggzcore_server_motd(GGZServer *server);
00929
00938 int ggzcore_server_list_rooms(GGZServer *server, const int type, const char verbose);
00939
00947 int ggzcore_server_list_gametypes(GGZServer *server, const char verbose);
00948
00955 int ggzcore_server_join_room(GGZServer *server, GGZRoom *room);
00956
00958 int ggzcore_server_logout(GGZServer *server);
00959
00961 int ggzcore_server_disconnect(GGZServer *server);
00962
00963
00964
00966 int ggzcore_server_data_is_pending(GGZServer *server);
00967
00970 int ggzcore_server_read_data(GGZServer *server, int fd);
00971
00973 void ggzcore_server_free(GGZServer *server);
00974
00975
00976
00977
00978
00980 GGZRoom* ggzcore_room_new(void);
00981
00983 void ggzcore_room_free(GGZRoom *room);
00984
00985
00987 GGZServer *ggzcore_room_get_server(const GGZRoom *room);
00988
00990 const char* ggzcore_room_get_name(const GGZRoom *room);
00991
00993 const char* ggzcore_room_get_desc(const GGZRoom *room);
00994
00996 GGZGameType* ggzcore_room_get_gametype(const GGZRoom *room);
00997
00999 int ggzcore_room_get_num_players(const GGZRoom *room);
01000
01002 GGZPlayer* ggzcore_room_get_nth_player(const GGZRoom *room,
01003 const unsigned int num);
01004
01006 int ggzcore_room_get_num_tables(const GGZRoom *room);
01007
01009 GGZTable* ggzcore_room_get_nth_table(const GGZRoom *room,
01010 const unsigned int num);
01011
01013 GGZTable* ggzcore_room_get_table_by_id(const GGZRoom *room,
01014 const unsigned int id);
01015
01017 int ggzcore_room_get_closed(const GGZRoom *room);
01018
01019
01035 int ggzcore_room_add_event_hook(GGZRoom *room,
01036 const GGZRoomEvent event,
01037 const GGZHookFunc func);
01038
01051 int ggzcore_room_add_event_hook_full(GGZRoom *room,
01052 const GGZRoomEvent event,
01053 const GGZHookFunc func,
01054 const void *data);
01055
01067 int ggzcore_room_remove_event_hook(GGZRoom *room,
01068 const GGZRoomEvent event,
01069 const GGZHookFunc func);
01070
01081 int ggzcore_room_remove_event_hook_id(GGZRoom *room,
01082 const GGZRoomEvent event,
01083 const unsigned int hook_id);
01084
01085
01088 int ggzcore_room_list_players(GGZRoom *room);
01089
01095 int ggzcore_room_list_tables(GGZRoom *room,
01096 const int type,
01097 const char global);
01098
01106 int ggzcore_room_chat(GGZRoom *room,
01107 const GGZChatType opcode,
01108 const char *player,
01109 const char *msg);
01110
01117 int ggzcore_room_admin(GGZRoom *room,
01118 GGZAdminType type,
01119 const char *player,
01120 const char *reason);
01121
01130 int ggzcore_room_launch_table(GGZRoom *room, GGZTable *table);
01131
01137 int ggzcore_room_join_table(GGZRoom *room, const unsigned int table_id,
01138 int spectator);
01139
01148 int ggzcore_room_leave_table(GGZRoom *room, int force);
01149
01150
01151
01152
01153
01155 char *ggzcore_player_get_name(const GGZPlayer *player);
01156
01158 GGZPlayerType ggzcore_player_get_type(const GGZPlayer *player);
01159
01161 GGZRoom *ggzcore_player_get_room(const GGZPlayer *player);
01162
01164 GGZTable* ggzcore_player_get_table(const GGZPlayer *player);
01165
01167 bool ggzcore_player_has_perm(const GGZPlayer *player, GGZPerm perm);
01168
01174 int ggzcore_player_set_perm(GGZPlayer *player, GGZPerm perm, bool set);
01175
01177 int ggzcore_player_get_lag(const GGZPlayer *player);
01178
01182 int ggzcore_player_get_record(const GGZPlayer *player,
01183 int *wins, int *losses,
01184 int *ties, int *forfeits);
01185
01189 int ggzcore_player_get_rating(const GGZPlayer *player, int *rating);
01190
01194 int ggzcore_player_get_ranking(const GGZPlayer *player, int *ranking);
01195
01199 int ggzcore_player_get_highscore(const GGZPlayer *player, int *highscore);
01200
01201
01204 GGZTable* ggzcore_table_new(void);
01205
01208 int ggzcore_table_init(GGZTable *table,
01209 const GGZGameType *gametype,
01210 const char *desc,
01211 const unsigned int num_seats);
01212
01214 void ggzcore_table_free(GGZTable *table);
01215
01229 int ggzcore_table_set_seat(GGZTable *table,
01230 const unsigned int seat,
01231 GGZSeatType type,
01232 const char *name);
01233
01235 int ggzcore_table_remove_player(GGZTable *table, const char *name);
01236
01238 int ggzcore_table_get_id(const GGZTable *table);
01239
01241 const GGZRoom *ggzcore_table_get_room(const GGZTable *table);
01242
01244 const GGZGameType *ggzcore_table_get_type(const GGZTable *table);
01245
01247 const char *ggzcore_table_get_desc(const GGZTable *table);
01248
01250 GGZTableState ggzcore_table_get_state(const GGZTable *table);
01251
01253 int ggzcore_table_get_num_seats(const GGZTable *table);
01254
01256 int ggzcore_table_set_desc(GGZTable *table, const char *desc);
01257
01267 int ggzcore_table_get_seat_count(const GGZTable *table, GGZSeatType type);
01268
01270 const char *ggzcore_table_get_nth_player_name(const GGZTable *table,
01271 const unsigned int num);
01272
01274 int ggzcore_table_get_num_spectator_seats(const GGZTable *table);
01275
01277 const char *ggzcore_table_get_nth_spectator_name(const GGZTable *table,
01278 const unsigned int num);
01279
01282 GGZSeatType ggzcore_table_get_nth_player_type(const GGZTable *table,
01283 const unsigned int num);
01284
01285
01288 unsigned int ggzcore_gametype_get_id(const GGZGameType *type);
01289
01291 const char * ggzcore_gametype_get_name(const GGZGameType *type);
01292
01294 const char* ggzcore_gametype_get_prot_engine(const GGZGameType *type);
01295
01297 const char* ggzcore_gametype_get_prot_version(const GGZGameType *type);
01298
01300 const char* ggzcore_gametype_get_version(const GGZGameType *type);
01301
01303 const char* ggzcore_gametype_get_author(const GGZGameType *type);
01304
01306 const char* ggzcore_gametype_get_url(const GGZGameType *type);
01307
01309 const char* ggzcore_gametype_get_desc(const GGZGameType *type);
01310
01313 int ggzcore_gametype_get_max_players(const GGZGameType *type);
01314
01317 int ggzcore_gametype_get_max_bots(const GGZGameType *type);
01318
01320 int ggzcore_gametype_get_spectators_allowed(const GGZGameType *type);
01321
01323 int ggzcore_gametype_num_players_is_valid(const GGZGameType *type,
01324 unsigned int num);
01325
01327 int ggzcore_gametype_num_bots_is_valid(const GGZGameType *type,
01328 unsigned int num);
01329
01331 int ggzcore_gametype_get_num_namedbots(const GGZGameType *type);
01332 const char* ggzcore_gametype_get_namedbot_name(const GGZGameType *type, unsigned int num);
01333 const char* ggzcore_gametype_get_namedbot_class(const GGZGameType *type, unsigned int num);
01334
01336 int ggzcore_gametype_get_peers_allowed(const GGZGameType *type);
01337
01338
01339
01340
01341
01349 int ggzcore_conf_initialize (const char *g_path,
01350 const char *u_path);
01351
01360 int ggzcore_conf_write_string(const char *section,
01361 const char *key,
01362 const char *value);
01363
01372 int ggzcore_conf_write_int(const char *section,
01373 const char *key,
01374 int value);
01375
01385 int ggzcore_conf_write_list(const char *section,
01386 const char *key,
01387 int argc,
01388 char **argv);
01389
01404 char * ggzcore_conf_read_string(const char *section,
01405 const char *key,
01406 const char *def);
01407
01423 int ggzcore_conf_read_int(const char *section, const char *key, int def);
01424
01435 int ggzcore_conf_read_list(const char *section,
01436 const char *key,
01437 int *argcp,
01438 char ***argvp);
01439
01447 int ggzcore_conf_remove_section(const char *section);
01448
01457 int ggzcore_conf_remove_key(const char *section, const char *key);
01458
01464 int ggzcore_conf_commit(void);
01465
01466
01467
01468
01469
01471 unsigned int ggzcore_module_get_num(void);
01472
01473
01476 int ggzcore_module_add(const char *name,
01477 const char *version,
01478 const char *prot_engine,
01479 const char *prot_version,
01480 const char *author,
01481 const char *frontend,
01482 const char *url,
01483 const char *exe_path,
01484 const char *icon_path,
01485 const char *help_path,
01486 GGZModuleEnvironment environment);
01487
01488
01490 int ggzcore_module_get_num_by_type(const char *game,
01491 const char *engine,
01492 const char *version);
01493
01495 GGZModule* ggzcore_module_get_nth_by_type(const char *game,
01496 const char *engine,
01497 const char *version,
01498 const unsigned int num);
01499
01501 const char * ggzcore_module_get_name(GGZModule *module);
01502
01504 const char* ggzcore_module_get_version(GGZModule *module);
01505
01507 const char* ggzcore_module_get_prot_engine(GGZModule *module);
01508
01510 const char* ggzcore_module_get_prot_version(GGZModule *module);
01511
01513 const char* ggzcore_module_get_author(GGZModule *module);
01514
01516 const char* ggzcore_module_get_frontend(GGZModule *module);
01517
01519 const char* ggzcore_module_get_url(GGZModule *module);
01520
01523 const char* ggzcore_module_get_icon_path(GGZModule *module);
01524
01526 const char* ggzcore_module_get_help_path(GGZModule *module);
01527
01529 char** ggzcore_module_get_argv(GGZModule *module);
01530
01532 GGZModuleEnvironment ggzcore_module_get_environment(GGZModule *module);
01533
01534
01535
01536
01538 GGZGame* ggzcore_game_new(void);
01539
01541 int ggzcore_game_init(GGZGame *game, GGZServer *server, GGZModule *module);
01542
01544 void ggzcore_game_free(GGZGame *game);
01545
01550 int ggzcore_game_add_event_hook(GGZGame *game,
01551 const GGZGameEvent event,
01552 const GGZHookFunc func);
01553
01558 int ggzcore_game_add_event_hook_full(GGZGame *game,
01559 const GGZGameEvent event,
01560 const GGZHookFunc func,
01561 const void *data);
01562
01567 int ggzcore_game_remove_event_hook(GGZGame *game,
01568 const GGZGameEvent event,
01569 const GGZHookFunc func);
01570
01575 int ggzcore_game_remove_event_hook_id(GGZGame *game,
01576 const GGZGameEvent event,
01577 const unsigned int hook_id);
01578
01580 int ggzcore_game_get_control_fd(GGZGame *game);
01581
01583 void ggzcore_game_set_server_fd(GGZGame *game, unsigned int fd);
01584
01586 GGZModule* ggzcore_game_get_module(GGZGame *game);
01587
01589 int ggzcore_game_launch(GGZGame *game);
01590
01595 int ggzcore_game_read_data(GGZGame *game);
01596
01597 #ifdef __cplusplus
01598 }
01599 #endif
01600
01601 #endif