channel_part(cl, chan, reason, kicker);
return 0;
}
+static int fn_client_chghost(lua_State *L)
+{
+ struct client_data *cl = *(struct client_data **)luaL_checkudata(L, 1, "client");
+ const char *newusername = luaL_checkstring(L, 2);
+ const char *newhostname = luaL_checkstring(L, 3);
+ client_chghost(cl, newusername, newhostname);
+ return 0;
+}
+
void admin_init(void)
{
lua_State *L = luaL_newstate();
lua_setglobal(L, "channel_join");
lua_pushcfunction(L, fn_channel_part);
lua_setglobal(L, "channel_part");
+ lua_pushcfunction(L, fn_client_chghost);
+ lua_setglobal(L, "client_chghost");
}
void admin_fini(void)
{
{ "away-notify", CAP_AWAYNOTIFY },
{ "invite-notify", CAP_INVITENOTIFY },
{ "extended-monitor", CAP_EXTENDEDMONITOR },
+ { "chghost", CAP_CHGHOST },
+ { "setname", CAP_SETNAME },
+ { "account-notify", CAP_ACCOUNTNOTIFY },
{ 0, 0 }
};
default:
return err_needmoreparams(client, command), sendbuf(client), 0; /* FIXME: wrong error */
}
+ } else if(strcmp(command, "SETNAME") == 0) {
+ if (!is_registered(client))
+ return err_notregistered(client), sendbuf(client), 0;
+ if (argc == 0)
+ return err_needmoreparams(client, command), sendbuf(client), 0;
+ free(client->realname);
+ client->realname = mystrdup(args[0]);
+ msg_setname(client);
+ int cookie = sendbuf_visible_caps(client, CAP_SETNAME, 0);
+ sendbuf_monitor(client->key, cookie, CAP_SETNAME|CAP_EXTENDEDMONITOR, 0);
#ifdef HAS_LUA
} else if(strcmp(command, "LUA") == 0) {
if (argc < 1)
if (map_set(&client_map, client->key, client, 0) == -1)
abort();
rpl_mononline(0, client), sendbuf_monitor(client->key, 0, 0, 0);
-
return;
}
+void client_chghost(struct client_data *client, const char *newusername, const char *newhostname)
+{
+ if (!strcmp(client->username, newusername) && !strcmp(client->hostname, newhostname))
+ return;
+ msg_quit(client, "Changing hostname", "");
+ sendbuf_visible_caps(client, 0, CAP_CHGHOST);
+ msg_chghost(client, newusername, newhostname);
+ int cookie = sendbuf_visible_caps(client, CAP_CHGHOST, 0);
+ sendbuf_monitor(client->key, cookie, CAP_CHGHOST|CAP_EXTENDEDMONITOR, 0);
+ int changedacc = client->username[0] != '~' || newusername[0] != '~';
+ free(client->username);
+ client->username = mystrdup(newusername);
+ free(client->hostname);
+ client->hostname = mystrdup(newhostname);
+ struct channel *chan;
+ map_foreach(&client->channels, 0, &chan) {
+ msg_join(client, chan);
+ sendbuf_list_sans_self_caps(client, &chan->members, 0, 0, CAP_EXTENDEDJOIN|CAP_CHGHOST);
+ msg_join(client, chan);
+ sendbuf_list_sans_self_caps(client, &chan->members, 0, CAP_EXTENDEDJOIN, CAP_CHGHOST);
+ if (map_get(&chan->v, client->key)) {
+ copy_strf(&databuf, ":cia!cia@cia.gov MODE %s +v %s\r\n", chan->name, client->nick);
+ sendbuf_list_sans_self_caps(client, &chan->members, 0, 0, CAP_CHGHOST);
+ }
+ if (map_get(&chan->o, client->key)) {
+ copy_strf(&databuf, ":cia!cia@cia.gov MODE %s +o %s\r\n", chan->name, client->nick);
+ sendbuf_list_sans_self_caps(client, &chan->members, 0, 0, CAP_CHGHOST);
+ }
+ }
+ if (changedacc) {
+ msg_account(client);
+ int cookie = sendbuf_visible_caps(client, CAP_ACCOUNTNOTIFY, 0);
+ sendbuf_monitor(client->key, cookie, CAP_ACCOUNTNOTIFY|CAP_EXTENDEDMONITOR, 0);
+ }
+}
void channel_sendtopic(struct client_data *client, struct channel *chan, int joining)
{
if (chan->topic) {
copy_strf(&databuf, ":%s!%s@%s WALLOPS :%s\r\n",
src->nick, src->username, src->hostname, msg);
}
+void msg_chghost(struct client_data *src, const char *newusername, const char *newhostname)
+{
+ copy_strf(&databuf, ":%s!%s@%s CHGHOST %s %s\r\n",
+ src->nick, src->username, src->hostname, newusername, newhostname);
+}
+void msg_setname(struct client_data *src)
+{
+ copy_strf(&databuf, ":%s!%s@%s SETNAME :%s\r\n",
+ src->nick, src->username, src->hostname, src->realname);
+}
+void msg_account(struct client_data *src)
+{
+ copy_strf(&databuf, ":%s!%s@%s ACCOUNT %s\r\n",
+ src->nick, src->username, src->hostname, src->username[0] != '~' ? src->username : "*");
+}
void rpl_welcome(struct client_data *client) // 001
{
copy_strf(&databuf, ":%s 001 %s :Welcome to the Patchy Network, %s\r\n", hostname, client->nick, client->nick);