diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/irc/proxy/dump.c | 18 | ||||
-rw-r--r-- | src/irc/proxy/listen.c | 62 | ||||
-rw-r--r-- | src/irc/proxy/module.h | 9 | ||||
-rw-r--r-- | src/irc/proxy/proxy.c | 8 |
4 files changed, 56 insertions, 41 deletions
diff --git a/src/irc/proxy/dump.c b/src/irc/proxy/dump.c index 49a4c6d2..0fe9ca4b 100644 --- a/src/irc/proxy/dump.c +++ b/src/irc/proxy/dump.c @@ -1,7 +1,7 @@ /* dump.c : proxy plugin - output all information about irc session - Copyright (C) 1999 Timo Sirainen + Copyright (C) 1999-2001 Timo Sirainen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -200,15 +200,9 @@ static void dump_join(IRC_CHANNEL_REC *channel, CLIENT_REC *client) } } -void plugin_proxy_dump_data(CLIENT_REC *client) +void proxy_dump_data(CLIENT_REC *client) { - if (client->server != NULL && - strcmp(client->server->nick, client->nick) != 0) { - /* change nick first so that clients won't try to eg. set - their own user mode with wrong nick.. hopefully works - with all clients. */ - proxy_outdata(client, ":%s!proxy NICK :%s\n", - client->nick, client->server->nick); + if (client->server != NULL) { g_free(client->nick); client->nick = g_strdup(client->server->nick); } @@ -216,11 +210,11 @@ void plugin_proxy_dump_data(CLIENT_REC *client) /* welcome info */ proxy_outdata(client, ":%s 001 %s :Welcome to the Internet Relay Network\n", client->proxy_address, client->nick); proxy_outdata(client, ":%s 002 %s :Your host is irssi-proxy, running version %s\n", client->proxy_address, client->nick, IRSSI_VERSION); - proxy_outdata(client, ":%s 003 %s :This server was created ...\n", client->nick); + proxy_outdata(client, ":%s 003 %s :This server was created ...\n", client->proxy_address, client->nick); if (client->server == NULL || !client->server->emode_known) - proxy_outdata(client, ":%s 004 %s proxy %s oirw abiklmnopqstv\n", client->proxy_address, client->nick, IRSSI_VERSION); + proxy_outdata(client, ":%s 004 %s %s %s oirw abiklmnopqstv\n", client->proxy_address, client->nick, client->proxy_address, IRSSI_VERSION); else - proxy_outdata(client, ":%s 004 %s proxy %s oirw abeIiklmnopqstv\n", client->proxy_address, client->nick, IRSSI_VERSION); + proxy_outdata(client, ":%s 004 %s %s %s oirw abeIiklmnopqstv\n", client->proxy_address, client->nick, client->proxy_address, IRSSI_VERSION); proxy_outdata(client, ":%s 251 %s :There are 0 users and 0 invisible on 1 servers\n", client->proxy_address, client->nick); proxy_outdata(client, ":%s 255 %s :I have 0 clients, 0 services and 0 servers\n", client->proxy_address, client->nick); proxy_outdata(client, ":%s 422 %s :MOTD File is missing\n", client->proxy_address, client->nick); diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c index 806b2db7..065d449b 100644 --- a/src/irc/proxy/listen.c +++ b/src/irc/proxy/listen.c @@ -1,7 +1,7 @@ /* - listen.c : sample plugin for irssi + listen.c : irc proxy - Copyright (C) 1999 Timo Sirainen + Copyright (C) 1999-2001 Timo Sirainen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -99,6 +99,7 @@ static void handle_client_connect_cmd(CLIENT_REC *client, else { /* wrong password! */ remove_client(client); + return; } } else if (strcmp(cmd, "NICK") == 0) { g_free_not_null(client->nick); @@ -113,7 +114,7 @@ static void handle_client_connect_cmd(CLIENT_REC *client, remove_client(client); } else { client->connected = TRUE; - plugin_proxy_dump_data(client); + proxy_dump_data(client); } } } @@ -130,24 +131,32 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args, remove_client(client); return; } if (strcmp(cmd, "PING") == 0) { - /* Reply to PING, if the parameter is either proxy_adress, - our own nick or empty. */ - char *server = args; - if (*server == ':') server++; + /* Reply to PING, if the server parameter is either + proxy_adress, our own nick or empty. */ + char *params, *server1, *server2, *server; + params = event_get_params(args, 2, &server1, &server2); + server = *server2 != '\0' ? server2 : server1; if (*server == '\0' || g_strncasecmp(server, client->proxy_address, strlen(client->proxy_address)) == 0 || g_strncasecmp(server, client->nick, strlen(client->nick)) == 0) { - if (*server == '\0') args = client->nick; - proxy_outdata(client, ":%s PONG %s\n", client->proxy_address, args); + if (*server == '\0') + args = client->nick; + else if (server == server2) { + /* <data> <server> - reply only with <data> */ + args = server1; + } + proxy_outdata(client, ":%s PONG %s :%s\n", client->proxy_address, client->proxy_address, args); + g_free(params); return; } + g_free(params); } if (client->server == NULL || !client->server->connected) { - proxy_outdata(client, ":%s NOTICE %s :Not connected to server", + proxy_outdata(client, ":%s NOTICE %s :Not connected to server\n", client->proxy_address, client->nick); return; } @@ -214,7 +223,6 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args, client->nick, client->proxy_address, target); g_free(params); } else if (strcmp(cmd, "PING") == 0) { - /* send all PINGs to server. */ proxy_redirect_event(client, "ping", 1, NULL, TRUE); } @@ -271,11 +279,14 @@ static void sig_listen(LISTEN_REC *listen) rec = g_new0(CLIENT_REC, 1); rec->listen = listen; rec->handle = handle; - rec->proxy_address = g_strdup(listen->ircnet); - rec->server = servers == NULL ? NULL : - strcmp(listen->ircnet, "*") == 0 ? - IRC_SERVER(servers->data) : - IRC_SERVER(server_find_chatnet(listen->ircnet)); + if (strcmp(listen->ircnet, "*") == 0) { + rec->proxy_address = g_strdup("irc.proxy"); + rec->server = servers == NULL ? NULL : IRC_SERVER(servers->data); + } else { + rec->proxy_address = g_strdup_printf("%s.proxy", listen->ircnet); + rec->server = servers == NULL ? NULL : + IRC_SERVER(server_find_chatnet(listen->ircnet)); + } rec->tag = g_input_add(handle, G_INPUT_READ, (GInputFunction) sig_listen_client, rec); @@ -347,6 +358,18 @@ static void sig_server_event(IRC_SERVER_REC *server, const char *line, g_free(event); } +static void proxy_client_reset_nick(CLIENT_REC *client) +{ + if (strcmp(client->nick, client->server->nick) == 0) + return; + + proxy_outdata(client, ":%s!proxy NICK :%s\n", + client->nick, client->server->nick); + + g_free(client->nick); + client->nick = g_strdup(client->server->nick); +} + static void event_connected(IRC_SERVER_REC *server) { GSList *tmp; @@ -360,9 +383,10 @@ static void event_connected(IRC_SERVER_REC *server) if (rec->connected && rec->server == NULL && (g_strcasecmp(server->connrec->chatnet, rec->listen->ircnet) == 0 || strcmp(rec->listen->ircnet, "*") == 0)) { - proxy_outdata(rec, ":%s NOTICE %s :Connected to server", + proxy_outdata(rec, ":%s NOTICE %s :Connected to server\n", rec->proxy_address, rec->nick); rec->server = server; + proxy_client_reset_nick(rec); } } } @@ -519,7 +543,7 @@ static void read_settings(void) } } -void plugin_proxy_listen_init(void) +void proxy_listen_init(void) { next_line = g_string_new(NULL); @@ -536,7 +560,7 @@ void plugin_proxy_listen_init(void) signal_add("setup changed", (SIGNAL_FUNC) read_settings); } -void plugin_proxy_listen_deinit(void) +void proxy_listen_deinit(void) { while (proxy_clients != NULL) remove_client(proxy_clients->data); diff --git a/src/irc/proxy/module.h b/src/irc/proxy/module.h index 3635d73f..2e5d0213 100644 --- a/src/irc/proxy/module.h +++ b/src/irc/proxy/module.h @@ -33,15 +33,12 @@ typedef struct { extern GSList *proxy_listens; extern GSList *proxy_clients; -void plugin_proxy_setup_init(void); -void plugin_proxy_setup_deinit(void); - -void plugin_proxy_listen_init(void); -void plugin_proxy_listen_deinit(void); +void proxy_listen_init(void); +void proxy_listen_deinit(void); void proxy_settings_init(void); -void plugin_proxy_dump_data(CLIENT_REC *client); +void proxy_dump_data(CLIENT_REC *client); void proxy_outdata(CLIENT_REC *client, const char *data, ...); void proxy_outdata_all(IRC_SERVER_REC *server, const char *data, ...); diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c index c7dc6418..f75a5b39 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -1,7 +1,7 @@ /* - sample.c : sample plugin for irssi + proxy.c : irc proxy - Copyright (C) 1999 Timo Sirainen + Copyright (C) 1999-2001 Timo Sirainen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -42,11 +42,11 @@ void irc_proxy_init(void) "... to set them."); } - plugin_proxy_listen_init(); + proxy_listen_init(); module_register("proxy", "irc"); } void irc_proxy_deinit(void) { - plugin_proxy_listen_deinit(); + proxy_listen_deinit(); } |