nick and time is useful for JOIN and TOPIC commands. `chanlog.txt` records all
channels changes in this format.
(NOTE: this feature is deprecated. We only use it for bootstrapping lua:
-`LUA eval :dofile"lua/init.lua"`. Then in `lua/local.lua` we set up the
+`LUA eval :dofile(getluafile"init.lua")`. Then in `lua/local.lua` we set up the
channels. Also, be sure to PART any `--autojoin` channels if you want to give
those a specific creation timestamp.)
channel. This option can be specified multiple times.
Data directory can be configured with `--datadir` argument. The default can be
-configured at compile time via IRCDDATADIR define. Otherwise it deafults to
-LOCALSTATEDIR/lib/patchyircd if LOCALSTATEDIR is defined. Otherwise it's "data"
-in the working directory.
+configured at compile time via `IRCDDATADIR` define. Otherwise it deafults to
+`LOCALSTATEDIR/lib/patchyircd` if `LOCALSTATEDIR` is defined. Otherwise it's
+`data` in the working directory.
+
+Similarly, the location of lua files is configured by `--luadir`, `IRCDLUADIR`,
+defaulting to `DATADIR/patchyircd/lua`, or `lua`.
+
+If you're installing system-wide, the following is sufficient:
+`-DLOCALSTATEDIR=/var -DDATADIR=/usr/share`
function commands.reload(client, source, command, args)
client_notice(client, "reloading...")
- dofile "lua/init.lua"
+ dofile(getluafile "init.lua")
client_notice(client, "done")
end
setmetatable(_G, getmetatable(ircd))
channel_join(client_map[args[1]], args[2], true)
end
-dofile "lua/irccloud.lua"
-dofile "lua/ctcp.lua"
-dofile "lua/spam.lua"
-pcall(dofile, "lua/local.lua")
+dofile(getluafile "irccloud.lua")
+dofile(getluafile "ctcp.lua")
+dofile(getluafile "spam.lua")
+pcall(dofile, getluafile "local.lua")
lua_pushstring(L, res);
return 1;
}
+static int fn_getdatafile(lua_State *L) {
+ const char *fn = luaL_checkstring(L, 1);
+ const char *res = getdatafile(fn);
+ lua_pushstring(L, res);
+ return 1;
+}
+static int fn_getluafile(lua_State *L) {
+ const char *fn = luaL_checkstring(L, 1);
+ const char *res = getluafile(fn);
+ lua_pushstring(L, res);
+ return 1;
+}
void admin_init(void)
{
{"client_chghost", fn_client_chghost},
{"rpl_whoisspecial", fn_rpl_whoisspecial},
{"db_read_rhs", fn_db_read_rhs},
+ {"getdatafile", fn_getdatafile},
+ {"getluafile", fn_getluafile},
{0, 0},
};
lua_pushglobaltable(L);
return fprintf(stderr, "not enough parameters\n"), 1;
datadir = argv[i+1];
i += 1;
+ } else if(!strcmp(argv[i], "--luadir")) {
+ if (i + 1 >= argc)
+ return fprintf(stderr, "not enough parameters\n"), 1;
+ luadir = argv[i+1];
+ i += 1;
} else {
return fprintf(stderr, "unknown flag '%s'\n", argv[i]), 1;
}
return 1;
}
+static const char *getdirfile_r(char *buf, size_t size, const char *dir, const char *fn)
+{
+ size_t len1 = strlen(dir);
+ size_t len2 = strlen(fn);
+ if (len1+1+len2+1 > size)
+ return 0;
+ memcpy(buf, dir, len1);
+ buf[len1] = '/';
+ int needslash = len1 && dir[len1-1] != '/';
+ memcpy(buf+len1+needslash, fn, len2);
+ buf[len1+needslash+len2] = '\0';
+ return buf;
+}
+
#ifndef IRCDDATADIR
# ifdef LOCALSTATEDIR
# define IRCDDATADIR LOCALSTATEDIR "/lib/patchyircd"
const char *getdatafile(const char *fn)
{
static char buf[256];
- size_t len1 = strlen(datadir);
- size_t len2 = strlen(fn);
- if (len1+1+len2+1 > sizeof(buf))
+ if (!getdirfile_r(buf, sizeof(buf), datadir, fn))
+ abort();
+ return buf;
+}
+
+#ifndef IRCDLUADIR
+# ifdef DATADIR
+# define IRCDLUADIR DATADIR "/patchyircd/lua"
+# else
+# define IRCDLUADIR "lua"
+# endif
+#endif
+const char *luadir = IRCDLUADIR;
+const char *getluafile(const char *fn)
+{
+ static char buf[256];
+ if (!getdirfile_r(buf, sizeof(buf), luadir, fn))
abort();
- memcpy(buf, datadir, len1);
- buf[len1] = '/';
- int needslash = len1 && datadir[len1-1] != '/';
- memcpy(buf+len1+needslash, fn, len2);
- buf[len1+needslash+len2] = '\0';
return buf;
}
int irc_glob(const char *key, const char *mask);
extern const char *datadir;
const char *getdatafile(const char *fn);
+extern const char *luadir;
+const char *getluafile(const char *fn);
#endif