HerculesWS / Hercules

Hercules is a collaborative software development project revolving around the creation of a robust massively multiplayer online role playing game (MMORPG) server package. Written in C, the program is very versatile and provides NPCs, warps and modifications. The project is jointly managed by a group of volunteers located around the world as well as a tremendous community providing QA and support. Hercules is a continuation of the original Athena project.
http://herc.ws
GNU General Public License v3.0
896 stars 753 forks source link

Handling IRC channel messages #1797

Open Helianthella opened 7 years ago

Helianthella commented 7 years ago

I recently added a buildin for reading messages from channels (#1719). However there's a problem: it cannot handle the #irc channel fully. This is because the way I set it up the event triggers when a player sends a message to a channel and not when a channel receives a message. When the player sends something, an event is dispatched with the player attached and the @channelmes$ variable is set.

For IRC this works when sending messages from Hercules to IRC but not the other way around, because it only triggers when sending. This means if a user in the IRC channel says something the server has no way to read the message, unless it was sent through Hercules.


There's two ways I could solve this:



Thoughts? Any other idea?

MishimaHaruna commented 7 years ago

Having the server call the event handler globally might indeed be a performance hit (assuming you'd run it through npc->event_do("::OnIRCEvent"), please correct me if I'm wrong), and would also affect those that don't have any handler configured, since we don't have a cache for the global, detached, events (like we do in npc->script_event() for the RID-specific events).

Having such an event fire on any activity from IRC might be a problem. From personal experience (I run a copy of Hercules connected to the Rizon IRC network, and I have some additional debug code that prints any event originating from IRC), the IRC servers can be very chatty, especially on (re)connection, due to the very long MOTD messages used. Occasionally, IRCops also send global notices, which might also be a bit verbose. I'm not sure what performance impact this might have, especially on reconnections or after a netsplit (when a large amount of channel join notifications are delivered).

While I like the possibilities of customization that the second approach would give, I'd advise some analysis on how it might affect the performance (unless we implement some caching for the global event handlers, like we do for the player events - in that case, it'd only affect the performance if a script with the event label is actually loaded)

Helianthella commented 7 years ago

@MishimaHaruna Actually some global events are cached because they are called very often (pc login, logout, die, kill, ...) so I could just add OnIRCEvent as one of them and then use npc->script_event() to invoke it. I would just add a copy of it named npc->script_event_detached(). Since IRC is very chatty I could make it relay only messages by default and add a config options for those that also want join/quit/part/...

MishimaHaruna commented 7 years ago

Yes, the ones you mention are the kind of global events that require a RID attached. Having a similar function for the events that run detached would work. This is what I meant wen I mentioned not having a cache for the global, detached, events.

FWIW, that the same mechanism can be extended to handle the OnAgitStart, OnAgitEnd, OnAgitStart2, OnAgitEnd2 events as well (the other ones, such as OnInit, OnInterIfInit, etc, are irrelevant and don't need to be cached).

I agree about having a configuration to filter some kind of messages that might be undesired.

Helianthella commented 7 years ago

Ok so to recap,




@MishimaHaruna is this correct?

MishimaHaruna commented 7 years ago

That looks correct @mekolat

In the list of triggers, where would CTCP 'ACTION' (i.e. /me) fall? Same trigger as message? kick could also be added, and perhaps other, although I'm not sure it can be of much use.