Continue uncrustifying

This commit is contained in:
Gergely Polonkai 2016-06-22 18:12:57 +02:00
parent c68b577fb3
commit 73b7c3db39
15 changed files with 1464 additions and 1380 deletions

View File

@ -96,13 +96,14 @@ wmud_configdata_free(ConfigData **config_data)
gboolean
wmud_config_init(ConfigData **config_data, GError **err)
{
GString *config_file = g_string_new(WMUD_CONFDIR);
GString *config_file = g_string_new(WMUD_CONFDIR);
GKeyFile *config;
GError *in_err = NULL;
gchar *pos;
GError *in_err = NULL;
gchar *pos;
if (!config_data)
if (!config_data) {
return FALSE;
}
if (*config_data) {
g_clear_error(err);
@ -255,8 +256,8 @@ wmud_config_init(ConfigData **config_data, GError **err)
if ((pos = g_strstr_len((*config_data)->database_dsn,
-1, "{statedir}")) != NULL) {
guint real_pos = pos - (*config_data)->database_dsn;
GString *tmp = g_string_new((*config_data)->database_dsn);
guint real_pos = pos - (*config_data)->database_dsn;
GString *tmp = g_string_new((*config_data)->database_dsn);
g_string_erase(tmp, real_pos, 10);
g_string_insert(tmp, real_pos, WMUD_STATEDIR);

236
wmud/db.c
View File

@ -39,8 +39,8 @@
* different (e.g MySQL or PostgreSQL) database.
*/
static GdaConnection *dbh = NULL;
static GdaSqlParser *parser = NULL;
static GdaConnection *dbh = NULL;
static GdaSqlParser *parser = NULL;
GQuark
wmud_db_error_quark()
@ -98,33 +98,34 @@ wmud_db_init(GError **err)
gboolean
wmud_db_load_players(GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res;
GdaStatement *sth = NULL;
GdaDataModel *res;
GdaDataModelIter *iter;
GError *local_err = NULL;
GError *local_err = NULL;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading players");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
sth = gda_sql_parser_parse_string(
parser,
"SELECT id, login, password, email FROM players",
NULL,
NULL);
parser,
"SELECT id, login, password, email FROM players",
NULL,
NULL);
/* TODO: error checking! */
if ((res = gda_connection_statement_execute_select(
dbh,
sth,
NULL,
&local_err)) == NULL) {
dbh,
sth,
NULL,
&local_err)) == NULL) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"Unable to load players: %s",
local_err->message);
@ -141,7 +142,7 @@ wmud_db_load_players(GError **err)
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
WmudPlayer *player;
WmudPlayer *player;
player = wmud_player_new();
@ -192,20 +193,21 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Saving player");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
login_value = gda_value_new_from_string(
wmud_player_get_player_name(player),
G_TYPE_STRING);
wmud_player_get_player_name(player),
G_TYPE_STRING);
email_value = gda_value_new_from_string(
wmud_player_get_email(player),
G_TYPE_STRING);
wmud_player_get_email(player),
G_TYPE_STRING);
if (!gda_connection_insert_row_into_table(dbh,
"players",
@ -228,8 +230,8 @@ wmud_db_save_player(WmudPlayer *player, GError **err)
gboolean
wmud_db_update_player_password(WmudPlayer *player,
gchar *crypted_password,
GError **err)
gchar *crypted_password,
GError **err)
{
GValue *cpw,
*player_id;
@ -271,16 +273,17 @@ wmud_db_update_player_password(WmudPlayer *player,
gboolean
wmud_db_load_planes(GSList **planes, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planes");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
@ -289,20 +292,20 @@ wmud_db_load_planes(GSList **planes, GError **err)
"SELECT id, name FROM planes",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
iter = gda_data_model_create_iter(res);
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
wmudPlane *plane;
wmudPlane *plane;
plane = g_new0(wmudPlane, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
plane->id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
plane->name = g_strdup(g_value_get_string(val));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
@ -323,16 +326,17 @@ wmud_db_load_planes(GSList **planes, GError **err)
gboolean
wmud_db_load_planets(GSList **planets, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading planets");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
@ -341,20 +345,20 @@ wmud_db_load_planets(GSList **planets, GError **err)
"SELECT id, name FROM planets",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
iter = gda_data_model_create_iter(res);
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
wmudPlanet *planet;
wmudPlanet *planet;
planet = g_new0(wmudPlanet, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
planet->id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
planet->name = g_strdup(g_value_get_string(val));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
@ -375,31 +379,32 @@ wmud_db_load_planets(GSList **planets, GError **err)
gboolean
wmud_db_load_directions(GSList **directions, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
GError *local_err = NULL;
GError *local_err = NULL;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading directions");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
sth = gda_sql_parser_parse_string(
parser,
"SELECT id, short_name, name FROM directions",
NULL,
NULL);
parser,
"SELECT id, short_name, name FROM directions",
NULL,
NULL);
if ((res = gda_connection_statement_execute_select(
dbh, sth,
NULL, &local_err)) == NULL) {
dbh, sth,
NULL, &local_err)) == NULL) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_SELECT_ERROR,
"Unable to load directions: %s",
@ -412,18 +417,18 @@ wmud_db_load_directions(GSList **directions, GError **err)
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
const GValue *val;
wmudDirection *dir;
dir = g_new0(wmudDirection, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
dir->id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
dir->short_name = g_strdup(g_value_get_string(val));
val = gda_data_model_iter_get_value_at(iter, 2);
val = gda_data_model_iter_get_value_at(iter, 2);
dir->name = g_strdup(g_value_get_string(val));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
@ -444,39 +449,40 @@ wmud_db_load_directions(GSList **directions, GError **err)
gboolean
wmud_db_load_areas(GSList **areas, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading areas");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
sth = gda_sql_parser_parse_string(
parser,
"SELECT id, name FROM areas",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
parser,
"SELECT id, name FROM areas",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
iter = gda_data_model_create_iter(res);
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
wmudArea *area;
wmudArea *area;
area = g_new0(wmudArea, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
area->id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
area->name = g_strdup(g_value_get_string(val));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loaded area _%s_", area->name);
@ -495,48 +501,49 @@ wmud_db_load_areas(GSList **areas, GError **err)
gboolean
wmud_db_load_rooms(GSList **rooms, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading rooms");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
sth = gda_sql_parser_parse_string(
parser,
"SELECT id, area, name, distant_description, close_description FROM rooms",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
parser,
"SELECT id, area, name, distant_description, close_description FROM rooms",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
iter = gda_data_model_create_iter(res);
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
wmudRoom *room;
wmudRoom *room;
room = g_new0(wmudRoom, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
room->id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
room->area_id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 2);
val = gda_data_model_iter_get_value_at(iter, 2);
room->name = g_strdup(g_value_get_string(val));
val = gda_data_model_iter_get_value_at(iter, 3);
val = gda_data_model_iter_get_value_at(iter, 3);
room->distant_description = g_strdup(g_value_get_string(val));
val = gda_data_model_iter_get_value_at(iter, 4);
val = gda_data_model_iter_get_value_at(iter, 4);
room->close_description = g_strdup(g_value_get_string(val));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
@ -558,42 +565,43 @@ wmud_db_load_rooms(GSList **rooms, GError **err)
gboolean
wmud_db_load_exits(GSList **exits, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading exits");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
sth = gda_sql_parser_parse_string(
parser,
"SELECT room_id, direction, other_side FROM room_exits",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
parser,
"SELECT room_id, direction, other_side FROM room_exits",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
iter = gda_data_model_create_iter(res);
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
wmudExit *room_exit;
wmudExit *room_exit;
room_exit = g_new0(wmudExit, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
room_exit->source_room_id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
room_exit->direction_id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 2);
val = gda_data_model_iter_get_value_at(iter, 2);
room_exit->destination_room_id = g_value_get_int(val);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
@ -616,40 +624,41 @@ wmud_db_load_exits(GSList **exits, GError **err)
gboolean
wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
"Loading planet<->plane associations");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
sth = gda_sql_parser_parse_string(
parser,
"SELECT planet_id, plane_id FROM planet_planes",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
parser,
"SELECT planet_id, plane_id FROM planet_planes",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
iter = gda_data_model_create_iter(res);
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
const GValue *val;
wmudPlanetPlaneAssoc *planet_plane;
planet_plane = g_new0(wmudPlanetPlaneAssoc, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
planet_plane->planet_id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
planet_plane->plane_id = g_value_get_int(val);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
@ -671,51 +680,52 @@ wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
gboolean
wmud_db_load_menu(GSList **menu_items, GError **err)
{
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaStatement *sth = NULL;
GdaDataModel *res = NULL;
GdaDataModelIter *iter;
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Loading menu items");
if (dbh == NULL) {
if (err)
if (err) {
g_set_error(err,
WMUD_DB_ERROR, WMUD_DB_ERROR_NOINIT,
"Database backend not initialized");
}
return FALSE;
}
sth = gda_sql_parser_parse_string(
parser,
"SELECT id, menuchar, need_active_char, placement, display_text, fnctn FROM menu ORDER BY placement",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
parser,
"SELECT id, menuchar, need_active_char, placement, display_text, fnctn FROM menu ORDER BY placement",
NULL,
NULL);
res = gda_connection_statement_execute_select(dbh, sth, NULL, NULL);
iter = gda_data_model_create_iter(res);
gda_data_model_iter_move_next(iter);
while (gda_data_model_iter_is_valid(iter)) {
const GValue *val;
wmudMenu *menu_item;
wmudMenu *menu_item;
menu_item = g_new0(wmudMenu, 1);
val = gda_data_model_iter_get_value_at(iter, 0);
val = gda_data_model_iter_get_value_at(iter, 0);
menu_item->id = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 1);
val = gda_data_model_iter_get_value_at(iter, 1);
menu_item->menuchar = *(g_value_get_string(val));
val = gda_data_model_iter_get_value_at(iter, 2);
val = gda_data_model_iter_get_value_at(iter, 2);
menu_item->need_active_char = g_value_get_boolean(val);
val = gda_data_model_iter_get_value_at(iter, 3);
val = gda_data_model_iter_get_value_at(iter, 3);
menu_item->placement = g_value_get_int(val);
val = gda_data_model_iter_get_value_at(iter, 4);
val = gda_data_model_iter_get_value_at(iter, 4);
menu_item->text = g_strdup(g_value_get_string(val));
val = gda_data_model_iter_get_value_at(iter, 5);
val = gda_data_model_iter_get_value_at(iter, 5);
menu_item->func = g_strdup(g_value_get_string(val));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,

View File

@ -6,28 +6,28 @@
/* enumerations from "wmudclientstate.h" */
GType
wmud_client_state_get_type (void)
wmud_client_state_get_type(void)
{
static volatile gsize g_define_type_id__volatile = 0;
static volatile gsize g_define_type_id__volatile = 0;
if (g_once_init_enter(&g_define_type_id__volatile)) {
static const GEnumValue values[] = {
{ WMUD_CLIENT_STATE_FRESH, "WMUD_CLIENT_STATE_FRESH", "fresh" },
{ WMUD_CLIENT_STATE_PASSWAIT, "WMUD_CLIENT_STATE_PASSWAIT", "passwait" },
{ WMUD_CLIENT_STATE_MENU, "WMUD_CLIENT_STATE_MENU", "menu" },
{ WMUD_CLIENT_STATE_INGAME, "WMUD_CLIENT_STATE_INGAME", "ingame" },
{ WMUD_CLIENT_STATE_YESNO, "WMUD_CLIENT_STATE_YESNO", "yesno" },
{ WMUD_CLIENT_STATE_REGISTERING, "WMUD_CLIENT_STATE_REGISTERING", "registering" },
{ WMUD_CLIENT_STATE_REGEMAIL_CONFIRM, "WMUD_CLIENT_STATE_REGEMAIL_CONFIRM", "regemail-confirm" },
{ 0, NULL, NULL }
};
if (g_once_init_enter(&g_define_type_id__volatile)) {
static const GEnumValue values[] = {
{ WMUD_CLIENT_STATE_FRESH, "WMUD_CLIENT_STATE_FRESH", "fresh" },
{ WMUD_CLIENT_STATE_PASSWAIT, "WMUD_CLIENT_STATE_PASSWAIT", "passwait" },
{ WMUD_CLIENT_STATE_MENU, "WMUD_CLIENT_STATE_MENU", "menu" },
{ WMUD_CLIENT_STATE_INGAME, "WMUD_CLIENT_STATE_INGAME", "ingame" },
{ WMUD_CLIENT_STATE_YESNO, "WMUD_CLIENT_STATE_YESNO", "yesno" },
{ WMUD_CLIENT_STATE_REGISTERING, "WMUD_CLIENT_STATE_REGISTERING", "registering" },
{ WMUD_CLIENT_STATE_REGEMAIL_CONFIRM, "WMUD_CLIENT_STATE_REGEMAIL_CONFIRM", "regemail-confirm" },
{ 0, NULL, NULL }
};
GType g_define_type_id = g_enum_register_static(g_intern_static_string("WmudClientState"), values);
GType g_define_type_id = g_enum_register_static(g_intern_static_string("WmudClientState"), values);
g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
}
g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
}
return g_define_type_id__volatile;
return g_define_type_id__volatile;
}

View File

@ -45,7 +45,7 @@
*/
struct AcceptData {
GMainContext *context;
GMainContext *context;
GSocketListener *listener;
};
@ -54,7 +54,7 @@ struct AcceptData {
*
* The full #GSList of the currently connected #WmudClient objects.
*/
GSList *clients = NULL;
GSList *clients = NULL;
static GRegex *email_regex = NULL;
@ -91,11 +91,11 @@ hup_client(WmudClient *client)
static void
recv_client(WmudClient *client)
{
GError *err = NULL;
GError *err = NULL;
GSocket *client_socket;
gssize len;
gchar *buf2;
gchar *buf = g_malloc0(sizeof(gchar) * (MAX_RECV_LEN + 1));
gssize len;
gchar *buf2;
gchar *buf = g_malloc0(sizeof(gchar) * (MAX_RECV_LEN + 1));
client_socket = wmud_client_get_socket(client);
@ -120,29 +120,32 @@ recv_client(WmudClient *client)
sloc = -1;
if ((r < n) && r) {
if (wmud_client_get_buffer_length(client) > 0)
if (wmud_client_get_buffer_length(client) > 0) {
g_string_append_len(wmud_client_get_buffer(client),
buf2,
(r - buf2));
else
} else {
g_string_overwrite_len(
wmud_client_get_buffer(client),
0,
buf2,
(r - buf2));
wmud_client_get_buffer(client),
0,
buf2,
(r - buf2));
}
buf2 = r;
} else if (n) {
if (wmud_client_get_buffer_length(client) > 0)
if (wmud_client_get_buffer_length(client) > 0) {
g_string_append_len(
wmud_client_get_buffer(client),
buf2,
(n - buf2));
else
wmud_client_get_buffer(client),
buf2,
(n - buf2));
} else {
g_string_overwrite_len(
wmud_client_get_buffer(client),
0,
buf2,
(n - buf2));
wmud_client_get_buffer(client),
0,
buf2,
(n - buf2));
}
buf2 = n;
}
@ -151,57 +154,67 @@ recv_client(WmudClient *client)
guchar c = (wmud_client_get_buffer(client)->str)[i];
if ((c >= 240) || (c == 1)) {
if (sloc == -1)
if (sloc == -1) {
sloc = i;
}
} else {
if (sloc != -1) {
g_string_erase(
wmud_client_get_buffer(client),
sloc,
i - sloc);
wmud_client_get_buffer(client),
sloc,
i - sloc);
sloc = -1;
}
}
}
if (sloc != -1)
if (sloc != -1) {
g_string_erase(wmud_client_get_buffer(client), sloc, -1);
}
switch (wmud_client_get_state(client))
{
switch (wmud_client_get_state(client)) {
case WMUD_CLIENT_STATE_FRESH:
state_fresh(client);
break;
case WMUD_CLIENT_STATE_PASSWAIT:
state_passwait(client);
break;
case WMUD_CLIENT_STATE_MENU:
state_menu(client);
break;
case WMUD_CLIENT_STATE_INGAME:
wmud_interpret_game_command(client);
break;
case WMUD_CLIENT_STATE_YESNO:
state_yesno(client);
break;
case WMUD_CLIENT_STATE_REGISTERING:
state_registering(client);
break;
case WMUD_CLIENT_STATE_REGEMAIL_CONFIRM:
state_regemail_confirm(client);
break;
}
g_string_erase(wmud_client_get_buffer(client), 0, -1);
for (; ((*buf2 == '\r') || (*buf2 == '\n')) && *buf2; buf2++);
if (!*buf2)
if (!*buf2) {
break;
}
} else {
if (wmud_client_get_buffer_length(client) > 0)
if (wmud_client_get_buffer_length(client) > 0) {
g_string_append(wmud_client_get_buffer(client), buf2);
else
} else {
g_string_overwrite(wmud_client_get_buffer(client), 0, buf2);
}
break;
}
@ -222,14 +235,14 @@ recv_client(WmudClient *client)
* Return value: this function always returns %TRUE
*/
gboolean
game_source_callback(GSocket *socket,
GIOCondition condition,
game_source_callback(GSocket *socket,
GIOCondition condition,
struct AcceptData *accept_data)
{
GSocket *client_socket;
GError *err = NULL;
GSocket *client_socket;
GError *err = NULL;
GSocketAddress *remote_addr;
WmudClient *client;
WmudClient *client;
/* This function should never return an error. If so, it is a huge bug,
* and will trigger a higher level error. */
@ -247,19 +260,20 @@ game_source_callback(GSocket *socket,
if ((remote_addr = g_socket_get_remote_address(client_socket, &err)) != NULL) {
GInetAddress *addr;
gchar *ip_addr;
gchar *ip_addr;
addr = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(remote_addr));
addr = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(remote_addr));
ip_addr = g_inet_address_to_string(addr);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "New game connection from %s", ip_addr);
g_free(ip_addr);
g_object_unref(addr);
g_object_unref(remote_addr);
} else {
if (err)
if (err) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "New game connection. The remote address is unknown. This is a bug. Message from upper level: %s", err->message);
else
} else {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "New game connection. The remote address is unknown. This is a bug.");
}
}
g_clear_error(&err);
@ -284,34 +298,34 @@ gboolean
wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu_items, GError **err)
{
struct AcceptData *accept_data;
GSocketListener *game_listener;
gboolean need_ipv4_socket = TRUE;
GSocket *game_socket6,
*game_socket4;
GError *in_err = NULL;
GSource *game_net_source4 = NULL,
*game_net_source6 = NULL;
GSocketListener *game_listener;
gboolean need_ipv4_socket = TRUE;
GSocket *game_socket6,
*game_socket4;
GError *in_err = NULL;
GSource *game_net_source4 = NULL,
*game_net_source6 = NULL;
clients = NULL;
clients = NULL;
game_listener = g_socket_listener_new();
/* The following snippet is borrowed from GLib 2.30's gsocketlistener.c
* code, to create the necessary sockets to listen on both IPv4 and
* IPv6 address */
if ((game_socket6 = g_socket_new(G_SOCKET_FAMILY_IPV6, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL)) != NULL) {
GInetAddress *inet_address;
GInetAddress *inet_address;
GSocketAddress *address;
gboolean result;
gboolean result;
inet_address = g_inet_address_new_any(G_SOCKET_FAMILY_IPV6);
address = g_inet_socket_address_new(inet_address, port_number);
address = g_inet_socket_address_new(inet_address, port_number);
g_object_unref(inet_address);
g_socket_set_listen_backlog(game_socket6, 10);
result =
g_socket_bind(game_socket6, address, TRUE, NULL)
&& g_socket_listen(game_socket6, NULL);
g_socket_bind(game_socket6, address, TRUE, NULL) &&
g_socket_listen(game_socket6, NULL);
g_object_unref(address);
@ -322,8 +336,9 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
return FALSE;
}
if (g_socket_speaks_ipv4(game_socket6))
if (g_socket_speaks_ipv4(game_socket6)) {
need_ipv4_socket = FALSE;
}
game_net_source6 = g_socket_create_source(game_socket6, G_IO_IN, NULL);
@ -334,26 +349,27 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
if (need_ipv4_socket) {
if ((game_socket4 = g_socket_new(G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, NULL)) != NULL) {
GInetAddress *inet_address;
GInetAddress *inet_address;
GSocketAddress *address;
gboolean result;
gboolean result;
inet_address = g_inet_address_new_any(G_SOCKET_FAMILY_IPV4);
address = g_inet_socket_address_new(inet_address, port_number);
address = g_inet_socket_address_new(inet_address, port_number);
g_object_unref(inet_address);
g_socket_set_listen_backlog(game_socket4, 10);
result = g_socket_bind(game_socket4, address, TRUE, NULL)
&& g_socket_listen(game_socket4, NULL);
result = g_socket_bind(game_socket4, address, TRUE, NULL) &&
g_socket_listen(game_socket4, NULL);
g_object_unref(address);
if (!result) {
g_object_unref(game_socket4);
if (!game_socket6)
if (!game_socket6) {
g_object_unref(game_socket6);
}
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Unable to create listener IPv4 socket!\n");
@ -364,15 +380,16 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
g_socket_listener_add_socket(game_listener, game_socket4, NULL, NULL);
}
} else {
if (game_socket6 != NULL)
if (game_socket6 != NULL) {
g_clear_error(&in_err);
else
} else {
return FALSE;
}
}
accept_data = g_new(struct AcceptData, 1);
accept_data = g_new(struct AcceptData, 1);
accept_data->listener = game_listener;
accept_data->context = game_context;
accept_data->context = game_context;
if (game_net_source6) {
g_source_set_callback(game_net_source6, (GSourceFunc)game_source_callback, (gpointer)accept_data, NULL);
@ -423,12 +440,12 @@ state_fresh(WmudClient *client)
if ((player = wmud_player_exists(wmud_client_get_buffer(client)->str)) != NULL) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Trying to"
" login with playername '%s'",
wmud_client_get_buffer(client)->str);
" login with playername '%s'",
wmud_client_get_buffer(client)->str);
if (wmud_player_get_cpassword(player) == NULL) {
wmud_client_send(client, "Your registration is"
" not finished yet.\r\n");
" not finished yet.\r\n");
remove_client(client, TRUE);
} else {
wmud_client_set_state(client, WMUD_CLIENT_STATE_PASSWAIT);
@ -457,21 +474,21 @@ state_passwait(WmudClient *client)
player = wmud_client_get_player(client);
if (wmud_player_password_valid(player, wmud_client_get_buffer(client)->str)) {
gint fail_count;
gint fail_count;
GSocketAddress *socket_address;
GInetAddress *inet_address;
gchar *ip_addr;
GError *err = NULL;
GInetAddress *inet_address;
gchar *ip_addr;
GError *err = NULL;
wmud_client_send(client, "%c%c%c\r\nLogin successful."
"\r\n", TELNET_IAC, TELNET_WONT,
"\r\n", TELNET_IAC, TELNET_WONT,
TELNET_ECHO);
wmud_client_set_authenticated(client, TRUE);
socket_address = g_socket_get_remote_address(wmud_client_get_socket(client), &err);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "socket family: %d", g_socket_address_get_family(socket_address));
inet_address = g_object_ref(g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(socket_address)));
ip_addr = g_inet_address_to_string(inet_address);
ip_addr = g_inet_address_to_string(inet_address);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Login by %s from %s", wmud_player_get_player_name(player), ip_addr);
@ -480,30 +497,30 @@ state_passwait(WmudClient *client)
if ((fail_count = wmud_player_get_fail_count(player)) > 0) {
wmud_client_send(client, "There %s %d failed"
" login attempt%s with your"
" account since your last"
" visit\r\n",
(fail_count == 1) ? "was" : "were",
fail_count,
(fail_count == 1) ? "" : "s");
" login attempt%s with your"
" account since your last"
" visit\r\n",
(fail_count == 1) ? "was" : "were",
fail_count,
(fail_count == 1) ? "" : "s");
}
wmud_text_send_to_client("motd", client);
wmud_menu_present(client);
} else {
wmud_client_send(client, "%c%c%cThis password doesn't"
" seem to be valid. Let's try it again..."
" \r\nBy what name would you like to be"
" be called? ", TELNET_IAC,
TELNET_WONT, TELNET_ECHO);
" seem to be valid. Let's try it again..."
" \r\nBy what name would you like to be"
" be called? ", TELNET_IAC,
TELNET_WONT, TELNET_ECHO);
wmud_client_set_state(client, WMUD_CLIENT_STATE_FRESH);
wmud_player_increase_fail_count(player);
wmud_client_increase_login_fail_count(client);
if (wmud_client_get_login_fail_count(client) == 3) {
wmud_client_send(client, "You are trying "
" these bad passwords for"
" too many times. Please"
" stop that!\r\n");
" these bad passwords for"
" too many times. Please"
" stop that!\r\n");
remove_client(client, TRUE);
/* TODO: Increase IP fail count, and ban IP if it's too high */
@ -515,7 +532,7 @@ state_passwait(WmudClient *client)
}
} else {
wmud_client_send(client, "\r\nEmpty passwords are"
" not valid.\r\nTry again: ");
" not valid.\r\nTry again: ");
}
}
@ -524,51 +541,55 @@ state_menu(WmudClient *client)
{
gchar *menu_command;
if ((menu_command = wmud_menu_get_command_by_menuchar(*(wmud_client_get_buffer(client)->str), game_menu)) != NULL)
if ((menu_command = wmud_menu_get_command_by_menuchar(*(wmud_client_get_buffer(client)->str), game_menu)) != NULL) {
wmud_menu_execute_command(client, menu_command);
else
} else {
wmud_client_send(client, "Unknown menu command.\r\n");
}
}
static void
state_yesno(WmudClient *client)
{
if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "y") == 0)
if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "y") == 0) {
(wmud_client_get_yesno_callback(client))(client, TRUE);
else if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "n") == 0)
} else if (g_ascii_strcasecmp(wmud_client_get_buffer(client)->str, "n") == 0) {
(wmud_client_get_yesno_callback(client))(client, FALSE);
else
} else {
wmud_client_send(client, "Please enter a 'Y' or 'N'"
" character: ");
" character: ");
}
}
static void
state_registering(WmudClient *client)
{
if (!*(wmud_client_get_buffer(client)->str) && (wmud_client_get_bademail(client) == TRUE))
if (!*(wmud_client_get_buffer(client)->str) && (wmud_client_get_bademail(client) == TRUE)) {
remove_client(client, TRUE);
}
if (g_regex_match(email_regex, wmud_client_get_buffer(client)->str, 0, NULL)) {
wmud_player_set_email(wmud_client_get_player(client), wmud_client_get_buffer(client)->str);
wmud_client_set_state(client, WMUD_CLIENT_STATE_REGEMAIL_CONFIRM);
wmud_client_send(client, "It seems to be a valid"
" address to me, but could you"
" write it again? ");
" address to me, but could you"
" write it again? ");
} else {
wmud_client_send(client, "\r\nSorry, but this"
"e-mail address doesn't seem to be"
" valid to me.\r\n\r\nIf you think"
" this is a valid address, simply"
" press enter to quit, and send an"
" e-mail to %s from that address,"
" so we can fix our e-mail"
" validation code.\r\n\r\nIf you"
" just mistyped your address, type"
" it now: ",
active_config->admin_email);
"e-mail address doesn't seem to be"
" valid to me.\r\n\r\nIf you think"
" this is a valid address, simply"
" press enter to quit, and send an"
" e-mail to %s from that address,"
" so we can fix our e-mail"
" validation code.\r\n\r\nIf you"
" just mistyped your address, type"
" it now: ",
active_config->admin_email);
if (*(wmud_client_get_buffer(client)->str))
if (*(wmud_client_get_buffer(client)->str)) {
wmud_client_set_bademail(client, TRUE);
}
}
}
@ -594,4 +615,3 @@ state_regemail_confirm(WmudClient *client)
wmud_client_set_state(client, WMUD_CLIENT_STATE_REGISTERING);
}
}

View File

@ -106,12 +106,12 @@ gboolean
wmud_game_init(GThread **game_thread, GMainContext **game_context)
{
GMainLoop *game_loop;
GSource *timeout_source;
GError *err = NULL;
GSource *timeout_source;
GError *err = NULL;
/* Create the game context and main loop */
*game_context = g_main_context_new();
game_loop = g_main_loop_new(*game_context, FALSE);
game_loop = g_main_loop_new(*game_context, FALSE);
/* Create the timeout source which keeps track of elapsed real-world
* time */

View File

@ -35,20 +35,20 @@
WMUD_COMMAND(quit);
struct findData {
GSList *list;
guint found;
gchar *last;
GSList *list;
guint found;
gchar *last;
};
static wmudCommand command_list[] = {
{ "quit", gcmd_quit },
{ NULL, NULL },
{ "quit", gcmd_quit },
{ NULL, NULL },
};
GQuark
wmud_interpreter_error_quark()
{
return g_quark_from_static_string("wmud-interpreter-error");
return g_quark_from_static_string("wmud-interpreter-error");
}
/**
@ -60,56 +60,60 @@ wmud_interpreter_error_quark()
static void
destroy_string(GString *string)
{
g_string_free(string, TRUE);
g_string_free(string, TRUE);
}
static gint
check_direction_dups2(wmudDirection *dir1, wmudDirection *dir2)
{
gint check;
gint check;
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->short_name)) != 0)
return check;
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->short_name)) != 0) {
return check;
}
if ((check = g_ascii_strcasecmp(dir1->name, dir2->name)) != 0)
return check;
if ((check = g_ascii_strcasecmp(dir1->name, dir2->name)) != 0) {
return check;
}
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->name)) != 0)
return check;
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->name)) != 0) {
return check;
}
return g_ascii_strcasecmp(dir1->name, dir2->short_name);
return g_ascii_strcasecmp(dir1->name, dir2->short_name);
}
static void
check_direction_dups1(wmudDirection *dir, struct findData *find_data)
{
if (find_data->last != dir->name) {
find_data->found = (find_data->found > 1) ? find_data->found : 0;
find_data->last = dir->name;
}
if (find_data->last != dir->name) {
find_data->found = (find_data->found > 1) ? find_data->found : 0;
find_data->last = dir->name;
}
if (g_slist_find_custom(find_data->list, dir, (GCompareFunc)check_direction_dups2))
find_data->found++;
if (g_slist_find_custom(find_data->list, dir, (GCompareFunc)check_direction_dups2)) {
find_data->found++;
}
}
static void
check_direction_command(wmudDirection *dir, gboolean *found)
{
wmudCommand *cmd;
wmudCommand *cmd;
for (cmd = command_list; cmd->command; cmd++) {
if (g_ascii_strcasecmp(dir->short_name, cmd->command) == 0) {
*found = TRUE;
for (cmd = command_list; cmd->command; cmd++) {
if (g_ascii_strcasecmp(dir->short_name, cmd->command) == 0) {
*found = TRUE;
return;
}
return;
}
if (g_ascii_strcasecmp(dir->name, cmd->command) == 0) {
*found = TRUE;
if (g_ascii_strcasecmp(dir->name, cmd->command) == 0) {
*found = TRUE;
return;
}
}
return;
}
}
}
/**
@ -124,26 +128,26 @@ check_direction_command(wmudDirection *dir, gboolean *found)
gboolean
wmud_interpreter_check_directions(GSList *directions, GError **err)
{
gboolean command_found = FALSE;
struct findData find_data = {directions, 0, NULL};
gboolean command_found = FALSE;
struct findData find_data = {directions, 0, NULL};
g_slist_foreach(directions, (GFunc)check_direction_command, &command_found);
g_slist_foreach(directions, (GFunc)check_direction_command, &command_found);
if (command_found) {
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands are not unique. Please check the database!");
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction command are not unique. Please check the database!");
}
if (command_found) {
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands are not unique. Please check the database!");
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction command are not unique. Please check the database!");
}
g_slist_foreach(directions, (GFunc)check_direction_dups1, &find_data);
g_slist_foreach(directions, (GFunc)check_direction_dups1, &find_data);
if (find_data.found > 1) {
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands defined in the database are not unique!");
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction commands defined in the databsae are not unique.");
if (find_data.found > 1) {
g_set_error(err, WMUD_INTERPRETER_ERROR, WMUD_INTERPRETER_ERROR_DUPCMD, "Direction commands defined in the database are not unique!");
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Direction commands defined in the databsae are not unique.");
return FALSE;
}
return FALSE;
}
return !command_found;
return !command_found;
}
/**
@ -156,122 +160,128 @@ wmud_interpreter_check_directions(GSList *directions, GError **err)
void
wmud_interpret_game_command(WmudClient *client)
{
GSList *command_parts = NULL;
gchar *a,
*start,
*end;
gchar str_delim = 0;
wmudCommand *cmd;
int command_parts_count = 0,
match_count = 0;
GSList *matches = NULL;
GSList *command_parts = NULL;
gchar *a,
*start,
*end;
gchar str_delim = 0;
wmudCommand *cmd;
int command_parts_count = 0,
match_count = 0;
GSList *matches = NULL;
if (strchr(wmud_client_get_buffer(client)->str, '\r') || strchr(wmud_client_get_buffer(client)->str, '\n')) {
/* We should NEVER reach this point! */
g_assert_not_reached();
if (strchr(wmud_client_get_buffer(client)->str, '\r') || strchr(wmud_client_get_buffer(client)->str, '\n')) {
/* We should NEVER reach this point! */
g_assert_not_reached();
return;
}
return;
}
a = wmud_client_get_buffer(client)->str;
a = wmud_client_get_buffer(client)->str;
GString *token;
GString *token;
while (*a) {
for (start = a; *start; start++) {
if (!str_delim) {
if ((*start == '"') || (*start == '\'')) {
str_delim = *start;
start++;
while (*a) {
for (start = a; *start; start++) {
if (!str_delim) {
if ((*start == '"') || (*start == '\'')) {
str_delim = *start;
start++;
break;
} else if (g_ascii_isspace(*start) || (!*start)) {
break;
}
}
}
break;
} else if (g_ascii_isspace(*start) || (!*start)) {
break;
}
}
}
for (end = start; *end; end++) {
if (!str_delim && strchr("'\" \t", *end)) {
break;
} else if (str_delim && (*end == str_delim)) {
str_delim = 0;
for (end = start; *end; end++) {
if (!str_delim && strchr("'\" \t", *end)) {
break;
} else if (str_delim && (*end == str_delim)) {
str_delim = 0;
break;
} else if (!*end) {
break;
}
}
break;
} else if (!*end) {
break;
}
}
if (*start) {
token = g_string_new_len(start, end - start);
command_parts = g_slist_prepend(command_parts, token);
command_parts_count++;
}
if (*start) {
token = g_string_new_len(start, end - start);
command_parts = g_slist_prepend(command_parts, token);
command_parts_count++;
}
a = end;
if (((*a == '"') || (*a == '\'')) && str_delim)
a++;
}
a = end;
if (((*a == '"') || (*a == '\'')) && str_delim) {
a++;
}
}
if (str_delim) {
wmud_client_send(client, "You should close quotes of any kind, like %c, shouldn't you?\r\n", str_delim);
if (str_delim) {
wmud_client_send(client, "You should close quotes of any kind, like %c, shouldn't you?\r\n", str_delim);
#if GLIB_CHECK_VERSION(2, 28, 0)
g_slist_free_full(command_parts, (GDestroyNotify)destroy_string);
g_slist_free_full(command_parts, (GDestroyNotify)destroy_string);
#else
g_slist_foreach(command_parts, (GFunc)destroy_string, NULL);
g_slist_free(command_parts);
g_slist_foreach(command_parts, (GFunc)destroy_string, NULL);
g_slist_free(command_parts);
#endif
return;
}
return;
}
if (command_parts_count == 0) {
/* TODO: handle empty command */
if (command_parts_count == 0) {
/* TODO: handle empty command */
return;
}
return;
}
command_parts = g_slist_reverse(command_parts);
command_parts = g_slist_reverse(command_parts);
for (cmd = command_list; cmd->command; cmd++) {
GString *input = (GString *)(command_parts->data);
gint cmp;
for (cmd = command_list; cmd->command; cmd++) {
GString *input = (GString *)(command_parts->data);
gint cmp;
if (((cmp = g_ascii_strncasecmp(input->str, cmd->command, input->len)) == 0) && !cmd->command[input->len]) {
g_slist_free(matches);
match_count = 1;
matches = NULL;
matches = g_slist_prepend(matches, cmd);
if (((cmp = g_ascii_strncasecmp(input->str, cmd->command, input->len)) == 0) && !cmd->command[input->len]) {
g_slist_free(matches);
match_count = 1;
matches = NULL;
matches = g_slist_prepend(matches, cmd);
break;
} else if (cmp == 0) {
matches = g_slist_prepend(matches, cmd);
match_count++;
}
}
break;
} else if (cmp == 0) {
matches = g_slist_prepend(matches, cmd);
match_count++;
}
}
switch (match_count) {
case 0:
switch (random_number(1, 3)) {
case 1:
wmud_client_send(client, "Huh?\r\n");
break;
case 2:
wmud_client_send(client, "What?\r\n");
break;
case 3:
wmud_client_send(client, "I can hardly understand you...\r\n");
break;
}
break;
case 1:
((wmudCommand *)(matches->data))->commandFunc(client, ((GString *)(command_parts->data))->str, command_parts->next);
break;
default:
wmud_client_send(client, "This command could mean several things, please try a more exact form!\r\n");
}
switch (match_count) {
case 0:
switch (random_number(1, 3)) {
case 1:
wmud_client_send(client, "Huh?\r\n");
g_slist_free(matches);
break;
case 2:
wmud_client_send(client, "What?\r\n");
break;
case 3:
wmud_client_send(client, "I can hardly understand you...\r\n");
break;
}
break;
case 1:
((wmudCommand *)(matches->data))->commandFunc(client, ((GString *)(command_parts->data))->str, command_parts->next);
break;
default:
wmud_client_send(client, "This command could mean several things, please try a more exact form!\r\n");
}
g_slist_free(matches);
}
/**
@ -281,7 +291,7 @@ wmud_interpret_game_command(WmudClient *client)
*/
WMUD_COMMAND(quit)
{
wmud_client_send(client, "Are you sure you want to get back to that freaky other reality? [y/N] ");
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
wmud_client_send(client, "Are you sure you want to get back to that freaky other reality? [y/N] ");
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
}

View File

@ -53,7 +53,7 @@
*/
struct {
char *file;
int line;
int line;
} debug_context_loc = {NULL, 0};
/**
@ -66,15 +66,16 @@ gchar *
wmud_random_string(gint len)
{
gchar *ret = g_malloc0(len + 1);
gint i;
gint i;
for (i = 0; i < len; i++) {
gchar c = 0;
/* Include only printable characters, but exclude $ because of
* salt generation, and space to avoid misunderstanding in the
* random generated passwords */
while (!g_ascii_isprint(c) || (c == '$') || (c == ' ') || (c == '\t'))
while (!g_ascii_isprint(c) || (c == '$') || (c == ' ') || (c == '\t')) {
c = random_number(1, 127);
}
ret[i] = c;
}
@ -97,8 +98,9 @@ void
*/
debug_context(char *file, int line)
{
if (debug_context_loc.file != NULL)
if (debug_context_loc.file != NULL) {
g_free(debug_context_loc.file);
}
debug_context_loc.file = g_strdup(file);
debug_context_loc.line = line;
@ -125,19 +127,19 @@ wmud_type_init(void)
{}
void
wmud_logger(const gchar *log_domain,
wmud_logger(const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
const gchar *message,
gpointer user_data)
{
static char timestamp[20];
struct tm *tm;
time_t ts = time(NULL);
size_t last_char;
struct tm *tm;
time_t ts = time(NULL);
size_t last_char;
tm = localtime(&ts);
last_char = strftime((char *)&timestamp, 20, "%F %T", tm);
last_char = strftime((char *)&timestamp, 20, "%F %T", tm);
timestamp[last_char] = '\0';
switch (log_level) {
@ -200,12 +202,12 @@ wmud_logger(const gchar *log_domain,
int
main(int argc, char **argv)
{
GError *err = NULL;
GThread *game_thread;
GError *err = NULL;
GThread *game_thread;
GMainContext *game_context;
GSList *game_menu = NULL;
GSList *game_menu = NULL;
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK , wmud_logger, NULL);
g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_MASK, wmud_logger, NULL);
/* Initialize the thread and type system */
wmud_type_init();

View File

@ -52,30 +52,30 @@
void
wmud_maintenance_check_players(WmudPlayer *player, gpointer user_data)
{
if (wmud_player_get_cpassword(player) == NULL) {
gchar *pw,
*salt,
*cpw;
GString *full_salt;
if (wmud_player_get_cpassword(player) == NULL) {
gchar *pw,
*salt,
*cpw;
GString *full_salt;
pw = wmud_random_string(8);
salt = wmud_random_string(8);
full_salt = g_string_new("$1$");
g_string_append(full_salt, salt);
cpw = g_strdup(crypt(pw, full_salt->str));
pw = wmud_random_string(8);
salt = wmud_random_string(8);
full_salt = g_string_new("$1$");
g_string_append(full_salt, salt);
cpw = g_strdup(crypt(pw, full_salt->str));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Player %s has no"
" password set", wmud_player_get_player_name(player));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "New password will be %s", pw);
wmud_player_set_cpassword(player, cpw);
/* TODO: Send e-mail about the new password. Upon completion, set it in
* the database */
wmud_db_update_player_password(player, cpw, NULL);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Player %s has no"
" password set", wmud_player_get_player_name(player));
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "New password will be %s", pw);
wmud_player_set_cpassword(player, cpw);
/* TODO: Send e-mail about the new password. Upon completion, set it in
* the database */
wmud_db_update_player_password(player, cpw, NULL);
g_free(pw);
g_free(salt);
g_string_free(full_salt, TRUE);
}
g_free(pw);
g_free(salt);
g_string_free(full_salt, TRUE);
}
}
/**
@ -87,14 +87,14 @@ wmud_maintenance_check_players(WmudPlayer *player, gpointer user_data)
gboolean
wmud_maintenance(gpointer user_data)
{
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Starting maintenance...");
/* Run through the player list, and generate a random password for each
* newly registered player */
g_slist_foreach(players, (GFunc)wmud_maintenance_check_players, NULL);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Starting maintenance...");
/* Run through the player list, and generate a random password for each
* newly registered player */
g_slist_foreach(players, (GFunc)wmud_maintenance_check_players, NULL);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Finished maintenance...");
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Finished maintenance...");
return TRUE;
return TRUE;
}
/**
@ -108,102 +108,106 @@ wmud_maintenance(gpointer user_data)
gpointer
maint_thread_func(GMainLoop *maint_loop)
{
g_main_loop_run(maint_loop);
g_main_loop_run(maint_loop);
return NULL;
return NULL;
}
const char *text[] = {
"To: Polonkai Gergely <polonkai.gergely@brokernet-group.com>\n",
"Subject: Teszt\n",
"\n",
"Hello!\n"
"To: Polonkai Gergely <polonkai.gergely@brokernet-group.com>\n",
"Subject: Teszt\n",
"\n",
"Hello!\n"
};
struct WriteThis {
int counter;
int counter;
};
static size_t
wmud_smtp_read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
{
struct WriteThis *pooh = (struct WriteThis *)userp;
const char *data;
struct WriteThis *pooh = (struct WriteThis *)userp;
const char *data;
if (size * nmemb < 1)
return 0;
if (size * nmemb < 1) {
return 0;
}
data = text[pooh->counter];
data = text[pooh->counter];
if (data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
pooh->counter++;
return len;
}
if (data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
pooh->counter++;
return 0;
return len;
}
return 0;
}
void
wmud_maintenance_init(void)
{
GSource *timeout_source;
GMainLoop *maint_loop;
GMainContext *maint_context;
CURL *curl;
CURLM *mcurl;
gchar *smtp_server_real;
struct WriteThis pooh = {0};
GSource *timeout_source;
GMainLoop *maint_loop;
GMainContext *maint_context;
CURL *curl;
CURLM *mcurl;
gchar *smtp_server_real;
struct WriteThis pooh = {0};
curl_global_init(CURL_GLOBAL_DEFAULT);
curl_global_init(CURL_GLOBAL_DEFAULT);
if (!(curl = curl_easy_init()))
g_error("Could not initialize the CURL library!");
if (!(curl = curl_easy_init())) {
g_error("Could not initialize the CURL library!");
}
if (!(mcurl = curl_multi_init()))
g_error("Could not initialize the CURL library!");
if (!(mcurl = curl_multi_init())) {
g_error("Could not initialize the CURL library!");
}
smtp_server_real = g_strconcat("smtp://", active_config->smtp_server, NULL);
curl_easy_setopt(curl, CURLOPT_URL, smtp_server_real);
g_free(smtp_server_real);
smtp_server_real = g_strconcat("smtp://", active_config->smtp_server, NULL);
curl_easy_setopt(curl, CURLOPT_URL, smtp_server_real);
g_free(smtp_server_real);
if (active_config->smtp_username && active_config->smtp_password) {
curl_easy_setopt(curl, CURLOPT_USERNAME, active_config->smtp_username);
curl_easy_setopt(curl, CURLOPT_PASSWORD, active_config->smtp_password);
}
if (active_config->smtp_username && active_config->smtp_password) {
curl_easy_setopt(curl, CURLOPT_USERNAME, active_config->smtp_username);
curl_easy_setopt(curl, CURLOPT_PASSWORD, active_config->smtp_password);
}
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, active_config->smtp_sender);
curl_easy_setopt(curl, CURLOPT_USE_SSL, (CURLUSESSL_ALL && active_config->smtp_tls));
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, active_config->smtp_sender);
curl_easy_setopt(curl, CURLOPT_USE_SSL, (CURLUSESSL_ALL && active_config->smtp_tls));
/* TODO: Maybe these could go into the configuration as well */
/* TODO: Maybe these could go into the configuration as well */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
#ifdef DEBUG
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
#else
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
#endif
curl_easy_setopt(curl, CURLOPT_READFUNCTION, wmud_smtp_read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, &pooh);
curl_multi_add_handle(mcurl, curl);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, wmud_smtp_read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, &pooh);
curl_multi_add_handle(mcurl, curl);
/* Create the maintenance context and main loop */
maint_context = g_main_context_new();
maint_loop = g_main_loop_new(maint_context, FALSE);
/* Create the maintenance context and main loop */
maint_context = g_main_context_new();
maint_loop = g_main_loop_new(maint_context, FALSE);
/* Create the timeout source which will do the maintenance tasks */
timeout_source = g_timeout_source_new_seconds(WMUD_MAINTENANCE_TIME);
g_source_set_callback(timeout_source, wmud_maintenance, NULL, NULL);
g_source_attach(timeout_source, maint_context);
g_source_unref(timeout_source);
/* Create the timeout source which will do the maintenance tasks */
timeout_source = g_timeout_source_new_seconds(WMUD_MAINTENANCE_TIME);
g_source_set_callback(timeout_source, wmud_maintenance, NULL, NULL);
g_source_attach(timeout_source, maint_context);
g_source_unref(timeout_source);
#if GLIB_CHECK_VERSION(2, 32, 0)
g_thread_new("maintenance", (GThreadFunc)maint_thread_func, maint_loop);
g_thread_new("maintenance", (GThreadFunc)maint_thread_func, maint_loop);
#else
g_thread_create((GThreadFunc)maint_thread_func, maint_loop, TRUE, NULL);
g_thread_create((GThreadFunc)maint_thread_func, maint_loop, TRUE, NULL);
#endif
}

View File

@ -46,98 +46,103 @@ GSList *game_menu = NULL;
GQuark
wmud_menu_error_quark()
{
return g_quark_from_static_string("wmud-menu-error");
return g_quark_from_static_string("wmud-menu-error");
}
gboolean
wmud_menu_items_check(GSList *menu_items, GError **err)
{
/* TODO: Check for duplicate menuchars */
/* TODO: Check for duplicate menu texts */
/* TODO: Check for duplicate placements */
/* TODO: Check for duplicate menuchars */
/* TODO: Check for duplicate menu texts */
/* TODO: Check for duplicate placements */
return TRUE;
return TRUE;
}
void
menu_item_free(wmudMenu *menu_item)
{
if (menu_item->text)
g_free(menu_item->text);
if (menu_item->text) {
g_free(menu_item->text);
}
if (menu_item->display_text)
g_free(menu_item->display_text);
if (menu_item->display_text) {
g_free(menu_item->display_text);
}
if (menu_item->display_text_ansi)
g_free(menu_item->display_text_ansi);
if (menu_item->display_text_ansi) {
g_free(menu_item->display_text_ansi);
}
if (menu_item->func)
g_free(menu_item->func);
if (menu_item->func) {
g_free(menu_item->func);
}
g_free(menu_item);
g_free(menu_item);
}
void
wmud_menu_items_free(GSList **menu_items)
{
if (menu_items)
{
if (menu_items) {
#if GLIB_CHECK_VERSION(2, 28, 0)
g_slist_free_full(*menu_items, (GDestroyNotify)menu_item_free);
g_slist_free_full(*menu_items, (GDestroyNotify)menu_item_free);
#else
g_slist_foreach(*menu_items, (GFunc)menu_item_free, NULL);
g_slist_free(*menu_items);
g_slist_foreach(*menu_items, (GFunc)menu_item_free, NULL);
g_slist_free(*menu_items);
#endif
*menu_items = NULL;
}
*menu_items = NULL;
}
}
void
menu_item_prepare(wmudMenu *item, GHashTable *cmdtable)
{
gchar m1, m2;
gchar *a,
*found = NULL;
GString *ds, *dsa;
gchar m1, m2;
gchar *a,
*found = NULL;
GString *ds, *dsa;
g_debug("Preparing menu item %s", item->text);
m1 = g_ascii_tolower(item->menuchar);
m2 = g_ascii_toupper(item->menuchar);
for (a = item->text; *a; a++)
if ((*a == m1) || (*a == m2)) {
found = a;
break;
}
g_debug("Preparing menu item %s", item->text);
m1 = g_ascii_tolower(item->menuchar);
m2 = g_ascii_toupper(item->menuchar);
for (a = item->text; *a; a++) {
if ((*a == m1) || (*a == m2)) {
found = a;
if (found) {
gchar *tmp;
break;
}
}
tmp = g_ascii_strdown(item->text, -1);
ds = g_string_new(tmp);
dsa = g_string_new(tmp);
g_free(tmp);
if (found) {
gchar *tmp;
ds->str[found - item->text] = g_ascii_toupper(item->menuchar);
dsa->str[found - item->text] = g_ascii_toupper(item->menuchar);
} else {
found = item->text;
ds = g_string_new(item->text);
dsa = g_string_new(item->text);
tmp = g_ascii_strdown(item->text, -1);
ds = g_string_new(tmp);
dsa = g_string_new(tmp);
g_free(tmp);
g_string_prepend_c(ds, ' ');
g_string_prepend_c(ds, g_ascii_toupper(item->menuchar));
g_string_prepend_c(dsa, ' ');
g_string_prepend_c(dsa, g_ascii_toupper(item->menuchar));
}
ds->str[found - item->text] = g_ascii_toupper(item->menuchar);
dsa->str[found - item->text] = g_ascii_toupper(item->menuchar);
} else {
found = item->text;
ds = g_string_new(item->text);
dsa = g_string_new(item->text);
g_string_insert_c(ds, found - item->text, '(');
g_string_insert_c(ds, found - item->text + 2, ')');
g_string_prepend_c(ds, ' ');
g_string_prepend_c(ds, g_ascii_toupper(item->menuchar));
g_string_prepend_c(dsa, ' ');
g_string_prepend_c(dsa, g_ascii_toupper(item->menuchar));
}
g_string_insert(dsa, found - item->text, "\x1b[31;1m");
g_string_insert(dsa, found - item->text + 8, "\x1b[0m");
item->display_text = g_string_free(ds, FALSE);
item->display_text_ansi = g_string_free(dsa, FALSE);
g_string_insert_c(ds, found - item->text, '(');
g_string_insert_c(ds, found - item->text + 2, ')');
g_string_insert(dsa, found - item->text, "\x1b[31;1m");
g_string_insert(dsa, found - item->text + 8, "\x1b[0m");
item->display_text = g_string_free(ds, FALSE);
item->display_text_ansi = g_string_free(dsa, FALSE);
}
WMUD_MENU_COMMAND(enter_world)
@ -190,117 +195,120 @@ WMUD_MENU_COMMAND(change_name)
WMUD_MENU_COMMAND(quit)
{
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
wmud_client_send(client, "Are you sure you want to get back to the real world? [y/N] ");
wmud_client_set_state(client, WMUD_CLIENT_STATE_YESNO);
wmud_client_set_yesno_callback(client, wmud_client_quitanswer);
wmud_client_send(client, "Are you sure you want to get back to the real world? [y/N] ");
}
WMUD_MENU_COMMAND(redisplay_menu)
{
wmud_menu_present(client);
wmud_menu_present(client);
}
gboolean
wmud_menu_init(GSList **menu)
{
GSList *menu_items = NULL;
GError *in_err = NULL;
GHashTable *cmdtable;
GSList *menu_items = NULL;
GError *in_err = NULL;
GHashTable *cmdtable;
if (!wmud_db_load_menu(&menu_items, &in_err)) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Unable to load menu items from the database: %s", in_err->message);
wmud_menu_items_free(&menu_items);
if (!wmud_db_load_menu(&menu_items, &in_err)) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Unable to load menu items from the database: %s", in_err->message);
wmud_menu_items_free(&menu_items);
return FALSE;
}
return FALSE;
}
if (!menu_items) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "No menu items were found in the database!");
if (!menu_items) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "No menu items were found in the database!");
return FALSE;
}
return FALSE;
}
if (!wmud_menu_items_check(menu_items, &in_err)) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Menu items pre-flight check error: %s", in_err->message);
wmud_menu_items_free(&menu_items);
if (!wmud_menu_items_check(menu_items, &in_err)) {
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "Menu items pre-flight check error: %s", in_err->message);
wmud_menu_items_free(&menu_items);
return FALSE;
}
return FALSE;
}
if (*menu)
wmud_menu_items_free(menu);
if (*menu) {
wmud_menu_items_free(menu);
}
*menu = menu_items;
*menu = menu_items;
cmdtable = g_hash_table_new(g_str_hash, g_str_equal);
cmdtable = g_hash_table_new(g_str_hash, g_str_equal);
g_slist_foreach(*menu, (GFunc)menu_item_prepare, cmdtable);
g_slist_foreach(*menu, (GFunc)menu_item_prepare, cmdtable);
g_hash_table_insert(cmdtable, "enter-world", wmud_mcmd_enter_world);
g_hash_table_insert(cmdtable, "change-password", wmud_mcmd_change_password);
g_hash_table_insert(cmdtable, "toggle-colour", wmud_mcmd_toggle_colour);
g_hash_table_insert(cmdtable, "documentation", wmud_mcmd_documentation);
g_hash_table_insert(cmdtable, "caracter-select", wmud_mcmd_character_select);
g_hash_table_insert(cmdtable, "character-create", wmud_mcmd_character_create);
g_hash_table_insert(cmdtable, "character-delete", wmud_mcmd_character_delete);
g_hash_table_insert(cmdtable, "chat", wmud_mcmd_chat);
g_hash_table_insert(cmdtable, "player-mail", wmud_mcmd_player_mail);
g_hash_table_insert(cmdtable, "colour-test", wmud_mcmd_colour_test);
g_hash_table_insert(cmdtable, "change-email", wmud_mcmd_change_email);
g_hash_table_insert(cmdtable, "change-name", wmud_mcmd_change_name);
g_hash_table_insert(cmdtable, "quit", wmud_mcmd_quit);
g_hash_table_insert(cmdtable, "redisplay-menu", wmud_mcmd_redisplay_menu);
g_hash_table_insert(cmdtable, "enter-world", wmud_mcmd_enter_world);
g_hash_table_insert(cmdtable, "change-password", wmud_mcmd_change_password);
g_hash_table_insert(cmdtable, "toggle-colour", wmud_mcmd_toggle_colour);
g_hash_table_insert(cmdtable, "documentation", wmud_mcmd_documentation);
g_hash_table_insert(cmdtable, "caracter-select", wmud_mcmd_character_select);
g_hash_table_insert(cmdtable, "character-create", wmud_mcmd_character_create);
g_hash_table_insert(cmdtable, "character-delete", wmud_mcmd_character_delete);
g_hash_table_insert(cmdtable, "chat", wmud_mcmd_chat);
g_hash_table_insert(cmdtable, "player-mail", wmud_mcmd_player_mail);
g_hash_table_insert(cmdtable, "colour-test", wmud_mcmd_colour_test);
g_hash_table_insert(cmdtable, "change-email", wmud_mcmd_change_email);
g_hash_table_insert(cmdtable, "change-name", wmud_mcmd_change_name);
g_hash_table_insert(cmdtable, "quit", wmud_mcmd_quit);
g_hash_table_insert(cmdtable, "redisplay-menu", wmud_mcmd_redisplay_menu);
/* TODO: Free previous hash table, if exists */
mcmd_table = cmdtable;
/* TODO: Free previous hash table, if exists */
mcmd_table = cmdtable;
return TRUE;
return TRUE;
}
static gint
find_by_menuchar(wmudMenu *item, gchar *menuchar)
{
if (g_ascii_toupper(*menuchar) == g_ascii_toupper(item->menuchar))
return 0;
if (g_ascii_toupper(*menuchar) == g_ascii_toupper(item->menuchar)) {
return 0;
}
return 1;
return 1;
}
gchar *
wmud_menu_get_command_by_menuchar(gchar menuchar, GSList *game_menu)
{
GSList *item;
GSList *item;
if ((item = g_slist_find_custom(game_menu, &menuchar, (GCompareFunc)find_by_menuchar)) != NULL)
return ((wmudMenu *)(item->data))->func;
if ((item = g_slist_find_custom(game_menu, &menuchar, (GCompareFunc)find_by_menuchar)) != NULL) {
return ((wmudMenu *)(item->data))->func;
}
return NULL;
return NULL;
}
void
wmud_menu_execute_command(WmudClient *client, gchar *command)
{
wmudMenuCommandFunc func;
wmudMenuCommandFunc func;
if ((func = g_hash_table_lookup(mcmd_table, command)) == NULL)
wmud_client_send(client, "Unknown menu command.\r\n");
else
func(client);
if ((func = g_hash_table_lookup(mcmd_table, command)) == NULL) {
wmud_client_send(client, "Unknown menu command.\r\n");
} else {
func(client);
}
}
void
send_menu_item(wmudMenu *item, WmudClient *client)
{
/* TODO: Send ANSI menu item only to ANSI players! */
wmud_client_send(client, "%s\r\n", item->display_text_ansi);
/* TODO: Send ANSI menu item only to ANSI players! */
wmud_client_send(client, "%s\r\n", item->display_text_ansi);
}
void
wmud_menu_present(WmudClient *client)
{
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
wmud_client_set_state(client, WMUD_CLIENT_STATE_MENU);
g_slist_foreach(game_menu, (GFunc)send_menu_item, client);
wmud_client_set_state(client, WMUD_CLIENT_STATE_MENU);
/* TODO: send menu prologue */
/* TODO: send menu prologue */
}

View File

@ -45,7 +45,7 @@ GSList *players = NULL;
static gint
find_player_by_name(WmudPlayer *player, gchar *player_name)
{
return g_ascii_strcasecmp(wmud_player_get_player_name(player), player_name);
return g_ascii_strcasecmp(wmud_player_get_player_name(player), player_name);
}
/**
@ -60,12 +60,11 @@ find_player_by_name(WmudPlayer *player, gchar *player_name)
WmudPlayer *
wmud_player_exists(gchar *player_name)
{
GSList *player_elem;
GSList *player_elem;
if ((player_elem = g_slist_find_custom(players, player_name, (GCompareFunc)find_player_by_name)) == NULL)
return NULL;
return player_elem->data;
if ((player_elem = g_slist_find_custom(players, player_name, (GCompareFunc)find_player_by_name)) == NULL) {
return NULL;
}
return player_elem->data;
}

View File

@ -24,62 +24,65 @@
#include "wmudclient.h"
static const gchar *text_files[] = {
"motd",
NULL
"motd",
NULL
};
GHashTable *text_table = NULL;
GHashTable *text_table = NULL;
void
wmud_texts_init(void)
{
int i;
gchar *texts_dir = g_strconcat(WMUD_STATEDIR, "/texts/", NULL);
int i;
gchar *texts_dir = g_strconcat(WMUD_STATEDIR, "/texts/", NULL);
text_table = g_hash_table_new(g_str_hash, g_str_equal);
text_table = g_hash_table_new(g_str_hash, g_str_equal);
for (i = 0; i < g_strv_length((gchar **)text_files); i++) {
GFile *tf;
GFileInfo *tfi;
GError *err = NULL;
guint64 tfs;
gchar *contents;
gsize length;
for (i = 0; i < g_strv_length((gchar **)text_files); i++) {
GFile *tf;
GFileInfo *tfi;
GError *err = NULL;
guint64 tfs;
gchar *contents;
gsize length;
gchar *text_file = g_strconcat(texts_dir, text_files[i], NULL);
gchar *text_file = g_strconcat(texts_dir, text_files[i], NULL);
g_debug("Loading text file %s from %s", text_files[i], text_file);
tf = g_file_new_for_path(text_file);
tfi = g_file_query_info(tf, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &err);
g_debug("Loading text file %s from %s", text_files[i], text_file);
tf = g_file_new_for_path(text_file);
tfi = g_file_query_info(tf, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &err);
if (err) {
g_warning("Error loading %s: %s", text_files[i], err->message);
continue;
}
if (err) {
g_warning("Error loading %s: %s", text_files[i], err->message);
tfs = g_file_info_get_attribute_uint64(tfi, G_FILE_ATTRIBUTE_STANDARD_SIZE);
continue;
}
contents = g_malloc0(tfs + 1);
tfs = g_file_info_get_attribute_uint64(tfi, G_FILE_ATTRIBUTE_STANDARD_SIZE);
g_clear_error(&err);
contents = g_malloc0(tfs + 1);
if (!g_file_load_contents(tf, NULL, &contents, &length, NULL, &err)) {
g_object_unref(tfi);
g_object_unref(tf);
continue;
}
g_clear_error(&err);
g_hash_table_insert(text_table, (char *)text_files[i], contents);
if (!g_file_load_contents(tf, NULL, &contents, &length, NULL, &err)) {
g_object_unref(tfi);
g_object_unref(tf);
g_object_unref(tfi);
g_object_unref(tf);
g_free(text_file);
}
continue;
}
g_free(texts_dir);
g_hash_table_insert(text_table, (char *)text_files[i], contents);
g_object_unref(tfi);
g_object_unref(tf);
g_free(text_file);
}
g_free(texts_dir);
}
void
wmud_text_send_to_client(gchar *text_name, WmudClient *client)
{
gchar *text = g_hash_table_lookup(text_table, text_name);
wmud_client_send(client, "%s\r\n", text);
gchar *text = g_hash_table_lookup(text_table, text_name);
wmud_client_send(client, "%s\r\n", text);
}

View File

@ -33,178 +33,179 @@
G_DEFINE_TYPE(WmudClient, wmud_client, G_TYPE_OBJECT);
enum {
SIG_CONNECTED,
SIG_NET_HUP,
SIG_NET_RECV,
SIG_STATE_CHANGE,
SIG_LAST
SIG_CONNECTED,
SIG_NET_HUP,
SIG_NET_RECV,
SIG_STATE_CHANGE,
SIG_LAST
};
static guint signals[SIG_LAST] = { 0 };
#define WMUD_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_CLIENT, WmudClientPrivate))
struct _WmudClientPrivate
{
GSocket *socket;
GSource *socket_source;
GString *buffer;
WmudClientState state;
gboolean authenticated;
WmudPlayer *player;
gboolean bademail;
gint login_try_count;
WmudClientYesnoCallback yesno_callback;
time_t last_recv;
struct _WmudClientPrivate {
GSocket *socket;
GSource *socket_source;
GString *buffer;
WmudClientState state;
gboolean authenticated;
WmudPlayer *player;
gboolean bademail;
gint login_try_count;
WmudClientYesnoCallback yesno_callback;
time_t last_recv;
};
static void
wmud_client_dispose(GObject *gobject)
{
WmudClient *self = WMUD_CLIENT(gobject);
WmudClient *self = WMUD_CLIENT(gobject);
if (self->priv->socket) {
g_object_unref(self->priv->socket);
if (self->priv->socket) {
g_object_unref(self->priv->socket);
self->priv->socket = NULL;
}
self->priv->socket = NULL;
}
G_OBJECT_CLASS(wmud_client_parent_class)->dispose(gobject);
G_OBJECT_CLASS(wmud_client_parent_class)->dispose(gobject);
}
static void
wmud_client_finalize(GObject *gobject)
{
WmudClient *self = WMUD_CLIENT(gobject);
WmudClient *self = WMUD_CLIENT(gobject);
g_string_free(self->priv->buffer, TRUE);
g_source_destroy(self->priv->socket_source);
g_string_free(self->priv->buffer, TRUE);
g_source_destroy(self->priv->socket_source);
G_OBJECT_CLASS(wmud_client_parent_class)->finalize(gobject);
G_OBJECT_CLASS(wmud_client_parent_class)->finalize(gobject);
}
static void net_recv(WmudClient *self)
static void
net_recv(WmudClient *self)
{
self->priv->last_recv = time(NULL);
self->priv->last_recv = time(NULL);
}
static void
wmud_client_class_init(WmudClientClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = wmud_client_dispose;
gobject_class->finalize = wmud_client_finalize;
gobject_class->dispose = wmud_client_dispose;
gobject_class->finalize = wmud_client_finalize;
/**
* WmudClient::connected:
* @client: The client emitting the signal
*
* Emitted when a new client connection is accepted
**/
signals[SIG_CONNECTED] = g_signal_newv("connected",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
NULL,
NULL, NULL,
NULL,
G_TYPE_NONE, 0, NULL);
/**
* WmudClient::connected:
* @client: The client emitting the signal
*
* Emitted when a new client connection is accepted
**/
signals[SIG_CONNECTED] = g_signal_newv("connected",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
NULL,
NULL, NULL,
NULL,
G_TYPE_NONE, 0, NULL);
/**
* WmudClient::net-hup:
* @client: The client emitting the signal
*
* Emitted when the remote side closes the connection
**/
signals[SIG_NET_HUP] = g_signal_newv("net-hup",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
NULL,
NULL, NULL,
NULL,
G_TYPE_NONE, 0, NULL);
/**
* WmudClient::net-recv:
* @client: The client emitting the signal
*
* Emitted when data is received through the client socket
**/
signals[SIG_NET_RECV] = g_signal_newv("net-recv",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
g_cclosure_new(G_CALLBACK(net_recv), NULL, NULL),
NULL, NULL,
NULL,
G_TYPE_NONE, 0, NULL);
/**
* WmudClient::net-hup:
* @client: The client emitting the signal
*
* Emitted when the remote side closes the connection
**/
signals[SIG_NET_HUP] = g_signal_newv("net-hup",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
NULL,
NULL, NULL,
NULL,
G_TYPE_NONE, 0, NULL);
/**
* WmudClient::net-recv:
* @client: The client emitting the signal
*
* Emitted when data is received through the client socket
**/
signals[SIG_NET_RECV] = g_signal_newv("net-recv",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
g_cclosure_new(G_CALLBACK(net_recv), NULL, NULL),
NULL, NULL,
NULL,
G_TYPE_NONE, 0, NULL);
/**
* WmudClient::state-change:
* @client: The client emitting the signal
* @old_state: The state which we are changing from.
* @new_state: The state which we are changing to.
*
* Emitted when the client changes state
**/
signals[SIG_STATE_CHANGE] = g_signal_new("state-change",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
NULL,
G_TYPE_NONE, 2, WMUD_TYPE_CLIENT_STATE, WMUD_TYPE_CLIENT_STATE);
/**
* WmudClient::state-change:
* @client: The client emitting the signal
* @old_state: The state which we are changing from.
* @new_state: The state which we are changing to.
*
* Emitted when the client changes state
**/
signals[SIG_STATE_CHANGE] = g_signal_new("state-change",
WMUD_TYPE_CLIENT,
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
NULL,
G_TYPE_NONE, 2, WMUD_TYPE_CLIENT_STATE, WMUD_TYPE_CLIENT_STATE);
g_type_class_add_private(klass, sizeof(WmudClientPrivate));
g_type_class_add_private(klass, sizeof(WmudClientPrivate));
}
static void
wmud_client_init(WmudClient *self)
{
self->priv = WMUD_CLIENT_GET_PRIVATE(self);
self->priv->socket_source = NULL;
self->priv->state = WMUD_CLIENT_STATE_FRESH;
self->priv->buffer = g_string_new("");
self->priv->last_recv = time(NULL);
self->priv = WMUD_CLIENT_GET_PRIVATE(self);
self->priv->socket_source = NULL;
self->priv->state = WMUD_CLIENT_STATE_FRESH;
self->priv->buffer = g_string_new("");
self->priv->last_recv = time(NULL);
g_signal_emit_by_name(self, "connected", G_TYPE_NONE);
g_signal_emit_by_name(self, "connected", G_TYPE_NONE);
}
static gboolean
net_emitter(GSocket *client_socket, GIOCondition condition, WmudClient *self)
{
if (condition & G_IO_HUP)
g_signal_emit_by_name(self, "net-close", G_TYPE_NONE);
else if ((condition & G_IO_IN) || (condition & G_IO_PRI))
g_signal_emit_by_name(self, "net-recv", G_TYPE_NONE);
if (condition & G_IO_HUP) {
g_signal_emit_by_name(self, "net-close", G_TYPE_NONE);
} else if ((condition & G_IO_IN) || (condition & G_IO_PRI)) {
g_signal_emit_by_name(self, "net-recv", G_TYPE_NONE);
}
return TRUE;
return TRUE;
}
WmudClient *
wmud_client_new(void)
{
return g_object_new(WMUD_TYPE_CLIENT, NULL, NULL);
return g_object_new(WMUD_TYPE_CLIENT, NULL, NULL);
}
void
wmud_client_set_socket(WmudClient *self, GSocket *socket)
{
/* TODO: Check if a socket is already set! */
self->priv->socket = socket;
self->priv->socket_source = g_socket_create_source(socket, G_IO_IN | G_IO_OUT | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, NULL);
/* TODO: Check if a socket is already set! */
self->priv->socket = socket;
self->priv->socket_source = g_socket_create_source(socket, G_IO_IN | G_IO_OUT | G_IO_PRI | G_IO_ERR | G_IO_HUP | G_IO_NVAL, NULL);
g_source_set_callback(self->priv->socket_source, (GSourceFunc)net_emitter, self, NULL);
g_source_set_callback(self->priv->socket_source, (GSourceFunc)net_emitter, self, NULL);
}
GSocket *
wmud_client_get_socket(WmudClient *self)
{
return self->priv->socket;
return self->priv->socket;
}
GSource *
wmud_client_get_socket_source(WmudClient *self)
{
return self->priv->socket_source;
return self->priv->socket_source;
}
/**
@ -218,16 +219,16 @@ wmud_client_get_socket_source(WmudClient *self)
void
wmud_client_send(WmudClient *self, const gchar *fmt, ...)
{
va_list ap;
GString *buf = g_string_new("");
va_list ap;
GString *buf = g_string_new("");
va_start(ap, fmt);
g_string_vprintf(buf, fmt, ap);
va_end(ap);
va_start(ap, fmt);
g_string_vprintf(buf, fmt, ap);
va_end(ap);
/* TODO: error checking */
g_socket_send(self->priv->socket, buf->str, buf->len, NULL, NULL);
g_string_free(buf, TRUE);
/* TODO: error checking */
g_socket_send(self->priv->socket, buf->str, buf->len, NULL, NULL);
g_string_free(buf, TRUE);
}
/**
@ -242,92 +243,94 @@ wmud_client_send(WmudClient *self, const gchar *fmt, ...)
void
wmud_client_close(WmudClient *self, gboolean send_goodbye)
{
if (send_goodbye)
wmud_client_send(self, "\r\nHave a nice real-world day!\r\n\r\n");
if (send_goodbye) {
wmud_client_send(self, "\r\nHave a nice real-world day!\r\n\r\n");
}
g_socket_shutdown(self->priv->socket, TRUE, TRUE, NULL);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Connection closed.");
g_socket_shutdown(self->priv->socket, TRUE, TRUE, NULL);
g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "Connection closed.");
if (self->priv->player && !wmud_player_get_registered(self->priv->player))
g_object_unref(self->priv->player);
if (self->priv->player && !wmud_player_get_registered(self->priv->player)) {
g_object_unref(self->priv->player);
}
g_object_unref(self);
g_object_unref(self);
}
gsize
wmud_client_get_buffer_length(WmudClient *self)
{
return self->priv->buffer->len;
return self->priv->buffer->len;
}
GString *
wmud_client_get_buffer(WmudClient *self)
{
return self->priv->buffer;
return self->priv->buffer;
}
WmudClientState
wmud_client_get_state(WmudClient *self)
{
return self->priv->state;
return self->priv->state;
}
void
wmud_client_set_state(WmudClient *self, WmudClientState new_state)
{
WmudClientState old_state = self->priv->state;
WmudClientState old_state = self->priv->state;
self->priv->state = new_state;
self->priv->state = new_state;
g_signal_emit_by_name(self, "state-change", old_state, new_state, G_TYPE_NONE);
g_signal_emit_by_name(self, "state-change", old_state, new_state, G_TYPE_NONE);
}
void
wmud_client_set_player(WmudClient *self, WmudPlayer *player)
{
self->priv->player = player;
self->priv->player = player;
}
WmudPlayer *
wmud_client_get_player(WmudClient *self)
{
return self->priv->player;
return self->priv->player;
}
void
wmud_client_set_yesno_callback(WmudClient *self, WmudClientYesnoCallback yesno_callback)
{
self->priv->yesno_callback = yesno_callback;
self->priv->yesno_callback = yesno_callback;
}
WmudClientYesnoCallback
wmud_client_get_yesno_callback(WmudClient *self)
{
return self->priv->yesno_callback;
return self->priv->yesno_callback;
}
void
wmud_client_set_authenticated(WmudClient *self, gboolean authenticated)
{
self->priv->authenticated = authenticated;
self->priv->authenticated = authenticated;
}
void
wmud_client_increase_login_fail_count(WmudClient *self)
{
self->priv->login_try_count++;
self->priv->login_try_count++;
}
gint
wmud_client_get_login_fail_count(WmudClient *self)
{
return self->priv->login_try_count;
return self->priv->login_try_count;
}
void
wmud_client_set_bademail(WmudClient *self, gboolean bademail)
{
self->priv->bademail = bademail;
self->priv->bademail = bademail;
}
/**
@ -340,18 +343,17 @@ wmud_client_set_bademail(WmudClient *self, gboolean bademail)
gboolean
wmud_client_get_bademail(WmudClient *client)
{
return client->priv->bademail;
return client->priv->bademail;
}
void
wmud_client_set_context(WmudClient *self, GMainContext *context)
{
g_source_attach(self->priv->socket_source, context);
g_source_attach(self->priv->socket_source, context);
}
guint32
wmud_client_get_last_recv_age(WmudClient *self)
{
return (time(NULL) - self->priv->last_recv);
return time(NULL) - self->priv->last_recv;
}

View File

@ -24,14 +24,13 @@
#define WMUD_PLAYER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_PLAYER, WmudPlayerPrivate))
struct _WmudPlayerPrivate
{
guint32 id;
gchar *player_name;
gchar *cpassword;
gchar *email;
gint fail_count;
gboolean registered;
struct _WmudPlayerPrivate {
guint32 id;
gchar *player_name;
gchar *cpassword;
gchar *email;
gint fail_count;
gboolean registered;
};
G_DEFINE_TYPE(WmudPlayer, wmud_player, G_TYPE_OBJECT);
@ -39,133 +38,136 @@ G_DEFINE_TYPE(WmudPlayer, wmud_player, G_TYPE_OBJECT);
static void
wmud_player_dispose(GObject *gobject)
{
//WmudPlayer *self = WMUD_PLAYER(gobject);
G_OBJECT_CLASS(wmud_player_parent_class)->dispose(gobject);
G_OBJECT_CLASS(wmud_player_parent_class)->dispose(gobject);
}
static void
wmud_player_finalize(GObject *gobject)
{
WmudPlayer *self = WMUD_PLAYER(gobject);
WmudPlayer *self = WMUD_PLAYER(gobject);
if (self->priv->player_name)
g_free(self->priv->player_name);
if (self->priv->player_name) {
g_free(self->priv->player_name);
}
if (self->priv->cpassword)
g_free(self->priv->cpassword);
if (self->priv->cpassword) {
g_free(self->priv->cpassword);
}
if (self->priv->email)
g_free(self->priv->email);
if (self->priv->email) {
g_free(self->priv->email);
}
G_OBJECT_CLASS(wmud_player_parent_class)->finalize(gobject);
G_OBJECT_CLASS(wmud_player_parent_class)->finalize(gobject);
}
static void
wmud_player_class_init(WmudPlayerClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = wmud_player_dispose;
gobject_class->finalize = wmud_player_finalize;
gobject_class->dispose = wmud_player_dispose;
gobject_class->finalize = wmud_player_finalize;
g_type_class_add_private(klass, sizeof(WmudPlayerPrivate));
g_type_class_add_private(klass, sizeof(WmudPlayerPrivate));
}
static void
wmud_player_init(WmudPlayer *self)
{
self->priv = WMUD_PLAYER_GET_PRIVATE(self);
self->priv = WMUD_PLAYER_GET_PRIVATE(self);
}
WmudPlayer *
wmud_player_new(void)
{
return g_object_new(WMUD_TYPE_PLAYER, NULL, NULL);
return g_object_new(WMUD_TYPE_PLAYER, NULL, NULL);
}
void
wmud_player_set_cpassword(WmudPlayer *self, const gchar *cpassword)
{
if (self->priv->cpassword)
g_free(self->priv->cpassword);
if (self->priv->cpassword) {
g_free(self->priv->cpassword);
}
self->priv->cpassword = g_strdup(cpassword);
self->priv->cpassword = g_strdup(cpassword);
}
gchar *
wmud_player_get_cpassword(WmudPlayer *self)
{
return self->priv->cpassword;
return self->priv->cpassword;
}
void
wmud_player_set_registered(WmudPlayer *self, gboolean registered)
{
self->priv->registered = registered;
self->priv->registered = registered;
}
gboolean
wmud_player_get_registered(WmudPlayer *self)
{
return self->priv->registered;
return self->priv->registered;
}
void
wmud_player_set_player_name(WmudPlayer *self, const gchar *name)
{
self->priv->player_name = g_strdup(name);
self->priv->player_name = g_strdup(name);
}
gchar *
wmud_player_get_player_name(WmudPlayer *self)
{
return self->priv->player_name;
return self->priv->player_name;
}
void
wmud_player_reset_fail_count(WmudPlayer *self)
{
self->priv->fail_count = 0;
self->priv->fail_count = 0;
}
void
wmud_player_increase_fail_count(WmudPlayer *self)
{
self->priv->fail_count++;
self->priv->fail_count++;
}
gint
wmud_player_get_fail_count(WmudPlayer *self)
{
return self->priv->fail_count;
return self->priv->fail_count;
}
void
wmud_player_set_email(WmudPlayer *self, const gchar *email)
{
if (self->priv->email)
g_free(self->priv->email);
if (self->priv->email) {
g_free(self->priv->email);
}
self->priv->email = g_strdup(email);
self->priv->email = g_strdup(email);
}
gchar *
wmud_player_get_email(WmudPlayer *self)
{
return self->priv->email;
return self->priv->email;
}
void
wmud_player_set_id(WmudPlayer *self, guint32 id)
{
self->priv->id = id;
self->priv->id = id;
}
guint32
wmud_player_get_id(WmudPlayer *self)
{
return self->priv->id;
return self->priv->id;
}
/**
@ -179,18 +181,19 @@ wmud_player_get_id(WmudPlayer *self)
WmudPlayer *
wmud_player_dup(WmudPlayer *self)
{
WmudPlayer *new_player;
WmudPlayer *new_player;
if (!self)
return NULL;
if (!self) {
return NULL;
}
new_player = wmud_player_new();
new_player->priv->id = self->priv->id;
new_player->priv->player_name = g_strdup(self->priv->player_name);
new_player->priv->cpassword = g_strdup(self->priv->cpassword);
new_player->priv->email = g_strdup(self->priv->email);
new_player = wmud_player_new();
new_player->priv->id = self->priv->id;
new_player->priv->player_name = g_strdup(self->priv->player_name);
new_player->priv->cpassword = g_strdup(self->priv->cpassword);
new_player->priv->email = g_strdup(self->priv->email);
return new_player;
return new_player;
}
/**
@ -206,6 +209,5 @@ wmud_player_dup(WmudPlayer *self)
gboolean
wmud_player_password_valid(WmudPlayer *player, const gchar *password)
{
return (g_strcmp0(crypt(password, player->priv->cpassword), player->priv->cpassword) == 0);
return g_strcmp0(crypt(password, player->priv->cpassword), player->priv->cpassword) == 0;
}

View File

@ -30,41 +30,40 @@ G_DEFINE_TYPE(WmudWorld, wmud_world, G_TYPE_OBJECT);
#define WMUD_WORLD_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_WORLD, WmudWorldPrivate))
struct _WmudWorldPrivate
{
struct _WmudWorldPrivate {
};
static void
wmud_world_dispose(GObject *gobject)
{
G_OBJECT_CLASS(wmud_world_parent_class)->dispose(gobject);
G_OBJECT_CLASS(wmud_world_parent_class)->dispose(gobject);
}
static void
wmud_world_finalize(GObject *gobject)
{
G_OBJECT_CLASS(wmud_world_parent_class)->finalize(gobject);
G_OBJECT_CLASS(wmud_world_parent_class)->finalize(gobject);
}
static void
wmud_world_class_init(WmudWorldClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = wmud_world_dispose;
gobject_class->finalize = wmud_world_finalize;
gobject_class->dispose = wmud_world_dispose;
gobject_class->finalize = wmud_world_finalize;
g_type_class_add_private(klass, sizeof(WmudWorldPrivate));
g_type_class_add_private(klass, sizeof(WmudWorldPrivate));
}
static void
wmud_world_init(WmudWorld *self)
{
self->priv = WMUD_WORLD_GET_PRIVATE(self);
self->priv = WMUD_WORLD_GET_PRIVATE(self);
}
WmudWorld *
wmud_world_new(void)
{
return g_object_new(WMUD_TYPE_WORLD, NULL, NULL);
return g_object_new(WMUD_TYPE_WORLD, NULL, NULL);
}

File diff suppressed because it is too large Load Diff