/* SYNTAX: WINDOW SERVER [-sticky | -unsticky] <tag> */ static void cmd_window_server(const char *data) { GHashTable *optlist; SERVER_REC *server; char *tag; void *free_arg; if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS, "window server", &optlist, &tag)) return; if (*tag == '\0' && active_win->active_server != NULL && (g_hash_table_lookup(optlist, "sticky") != NULL || g_hash_table_lookup(optlist, "unsticky") != NULL)) { tag = active_win->active_server->tag; } if (*tag == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS); server = server_find_tag(tag); if (server == NULL) server = server_find_lookup_tag(tag); if (g_hash_table_lookup(optlist, "unsticky") != NULL && active_win->servertag != NULL) { g_free_and_null(active_win->servertag); printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_UNSET_SERVER_STICKY); } if (active_win->servertag != NULL && g_hash_table_lookup(optlist, "sticky") == NULL) { printformat_window(active_win, MSGLEVEL_CLIENTERROR, TXT_ERROR_SERVER_STICKY); } else if (server == NULL) { printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_UNKNOWN_SERVER_TAG, tag); } else if (active_win->active == NULL) { window_change_server(active_win, server); if (g_hash_table_lookup(optlist, "sticky") != NULL) { g_free_not_null(active_win->servertag); active_win->servertag = g_strdup(server->tag); printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_SET_SERVER_STICKY, server->tag); } printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_SERVER_CHANGED, server->tag, server->connrec->address, server->connrec->chatnet == NULL ? "" : server->connrec->chatnet); } cmd_params_free(free_arg); }
/* create unique tag for server. prefer ircnet's name or generate it from server's address */ static char *server_create_tag(SERVER_CONNECT_REC *conn) { GString *str; char *tag; int num; g_return_val_if_fail(IS_SERVER_CONNECT(conn), NULL); tag = conn->chatnet != NULL && *conn->chatnet != '\0' ? g_strdup(conn->chatnet) : server_create_address_tag(conn->address); if (conn->tag != NULL && server_find_tag(conn->tag) == NULL && server_find_lookup_tag(conn->tag) == NULL && strncmp(conn->tag, tag, strlen(tag)) == 0) { /* use the existing tag if it begins with the same ID - this is useful when you have several connections to same server and you want to keep the same tags with the servers (or it would cause problems when rejoining /LAYOUT SAVEd channels). */ g_free(tag); return g_strdup(conn->tag); } /* then just append numbers after tag until unused is found.. */ str = g_string_new(tag); num = 2; while (server_find_tag(str->str) != NULL || server_find_lookup_tag(str->str) != NULL) { g_string_sprintf(str, "%s%d", tag, num); num++; } g_free(tag); tag = str->str; g_string_free(str, FALSE); return tag; }
/* SYNTAX: DISCONNECT *|<tag> [<message>] */ static void cmd_disconnect(const char *data, SERVER_REC *server) { char *tag, *msg; void *free_arg; g_return_if_fail(data != NULL); if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg)) return; if (*tag != '\0' && strcmp(tag, "*") != 0) { server = server_find_tag(tag); if (server == NULL) server = server_find_lookup_tag(tag); } if (server == NULL) cmd_param_error(CMDERR_NOT_CONNECTED); if (*msg == '\0') msg = (char *) settings_get_str("quit_message"); signal_emit("server quit", 2, server, msg); cmd_params_free(free_arg); server_disconnect(server); }