From 13c7cb9dd42a741c250e071bea27cf5117548a02 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 28 Sep 2003 22:05:06 +0000 Subject: Added /connect and /disconnect commands --- src/irc/irc-server.c | 38 ++++++++++++++++++++++++++++++++++---- src/irc/irc.h | 1 + 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'src/irc') diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index dce3d337e..daa059ca3 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -208,15 +208,15 @@ server_new (char *name, int autoconnect, char *address, int port, { t_irc_server *new_server; - if (!name || !address || (port < 0) || !nick1 || !nick2 || !nick3 - || !username || !realname) + if (!name || !address || (port < 0)) return NULL; #if DEBUG >= 1 log_printf ("creating new server (name:%s, address:%s, port:%d, pwd:%s, " "nick1:%s, nick2:%s, nick3:%s, username:%s, realname:%s)\n", - name, address, port, password, nick1, nick2, nick3, - username, realname); + name, address, port, (password) ? password : "", + (nick1) ? nick1 : "", (nick2) ? nick2 : "", (nick3) ? nick3 : "", + (username) ? username : "", (realname) ? realname : ""); #endif if ((new_server = server_alloc ())) @@ -576,12 +576,24 @@ server_connect (t_irc_server *server) void server_disconnect (t_irc_server *server) { + t_irc_channel *ptr_channel; + if (server->is_connected) { + /* write disconnection message on each channel/private window */ + for (ptr_channel = server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + irc_display_prefix (ptr_channel->window, PREFIX_INFO); + gui_printf (ptr_channel->window, "Disconnected from server!\n"); + } + + /* close communication with server */ close (server->server_read); close (server->server_write); close (server->sock4); server->is_connected = 0; + server->sock4 = -1; } } @@ -598,6 +610,24 @@ server_disconnect_all () server_disconnect (ptr_server); } +/* + * server_search: return pointer on a server with a name + */ + +t_irc_server * +server_search (char *servername) +{ + t_irc_server *ptr_server; + + for (ptr_server = irc_servers; ptr_server; + ptr_server = ptr_server->next_server) + { + if (strcmp (ptr_server->name, servername) == 0) + return ptr_server; + } + return NULL; +} + /* * server_get_number_connected: returns number of connected server */ diff --git a/src/irc/irc.h b/src/irc/irc.h index b74c8e28f..389a9f70f 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -152,6 +152,7 @@ extern void server_recv (t_irc_server *); extern int server_connect (); extern void server_disconnect (t_irc_server *); extern void server_disconnect_all (); +extern t_irc_server *server_search (char *); extern int server_get_number_connected (); extern int server_name_already_exists (char *); -- cgit v1.2.3