InspIRCd
2.0
|
#include <inspircd.h>
Public Member Functions | |
std::string | GetUID () |
User * | FindUUID (const std::string &uid) |
User * | FindUUID (const char *uid) |
void | BuildISupport () |
time_t | Time () |
long | Time_ns () |
void | UpdateTime () |
std::string | GenRandomStr (int length, bool printable=true) |
unsigned long | GenRandomInt (unsigned long max) |
int | BindPorts (FailedPortList &failed_ports) |
bool | BindSocket (int sockfd, int port, const char *addr, bool dolisten=true) |
std::string | GetServerDescription (const std::string &servername) |
User * | FindNick (const std::string &nick) |
User * | FindNick (const char *nick) |
User * | FindNickOnly (const char *nick) |
User * | FindNickOnly (const std::string &nick) |
Channel * | FindChan (const std::string &chan) |
Channel * | FindChan (const char *chan) |
void | CheckRoot () |
bool | OpenLog (char **argv, int argc) |
void | SignalHandler (int signal) |
void | Exit (int status) |
long | ChannelCount () |
void | SendError (const std::string &s) |
bool | AddResolver (Resolver *r, bool cached) |
void | AddCommand (Command *f) |
void | SendMode (const std::vector< std::string > ¶meters, User *user) |
void | SendGlobalMode (const std::vector< std::string > ¶meters, User *user) |
CmdResult | CallCommandHandler (const std::string &commandname, const std::vector< std::string > ¶meters, User *user) |
bool | IsValidModuleCommand (const std::string &commandname, int pcnt, User *user) |
bool | IsValidMask (const std::string &mask) |
void | RehashServer () |
bool | NickMatchesEveryone (const std::string &nick, User *user) |
bool | IPMatchesEveryone (const std::string &ip, User *user) |
bool | HostMatchesEveryone (const std::string &mask, User *user) |
long | Duration (const std::string &str) |
int | PassCompare (Extensible *ex, const std::string &data, const std::string &input, const std::string &hashtype) |
bool | ULine (const std::string &server) |
bool | SilentULine (const std::string &server) |
std::string | GetVersionString (bool rawversion=false) |
void | WritePID (const std::string &filename, bool exitonfail=true) |
InspIRCd (int argc, char **argv) | |
void | SendWhoisLine (User *user, User *dest, int numeric, const std::string &text) |
void | SendWhoisLine (User *user, User *dest, int numeric, const char *format,...) |
void | DoWhois (User *user, User *dest, unsigned long signon, unsigned long idle, const char *nick) |
void | Restart (const std::string &reason) |
void | Cleanup () |
void | RehashUsersAndChans () |
void | ResetMaxBans () |
std::string | TimeString (time_t curtime) |
int | Run () |
void | AddExtBanChar (char c) |
char * | GetReadBuffer () |
Static Public Member Functions | |
static void | SetSignal (int signal) |
static void | QuickExit (int status) |
static bool | Match (const std::string &str, const std::string &mask, unsigned const char *map=NULL) |
static bool | Match (const char *str, const char *mask, unsigned const char *map=NULL) |
static bool | MatchCIDR (const std::string &str, const std::string &mask, unsigned const char *map=NULL) |
static bool | MatchCIDR (const char *str, const char *mask, unsigned const char *map=NULL) |
static void | StripColor (std::string &sentence) |
static void | ProcessColors (file_cache &input) |
Static Public Attributes | |
static const char | LogHeader [] |
static sig_atomic_t | s_signal = 0 |
Friends | |
class | TestSuite |
The main class of the irc server. This class contains instances of all the other classes in this software. Amongst other things, it contains a ModeParser, a DNS object, a CommandParser object, and a list of active Module objects, and facilities for Module objects to interact with the core system it implements.
InspIRCd::InspIRCd | ( | int | argc, |
char ** | argv | ||
) |
This constructor initialises all the subsystems and reads the config file.
argc | The argument count passed to main() |
argv | The argument list passed to main() |
<anything> | If anything is thrown from here and makes it to you, you should probably just give up and go home. Yes, really. It's that bad. Higher level classes should catch any non-fatal exceptions. |
|
inline |
Add a command to this server's command parser
f | A Command command handler object to add |
ModuleException | Will throw ModuleExcption if the command already exists |
void InspIRCd::AddExtBanChar | ( | char | c | ) |
Adds an extban char to the 005 token.
bool InspIRCd::AddResolver | ( | Resolver * | r, |
bool | cached | ||
) |
Add a dns Resolver class to this server's active set
r | The resolver to add |
cached | If this value is true, then the cache will be searched for the DNS result, immediately. If the value is false, then a request will be sent to the nameserver, and the result will not be immediately available. You should usually use the boolean value which you passed to the Resolver constructor, which Resolver will set appropriately depending on if cached results are available and haven't expired. It is however safe to force this value to false, forcing a remote DNS lookup, but not an update of the cache. |
int InspIRCd::BindPorts | ( | FailedPortList & | failed_ports | ) |
Bind all ports specified in the configuration file.
bool InspIRCd::BindSocket | ( | int | sockfd, |
int | port, | ||
const char * | addr, | ||
bool | dolisten = true |
||
) |
Binds a socket on an already open file descriptor
sockfd | A valid file descriptor of an open socket |
port | The port number to bind to |
addr | The address to bind to (IP only) |
dolisten | Should this port be listened on? |
This will bind a socket to a port. It works for UDP/TCP. It can only bind to IP addresses, if you wish to bind to hostnames you should first resolve them using class 'Resolver'.
void InspIRCd::BuildISupport | ( | ) |
Build the ISUPPORT string by triggering all modules On005Numeric events
CmdResult InspIRCd::CallCommandHandler | ( | const std::string & | commandname, |
const std::vector< std::string > & | parameters, | ||
User * | user | ||
) |
Call the handler for a given command.
commandname | The command whos handler you wish to call |
parameters | The mode parameters |
user | The user to execute the command as |
long InspIRCd::ChannelCount | ( | ) |
Return a count of channels on the network
void InspIRCd::CheckRoot | ( | ) |
Check we aren't running as root, and exit if we are
void InspIRCd::Cleanup | ( | ) |
Prepare the ircd for restart or shutdown. This function unloads all modules which can be unloaded, closes all open sockets, and closes the logfile.
void InspIRCd::DoWhois | ( | User * | user, |
User * | dest, | ||
unsigned long | signon, | ||
unsigned long | idle, | ||
const char * | nick | ||
) |
Handle /WHOIS
long InspIRCd::Duration | ( | const std::string & | str | ) |
Calculate a duration in seconds from a string in the form 1y2w3d4h6m5s
str | A string containing a time in the form 1y2w3d4h6m5s (one year, two weeks, three days, four hours, six minutes and five seconds) |
Refactored by Brain, Jun 2009. Much faster with some clever O(1) array lookups and pointer maths.
void InspIRCd::Exit | ( | int | status | ) |
Causes the server to exit after unloading modules and closing all open file descriptors.
status | The exit code to give to the operating system (See the ExitStatus enum for valid values) |
Channel * InspIRCd::FindChan | ( | const char * | chan | ) |
Find a channel in the channels hash
chan | The channel to find |
Channel * InspIRCd::FindChan | ( | const std::string & | chan | ) |
Find a channel in the channels hash
chan | The channel to find |
User * InspIRCd::FindNick | ( | const char * | nick | ) |
Find a user in the nick hash. If the user cant be found in the nick hash check the uuid hash
nick | The nickname to find |
User * InspIRCd::FindNick | ( | const std::string & | nick | ) |
Find a user in the nick hash. If the user cant be found in the nick hash check the uuid hash
nick | The nickname to find |
User * InspIRCd::FindNickOnly | ( | const char * | nick | ) |
Find a user in the nick hash ONLY
User * InspIRCd::FindNickOnly | ( | const std::string & | nick | ) |
Find a user in the nick hash ONLY
User * InspIRCd::FindUUID | ( | const char * | uid | ) |
Find a user in the UUID hash
uid | The UUID to find |
User * InspIRCd::FindUUID | ( | const std::string & | uid | ) |
Find a user in the UUID hash
uid | The UUID to find |
unsigned long InspIRCd::GenRandomInt | ( | unsigned long | max | ) |
Generate a random integer. This is generally more secure than rand()
std::string InspIRCd::GenRandomStr | ( | int | length, |
bool | printable = true |
||
) |
Generate a random string with the given length
length | The length in bytes |
printable | if false, the string will use characters 0-255; otherwise, it will be limited to 0x30-0x7E ('0'-'~', nonspace printable characters) |
std::string InspIRCd::GetServerDescription | ( | const std::string & | servername | ) |
Gets the GECOS (description) field of the given server. If the servername is not that of the local server, the name is passed to handling modules which will attempt to determine the GECOS that bleongs to the given servername.
servername | The servername to find the description of |
std::string InspIRCd::GetUID | ( | ) |
Returns the next available UID for this server.
std::string InspIRCd::GetVersionString | ( | bool | rawversion = false | ) |
Returns the full version string of this ircd
bool InspIRCd::HostMatchesEveryone | ( | const std::string & | mask, |
User * | user | ||
) |
Check if the given hostmask matches too many users, send errors to the given user
mask | A hostmask to match against |
user | A user to send error text to |
bool InspIRCd::IPMatchesEveryone | ( | const std::string & | ip, |
User * | user | ||
) |
Check if the given IP mask matches too many users, send errors to the given user
ip | An ipmask to match against |
user | A user to send error text to |
bool InspIRCd::IsValidMask | ( | const std::string & | mask | ) |
Return true if the given parameter is a valid [email protected] mask
mask | A [email protected] masak to match against |
bool InspIRCd::IsValidModuleCommand | ( | const std::string & | commandname, |
int | pcnt, | ||
User * | user | ||
) |
Return true if the command is a module-implemented command and the given parameters are valid for it
commandname | The command name to check |
pcnt | The parameter count |
user | The user to test-execute the command as |
|
static |
Match two strings using pattern matching, optionally, with a map to check case against (may be NULL). If map is null, match will be case insensitive.
str | The literal string to match against |
mask | The glob pattern to match against. |
map | The character map to use when matching. |
|
static |
Match two strings using pattern matching, optionally, with a map to check case against (may be NULL). If map is null, match will be case insensitive. Supports CIDR patterns as well as globs.
str | The literal string to match against |
mask | The glob or CIDR pattern to match against. |
map | The character map to use when matching. |
bool InspIRCd::NickMatchesEveryone | ( | const std::string & | nick, |
User * | user | ||
) |
Check if the given nickmask matches too many users, send errors to the given user
nick | A nickmask to match against |
user | A user to send error text to |
bool InspIRCd::OpenLog | ( | char ** | argv, |
int | argc | ||
) |
Determine the right path for, and open, the logfile
argv | The argv passed to main() initially, used to calculate program path |
argc | The argc passed to main() initially, used to calculate program path |
int InspIRCd::PassCompare | ( | Extensible * | ex, |
const std::string & | data, | ||
const std::string & | input, | ||
const std::string & | hashtype | ||
) |
Attempt to compare a password to a string from the config file. This will be passed to handling modules which will compare the data against possible hashed equivalents in the input string.
ex | The object (user, server, whatever) causing the comparison. |
data | The data from the config file |
input | The data input by the oper |
hashtype | The hash from the config file |
|
static |
Parses color codes from string values to actual color codes
input | The data to process |
|
static |
Causes the server to exit immediately with exit code 0. The status code is required for signal handlers, and ignored.
void InspIRCd::RehashServer | ( | ) |
Rehash the local server
void InspIRCd::RehashUsersAndChans | ( | ) |
This copies the user and channel hash_maps into new hash maps. This frees memory used by the hash_map allocator (which it neglects to free, most of the time, using tons of ram)
Because hash_map doesn't free its buckets when we delete items, we occasionally recreate the hash to free them up. We do this by copying the entries from the old hash to a new hash, causing all empty buckets to be weeded out of the hash. Since this is quite expensive, it's not done very often.
void InspIRCd::ResetMaxBans | ( | ) |
Resets the cached max bans value on all channels. Called by rehash.
void InspIRCd::Restart | ( | const std::string & | reason | ) |
Restart the server. This function will not return. If an error occurs, it will throw an instance of CoreException.
reason | The restart reason to show to all clients |
CoreException | An instance of CoreException indicating the error from execv(). |
int InspIRCd::Run | ( | ) |
Begin execution of the server. NOTE: this function NEVER returns. Internally, it will repeatedly loop.
void InspIRCd::SendError | ( | const std::string & | s | ) |
Send an error notice to all local users, opered and unopered
s | The error string to send |
void InspIRCd::SendGlobalMode | ( | const std::vector< std::string > & | parameters, |
User * | user | ||
) |
Send a modechange and route it to the network. The parameters provided are identical to that sent to the handler for class cmd_mode.
parameters | The mode parameters |
user | The user to send error messages to |
void InspIRCd::SendMode | ( | const std::vector< std::string > & | parameters, |
User * | user | ||
) |
Send a modechange. The parameters provided are identical to that sent to the handler for class cmd_mode.
parameters | The mode parameters |
user | The user to send error messages to |
Send a line of WHOIS data to a user.
user | user to send the line to |
dest | user being WHOISed |
numeric | Numeric to send |
format | Format string for the numeric |
... | Parameters for the format string |
Send a line of WHOIS data to a user.
user | user to send the line to |
dest | user being WHOISed |
numeric | Numeric to send |
text | Text of the numeric |
|
static |
Sets the signal recieved
signal | the signal recieved |
void InspIRCd::SignalHandler | ( | int | signal | ) |
Handles incoming signals after being set
signal | the signal recieved |
bool InspIRCd::SilentULine | ( | const std::string & | server | ) |
Returns true if the uline is 'silent' (doesnt generate remote connect notices etc).
|
static |
Strips all color codes from the given string
sentence | The string to strip from |
|
inline |
Get the current time Because this only calls time() once every time around the mainloop, it is much faster than calling time() directly.
|
inline |
The fractional time at the start of this mainloop iteration (nanoseconds)
std::string InspIRCd::TimeString | ( | time_t | curtime | ) |
Return a time_t as a human-readable string.
bool InspIRCd::ULine | ( | const std::string & | server | ) |
Check if a given server is a uline. An empty string returns true, this is by design.
server | The server to check for uline status |
void InspIRCd::UpdateTime | ( | ) |
Update the current time. Don't call this unless you have reason to do so.
void InspIRCd::WritePID | ( | const std::string & | filename, |
bool | exitonfail = true |
||
) |
Attempt to write the process id to a given file
filename | The PID file to attempt to write to |
exitonfail | If true and the PID fail cannot be written log to stdout and exit, otherwise only log on failure |
ActionList InspIRCd::AtomicActions |
Actions that must happen outside of the current call stack
BanCacheManager* InspIRCd::BanCache |
BanCacheManager is used to speed up checking of restrictions on connection to the IRCd.
chan_hash* InspIRCd::chanlist |
Channel list, a hash_map containing all channels XXX move to channel manager class
ServerConfig* InspIRCd::Config |
Server Config class, holds configuration file data
std::string InspIRCd::ConfigFileName |
Config file pathname specified on the commandline or via ./configure
ConfigReaderThread* InspIRCd::ConfigThread |
The thread/class used to read config files in REHASH and on startup
FakeUser* InspIRCd::FakeClient |
Globally accessible fake user record. This is used to force mode changes etc across s2s, etc.. bit ugly, but.. better than how this was done in 1.1 Reason for it: kludge alert! SendMode expects a User* to send the numeric replies back to, so we create it a fake user that isnt in the user hash and set its descriptor to FD_MAGIC_NUMBER so the data falls into the abyss :p
Quit a user for excess flood, and if they are not fully registered yet, temporarily zline their IP.
current | user to quit |
caller2<void, char*, size_t> InspIRCd::GenRandom |
Fill a buffer with random bits
CullList InspIRCd::GlobalCulls |
Global cull list, will be processed on next iteration
caller2<bool, const char*, size_t> InspIRCd::IsChannel |
Return true if a channel name is valid
chname | A channel name to verify |
caller1<bool, const char*> InspIRCd::IsIdent |
Return true if an ident is valid
An | ident to verify |
caller2<bool, const char*, size_t> InspIRCd::IsNick |
Return true if a nickname is valid
n | A nickname to verify |
caller1<bool, const std::string&> InspIRCd::IsSID |
Return true if str looks like a server ID
string | to check against |
|
static |
LogManager* InspIRCd::Logs |
LogManager handles logging.
ModeParser* InspIRCd::Modes |
Mode handler, handles mode setting and removal
ModuleManager* InspIRCd::Modules |
ModuleManager contains everything related to loading/unloading modules.
LocalIntExt InspIRCd::NICKForced |
Holds extensible for user nickforced
LocalStringExt InspIRCd::OperQuit |
Holds extensible for user operquit
CommandParser* InspIRCd::Parser |
Command parser, handles client to server commands
ProtocolInterface* InspIRCd::PI |
Protocol interface, overridden by server protocol modules
std::vector<ListenSocket*> InspIRCd::ports |
List of the open ports
caller1<void, const std::string&> InspIRCd::Rehash |
Rehash the local server
|
static |
Set to the current signal recieved
SocketEngine* InspIRCd::SE |
Socket engine, handles socket activity events
SnomaskManager* InspIRCd::SNO |
Snomask manager - handles routing of snomask messages to opers.
time_t InspIRCd::startup_time |
Time this ircd was booted
serverstats* InspIRCd::stats |
Stats class, holds miscellaneous stats counters
ThreadEngine* InspIRCd::Threads |
Thread engine, Handles threading where required
TimerManager* InspIRCd::Timers |
UserManager* InspIRCd::Users |
User manager. Various methods and data associated with users.
XLineManager* InspIRCd::XLines |
X-Line manager. Handles G/K/Q/E line setting, removal and matching