/** * Plugin entry point. */ int hexchat_plugin_init(hexchat_plugin *plugin_handle, const char **name, const char **desc, const char **version, char *arg) { ph = plugin_handle; /* Send our info to HexChat */ *name = plugin_name; *desc = plugin_desc; *version = plugin_version; /* Register commands */ hexchat_hook_command(ph, "SETKEY", HEXCHAT_PRI_NORM, handle_setkey, usage_setkey, NULL); hexchat_hook_command(ph, "DELKEY", HEXCHAT_PRI_NORM, handle_delkey, usage_delkey, NULL); hexchat_hook_command(ph, "GETKEY", HEXCHAT_PRI_NORM, handle_getkey, usage_getkey, NULL); /* Add handlers */ hexchat_hook_command(ph, "", HEXCHAT_PRI_NORM, handle_outgoing, NULL, NULL); hexchat_hook_server(ph, "NOTICE", HEXCHAT_PRI_NORM, handle_incoming, NULL); hexchat_hook_server(ph, "PRIVMSG", HEXCHAT_PRI_NORM, handle_incoming, NULL); //hexchat_hook_server(ph, "RAW LINE", HEXCHAT_PRI_NORM, handle_debug, NULL); hexchat_hook_server(ph, "TOPIC", HEXCHAT_PRI_NORM, handle_incoming, NULL); hexchat_hook_server(ph, "332", HEXCHAT_PRI_NORM, handle_incoming, NULL); hexchat_printf(ph, "%s plugin loaded\n", plugin_name); /* Return success */ return 1; }
int hexchat_plugin_init (hexchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg) { /* we need to save this for use with any hexchat_* functions */ ph = plugin_handle; /* tell HexChat our info */ *plugin_name = name; *plugin_desc = desc; *plugin_version = version; hexchat_hook_command (ph, "SASL", HEXCHAT_PRI_NORM, sasl_cmd_cb, sasl_help, 0); hexchat_hook_print (ph, "Connected", HEXCHAT_PRI_NORM, connect_cb, NULL); /* hexchat_hook_print (ph, "Disconnected", HEXCHAT_PRI_NORM, disconnect_cb, NULL); */ hexchat_hook_server (ph, "CAP", HEXCHAT_PRI_NORM, cap_cb, NULL); hexchat_hook_server (ph, "RAW LINE", HEXCHAT_PRI_NORM, server_cb, NULL); hexchat_hook_server (ph, "903", HEXCHAT_PRI_NORM, authend_cb, NULL); hexchat_hook_server (ph, "904", HEXCHAT_PRI_NORM, authend_cb, NULL); hexchat_hook_server (ph, "905", HEXCHAT_PRI_NORM, authend_cb, NULL); hexchat_hook_server (ph, "906", HEXCHAT_PRI_NORM, authend_cb, NULL); hexchat_hook_server (ph, "907", HEXCHAT_PRI_NORM, authend_cb, NULL); hexchat_printf (ph, "%s plugin loaded\n", name); return 1; }
static int api_hexchat_hook_server(lua_State *L) { char const *command = luaL_optstring(L, 1, "RAW LINE"); hook_info *info, **u; int ref, pri; lua_pushvalue(L, 2); ref = luaL_ref(L, LUA_REGISTRYINDEX); pri = luaL_optinteger(L, 3, HEXCHAT_PRI_NORM); info = g_new(hook_info, 1); info->state = L; info->ref = ref; info->hook = hexchat_hook_server(ph, command, pri, api_server_closure, info); u = lua_newuserdata(L, sizeof(hook_info *)); *u = info; luaL_newmetatable(L, "hook"); lua_setmetatable(L, -2); register_hook(info); return 1; }
/* Xchat::Internal::hook_server(name, priority, callback, userdata) */ static XS (XS_Xchat_hook_server) { char *name; int pri; SV *callback; SV *userdata; SV *package; hexchat_hook *hook; HookData *data; dXSARGS; if (items != 5) { hexchat_print (ph, "Usage: Xchat::Internal::hook_server(name, priority, callback, userdata, package)"); } else { name = SvPV_nolen (ST (0)); pri = (int) SvIV (ST (1)); callback = ST (2); userdata = ST (3); package = ST (4); data = NULL; data = malloc (sizeof (HookData)); if (data == NULL) { XSRETURN_UNDEF; } data->callback = newSVsv (callback); data->userdata = newSVsv (userdata); data->depth = 0; data->package = newSVsv (package); hook = hexchat_hook_server (ph, name, pri, server_cb, data); XSRETURN_IV (PTR2IV (hook)); } }