gnoemoe/gm-app.c: added default userlist options, added default logging options

gnoemoe/gm-world.[ch]: fixed const, added gm_world_status, world specific log 
  settings
gnoemoe/gm-scripts.c: added World.status function
gnoemoe/gm-pixbuf.c: added NULL filename checks
This commit is contained in:
Jesse van den Kieboom 2006-04-07 16:37:10 +00:00
parent 65d460b3ee
commit 7fa44d1bbb
6 changed files with 138 additions and 51 deletions

View File

@ -1,3 +1,11 @@
2006-07-04 Jesse van den Kieboom <jesse@icecrew.nl>
* gnoemoe/gm-app.c: added default userlist options,
added default logging options
* gnoemoe/gm-world.[ch]: fixed const, added gm_world_status, world
specific log settings
* gnoemoe/gm-scripts.c: added World.status function
* gnoemoe/gm-pixbuf.c: added NULL filename checks
2006-07-04 Jesse van den Kieboom <jesse@icecrew.nl>
* gnoemoe/mcp/gm-mcp-icecrew-playerdb.c: max version to 1.1
* gnoemoe/mcp/gm-mcp.c: fixed version check

View File

@ -283,6 +283,8 @@ gm_app_create_settings(GmApp *app) {
gm_options_set(app->priv->options, "logging_mcp_in", "0");
gm_options_set(app->priv->options, "logging_mcp_out", "0");
gm_options_set(app->priv->options, "logging_mcp_status", "0");
gm_options_set(app->priv->options, "logging_add_timestamp", "1");
gm_options_set(app->priv->options, "logging_add_log_type", "1");
// Default logging filter settings
gm_options_set(app->priv->options, "logging_filter_in", "1");
@ -291,6 +293,12 @@ gm_app_create_settings(GmApp *app) {
gm_options_set(app->priv->options, "logging_filter_mcp_in", "0");
gm_options_set(app->priv->options, "logging_filter_mcp_out", "0");
gm_options_set(app->priv->options, "logging_filter_mcp_status", "0");
// Default userlist settings
gm_options_set(app->priv->options, "userlist_sort_type", "0");
gm_options_set(app->priv->options, "userlist_show_object_number", "0");
gm_options_set(app->priv->options, "userlist_show_status", "1");
gm_options_set(app->priv->options, "userlist_use_state_icon", "1");
}
void
@ -431,7 +439,7 @@ gm_app_run(GmApp *app) {
const gchar *savedState;
int i = 0;
GmWorld *world;
app->priv->view = gm_app_view_new(app);
gtk_widget_show(GTK_WIDGET(app->priv->view));
@ -520,6 +528,8 @@ gm_app_new(int argc, char *argv[]) {
printf(_("Current version of GnoeMoe is %s\n"), VERSION);
return NULL;
}
return app;
}

View File

@ -124,6 +124,10 @@ gchar *
gm_pixbuf_find(const gchar *filename) {
GList *elem;
if (filename == NULL) {
return NULL;
}
if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
return g_strdup(filename);
}
@ -149,7 +153,7 @@ gm_pixbuf_create(const gchar * filename, int width, int height) {
GdkPixbuf *pixbuf = NULL;
GError *error = NULL;
if (!filename || strlen(filename) == 0) {
if (!filename || *filename == '\0') {
return NULL;
}
@ -185,6 +189,10 @@ gm_pixbuf_get_at_size(const gchar *filename, int width, int height) {
GList *elem;
GmPixbufInfo *i;
if (filename == NULL || *filename == '\0') {
return NULL;
}
for (elem = gm_pixbufs; elem; elem = elem->next) {
i = (GmPixbufInfo *) (elem->data);

View File

@ -500,6 +500,20 @@ gm_scripts_add_file(GmScripts *scripts, const gchar *uri) {
GList *f;
GmScript *script;
gchar *msg;
gchar *ext;
// Only .rb files
ext = strrchr(uri, '.');
if (ext == NULL || strncmp(ext, ".rb", 2) != 0) {
msg = g_strdup_printf(_("File `%s' is not a valid ruby file"), uri);
gm_debug_msg(DEBUG_DEFAULT, "GmScripts.AddFile: %s", msg);
g_signal_emit(scripts, gm_scripts_signals[ERROR], 0, msg);
g_free(msg);
return FALSE;
}
for (f = scripts->priv->files; f; f = f->next) {
script = (GmScript *)(f->data);
@ -599,8 +613,15 @@ gm_scripts_load(GmScripts *scripts) {
path = g_strconcat(gm_app_path(gm_app_instance()), "/scripts", NULL);
// Make user dir if it doesn't exist
if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
mkdir(path, 0750);
}
gm_scripts_load_dir(scripts, path);
gm_scripts_load_dir(scripts, GM_SCRIPTS_GLOBAL);
g_free(path);
}
GList *
@ -664,6 +685,19 @@ gm_scripts_rb_world_writeln(VALUE self, VALUE str) {
return Qnil;
}
static VALUE
gm_scripts_rb_world_status(VALUE self, VALUE str) {
GmWorld *world;
gchar *strVal;
Data_Get_Struct(self, GmWorld, world);
strVal = rb_string_value_cstr(&str);
gm_world_status(world, strVal);
return Qnil;
}
static VALUE
gm_scripts_rb_world_sendln(VALUE self, VALUE str) {
GmWorld *world;
@ -850,6 +884,7 @@ gm_scripts_rb_world_class_init() {
rb_define_method(rb_world_class, "writeln", gm_scripts_rb_world_writeln, 1);
rb_define_method(rb_world_class, "println", gm_scripts_rb_world_writeln, 1);
rb_define_method(rb_world_class, "status", gm_scripts_rb_world_status, 1);
rb_define_method(rb_world_class, "sendln", gm_scripts_rb_world_sendln, 1);
rb_define_method(rb_world_class, "input", gm_scripts_rb_world_input, 1);
rb_define_method(rb_world_class, "quit", gm_scripts_rb_world_quit, 0);

View File

@ -664,9 +664,17 @@ gm_world_prepare_disconnect(GmWorld *world) {
}
gboolean
gm_world_log_allowed(GmLogType type) {
gm_world_log_allowed(GmWorld *world, GmLogType type) {
GmOptions *options = gm_app_options(gm_app_instance());
if (!gm_options_get_int(options, "logging_enable")) {
return FALSE;
}
if (gm_options_get_int(world->priv->options, "logging_override")) {
options = world->priv->options;
}
switch (type) {
case LOG_IN:
return gm_options_get_int(options, "logging_in");
@ -693,28 +701,29 @@ gm_world_log_allowed(GmLogType type) {
}
void
gm_world_log(GmWorld *world, GmLogType type, gchar *text) {
gm_world_log(GmWorld *world, GmLogType type, gchar const *text) {
GString *s;
gchar *start, *log, *no_ansi;
struct tm *timet;
time_t timer;
gint len;
GmOptions *options;
if (type == LOG_NONE) {
return;
}
// Check whether to log at all
if (!gm_options_get_int(gm_app_options(gm_app_instance()),
"logging_enable")) {
return;
}
// Check whether to log this type
if (!gm_world_log_allowed(type)) {
if (!gm_world_log_allowed(world, type)) {
return;
}
options = gm_app_options(gm_app_instance());
if (gm_options_get_int(world->priv->options, "logging_override")) {
options = world->priv->options;
}
timer = time(0);
timet = localtime(&timer);
@ -737,36 +746,42 @@ gm_world_log(GmWorld *world, GmLogType type, gchar *text) {
return;
}
start = g_strdup_printf("[%02d:%02d:%02d] ", timet->tm_hour, timet->tm_min,
timet->tm_sec);
s = g_string_new(start);
g_free(start);
switch (type) {
case LOG_IN:
s = g_string_append_c(s, '<');
break;
case LOG_OUT:
s = g_string_append_c(s, '>');
break;
case LOG_STATUS:
s = g_string_append_c(s, '#');
break;
case LOG_MCP_IN:
s = g_string_append(s, "[MCP] <");
break;
case LOG_MCP_OUT:
s = g_string_append(s, "[MCP] >");
break;
case LOG_MCP_STATUS:
s = g_string_append(s, "[MCP] #");
break;
default:
break;
if (gm_options_get_int(options, "logging_add_timestamp")) {
start = g_strdup_printf("[%02d:%02d:%02d] ", timet->tm_hour,
timet->tm_min, timet->tm_sec);
s = g_string_new(start);
g_free(start);
} else {
s = g_string_new("");
}
s = g_string_append(s, " ");
if (gm_options_get_int(options, "logging_add_log_type")) {
switch (type) {
case LOG_IN:
s = g_string_append_c(s, '<');
break;
case LOG_OUT:
s = g_string_append_c(s, '>');
break;
case LOG_STATUS:
s = g_string_append_c(s, '#');
break;
case LOG_MCP_IN:
s = g_string_append(s, "[MCP] <");
break;
case LOG_MCP_OUT:
s = g_string_append(s, "[MCP] >");
break;
case LOG_MCP_STATUS:
s = g_string_append(s, "[MCP] #");
break;
default:
break;
}
s = g_string_append_c(s, ' ');
}
s = g_string_append(s, text);
no_ansi = gm_ansi_strip(g_strdup(s->str));
@ -1042,7 +1057,7 @@ gm_world_process_line(GmWorld *world, gchar *line, gint len) {
}
void
gm_world_process_input(GmWorld *world, gchar *text) {
gm_world_process_input(GmWorld *world, gchar const *text) {
#ifdef HAVE_RUBY
gchar *space, *script, *argstr;
gboolean script_ran = FALSE;
@ -1080,7 +1095,17 @@ gm_world_process_input(GmWorld *world, gchar *text) {
}
void
gm_world_writeln(GmWorld *world, gchar *text) {
gm_world_status(GmWorld *world, gchar const *text) {
gchar *line = g_strconcat("\x1B[1;33m# ", text, "\x1B[0m", NULL);
gm_world_writeln(world, line);
gm_world_log(world, LOG_STATUS, line);
g_free(line);
}
void
gm_world_writeln(GmWorld *world, gchar const *text) {
gchar *newline = g_strconcat(text, "\n", NULL);
g_signal_emit(world, world_signals[TEXT_RECEIVED], 0, newline);
@ -1107,7 +1132,7 @@ gm_world_add_editor(GmWorld *world, GmEditor *editor) {
}
void
gm_world_sendln_log(GmWorld *world, gchar *text, GmLogType logtype) {
gm_world_sendln_log(GmWorld *world, gchar const *text, GmLogType logtype) {
gchar *normal;
// Convert text from utf-8 to the correct locale
@ -1128,7 +1153,7 @@ gm_world_sendln_log(GmWorld *world, gchar *text, GmLogType logtype) {
}
void
gm_world_sendln(GmWorld *world, gchar *text) {
gm_world_sendln(GmWorld *world, gchar const *text) {
world->priv->last_command = time(0);
gm_world_sendln_log(world, text, LOG_OUT);
}
@ -1237,7 +1262,7 @@ on_gm_world_editor_save(GmEditor *editor, GmWorld *world) {
gm_world_sendln(world, ".");
gm_editor_saved(editor);
} else {
gm_world_writeln(world, _("# Could not save editor text, world is "
gm_world_status(world, _("Could not save editor text, world is "
"not connected at the moment"));
}
}
@ -1274,7 +1299,7 @@ on_gm_world_net_state_changing(GmNet *net, GmNetState state, GmWorld *world) {
world->priv->reconnect_id = g_timeout_add(3000,
(GSourceFunc)gm_world_reconnect, world);
gm_world_writeln(world, _("# Reconnecting in 3 seconds..."));
gm_world_status(world, _("Reconnecting in 3 seconds..."));
}
}
}

View File

@ -130,11 +130,12 @@ void gm_world_disconnect(GmWorld *world);
void gm_world_prepare_disconnect(GmWorld *world);
void gm_world_add_editor(GmWorld *world, GmEditor *editor);
void gm_world_remove_editor(GmWorld *world, GmEditor *editor);
void gm_world_sendln_log(GmWorld *world, gchar *text, GmLogType logtype);
void gm_world_sendln(GmWorld *world, gchar *text);
void gm_world_writeln(GmWorld *world, gchar *text);
void gm_world_process_input(GmWorld *world, gchar *text);
void gm_world_log(GmWorld *world, GmLogType type, gchar *text);
void gm_world_sendln_log(GmWorld *world, gchar const *text, GmLogType logtype);
void gm_world_sendln(GmWorld *world, gchar const *text);
void gm_world_writeln(GmWorld *world, gchar const *text);
void gm_world_status(GmWorld *world, gchar const *text);
void gm_world_process_input(GmWorld *world, gchar const *text);
void gm_world_log(GmWorld *world, GmLogType type, gchar const *text);
void gm_world_apply_trigger(GmWorld *world, GmTrigger *trigger,
gchar const *text, regmatch_t *matches, gint nummatches);