Tip of the day: You can allow trusted users to send more messages per second without having to make them IRCOp. Especially useful for bots.

Defines and conditional config

From UnrealIRCd documentation wiki
Jump to navigation Jump to search

You can define variables in the configuration file and use these variables elsewhere in the configuration file. You can also use this for conditional configuration. This can be used by advanced users, especially when sharing settings between servers and trying to use the same configuration files for all your servers.

Defining variables

You can define variables, like:

@define $SERVER "hub.example.org"

Using variables

Anywhere in the configuration file you can refer to $VARIABLENAME. For example:

me {
        name "$SERVER";
        info "TestNET Server ($SERVER)";
        sid 001;
}

Conditional configuration

You can use @if to activate/deactivate configuration depending on conditions:

@if $SERVER == "hub.example.org"
link {
        [..]
}
@endif

The following operations are supported:

Type of check Syntax example
Checking if the value of a variable matches @if $VARNAME == "something"
Checking if the value of a variable does NOT match @if $VARNAME != "something"
Checking if the value of a variable is greater than @if $VARNAME > "something"
Checking if the value of a variable is greater than or equal to @if $VARNAME >= "something"
Checking if the value of a variable is less than @if $VARNAME < "something"
Checking if the value of a variable is less than or equal to @if $VARNAME <= "something"
Check if a variable is defined (via @define earlier) @if defined(VARNAME)
Check if a variable is NOT defined (via @define earlier) @if !defined(VARNAME)
Check if a module is loaded @if module-loaded("somemod")
Check if a module is NOT loaded @if !module-loaded("somemod")
Check if a module exists on disk @if module-exists("third/somemod")
Check if a module does NOT exist on disk @if !module-exists("third/somemod")
Check if UnrealIRCd version is at least the specified version @if minimum-version("6.2.4")
Check if a file exists @if file-exists("somefile.conf")

The comparison operators (>, >=, <, <=) use natural ordering, so version strings and numbers compare correctly. For example @if $MAXCONNECTIONS >= 1024 works as expected. Double quotes around the value are optional. This requires UnrealIRCd 6.2.4 or later, older versions only support == and != and always require double quotes around the value.

Examples

The help.conf shipped with UnrealIRCd uses @if module-loaded() so /HELPOP CHMODES only displays certain lines if the module is actually loaded:

helpop chmodes {
        [..]
@if module-loaded("chanmodes/noctcp")
        " C = No CTCPs allowed in the channel [h]";
@endif
}

Similarly, module-exists can come in handy for third party modules:

@if module-exists("third/coolmodule")
loadmodule "third/coolmodule";
// do configuration here as well
@endif

The minimum-version function is useful if your config needs to support different UnrealIRCd versions:

@if minimum-version("6.2.4")
// use features only available in 6.2.4+
@endif

The file-exists function checks if a file exists. Paths are relative to the config directory, or absolute if starting with /:

@if file-exists("local.conf")
include "local.conf";
@endif

And variable comparison could be used to limit class::maxclients for instance (requires UnrealIRCd 6.2.4 or later):

class clients
{
	pingfreq 90;
	sendq 200k;
	recvq 8000;
@if $MAXCONNECTIONS >= 8192
	maxclients 5000;
@else
	maxclients 1000;
@endif
}

Default defines

The following built-in defines are available:

  • UNREALIRCD_VERSION: The full version, like 6.1.2-rc1
  • UNREALIRCD_VERSION_GENERATION: the first part of the version (generation), e.g. 6
  • UNREALIRCD_VERSION_MAJOR: the second part of the version (major version), e.g. 1
  • UNREALIRCD_VERSION_MINOR: the third part of the version (minor version), e.g. 2
  • UNREALIRCD_VERSION_SUFFIX: the last part of the version (version suffix), e.g. -rc1

And these are available in UnrealIRCd 6.2.4 and later:

  • GEOIP_ENGINE: depending on your answer in ./Config this is one of: geoip_classic, geoip_mmdb or none.
  • CONFDIR: the configuration directory, e.g. /home/user/unrealircd/conf
  • DATADIR: the permanent data directory, e.g. /home/user/unrealircd/data
  • LOGDIR: the log directory, e.g. /home/user/unrealircd/logs
  • TMPDIR: the temporary files directory, e.g. /home/user/unrealircd/tmp
  • DOCDIR: the documentation directory, e.g. /home/user/unrealircd/doc
  • MODULESDIR: the modules directory, e.g. /home/user/unrealircd/modules
  • MAXCONNECTIONS: the maximum number of connections, e.g. 16384