Commit Graph

507 Commits

Author SHA1 Message Date
Blair Bonnett
f40451a24c Update UCMD comment in user feature support flags. 2012-08-14 18:28:29 +12:00
Blair Bonnett
6f8bc0d270 Broadcast command: escape the message so it sends properly. 2012-08-14 12:08:31 +12:00
Blair Bonnett
a12e79c7ce Check plugin API version in UCMD plugin. 2012-08-14 11:48:08 +12:00
Blair Bonnett
a95e703b36 Documentation update for reserved SIDs. 2012-08-14 11:35:50 +12:00
Blair Bonnett
dc94754488 Add hub function for plugins to get list of currently connected users.
Can be filtered to include only users of a certain credential level, or
users of a certain credential level or greater. Results are returned as
a linked list of plugin_user objects.

Hub function to free the memory used by the list also added.

As plugins may store the list, users may disconnect before the list is
used. Hence a copy of each user is made for the list, so that if a
plugin tries to send a message to a user who has left the hub it will be
ignored, rather than the hub trying to access memory that was free()d
when the user disconnected. The lookup function to turn a plugin_user
into a hub_user for some of the other hub functions is changed
accordingly. (I think this description is possibly more confusing than
just looking at the code, but oh well...)
2012-08-09 15:23:33 +12:00
Blair Bonnett
7a440211dd Fix escaping of keyword substitutions.
Using adc_msg_escape will escape spaces etc inside keyword subsitutions
in user command messages (e.g., %[line:Enter a value] becomes
%[line:Enter\sa\svalue]) which leads to them being displayed wrong in
the client. Values outside the substitutions still need to be escaped.

This commit adds an (internal) ucmd_msg_escape() function, plus a
ucmd_msg_escape_length() helper, to the user command handler which
correctly handles keyword substitutions.
2012-08-09 00:38:36 +12:00
Blair Bonnett
2e7f0f9c12 Add plugin to send user commands.
Adds a mod_ucmd plugin which uses the previously added user command
plugin functions to send user commands when users log in. These are read
from a text file in a simple format. They can be restricted to users
with certain credentials, and can have multiple actions (e.g., send a PM
and a message in the main chat).

A sample user command file for the standard uhub commands is at
doc/ucmd.conf, and will be automatically installed if appropriate.

This currently won't send commands to existing users (e.g., if the
plugin is (re)loaded after the hub is already up and running). To
support this, a plugin function to list all current users would need to
be added.

I'm not sure how efficient this would be due to the volume of
messages needed to delete the existing commands on shutdown and send
them again on startup. As the commands are reloaded properly within the
plugin, it may be easier to require users to reconnect after the
configuration changes (and, of course, an admin could force this by
restarting the hub).
2012-08-08 19:34:19 +12:00
Blair Bonnett
30ec879cd2 Fix small memory leak in reserved SID code. 2012-08-08 17:14:24 +12:00
Blair Bonnett
c3b368a68a Add ability to reserve SIDs for certain users.
If you have a bot connected to the hub, and you want to add a user
command to interact with the bot via PM, you need to know its session ID
(SID). However, SIDs are assigned when the client first connects, prior
to the nickname being sent, and so we cannot just assign a certain SID
based on the nickname as part of the connection routine.

To overcome this, this commit adds the ability to reserve the first few
SIDs (at hub start time, when the SIDs are known) for certain nicknames.
The user manager then checks each time a user logs in to see if the
nickname matches a reserved one, and if so sets up an alias from the
reserved SID to the SID the user was given. This alias is only checked
for private messages (the ADC DMSG or EMSG commands) which are routed to
the real user. Any other commands are ignored as there should be no need
for such aliasing.

The list of nicknames to reserve SIDs for is read from a space-separated
list in the reserved_sids parameter of the config file. The reserved
users must also be registered users (i.e., given a password) -- if they
are not, the alias is not set up for them.
2012-08-06 23:58:57 +12:00
Blair Bonnett
2608f6be76 Add user command support for sending private messages.
Can send to either the currently selected user (the %[userSID] keyword
substitution) or a given SID. To make the latter useful (e.g, for
commands sent to a bot) support for static SIDs is needed.
2012-08-02 21:13:34 +12:00
Blair Bonnett
66854bc204 Add UCMD extension methods to plugin API.
The user command (UCMD) extension to the ADC protocol allows for sending
hub-specific commands to clients. These commands have a name (which
generally appears in a menu in the client) and a command string which
the client sends back to the hub when the command is selected. These
command strings can contain keyword substitutions for useful
information, such as the SID of another user that was selected in the
client.

This commit adds some support for sending user commands to the uhub
plugin API. It currently restricts the command string to containing main
chat messages (BMSG commands in ADC parlance).

A plugin_ucmd structure is added to store the details of a user command,
and four methods are added to the plugin_handle.hub structure:

* plugin->hub.ucmd_create(plugin, name, length) creates a new user
  command.
* plugin->hub.ucmd_add_chat(plugin, ucmd, message, me) adds a main chat
  message to the list of commands to be run when the user command is
  selected. The me flag allows IRC /me style messages.
* plugin->hub.ucmd_send(plugin, user, ucmd) sends the command to a user.
* plugin->hub.ucmd_free(plugin, ucmd) frees the memory taken by a user
  command.

The structure has a number of flags (categories, remove, separator,
constrained) which correspond to the flags in the UCMD specification.
The categories flag must be set prior to sending to one (or more, via
a logical OR) of the ucmd_category_* enumeration values defined in
plugin_api/types.h.

The PLUGIN_API_VERSION has been increased to 2 to mark the change.
2012-08-02 02:26:54 +12:00
Jan Vidar Krey
fb11589bb0 Drop all ADC messages containing illegal ADC escapes. 2012-08-07 11:55:29 +02:00
Jan Vidar Krey
cba0121574 ADCH++ had a security bug that allowed UCMD extension to be relayed.
uhub did not have this security bug since the hub did not advertise support for the
UCMD extension, but the message was still correctly relayed as specified in the
protocol specification.

However, this commit adds support for the UCMD extension, but only to the extent
that uhub will advertise it and uhub will also drop any such CMD message
generated by a client and will (currently) never issues a CMD message by itself.
2012-07-30 00:08:12 +02:00
Yorhel
b9005b1724 core/probe.c: Fix TLS probe when handshake version != SSL version
GnuTLS sends a handshake with SSL 3.0 (0x0300) in the outer packet, but
mentions TLS 1.2 (0x0303) in the Client Hello. There's no real need for
uhub to validate these fields, as OpenSSL should do that itself already.
Just use the version mentioned in Client Hello for logging output.
2012-06-02 14:46:47 +02:00
Jan Vidar Krey
571abddd98 Cleaned up code generator for config file parsing. 2012-05-23 23:37:42 +02:00
Jan Vidar Krey
3ae6da4a64 Print error message in case of shutting down due to errors loading plugins. 2012-05-14 23:35:53 +02:00
Jan Vidar Krey
f3754fb4e4 Fix Windows file read discrepancy. 2012-05-14 23:33:54 +02:00
Tilka
274f17bce0 use "I64u" instead of PRIu64 on Windows 2012-05-11 16:45:07 +02:00
Tilka
8365278cbf fix uhub_itoa() and uhub_ulltoa() 2012-05-10 23:24:42 +02:00
Tilka
eb49174ab3 marked plugin callbacks that are not called yet 2012-05-10 01:37:20 +02:00
Tilka
9e52ea7eff add on_change_nick() to struct plugin_funcs
It's not called anywhere yet.
Also reorder some typedefs, rename the ip check functions and add
struct {hub,plugin}_user parameter to on_check_ip_late(). Not sure where
to insert a call to that...
2012-05-09 23:33:03 +02:00
Tilka
05fd6bb723 minimal changes 2012-05-09 23:27:06 +02:00
Jan Vidar Krey
c5516b5729 Merge branch 'master' of https://github.com/Tilka/uhub 2012-05-06 23:15:06 +02:00
Jan Vidar Krey
3aaabbc543 Fix issue with QUI messages being allowed through the hub 2012-05-06 23:09:02 +02:00
Tilka
ccb66ced4f don't show error on SIGTERM in select() backend 2012-05-05 01:10:24 +02:00
Tilka
d49127b507 changed all calls to assert() to uhub_assert() 2012-05-02 21:06:46 +02:00
Jan Vidar Krey
ccded3f642 Don't strip the U4/U6 port numbers if updated after login. 2012-05-02 20:45:31 +02:00
Jan Vidar Krey
216757a1f4 Fix compile issue with double typedefs. 2012-05-02 00:29:26 +02:00
Jan Vidar Krey
458c7fa741 Remove list assertion when removing element that is not in the list.
Breaks autotest.
2012-05-01 20:40:27 +02:00
Jan Vidar Krey
74ca5a0a33 Cleaned up command handling code, by splitting into multiple files. 2012-05-01 20:15:49 +02:00
Tilka
e4cf01ff1f OMG OPTIMIZED 2012-04-21 16:56:22 +02:00
Tilka
b72f5a407a fix double free 2012-04-21 16:51:41 +02:00
Tilka
776f7d0bff use "0" instead of "false"
otherwise compilation breaks when using a C90 compiler
2012-04-21 13:35:06 +02:00
Tilka
27ceb7ad33 fix use of uninitialized struct ip_range 2012-04-21 09:46:50 +02:00
Tilka
c5036a3ff8 fix random crashes upon !reload
A struct plugin_hub_internals was falsely casted to struct
plugin_callback_data. This caused the contained commands list pointer to point to
a struct hub_info and commands->size took the value of a pointer to a struct
net_connection. Since size is increased/decreased every time an item is
added to/removed from the list, this resulted in some funny crashes.

This fix is a little dirty as it exports some internals.
2012-04-21 09:22:06 +02:00
Tilka
832277f653 fix command syntax 2012-04-21 06:08:36 +02:00
Tilka
c525e59fa5 use arg parser in !broadcast 2012-04-21 01:56:26 +02:00
Jan Vidar Krey
781f22edab Fixed tiny memory leak on reload/shutdown. 2012-04-19 20:05:37 +02:00
Jan Vidar Krey
55030935a7 Merge https://github.com/Tilka/uhub 2012-04-19 23:17:39 +02:00
Tilka
4f0c8e0356 fix multiple optional arguments
Assuming the argument definition "?xy", it was previously not possible
to specify only x. Also, the syntax will now be shown as "[x [y]]"
instead of "[x] [y]".
2012-04-19 03:06:52 +02:00
Tilka
e925db2b98 small cleanup 2012-04-19 02:56:27 +02:00
Tilka
e408ae3eba automatically clean up plugin commands 2012-04-19 02:53:43 +02:00
Jan Vidar Krey
1dba731cc3 Fix bug #158 - Added plugin for setting topic (hub description).
Load plugin mod_topic, and it will provide 3 new user commands:

!topic - set new topic
!cleartopic - reset the topic (use default hub description)
!showtopic - show the current topic
2012-04-19 00:33:38 +02:00
Jan Vidar Krey
df7bbc094f Command arguments handling + cleanups
Fix bug #185 - Args of !commands lost/damaged.
All string arguments were incorrectly freed after being added to the argument list for a command.
Instead this fix makes sure it is properly copied into a new string, and by doing so this requires
a new API for dealing with hub command arguments in a type safe manner, and also allows for each
argument to be cleaned up properly when the command is no longer needed.

This also fixes issues with parse errors for certain types, and optional arguments (previously it was impossible
to tell the difference for an integer with value 0 or if no integer was given).

All arguments can now be accessed through the new functions
hub_command_arg_reset() and hub_command_arg_next().

These functions are also exposed to plug-ins.

The argument type notations for 'n' has changed to mean nick (string),
and 'u' is used for a user (struct hub_user - must be online).
2012-04-18 23:03:05 +02:00
Jan Vidar Krey
5068fe8351 Cygwin/Mingw32 compile fixes. 2012-01-25 00:20:59 +01:00
Jan Vidar Krey
8607b40278 Fix bug #180 - Crash after signal SIGHUP. 2012-01-19 02:58:20 +01:00
Jan Vidar Krey
a9b5c6db38 Fixed minor issues found with static code analyzis (Clang). 2012-01-13 01:31:34 +01:00
Jan Vidar Krey
ff639d87c3 Disable SQL debugging output. 2012-01-10 02:21:22 +01:00
Jan Vidar Krey
5edf2b60d4 Fixed bug #179 - !broadcast command does not work properly. 2012-01-10 02:21:22 +01:00
Jan Vidar Krey
eee2636582 Added a chat only hub plugin that disables searching and connection setup.
This also deprecates the built-in chat_only configuration option.
If you need this functionality, then load the mod_chat_only plugin (if it is loaded then only operators
are able to search, connect, etc).
2012-01-09 20:58:19 +01:00