Mercurial > pidgin
comparison src/protocols/irc/irc.c @ 4966:54cd43869333
[gaim-migrate @ 5300]
fun stuff
this makes the modify account dialog make a little more sense for jabber,
and makes irc accounts distinguishable in the assorted dropdowns.
however, there is a slight catch. IRC accounts now take the form of
nick@server. The first time you log on with an IRC account, it will change
it for you. However, if you try to edit the account before it gets signed
on, the server will revert to the default (irc.freenode.net).
So go log in with all of your IRC accounts before you go editing them ;-)
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Thu, 03 Apr 2003 02:34:48 +0000 |
| parents | d9b6b5ae34e4 |
| children | ed2a6196ccab |
comparison
equal
deleted
inserted
replaced
| 4965:6e7082cf0892 | 4966:54cd43869333 |
|---|---|
| 55 | 55 |
| 56 #define USEROPT_SERV 0 | 56 #define USEROPT_SERV 0 |
| 57 #define USEROPT_PORT 1 | 57 #define USEROPT_PORT 1 |
| 58 #define USEROPT_CHARSET 2 | 58 #define USEROPT_CHARSET 2 |
| 59 | 59 |
| 60 #define DEFAULT_SERVER "irc.freenode.net" | |
| 61 | |
| 60 static struct prpl *my_protocol = NULL; | 62 static struct prpl *my_protocol = NULL; |
| 61 | 63 |
| 62 /* for win32 compatability */ | 64 /* for win32 compatability */ |
| 63 G_MODULE_IMPORT GSList *connections; | 65 G_MODULE_IMPORT GSList *connections; |
| 64 | 66 |
| 87 | 89 |
| 88 struct irc_data { | 90 struct irc_data { |
| 89 int fd; | 91 int fd; |
| 90 gboolean online; | 92 gboolean online; |
| 91 guint32 timer; | 93 guint32 timer; |
| 94 | |
| 95 char *server; | |
| 92 | 96 |
| 93 char *rxqueue; | 97 char *rxqueue; |
| 94 int rxlen; | 98 int rxlen; |
| 95 | 99 |
| 96 GString *str; | 100 GString *str; |
| 1789 return; | 1793 return; |
| 1790 } | 1794 } |
| 1791 } | 1795 } |
| 1792 | 1796 |
| 1793 g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n", | 1797 g_snprintf(buf, sizeof(buf), "USER %s %s %s :%s\r\n", |
| 1794 g_get_user_name(), hostname, | 1798 g_get_user_name(), hostname, |
| 1795 gc->account->proto_opt[USEROPT_SERV], | 1799 idata->server, |
| 1796 gc->account->alias && strlen(gc->account->alias) ? gc->account->alias : "gaim"); | 1800 *gc->account->alias ? gc->account->alias : "gaim"); |
| 1797 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { | 1801 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
| 1798 hide_login_progress(gc, "Write error"); | 1802 hide_login_progress(gc, "Write error"); |
| 1799 signoff(gc); | 1803 signoff(gc); |
| 1800 return; | 1804 return; |
| 1801 } | 1805 } |
| 1802 | 1806 |
| 1803 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", gc->username); | 1807 g_snprintf(buf, sizeof(buf), "NICK %s\r\n", gc->displayname); |
| 1804 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { | 1808 if (irc_write(idata->fd, buf, strlen(buf)) < 0) { |
| 1805 hide_login_progress(gc, "Write error"); | 1809 hide_login_progress(gc, "Write error"); |
| 1806 signoff(gc); | 1810 signoff(gc); |
| 1807 return; | 1811 return; |
| 1808 } | 1812 } |
| 1814 irc_login(struct gaim_account *account) | 1818 irc_login(struct gaim_account *account) |
| 1815 { | 1819 { |
| 1816 char buf[IRC_BUF_LEN]; | 1820 char buf[IRC_BUF_LEN]; |
| 1817 int rc; | 1821 int rc; |
| 1818 | 1822 |
| 1819 struct gaim_connection *gc = new_gaim_conn(account); | 1823 struct gaim_connection *gc; |
| 1820 struct irc_data *idata = gc->proto_data = g_new0(struct irc_data, 1); | 1824 struct irc_data *idata; |
| 1821 | 1825 char **parts; |
| 1822 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", gc->username); | 1826 if(!strrchr(account->username, '@')) { |
| 1827 char *username = g_strdup(account->username); | |
| 1828 g_snprintf(account->username, sizeof(account->username), "%s@%s", | |
| 1829 username, *account->proto_opt[USEROPT_SERV] ? | |
| 1830 account->proto_opt[USEROPT_SERV] : DEFAULT_SERVER); | |
| 1831 g_free(username); | |
| 1832 strcpy(account->proto_opt[USEROPT_SERV], ""); | |
| 1833 save_prefs(); | |
| 1834 } | |
| 1835 | |
| 1836 gc = new_gaim_conn(account); | |
| 1837 idata = gc->proto_data = g_new0(struct irc_data, 1); | |
| 1838 | |
| 1839 parts = g_strsplit(gc->username, "@", 2); | |
| 1840 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", parts[0]); | |
| 1841 idata->server = g_strdup(parts[1]); | |
| 1842 g_strfreev(parts); | |
| 1823 | 1843 |
| 1824 g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username); | 1844 g_snprintf(buf, sizeof(buf), _("Signon: %s"), gc->username); |
| 1825 set_login_progress(gc, 2, buf); | 1845 set_login_progress(gc, 2, buf); |
| 1826 | 1846 |
| 1827 idata->chantypes = g_strdup("#&!+"); | 1847 idata->chantypes = g_strdup("#&!+"); |
| 1828 idata->chanmodes = g_strdup("beI,k,lnt"); | 1848 idata->chanmodes = g_strdup("beI,k,lnt"); |
| 1829 idata->nickmodes = g_strdup("ohv"); | 1849 idata->nickmodes = g_strdup("ohv"); |
| 1830 idata->str = g_string_new(""); | 1850 idata->str = g_string_new(""); |
| 1831 idata->fd = -1; | 1851 idata->fd = -1; |
| 1832 | 1852 |
| 1833 rc = proxy_connect(account, account->proto_opt[USEROPT_SERV], | 1853 rc = proxy_connect(account, idata->server, |
| 1834 account->proto_opt[USEROPT_PORT][0] ? | 1854 account->proto_opt[USEROPT_PORT][0] ? |
| 1835 atoi(account->proto_opt[USEROPT_PORT]) : 6667, | 1855 atoi(account->proto_opt[USEROPT_PORT]) : 6667, |
| 1836 irc_login_callback, gc); | 1856 irc_login_callback, gc); |
| 1837 if (!account->gc || (rc != 0)) { | 1857 if (!account->gc || (rc != 0)) { |
| 1838 hide_login_progress(gc, "Unable to create socket"); | 1858 hide_login_progress(gc, "Unable to create socket"); |
| 2811 } | 2831 } |
| 2812 | 2832 |
| 2813 G_MODULE_EXPORT void | 2833 G_MODULE_EXPORT void |
| 2814 irc_init(struct prpl *ret) | 2834 irc_init(struct prpl *ret) |
| 2815 { | 2835 { |
| 2836 struct proto_user_split *pus; | |
| 2816 struct proto_user_opt *puo; | 2837 struct proto_user_opt *puo; |
| 2817 ret->protocol = PROTO_IRC; | 2838 ret->protocol = PROTO_IRC; |
| 2818 ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL; | 2839 ret->options = OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL; |
| 2819 ret->name = g_strdup("IRC"); | 2840 ret->name = g_strdup("IRC"); |
| 2820 ret->list_icon = irc_list_icon; | 2841 ret->list_icon = irc_list_icon; |
| 2840 ret->file_transfer_data_chunk = irc_file_transfer_data_chunk; | 2861 ret->file_transfer_data_chunk = irc_file_transfer_data_chunk; |
| 2841 ret->file_transfer_done = irc_file_transfer_done; | 2862 ret->file_transfer_done = irc_file_transfer_done; |
| 2842 ret->file_transfer_cancel =irc_file_transfer_cancel; | 2863 ret->file_transfer_cancel =irc_file_transfer_cancel; |
| 2843 #endif | 2864 #endif |
| 2844 | 2865 |
| 2845 puo = g_new0(struct proto_user_opt, 1); | 2866 pus = g_new0(struct proto_user_split, 1); |
| 2846 puo->label = g_strdup(_("Server:")); | 2867 pus->sep = '@'; |
| 2847 puo->def = g_strdup("irc.freenode.net"); | 2868 pus->label = g_strdup(_("Server:")); |
| 2848 puo->pos = USEROPT_SERV; | 2869 pus->def = g_strdup(DEFAULT_SERVER); |
| 2849 ret->user_opts = g_list_append(ret->user_opts, puo); | 2870 ret->user_splits = g_list_append(ret->user_splits, pus); |
| 2850 | 2871 |
| 2851 puo = g_new0(struct proto_user_opt, 1); | 2872 puo = g_new0(struct proto_user_opt, 1); |
| 2852 puo->label = g_strdup(_("Port:")); | 2873 puo->label = g_strdup(_("Port:")); |
| 2853 puo->def = g_strdup("6667"); | 2874 puo->def = g_strdup("6667"); |
| 2854 puo->pos = USEROPT_PORT; | 2875 puo->pos = USEROPT_PORT; |
| 2857 puo = g_new0(struct proto_user_opt, 1); | 2878 puo = g_new0(struct proto_user_opt, 1); |
| 2858 puo->label = g_strdup(_("Encoding:")); | 2879 puo->label = g_strdup(_("Encoding:")); |
| 2859 puo->def = g_strdup("ISO-8859-1"); | 2880 puo->def = g_strdup("ISO-8859-1"); |
| 2860 puo->pos = USEROPT_CHARSET; | 2881 puo->pos = USEROPT_CHARSET; |
| 2861 ret->user_opts = g_list_append(ret->user_opts, puo); | 2882 ret->user_opts = g_list_append(ret->user_opts, puo); |
| 2862 | 2883 |
| 2863 my_protocol = ret; | 2884 my_protocol = ret; |
| 2864 } | 2885 } |
| 2865 | 2886 |
| 2866 #ifndef STATIC | 2887 #ifndef STATIC |
| 2867 G_MODULE_EXPORT void | 2888 G_MODULE_EXPORT void |
