static void master_okbutton_callback (GtkWidget *widget, GtkWidget* window) { master_check_master_addr_prefix(); master_addr_result = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (master_addr_combo)->entry))); master_name_result = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (master_name_combo)->entry))); config_set_string ("/" CONFIG_FILE "/Add Master/game", type2id (master_type)); if (!master_addr_result || !master_name_result) { dialog_ok (NULL, _("You have to specify a name and an address.")); return; } master_to_add = add_master (master_addr_result, master_name_result, master_type, NULL, TRUE, FALSE); if (!master_to_add) { dialog_ok (NULL, _("Master address \"%s\" is not valid."), master_addr_result); } else { if (master_addr_result) history_add (master_history_addr, master_addr_result); if (master_name_result) history_add (master_history_name, master_name_result); gtk_widget_destroy(window); } }
int player_filter_add_player (char *name, unsigned mask) { GSList *list; struct player_pattern *pp; char *pattern; int changed = FALSE; pattern = strdup_strip (name); if (!pattern) return FALSE; for (list = players; list; list = list->next) { pp = (struct player_pattern *) list->data; if (pp->mode == PATTERN_MODE_STRING && pp->pattern && g_strcasecmp (pattern, pp->pattern) == 0) { break; } } if (!list) { pp = player_pattern_new (NULL); pp->pattern = pattern; pp->groups = 0; player_pattern_compile (pp); players = g_slist_append (players, pp); changed = TRUE; } mask &= PLAYER_GROUP_MASK; if ((pp->groups & mask) != mask) { pp->groups |= mask; filters[FILTER_PLAYER].last_changed = filter_time_inc(); player_filter_save_patterns (); changed = TRUE; } return changed; }
static void enter_string_activate_callback (GtkWidget *widget, gpointer data) { enter_string_res = strdup_strip (gtk_entry_get_text (GTK_ENTRY (widget))); if (enter_string_optval) { *enter_string_optval = GTK_TOGGLE_BUTTON (enter_string_opt_button)->active; } }
static void sync_pattern_data (void) { struct player_pattern *pp; char *pattern; char *comment; enum pattern_mode mode; int update_pattern = FALSE; int update_comment = FALSE; GSList *list; if (current_row < 0) return; list = g_slist_nth (curplrs, current_row); pp = (struct player_pattern *) list->data; if (GTK_TOGGLE_BUTTON (mode_buttons[PATTERN_MODE_STRING])->active) mode = PATTERN_MODE_STRING; else if (GTK_TOGGLE_BUTTON (mode_buttons[PATTERN_MODE_SUBSTR])->active) mode = PATTERN_MODE_SUBSTR; else mode = PATTERN_MODE_REGEXP; pattern = strdup_strip (gtk_entry_get_text (GTK_ENTRY (pattern_entry))); comment = gtk_editable_get_chars (GTK_EDITABLE (comment_text), 0, -1); update_pattern = (pp->pattern && pp->pattern[0])? !pattern || !pattern[0] || strcmp (pp->pattern, pattern) : pattern && pattern[0]; update_comment = (pp->comment && pp->comment[0])? !comment || !comment[0] || strcmp (pp->comment, comment) : comment && comment[0]; /* * Test everything but groups. * They are synchronized by pattern_set_groups() */ if (mode != pp->mode || update_comment || update_pattern) { if (!pp->dirty) { pp = player_pattern_new (pp); list->data = pp; } if (update_pattern) { if (pp->pattern) g_free (pp->pattern); pp->pattern = pattern; } if (update_comment) { if (pp->comment) g_free (pp->comment); pp->comment = comment; } if (pp->mode != mode || update_pattern) { free_player_pattern_compiled_data (pp); pp->mode = mode; player_pattern_compile (pp); } pattern_clist_update_row (pp, current_row); } if (!update_comment) g_free (comment); if (!update_pattern) g_free (pattern); }
static int player_pattern_parse_statement (GScanner *scanner, char *fn) { struct player_pattern *pp; int token; token = g_scanner_get_next_token (scanner); switch (token) { case TOKEN_STRING: case TOKEN_SUBSTR: case TOKEN_REGEXP: pp = player_pattern_new (NULL); switch (token) { case TOKEN_REGEXP: pp->mode = PATTERN_MODE_REGEXP; break; case TOKEN_SUBSTR: pp->mode = PATTERN_MODE_SUBSTR; break; case TOKEN_STRING: default: pp->mode = PATTERN_MODE_STRING; break; } token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_LEFT_CURLY) { free_player_pattern (pp); return skip_to_right_curly_bracket (scanner); } token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_STRING) { free_player_pattern (pp); return skip_to_right_curly_bracket (scanner); } pp->pattern = strdup_strip (scanner->value.v_string); token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_COMMA) { free_player_pattern (pp); return skip_to_right_curly_bracket (scanner); } token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_INT) { free_player_pattern (pp); return skip_to_right_curly_bracket (scanner); } pp->groups = scanner->value.v_int & PLAYER_GROUP_MASK; token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_COMMA) { free_player_pattern (pp); return skip_to_right_curly_bracket (scanner); } token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_STRING) { free_player_pattern (pp); return skip_to_right_curly_bracket (scanner); } pp->comment = strdup_strip (scanner->value.v_string); token = g_scanner_get_next_token (scanner); if (token != G_TOKEN_RIGHT_CURLY) { free_player_pattern (pp); return skip_to_right_curly_bracket (scanner); } player_pattern_compile (pp); players = g_slist_append (players, pp); filters[FILTER_PLAYER].changed = FILTER_CHANGED; break; case G_TOKEN_EOF: return FALSE; default: fprintf (stderr, "%s[%d:%d] parse error\n\n", fn, scanner->line, scanner->position); return skip_to_right_curly_bracket (scanner); } return TRUE; }
static void set_new_properties (GtkWidget *widget, struct server *s) { struct server_props *props; char *customcfg; char *srvpwd; char *spectpwd; char *rconpwd; int reserved; int sucks; char* comment = NULL; customcfg = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (customcfg_combo)->entry))); srvpwd = strdup_strip (gtk_entry_get_text (GTK_ENTRY (password_entry))); spectpwd = strdup_strip (gtk_entry_get_text (GTK_ENTRY (spectator_entry))); rconpwd = strdup_strip (gtk_entry_get_text (GTK_ENTRY (rcon_entry))); reserved = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinner)); sucks = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (sucks_check_button)); comment = gtk_editable_get_chars (GTK_EDITABLE (comment_text), 0, -1); props = properties (s); if (props) { if (customcfg || srvpwd || spectpwd || rconpwd || reserved || sucks || comment) { g_free (props->custom_cfg); props->custom_cfg = customcfg; g_free (props->server_password); props->server_password = srvpwd; g_free (props->spectator_password); props->spectator_password = spectpwd; g_free (props->rcon_password); props->rcon_password = rconpwd; props->reserved_slots = reserved; props->sucks = sucks; g_free(props->comment); props->comment = comment; } else { props_list = g_slist_remove (props_list, props); props_free (props); } } else { if (customcfg || srvpwd || spectpwd || rconpwd || reserved || sucks || comment) { props = properties_new (s->host, s->port); props->custom_cfg = customcfg; props->server_password = srvpwd; props->spectator_password = spectpwd; props->rcon_password = rconpwd; props->reserved_slots = reserved; props->sucks = sucks; props->comment = comment; } } props_save (); }
void props_load (void) { FILE *f; char *fn; struct host *h; struct server_props *p = NULL; char *addr; unsigned short port; char buf[1024]; char *ptr; props_free_all (); fn = file_in_dir (user_rcdir, SERVERS_FILE); f = fopen (fn, "r"); g_free (fn); if (!f) return; while (!feof (f)) { fgets (buf, 1024, f); if (buf[0] == '\n') { if (p) p = NULL; } else if (buf[0] == '[') { if (p) continue; ptr = strchr (&buf[1], ']'); if (!ptr) continue; *ptr = '\0'; if (!parse_address (&buf[1], &addr, &port)) continue; if (port == 0) { g_free (addr); continue; } h = host_add (addr); g_free (addr); if (!h) continue; p = __properties (h, port); if (!p) p = properties_new (h, port); } else { if (!p) continue; ptr = strchr (buf, ' '); if (!ptr) continue; *ptr++ = '\0'; if (strcmp (buf, "custom_cfg") == 0) { g_free (p->custom_cfg); p->custom_cfg = strdup_strip (ptr); } else if (strcmp (buf, "password") == 0) { g_free (p->server_password); p->server_password = strdup_strip (ptr); } else if (strcmp (buf, "spectator_password") == 0) { g_free (p->spectator_password); p->spectator_password = strdup_strip (ptr); } else if (strcmp (buf, "rcon_password") == 0) { g_free (p->rcon_password); p->rcon_password = strdup_strip (ptr); } else if (strcmp (buf, "reserved_slots") == 0) { p->reserved_slots= atoi(ptr); } else if (strcmp (buf, "sucks") == 0) { p->sucks = atoi(ptr); } else if (strcmp (buf, "comment") == 0) { unsigned di, si; size_t slen = strlen(ptr); int quote = 0; g_free (p->comment); p->comment = g_malloc0 (slen + 1); for (si = 0, di = 0; si < slen; ++si) { if (quote) { quote = 0; if (ptr[si] == 'n') p->comment[di++] = '\n'; else if (ptr[si] == '\\') p->comment[di++] = '\\'; else xqf_warning("unknown control sequence \\%c", ptr[si]); } else if (ptr[si] == '\\') { quote = 1; } else { p->comment[di++] = ptr[si]; } } } } } fclose (f); }