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

@ -101,8 +101,9 @@ wmud_config_init(ConfigData **config_data, GError **err)
GError *in_err = NULL;
gchar *pos;
if (!config_data)
if (!config_data) {
return FALSE;
}
if (*config_data) {
g_clear_error(err);

View File

@ -105,10 +105,11 @@ wmud_db_load_players(GError **err)
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;
}
@ -192,10 +193,11 @@ 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;
}
@ -277,10 +279,11 @@ wmud_db_load_planes(GSList **planes, GError **err)
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;
}
@ -329,10 +332,11 @@ wmud_db_load_planets(GSList **planets, GError **err)
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;
}
@ -383,10 +387,11 @@ wmud_db_load_directions(GSList **directions, GError **err)
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;
}
@ -450,10 +455,11 @@ wmud_db_load_areas(GSList **areas, GError **err)
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;
}
@ -501,10 +507,11 @@ wmud_db_load_rooms(GSList **rooms, GError **err)
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;
}
@ -564,10 +571,11 @@ wmud_db_load_exits(GSList **exits, GError **err)
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;
}
@ -623,10 +631,11 @@ wmud_db_load_planet_planes(GSList **planet_planes, GError **err)
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;
}
@ -677,10 +686,11 @@ wmud_db_load_menu(GSList **menu_items, GError **err)
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;
}

View File

@ -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));
}
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
} else {
g_string_overwrite_len(
wmud_client_get_buffer(client),
0,
buf2,
(n - buf2));
}
buf2 = n;
}
@ -151,8 +154,9 @@ 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(
@ -164,44 +168,53 @@ recv_client(WmudClient *client)
}
}
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;
}
@ -256,11 +269,12 @@ game_source_callback(GSocket *socket,
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);
wmud_client_send(WMUD_CLIENT(client), "By what name shall we call you? ");
@ -310,8 +324,8 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
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);
@ -344,16 +359,17 @@ wmud_networking_init(guint port_number, GMainContext *game_context, GSList *menu
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,11 +380,12 @@ 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->listener = game_listener;
@ -524,29 +541,32 @@ 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: ");
}
}
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);
@ -567,10 +587,11 @@ state_registering(WmudClient *client)
" 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);
}
}
}
static void
state_regemail_confirm(WmudClient *client)
@ -594,4 +615,3 @@ state_regemail_confirm(WmudClient *client)
wmud_client_set_state(client, WMUD_CLIENT_STATE_REGISTERING);
}
}

View File

@ -68,14 +68,17 @@ check_direction_dups2(wmudDirection *dir1, wmudDirection *dir2)
{
gint check;
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->short_name)) != 0)
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->short_name)) != 0) {
return check;
}
if ((check = g_ascii_strcasecmp(dir1->name, dir2->name)) != 0)
if ((check = g_ascii_strcasecmp(dir1->name, dir2->name)) != 0) {
return check;
}
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->name)) != 0)
if ((check = g_ascii_strcasecmp(dir1->short_name, dir2->name)) != 0) {
return check;
}
return g_ascii_strcasecmp(dir1->name, dir2->short_name);
}
@ -88,9 +91,10 @@ check_direction_dups1(wmudDirection *dir, struct findData *find_data)
find_data->last = dir->name;
}
if (g_slist_find_custom(find_data->list, dir, (GCompareFunc)check_direction_dups2))
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)
@ -210,9 +214,10 @@ wmud_interpret_game_command(WmudClient *client)
}
a = end;
if (((*a == '"') || (*a == '\'')) && str_delim)
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);
@ -255,17 +260,22 @@ wmud_interpret_game_command(WmudClient *client)
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");

View File

@ -73,8 +73,9 @@ wmud_random_string(gint len)
/* 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;

View File

@ -130,8 +130,9 @@ wmud_smtp_read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
struct WriteThis *pooh = (struct WriteThis *)userp;
const char *data;
if (size * nmemb < 1)
if (size * nmemb < 1) {
return 0;
}
data = text[pooh->counter];
@ -139,6 +140,7 @@ wmud_smtp_read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
size_t len = strlen(data);
memcpy(ptr, data, len);
pooh->counter++;
return len;
}
@ -158,11 +160,13 @@ wmud_maintenance_init(void)
curl_global_init(CURL_GLOBAL_DEFAULT);
if (!(curl = curl_easy_init()))
if (!(curl = curl_easy_init())) {
g_error("Could not initialize the CURL library!");
}
if (!(mcurl = curl_multi_init()))
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);

View File

@ -62,17 +62,21 @@ wmud_menu_items_check(GSList *menu_items, GError **err)
void
menu_item_free(wmudMenu *menu_item)
{
if (menu_item->text)
if (menu_item->text) {
g_free(menu_item->text);
}
if (menu_item->display_text)
if (menu_item->display_text) {
g_free(menu_item->display_text);
}
if (menu_item->display_text_ansi)
if (menu_item->display_text_ansi) {
g_free(menu_item->display_text_ansi);
}
if (menu_item->func)
if (menu_item->func) {
g_free(menu_item->func);
}
g_free(menu_item);
}
@ -80,8 +84,7 @@ menu_item_free(wmudMenu *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);
#else
@ -104,11 +107,13 @@ menu_item_prepare(wmudMenu *item, GHashTable *cmdtable)
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++)
for (a = item->text; *a; a++) {
if ((*a == m1) || (*a == m2)) {
found = a;
break;
}
}
if (found) {
gchar *tmp;
@ -227,8 +232,9 @@ wmud_menu_init(GSList **menu)
return FALSE;
}
if (*menu)
if (*menu) {
wmud_menu_items_free(menu);
}
*menu = menu_items;
@ -260,8 +266,9 @@ wmud_menu_init(GSList **menu)
static gint
find_by_menuchar(wmudMenu *item, gchar *menuchar)
{
if (g_ascii_toupper(*menuchar) == g_ascii_toupper(item->menuchar))
if (g_ascii_toupper(*menuchar) == g_ascii_toupper(item->menuchar)) {
return 0;
}
return 1;
}
@ -271,8 +278,9 @@ wmud_menu_get_command_by_menuchar(gchar menuchar, GSList *game_menu)
{
GSList *item;
if ((item = g_slist_find_custom(game_menu, &menuchar, (GCompareFunc)find_by_menuchar)) != NULL)
if ((item = g_slist_find_custom(game_menu, &menuchar, (GCompareFunc)find_by_menuchar)) != NULL) {
return ((wmudMenu *)(item->data))->func;
}
return NULL;
}
@ -282,11 +290,12 @@ wmud_menu_execute_command(WmudClient *client, gchar *command)
{
wmudMenuCommandFunc func;
if ((func = g_hash_table_lookup(mcmd_table, command)) == NULL)
if ((func = g_hash_table_lookup(mcmd_table, command)) == NULL) {
wmud_client_send(client, "Unknown menu command.\r\n");
else
} else {
func(client);
}
}
void
send_menu_item(wmudMenu *item, WmudClient *client)
@ -303,4 +312,3 @@ wmud_menu_present(WmudClient *client)
/* TODO: send menu prologue */
}

View File

@ -62,10 +62,9 @@ wmud_player_exists(gchar *player_name)
{
GSList *player_elem;
if ((player_elem = g_slist_find_custom(players, player_name, (GCompareFunc)find_player_by_name)) == NULL)
if ((player_elem = g_slist_find_custom(players, player_name, (GCompareFunc)find_player_by_name)) == NULL) {
return NULL;
return player_elem->data;
}
return player_elem->data;
}

View File

@ -44,14 +44,15 @@ wmud_texts_init(void)
guint64 tfs;
gchar *contents;
gsize length;
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);
if (err) {
g_warning("Error loading %s: %s", text_files[i], err->message);
continue;
}
@ -64,6 +65,7 @@ wmud_texts_init(void)
if (!g_file_load_contents(tf, NULL, &contents, &length, NULL, &err)) {
g_object_unref(tfi);
g_object_unref(tf);
continue;
}
@ -81,5 +83,6 @@ 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);
}

View File

@ -44,8 +44,7 @@ static guint signals[SIG_LAST] = { 0 };
#define WMUD_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_CLIENT, WmudClientPrivate))
struct _WmudClientPrivate
{
struct _WmudClientPrivate {
GSocket *socket;
GSource *socket_source;
GString *buffer;
@ -83,7 +82,8 @@ wmud_client_finalize(GObject *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);
}
@ -171,10 +171,11 @@ wmud_client_init(WmudClient *self)
static gboolean
net_emitter(GSocket *client_socket, GIOCondition condition, WmudClient *self)
{
if (condition & G_IO_HUP)
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))
} else if ((condition & G_IO_IN) || (condition & G_IO_PRI)) {
g_signal_emit_by_name(self, "net-recv", G_TYPE_NONE);
}
return TRUE;
}
@ -242,14 +243,16 @@ wmud_client_send(WmudClient *self, const gchar *fmt, ...)
void
wmud_client_close(WmudClient *self, gboolean send_goodbye)
{
if (send_goodbye)
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.");
if (self->priv->player && !wmud_player_get_registered(self->priv->player))
if (self->priv->player && !wmud_player_get_registered(self->priv->player)) {
g_object_unref(self->priv->player);
}
g_object_unref(self);
}
@ -352,6 +355,5 @@ wmud_client_set_context(WmudClient *self, GMainContext *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,8 +24,7 @@
#define WMUD_PLAYER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WMUD_TYPE_PLAYER, WmudPlayerPrivate))
struct _WmudPlayerPrivate
{
struct _WmudPlayerPrivate {
guint32 id;
gchar *player_name;
gchar *cpassword;
@ -39,8 +38,6 @@ 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);
}
@ -49,14 +46,17 @@ wmud_player_finalize(GObject *gobject)
{
WmudPlayer *self = WMUD_PLAYER(gobject);
if (self->priv->player_name)
if (self->priv->player_name) {
g_free(self->priv->player_name);
}
if (self->priv->cpassword)
if (self->priv->cpassword) {
g_free(self->priv->cpassword);
}
if (self->priv->email)
if (self->priv->email) {
g_free(self->priv->email);
}
G_OBJECT_CLASS(wmud_player_parent_class)->finalize(gobject);
}
@ -87,8 +87,9 @@ wmud_player_new(void)
void
wmud_player_set_cpassword(WmudPlayer *self, const gchar *cpassword)
{
if (self->priv->cpassword)
if (self->priv->cpassword) {
g_free(self->priv->cpassword);
}
self->priv->cpassword = g_strdup(cpassword);
}
@ -144,8 +145,9 @@ wmud_player_get_fail_count(WmudPlayer *self)
void
wmud_player_set_email(WmudPlayer *self, const gchar *email)
{
if (self->priv->email)
if (self->priv->email) {
g_free(self->priv->email);
}
self->priv->email = g_strdup(email);
}
@ -181,8 +183,9 @@ wmud_player_dup(WmudPlayer *self)
{
WmudPlayer *new_player;
if (!self)
if (!self) {
return NULL;
}
new_player = wmud_player_new();
new_player->priv->id = self->priv->id;
@ -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,8 +30,7 @@ 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

View File

@ -68,7 +68,7 @@ wmud_world_error_quark()
static gint
check_plane_dups2(wmudPlane *plane, gchar *name)
{
return (g_ascii_strcasecmp(plane->name, name));
return g_ascii_strcasecmp(plane->name, name);
}
static void
@ -79,9 +79,10 @@ check_plane_dups1(wmudPlane *plane, struct findData *find_data)
find_data->found = (find_data->found > 1) ? find_data->found : 0;
}
if (g_slist_find_custom(find_data->list, plane->name, (GCompareFunc)check_plane_dups2))
if (g_slist_find_custom(find_data->list, plane->name, (GCompareFunc)check_plane_dups2)) {
find_data->found++;
}
}
/**
* wmud_world_check_planes:
@ -101,16 +102,17 @@ wmud_world_check_planes(GSList *planes, GError **err)
g_slist_foreach(planes, (GFunc)check_plane_dups1, &find_data);
if (find_data.found > 1)
if (find_data.found > 1) {
g_set_error(err, WMUD_WORLD_ERROR, WMUD_WORLD_ERROR_DUPPLANE, "Duplicate plane names found. Please check your database!\n");
}
return (find_data.found < 2);
return find_data.found < 2;
}
static gint
check_planet_dups2(wmudPlanet *planet, gchar *name)
{
return (g_ascii_strcasecmp(planet->name, name));
return g_ascii_strcasecmp(planet->name, name);
}
static void
@ -121,9 +123,10 @@ check_planet_dups1(wmudPlanet *planet, struct findData *find_data)
find_data->found = (find_data->found > 1) ? find_data->found : 0;
}
if (g_slist_find_custom(find_data->list, planet->name, (GCompareFunc)check_planet_dups2))
if (g_slist_find_custom(find_data->list, planet->name, (GCompareFunc)check_planet_dups2)) {
find_data->found++;
}
}
/**
* wmud_world_check_planets:
@ -143,16 +146,17 @@ wmud_world_check_planets(GSList *planets, GError **err)
g_slist_foreach(planets, (GFunc)check_planet_dups1, &find_data);
if (find_data.found > 1)
if (find_data.found > 1) {
g_set_error(err, WMUD_WORLD_ERROR, WMUD_WORLD_ERROR_DUPPLANET, "Duplicate planet names found. Please check your database!\n");
}
return (find_data.found < 2);
return find_data.found < 2;
}
static gint
check_area_dups2(wmudArea *area, gchar *name)
{
return (g_ascii_strcasecmp(area->name, name));
return g_ascii_strcasecmp(area->name, name);
}
static void
@ -163,9 +167,10 @@ check_area_dups1(wmudArea *area, struct findData *find_data)
find_data->found = (find_data->found > 1) ? find_data->found : 0;
}
if (g_slist_find_custom(find_data->list, area->name, (GCompareFunc)check_area_dups2))
if (g_slist_find_custom(find_data->list, area->name, (GCompareFunc)check_area_dups2)) {
find_data->found++;
}
}
/**
* wmud_world_check_areas:
@ -185,10 +190,11 @@ wmud_world_check_areas(GSList *areas, GError **err)
g_slist_foreach(areas, (GFunc)check_area_dups1, &find_data);
if (find_data.found > 1)
if (find_data.found > 1) {
g_set_error(err, WMUD_WORLD_ERROR, WMUD_WORLD_ERROR_DUPAREA, "Duplicate area names found. Please check your database!");
}
return (find_data.found < 2);
return find_data.found < 2;
}
static gint
@ -207,11 +213,12 @@ static void
exit_sanity_check(wmudExit *room_exit, struct dirCheckData *dir_check_data)
{
if (
!g_slist_find_custom(dir_check_data->rooms, room_exit, (GCompareFunc)check_room_exit_room)
|| !g_slist_find_custom(dir_check_data->directions, room_exit, (GCompareFunc)check_room_exit_dir)
)
!g_slist_find_custom(dir_check_data->rooms, room_exit, (GCompareFunc)check_room_exit_room) ||
!g_slist_find_custom(dir_check_data->directions, room_exit, (GCompareFunc)check_room_exit_dir)
) {
dir_check_data->sane = FALSE;
}
}
/**
* wmud_world_check_exits:
@ -251,9 +258,10 @@ check_room_dups1(wmudRoom *room, struct findData *find_data)
find_data->found = (find_data->found > 1) ? find_data->found : 0;
}
if (g_slist_find_custom(find_data->list, room, (GCompareFunc)check_room_dups2))
if (g_slist_find_custom(find_data->list, room, (GCompareFunc)check_room_dups2)) {
find_data->found++;
}
}
/**
* wmud_world_check_rooms:
@ -273,17 +281,19 @@ wmud_world_check_rooms(GSList *rooms, GError **err)
g_slist_foreach(rooms, (GFunc)check_room_dups1, &find_data);
if (find_data.found > 1)
if (find_data.found > 1) {
g_set_error(err, WMUD_WORLD_ERROR, WMUD_WORLD_ERROR_DUPROOM, "Duplicate room names found. Please check your database!");
}
return (find_data.found < 2);
return find_data.found < 2;
}
gint
find_planet_by_id(wmudPlanet *planet, guint *planet_id)
{
if (planet->id == *planet_id)
if (planet->id == *planet_id) {
return 0;
}
return 1;
}
@ -291,8 +301,9 @@ find_planet_by_id(wmudPlanet *planet, guint *planet_id)
gint
find_plane_by_id(wmudPlane *plane, guint *plane_id)
{
if (plane->id == *plane_id)
if (plane->id == *plane_id) {
return 0;
}
return 1;
}
@ -323,8 +334,9 @@ planet_plane_assoc(wmudPlanetPlaneAssoc *association, struct assocPlanetPlanes *
gint
find_noplane_planet(wmudPlanet *planet, gconstpointer data)
{
if (planet->planes == NULL)
if (planet->planes == NULL) {
return 0;
}
return 1;
}
@ -367,8 +379,9 @@ wmud_world_assoc_planets_planes(GSList *planets, GSList *planes, GSList *planet_
gint
find_area_by_id(wmudArea *area, guint *id)
{
if (area->id == *id)
if (area->id == *id) {
return 0;
}
return 1;
}
@ -451,14 +464,15 @@ wmud_world_assoc_rooms_planets(GSList *rooms, GSList *planets, GError **err)
g_slist_foreach(rooms, (GFunc)assoc_room_planets, planets);
/* Check the rooms */
return (g_slist_find_custom(rooms, NULL, (GCompareFunc)find_noplane_room) == NULL);
return g_slist_find_custom(rooms, NULL, (GCompareFunc)find_noplane_room) == NULL;
}
gint
find_room_by_id(wmudRoom *room, guint *id)
{
if (room->id == *id)
if (room->id == *id) {
return 0;
}
return 1;
}
@ -466,8 +480,9 @@ find_room_by_id(wmudRoom *room, guint *id)
gint
find_direction_by_id(wmudDirection *dir, guint *id)
{
if (dir->id == *id)
if (dir->id == *id) {
return 0;
}
return 1;
}
@ -478,6 +493,7 @@ assoc_room_exit(wmudExit *exit, struct assocExitRooms *assoc_data)
wmudRoomExit *room_exit = g_new0(wmudRoomExit, 1);
wmudRoom *src_room = (wmudRoom *)(g_slist_find_custom(assoc_data->rooms, &(exit->source_room_id), (GCompareFunc)find_room_by_id)->data);
room_exit->other_side = (wmudRoom *)(g_slist_find_custom(assoc_data->rooms, &(exit->destination_room_id), (GCompareFunc)find_room_by_id)->data);
room_exit->direction = (wmudDirection *)(g_slist_find_custom(assoc_data->directions, &(exit->direction_id), (GCompareFunc)find_direction_by_id)->data);
@ -504,11 +520,13 @@ wmud_world_assoc_exits_rooms(GSList *exits, GSList *directions, GSList *rooms, G
static void
free_direction(wmudDirection *dir)
{
if (dir->short_name)
if (dir->short_name) {
g_free(dir->short_name);
}
if (dir->name)
if (dir->name) {
g_free(dir->name);
}
g_free(dir);
}
@ -531,8 +549,9 @@ wmud_world_free_directions(GSList *directions)
static void
free_plane(wmudPlane *plane)
{
if (plane->name)
if (plane->name) {
g_free(plane->name);
}
g_free(plane);
}
@ -555,8 +574,9 @@ wmud_world_free_planes(GSList *planes)
static void
free_planet(wmudPlanet *planet)
{
if (planet->name)
if (planet->name) {
g_free(planet->name);
}
g_free(planet);
}
@ -579,8 +599,9 @@ wmud_world_free_planets(GSList *planets)
static void
free_area(wmudArea *area)
{
if (area->name)
if (area->name) {
g_free(area->name);
}
g_free(area);
}
@ -603,14 +624,17 @@ wmud_world_free_areas(GSList *areas)
static void
free_room(wmudRoom *room)
{
if (room->name)
if (room->name) {
g_free(room->name);
}
if (room->distant_description)
if (room->distant_description) {
g_free(room->distant_description);
}
if (room->close_description)
if (room->close_description) {
g_free(room->close_description);
}
g_free(room);
}