rewrote IRC cache parser to be (hopefully) more stable
[NeonServV5.git] / src / modules / NeonServ.mod / bot_NeonServ.c
1 /* bot_NeonServ.c - NeonServ v5.4
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17 #include "../module.h"
18 #include "../botid.h"
19  
20 #include "bot_NeonServ.h"
21 #include "../../modcmd.h"
22 #include "../../IRCEvents.h"
23 #include "../../IRCParser.h"
24 #include "../../UserNode.h"
25 #include "../../ChanNode.h"
26 #include "../../ChanUser.h"
27 #include "../../BanNode.h"
28 #include "../../ModeNode.h"
29 #include "../../ClientSocket.h"
30 #include "../../mysqlConn.h"
31 #include "../../lang.h"
32 #include "../../HandleInfoHandler.h"
33 #include "../../WHOHandler.h"
34 #include "../../DBHelper.h"
35 #include "../../tools.h"
36 #include "../../timeq.h"
37 #include "../../EventLogger.h"
38 #include "cmd_neonserv.h"
39 #include "../../ConfigParser.h"
40
41 #define BOTID NEONSERV_BOTID
42 #define BOTALIAS "NeonServ"
43
44 static const struct default_language_entry msgtab[] = {
45     {"NS_USER_UNKNOWN", "User with nick $b%s$b does not exist."}, /* {ARGS: "TestUser"} */
46     {"NS_AUTH_UNKNOWN", "Account $b%s$b has not been registered."}, /* {ARGS: "TestAuth"} */
47     {"NS_USER_NEED_AUTH", "%s must first authenticate with $bAuthServ$b."}, /* {ARGS: "TestUser"} */
48     {"NS_YOU_NEED_AUTH", "You must first authenticate with $bAuthServ$b."},
49     {"NS_INVALID_ACCESS", "$b%d$b is an invalid access level."}, /* {ARGS: 1337} */
50     {"NS_ADDUSER_ALREADY_ADDED", "%s is already on the $b%s$b user list (with access %d)."}, /* {ARGS: "TestUser", "#TestChan", 123} */
51     {"NS_ADDUSER_DONE", "Added %s to the %s user list with access %d."}, /* {ARGS: "TestUser", "#TestChan", 123} */
52     {"NS_NOT_ON_USERLIST", "%s lacks access to $b%s$b."}, /* {ARGS: "TestUser", "#TestChan"} */
53     {"NS_NOT_ON_USERLIST_YOU", "You lack access to $b%s$b."}, /* {ARGS: "#TestChan"} */
54     {"NS_NOT_ON_CHANNEL", "%s isn't currently in $b%s$b."}, /* {ARGS: "TestUser", "#TestChan"} */
55     {"NS_NOT_ON_CHANNEL_YOU", "You aren't currently in $b%s$b."}, /* {ARGS: "#TestChan"} */
56     {"NS_DELUSER_DONE", "Deleted %s (with access %d) from the %s user list."}, /* {ARGS: "TestUser", 123, "#TestChan"} */
57     {"NS_ACCESS_OUTRANKED", "You cannot give users access greater than or equal to your own."},
58     {"NS_USER_OUTRANKED", "$b%s$b outranks you (command has no effect)."}, /* {ARGS: "TestUser"} */
59     {"NS_ACCESS_DENIED", "Access denied."},
60     {"NS_NO_ACCESS", "You lack sufficient access to use this command."},
61     {"NS_USER_PROTECTED", "Sorry, $b%s$b is protected."}, /* {ARGS: "TestUser"} */
62     {"NS_SERVICE_IMMUNE", "$b%s$b may not be kicked, killed, banned, or deopped."}, /* {ARGS: "TestUser"} */
63         {"NS_YOU_PROTECTED", "You may not kick or ban yourself."},
64     {"NS_TABLE_NONE", "   None"},
65     {"NS_TABLE_COUNT", "Found $b%d$b matches."}, /* {ARGS: 5} */
66     {"NS_BAN_ALREADY_ADDED", "$b%s$b is already banned in %s."}, /* {ARGS: "*!*@moeeep.*", "#TestChan"} */
67     {"NS_INVALID_ACCESS_RANGE", "Invalid access range; minimum (%d) must be lower than maximum (%d)."}, /* {ARGS: 450, 400} */
68     {"NS_CLVL_DONE", "%s now has access $b%d$b in %s."}, /* {ARGS: "TestUser", 123, "#TestChan"} */
69     {"NS_A_LACKS_ACCESS_BUT_GOD_NICK", "%s lacks access to %s but has $bsecurity override$b enabled."}, /* {ARGS: "TestAuth", "#TestChan"} */
70     {"NS_A_LACKS_ACCESS_BUT_GOD_AUTH", "%s (%s) lacks access to %s but has $bsecurity override$b enabled."}, /* {ARGS: "TestAuth", "TestUser", "#TestChan"} */
71     {"NS_A_ACCESS_NICK", "%s has access $b%d$b in %s."}, /* {ARGS: "TestAuth", 123, "#TestChan"} */
72     {"NS_A_ACCESS_AUTH", "%s (%s) has access $b%d$b in %s."}, /* {ARGS: "TestAuth", "TestUser", 123, "#TestChan"} */
73     {"NS_A_ACCESS_NICK_GOD", "%s has access $b%d$b in %s and has $bsecurity override$b enabled."}, /* {ARGS: "TestAuth", 123, "#TestChan"} */
74     {"NS_A_ACCESS_AUTH_GOD", "%s (%s) has access $b%d$b in %s and has $bsecurity override$b enabled."}, /* {ARGS: "TestAuth", "TestUser", 123, "#TestChan"} */
75     {"NS_A_SUSPENDED", "$b%s$b's access to %s has been suspended."}, /* {ARGS: "TestAuth", "#TestChan"} */
76     {"NS_A_IS_IRCOP", "%s is an $bIRC operator$b."}, /* {ARGS: "TestUser", "#TestChan"} */
77     {"NS_USERS_HEADER", "%s users from level %d to %d:"}, /* {ARGS: "#TestChan", 1, 500} */
78     {"NS_USERS_HEADER_MATCH", "%s users from level %d to %d matching %s:"}, /* {ARGS: "#TestChan", 1, 500, "Test*"} */
79     {"NS_USERS_HEADER_ACCESS", "Access"},
80     {"NS_USERS_HEADER_ACCOUNT", "Account"},
81     {"NS_USERS_HEADER_SEEN", "Last Seen"},
82     {"NS_USERS_HEADER_STATE", "Status"},
83     {"NS_USERS_COUNT", "There are $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
84     {"NS_USERS_COUNT_1", "There is $b%d$b user in %s."}, /* {ARGS: 1, "#TestChan"} */
85     {"NS_USERS_COUNT_MATCH", "There are $b%d$b users in %s. ($b%d$b matching your request)"}, /* {ARGS: 20, "#TestChan", 5} */
86     {"NS_USERS_COUNT_MATCH_1", "There is $b%d$b user in %s. ($b%d$b matching your request)"}, /* {ARGS: 1, "#TestChan", 1} */
87     {"NS_USERS_SEEN_HERE", "Here"},
88     {"NS_USERS_SEEN_INVISIBLE", "Here (invisible)"},
89     {"NS_USERS_SEEN_NEVER", "Never"},
90     {"NS_USERS_STATE_SUSPENDED", "Suspended"},
91     {"NS_USERS_STATE_NORMAL", "Normal"},
92     {"NS_SUSPEND_ALREADY", "$b%s$b is already suspended." }, /* {ARGS: "TestUser"} */
93     {"NS_SUSPEND_NOT", "$b%s$b is not suspended." }, /* {ARGS: "TestUser"} */
94     {"NS_SUSPEND_DONE", "$b%s$b's access to $b%s$b has been suspended." }, /* {ARGS: "TestUser", "#TestChan"} */
95     {"NS_SUSPEND_RESTORED", "$b%s$b's access to $b%s$b has been restored." }, /* {ARGS: "TestUser", "#TestChan"} */
96     {"NS_DELME_OWNER", "You cannot delete your owner access in $b%s$b."}, /* {ARGS: "#TestChan"} */
97     {"NS_DELME_KEY", "To really remove yourself, you must use 'deleteme %s'."}, /* {ARGS: "abc123"} */
98     {"NS_DELME_DONE", "Your $b%d$b access has been deleted from $b%s$b."}, /* {ARGS: 123, "#TestChan"} */
99     {"NS_MYACCESS_SELF_ONLY", "You may only see the list of infolines for yourself (by using $bmyaccess$b with no arguments)."},
100     {"NS_MYACCESS_HEADER", "Showing all channel entries for account $b%s$b:"}, /* {ARGS: "TestAuth"} */
101     {"NS_MYACCESS_HEADER_MATCH", "Showing all channel entries for account $b%s$b matching %s:"}, /* {ARGS: "TestAuth", "#Test*"} */
102     {"NS_MYACCESS_HEADER_NAME", "Name"},
103     {"NS_MYACCESS_HEADER_ACCESS", "Access"},
104     {"NS_MYACCESS_HEADER_FLAGS", "Rights"},
105     {"NS_MYACCESS_HEADER_INFO", "Info"},
106     {"NS_MYACCESS_COUNT", "%s has access in $b%d$b channel(s) and is owner of $b%d$b channel(s)."}, /* {ARGS: "TestUser", 15, 5} */
107     {"NS_MYACCESS_COUNT_MATCH", "%s has access in $b%d$b channel(s) and is owner of $b%d$b channel(s) ($b%d$b channels matching your request)."}, /* {ARGS: "TestUser", 15, 5, 7} */
108     {"NS_UP_ALREADY_OP", "You are already opped in $b%s$b."}, /* {ARGS: "#TestChan"} */
109     {"NS_UP_ALREADY_VOICE", "You are already voiced in $b%s$b."}, /* {ARGS: "#TestChan"} */
110     {"NS_DOWN_ALREADY", "You are not opped or voiced in $b%s$b."}, /* {ARGS: "#TestChan"} */
111     {"NS_MDELUSER_DONE", "Deleted $b%d$b account(s) matching $b%s$b with access from $b%d$b to $b%d$b from the %s user list."}, /* {ARGS: 10, "Test*", 1, 200, "#TestChan"} */
112     {"NS_TRIM_DURATION_TOO_SHORT", "You must include a minimum inactivity duration of at least %d seconds to trim."},
113     {"NS_TRIM_DONE", "Trimmed $b%d users$b with access from %d to %d from the %s user list who were inactive for at least %s."}, /* {ARGS: 10, 1, 100, "#TestChan", "10 days"} */
114     {"NS_TRIM_BAN_DONE", "Trimmed $b%d bans$b from the %s ban list who were banned for at least %s."}, /* {ARGS: 5, "#TestChan", "1 day"} */
115     {"NS_GIVEOWNER_SELF", "You cannot give ownership to your own account."},
116     {"NS_GIVEOWNER_TIMEOUT", "You must wait %s before you can give ownership of $b%s$b to someone else."}, /* {ARGS: "5 hours", "#TestChan"} */
117     {"NS_GIVEOWNER_CONFIRM", "To really give ownership to $b%1$s$b, you must use 'giveownership *%1$s %2$s'."}, /* {ARGS: "TestUser", "abc123"} */
118     {"NS_GIVEOWNER_DONE", "Ownership of $b%s$b has been transferred to account $b%s$b."}, /* {ARGS: "#TestChan", "TestUser"} */
119     {"NS_OP_FAIL", "$b%s$b could not op some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
120     {"NS_OP_DONE", "Opped users in $b%s$b."}, /* {ARGS: "#TestChan"} */
121     {"NS_HALFOP_FAIL", "$b%s$b could not halfop some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
122     {"NS_HALFOP_DONE", "Half-Opped users in $b%s$b."}, /* {ARGS: "#TestChan"} */
123     {"NS_VOICE_FAIL", "$b%s$b could not voice some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
124     {"NS_VOICE_DONE", "Voiced users in $b%s$b."}, /* {ARGS: "#TestChan"} */
125     {"NS_DEOP_FAIL", "$b%s$b could not deop some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
126     {"NS_DEOP_DONE", "Deopped users in $b%s$b."}, /* {ARGS: "#TestChan"} */
127     {"NS_DEHALFOP_FAIL", "$b%s$b could not dehalfop some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
128     {"NS_DEHALFOP_DONE", "Dehalfopped users in $b%s$b."}, /* {ARGS: "#TestChan"} */
129     {"NS_DEVOICE_FAIL", "$b%s$b could not devoice some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
130     {"NS_DEVOICE_DONE", "Devoiced users in $b%s$b."}, /* {ARGS: "#TestChan"} */
131     {"NS_OPALL_SECURITY", "$bWARNING$b: Opping all users on a channel is very insecure! If you still want do op all users on %s use: '$bopall FORCE$b [nick mask]'"},
132     {"NS_OPALL_DONE", "Opped $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
133     {"NS_HALFOPALL_DONE", "Half-Opped $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
134     {"NS_VOICEALL_DONE", "Voiced $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
135     {"NS_DEOPALL_DONE", "Deopped $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
136     {"NS_DEHALFOPALL_DONE", "Dehalfopped $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
137     {"NS_DEVOICEALL_DONE", "Devoiced $b%d$b users in %s."}, /* {ARGS: 20, "#TestChan"} */
138     {"NS_KICK_DONE", "Kicked $b%d$b users from %s"}, /* {ARGS: 20, "#TestChan"} */
139     {"NS_KICK_FAIL", "$b%s$b could not kick some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
140     {"NS_KICKBAN_DONE", "KickBanned $b%d$b users from %s"}, /* {ARGS: 10, "#TestChan"} */
141     {"NS_KICKBAN_FAIL", "$b%s$b could not kickban some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
142     {"NS_BAN_DONE", "$b%d$b masks added to the %s ban list. (matching %d users)"}, /* {ARGS: 5, "#TestChan", 15} */
143     {"NS_BAN_FAIL", "$b%s$b could not ban some of the nicks you provided."}, /* {ARGS: "NeonServ"} */
144     {"NS_LAME_MASK", "$b%s$b is a little too general. Try making it more specific."}, /* {ARGS: "*!*@*"} */
145     {"NS_LAME_MASK_WARNING", "$k4WARNING$k: $b%s$b is very general. (matches %d users)"},
146     {"NS_SET_HEADER", "Channel Settings for %s:"}, /* {ARGS: "#TestChan"} */
147     {"NS_SET_ON", "on"},
148     {"NS_SET_OFF", "off"},
149     {"NS_SET_UNKNOWN_SETTING", "$b%s$b is an unknown channel setting."}, /* {ARGS: "TestSetting"} */
150     {"NS_SET_CANNOT_SET", "That setting is above your current level, so you cannot change it."},
151     {"NS_SET_BADLEVEL", "You cannot change any setting to above your level."},
152     {"NS_SET_INVALID_OPTION", "$b%d$b is not a valid choice.  Choose one:"}, /* {ARGS: 5} */
153     {"NS_SET_INVALID_BOOLEAN", "$b%s$b is an invalid binary value."}, /* {ARGS: "3"} */
154     {"NS_SET_DEFAULTS_OWNER", "You must have access 500 in %s to reset it to the default options."}, /* {ARGS: "#TestChan"} */
155     {"NS_SET_DEFAULTS_CODE", "To reset %s's settings to the defaults, you must use 'set defaults %s'."}, /* {ARGS: "#TestChan", "abc123"} */
156     {"NS_SET_DEFAULTS_DONE", "All settings for %s have been reset to default values."}, /* {ARGS: "#TestChan"} */
157     {"NS_SET_TRIGGER_OWNER", "You must have access 500 in %s to change the channel trigger."}, /* {ARGS: "#TestChan"} */
158     {"NS_SET_HELP_USERINFO","(access to set the userinfo)"},
159     {"NS_SET_HELP_WIPEINFO","(access to clear the userinfo of other users)"},
160     {"NS_SET_HELP_INVITEME","(access to get invited by the bot)"},
161     {"NS_SET_HELP_ENFVOICE","(access to give voice to other users)"},
162     {"NS_SET_HELP_ENFOPS","(access to give op to their users)"},
163     {"NS_SET_HELP_GIVEOPS","(access to get op by the bot)"},
164     {"NS_SET_HELP_GIVEVOICE","(access to get voice by the bot)"},
165     {"NS_SET_HELP_KICK","(access to kick other users from the channel)"},
166     {"NS_SET_HELP_BAN","(access to ban other users from the channel)"},
167     {"NS_SET_HELP_STATICBAN","(access to add static bans to the channel banlist  e.g. +addban)"},
168     {"NS_SET_HELP_PUBCMD","(access to do public commands in the channel  e.g. +users)"},
169     {"NS_SET_HELP_ENFMODES","(access to override the modelock)"},
170     {"NS_SET_HELP_ENFTOPIC","(access to override the topicmask)"},
171     {"NS_SET_HELP_TOPICSNARF","(access to set the default topic by changing the topic with /TOPIC)"},
172     {"NS_SET_HELP_CHANGETOPIC","(access to change the topic)"},
173     {"NS_SET_HELP_SETTERS","(access to change this settings)"},
174     {"NS_SET_HELP_ADDUSER","(access to add an user to the userlist)"},
175     {"NS_SET_HELP_DELUSER","(access to delete an user from the userlist)"},
176     {"NS_SET_HELP_CLVL","(access to change the access of an user in the userlist)"},
177     {"NS_SET_HELP_RESYNC","(access to synchronize the channelrights (@,+) with the userlist)"},
178     {"NS_SET_HELP_SUSPEND","(access to suspend an user on the userlist)"},
179     {"NS_SET_OPTION_CTCPREACTION_0","Kick on disallowed CTCPs"},
180     {"NS_SET_OPTION_CTCPREACTION_1","Kickban on disallowed CTCPs"},
181     {"NS_SET_OPTION_CTCPREACTION_2","Short timed ban on disallowed CTCPs"},
182     {"NS_SET_OPTION_CTCPREACTION_3","Long timed ban on disallowed CTCPs"},
183     {"NS_SET_OPTION_NOTICEREACTION_0","Kick on disallowed NOTICEs"},
184     {"NS_SET_OPTION_NOTICEREACTION_1","Kickban on disallowed NOTICEs"},
185     {"NS_SET_OPTION_NOTICEREACTION_2","Short timed ban on disallowed NOTICEs"},
186     {"NS_SET_OPTION_NOTICEREACTION_3","Long timed ban on disallowed NOTICEs"},
187     {"NS_SET_OPTION_PROTECT_0","All users will be protected from users with equal or lower access."},
188     {"NS_SET_OPTION_PROTECT_1","All users with access will be protected from users with equal or lower access."},
189     {"NS_SET_OPTION_PROTECT_2","All users with access will be protected from user with lower access."},
190     {"NS_SET_OPTION_PROTECT_3","Nobody will be protected."},
191     {"NS_SET_OPTION_TOYS_0","Funcommands can't be used."},
192     {"NS_SET_OPTION_TOYS_1","Funcommands are possible but the reply will be sent as a notice."},
193     {"NS_SET_OPTION_TOYS_2","Funcommands are possible and the reply will be sent to the channel."},
194     {"NS_SET_OPTION_DYNLIMIT_0","off"},
195     {"NS_SET_OPTION_NODELETE_0","off  (only bot masters)"},
196     {"NS_SET_OPTION_NODELETE_1","on  (only bot masters)"},
197     {"NS_WIPEINFO_DONE", "Removed $b%s$b's infoline in $b%s$b."}, /* {ARGS: "TestUser", "#TestChan"} */
198     {"NS_TRACE_HEADER", "The following users were found:"},
199     {"NS_ADDBAN_DONE", "$b%s$b permantly added to the %s ban list. (matching %d users)"}, /* {ARGS: "*!*@Test.*", "#TestChan", 4} */
200     {"NS_BANS_HEADER_MASK", "Mask"},
201     {"NS_BANS_HEADER_SETBY", "Set By"},
202     {"NS_BANS_HEADER_TRIGGERED", "Triggered"},
203     {"NS_BANS_HEADER_EXPIRES", "Expires"},
204     {"NS_BANS_HEADER_REASON", "Reason"},
205     {"NS_DELBAN_BANNED_BY", "%s is banned by %s."}, /* {ARGS: "*!*@bla*", "*!*@b*"} */
206     {"NS_DELBAN_FAIL", "Sorry, no ban found for $b%s$b."}, /* {ARGS: "*!*@bla*"} */
207     {"NS_DELBAN_DONE", "Removed $b%s$b from the %s ban list."}, /* {ARGS: "*!*@bla.*", "#TestChan"} */
208     {"NS_NETINFO_HEADER", "$bNetwork information$b"},
209     {"NS_NETINFO_BOTS", "Bots:"},
210     {"NS_NETINFO_UPTIME", "Uptime:"},
211     {"NS_NETINFO_TRAFFIC", "Traffic:"},
212     {"NS_NETINFO_CACHE", "Cache:"},
213     {"NS_NETINFO_DATABASE", "Database:"},
214     {"NS_NETINFO_CHANNEL", "  Channel:"},
215     {"NS_NETINFO_CHANNEL_BAN", "    Bans:"},
216     {"NS_NETINFO_USER", "  User:"},
217     {"NS_NETINFO_CHANUSER", "  Channel-User:"},
218     {"NS_NETINFO_OTHER", "  Other:"},
219     {"NS_NETINFO_THREADS", "Threads:"},
220     {"NS_NETINFO_VERSION", "Version:"},
221     {"NS_NETINFO_CODE", "Code:"},
222     {"NS_NETINFO_CODE_VALUE", "%s lines c code (view it at http://dev.pk910.de/NeonServ)"}, /* {ARGS: 20} */
223     {"NS_NETINFO_COMPILER", "Compiler:"},
224     {"NS_NETINFO_COMPILER_VALUE", "%s  (%s)"}, /* {ARGS: "GCC 4.4.5", "Sun Sep 18 2011 at 05:21:33 CEST"} */
225     {"NS_EXTTOPIC_INVALID_ID", "ADVANCEDTOPIC is enabled and $b%s$b is an invalid TOPIC ID. Valid topic id's are: 1-9"}, /* {ARGS: 10} */
226     {"NS_EXTTOPIC_TOPICID", "Topic %d: %s"}, /* {ARGS: 5, "topic"} */
227     {"NS_TOPIC_DONE", "Topic is now '%s'."}, /* {ARGS: "i like you :D"} */
228     {"NS_CHANSERVSYNC_UNSUPPORTED", "\0034WARNING\003: the user list style of %s is not known. %s can try to synchronize the userlist, but there is no guarantee that it is successful!"}, /* {ARGS: "CowBot"} */
229     {"NS_CHANSERVSYNC_KEY", "If you really want to synchronize the %s userlist with %s use: chanservsync %s %s"}, /* {ARGS: "#TestChan", "CowBot", "CowBot", "abc123"} */
230     {"NS_CHANSERVSYNC_INUSE", "$bchanservsync$b is already in use by someone else. Please try again in a few seconds..."},
231     {"NS_CHANSERVSYNC_SYNCHRONIZING", "Synchronizing userlist in %s with $b%s$b..."}, /* {ARGS: "#TestChan", "CowBot"} */
232     {"NS_CHANSERVSYNC_SYNCHRONIZED", "Synchronized user $b%s$b: access $b%d$b"}, /* {ARGS: "TestUser", 123} */
233     {"NS_REGISTER_ALREADY", "%s is already registered with %s."}, /* {ARGS: "#TestChan", "NeonServ"} */
234     {"NS_INVALID_CHANNEL_NAME", "%s is not a valid channel name."}, /* {ARGS: "#invalid"} */
235     {"NS_REGISTER_FULL", "the bot can not join more channels."},
236     {"NS_REGISTER_DISCONNECTED", "%s has been registered with a Bot, that is currently NOT connected. The Bot should join the channel, when it reconnects to the IRC-Network."}, /* {ARGS: "#TestChan"} */
237     {"NS_REGISTER_DONE", "$b%s$b is now registered to $b%s$b."}, /* {ARGS: "#TestChan", "TestUser"} */
238     {"NS_REGISTER_DONE_NOAUTH", "$b%s$b is now registered."}, /* {ARGS: "#TestChan"} */
239     {"NS_UNREGISTER_NOT_REGISTERED", "$b%s$b is not registered with %s."}, /* {ARGS: "#TestChan", "NeonServ"} */
240     {"NS_UNREGISTER_NODELETE", "$b%s$b is protected from being unregistered (nodelete)."}, /* {ARGS: "#TestChan"} */
241     {"NS_UNREGISTER_DONE", "$b%s$b unregistered."}, /* {ARGS: "#TestChan"} */
242     {"NS_RECOVER_DONE", "$b%s$b has been recovered."}, /* {ARGS: "#TestChan"} */
243     {"NS_RESYNC_DONE", "Synchronized users in $b%s$b with the userlist."}, /* {ARGS: "#TestChan"} */
244     {"NS_TIMEBAN_DURATION_TOO_SHORT", "You must specify a ban duration of at least %d seconds."}, /* {ARGS: 30} */
245     {"NS_TIMEBAN_DONE", "Banned $b%s$b from %s for %s. (matching %d users)"}, /* {ARGS: "*!*@bla*", "#TestChan", "2 hours", 5} */
246     {"NS_MODE_INVALID", "$b%c$b is an invalid set of channel modes."}, /* {ARGS: "+xyz"} */
247     {"NS_MODE_LOCKED", "Modes conflicting with $b%s$b are not allowed in %s."}, /* {ARGS: "+xyz", "#TestChan"} */
248     {"NS_MODE_DONE", "Channel modes are now $b%s$b."}, /* {ARGS: "+xyz"} */
249     {"NS_MODE_ENFOPS", "You may not op or deop users on $b%s$b."}, /* {ARGS: "#TestChan"} */
250     {"NS_MODE_ENFVOICE", "You may not voice or devoice users on $b%s$b."}, /* {ARGS: "#TestChan"} */
251     {"NS_MODE_CANBAN", "You may not ban or unban users on $b%s$b."}, /* {ARGS: "#TestChan"} */
252     {"NS_GOD_ON", "Security override has been enabled."},
253     {"NS_GOD_OFF", "Security override has been disabled."},
254     {"NS_PEEK_HEADER", "$b%s$b Status:"}, /* {ARGS: "#TestChan"} */
255     {"NS_PEEK_TOPIC", "Topic:       %s"}, /* {ARGS: "TOPIC"} */
256     {"NS_PEEK_MODES", "Modes:       %s"}, /* {ARGS: "+xyz"} */
257     {"NS_PEEK_USERS", "Total Users: %d (%d ops, %d voices, %d regulars, %d invisible)"}, /* {ARGS: 20, 4, 6, 8, 2} */
258     {"NS_PEEK_USERS_HALFOP", "Total Users: %d (%d ops, %d halfops, %d voices, %d regulars, %d invisible)"}, /* {ARGS: 25, 5, 4, 6, 8, 2} */
259     {"NS_PEEK_OPS", "Ops:"},
260     {"NS_USET_GLOBAL", "$b--- Global ---$b"},
261     {"NS_USET_CHANNEL", "$b--- User options (channel) ---$b"},
262     {"NS_USET_NO_ACCESS", "no access"},
263     {"NS_USET_UNKNOWN_SETTING", "$b%s$b is an unknown uset setting."}, /* {ARGS: "TestSetting"} */
264     {"NS_RELOADLANG_UNKNOWN", "$b%s$b is an unknown language tag."}, /* {ARGS: "de"} */
265     {"NS_RELOADLANG_DONE", "$b%s$b (%s) reloaded."}, /* {ARGS: "Deutsch", "de"} */
266     {"NS_UNBAN_DONE", "$b%d$b masks removed from the %s ban list."}, /* {ARGS: 5, "#TestChan"} */
267     {"NS_UNBAN_FAIL", "$b%s$b could not unban some of the masks you provided."}, /* {ARGS: "NeonServ"} */
268     {"NS_UNBANALL_DONE", "all $b%d$b masks removed from the %s ban list."}, /* {ARGS: 5, "#TestChan"} */
269     {"NS_UNBANALL_FAIL", "$b%s$b could not find any bans in %s."}, /* {ARGS: "NeonServ", "#TestChan"} */
270     {"NS_UNBANME_DONE", "removed $b%d$b masks from the %s ban list."}, /* {ARGS: 5, "#TestChan"} */
271     {"NS_UNBANME_FAIL", "$b%s$b could not find any bans matching %s."}, /* {ARGS: "NeonServ", "TestUser!TestIdent@TestUser.user.WebGamesNet"} */
272     {"NS_INVITE_GLOBALLY_BLOCKED", "$b%s$b doesn't want to be invited at all."}, /* {ARGS: "TestUser"} */
273     {"NS_INVITE_RESTRICTION", "%s doesn't want to be invited to %s."}, /* {ARGS: "TestUser", "#TestChan"} */
274     {"NS_INVITE_TIMEOUT", "%s has already been invited to $b%s$b."}, /* {ARGS: "TestUser", "#TestChan"} */
275     {"NS_INVITE_ON_CHAN", "%s is already in $b%s$b."}, /* {ARGS: "TestUser", "#TestChan"} */
276     {"NS_INVITE_DONE_USER", "You have been invited to join $b%s$b by %s. (Do $b/msg %s %1$s uset noinvite 1$b if you don't want to be invited to %1$s anymore.)"}, /* {ARGS: "#TestChan", "TestUser", "NeonServ"} */
277     {"NS_INVITE_DONE", "Invited $b%s$b to join %s."}, /* {ARGS: "TestUser", "#TestChan"} */
278     {"NS_INVITEME_ON_CHAN", "You are already in $b%s$b."}, /* {ARGS: "#TestChan"} */
279     {"NS_INVITEME_DONE", "You have been invited to join %s."}, /* {ARGS: "#TestChan"} */
280     {"NS_HELP_TOPIC", "No help on that topic."},
281     {"NS_CSUSPEND_ALREADY", "$b%s$b is already suspended."}, /* {ARGS: "#TestChan"} */
282     {"NS_CSUSPEND_DONE", "Channel $b%s$b has been temporarily suspended."}, /* {ARGS: "#TestChan"} */
283     {"NS_CUNSUSPEND_NOT", "$b%s$b is not suspended."}, /* {ARGS: "#TestChan"} */
284     {"NS_CUNSUSPEND_DONE", "Channel $b%s$b has been restored."}, /* {ARGS: "#TestChan"} */
285     {"NS_MOVE_SUSPENDED", "Moving cannot be performed if the source channel is suspended."},
286     {"NS_MOVE_SELF", "Moving cannot be performed if the source and target channels are the same."},
287     {"NS_MOVE_DONE", "Channel $b%s$b has been moved to $b%s$b."}, /* {ARGS: "#TestChan", "#NewTestChan"} */
288     {"NS_BIND_ALREADY", "$b%s$b is already bound to %s."}, /* {ARGS: "TestCommand", "TestFunction"} */
289     {"NS_BIND_UNKNOWN", "$b%s$b is an undefined function."}, /* {ARGS: "TestFunction"} */
290     {"NS_BIND_DONE", "New command $b%s$b bound to %s."}, /* {ARGS: "TestCommand", "TestFunction"} */
291     {"NS_UNBIND_NOT_FOUND", "There is no command called $b%s$b bound."}, /* {ARGS: "TestCommand"} */
292     {"NS_UNBIND_DONE", "Unbound command $b%s$b."}, /* {ARGS: "TestCommand"} */
293     {"NS_EVENTS_HEADER", "The following channel events were found:"},
294     {"NS_OPLOG_HEADER", "The following oper events were found:"},
295     {"NS_SEARCH_ZOMBIE_SCAN_IN_PROGRESS", "Another Zombie Scan is already in progress."},
296     {"NS_SEARCH_HEADER", "The following channels were found:"},
297     {"NS_COMMAND_BINDING", "$b%s$b is a binding of %s %s"}, /* {ARGS: "TestCommand", "TestFunction", "TestParameters"} */
298     {"NS_COMMAND_ACCESS", "You need at least %d channel access and %d oper access to execute this command."}, /* {ARGS: 500, 100} */
299     {"NS_TOPIC_ACCESS", "You lack sufficient access in %s to change the topic."}, /* {ARGS: "#TestChan"} */
300     {"NS_BOTWAR_DETECTED", "$b$k4BOTWAR DETECTED!$k Please check the channel configuration!$b"},
301     {"NS_BOTWAR_REPORTED", "A supporter has been informed to help you preventing botwars in the future."},
302     {"NS_BOTWAR_ALERT", "$b$k4BOTWAR ALERT:$k$b Botwar in $b%s$b detected. (opponent: $b%s$b) Please join and help them preventing Botwars."}, /* {ARGS: "#TestChan", "OtherBot"} */
303     {"NS_INVITE_FAIL", "$b%s$b is not registered with %s or suspended."}, /* {ARGS: "#TestChan", "NeonServ"} */
304     {"NS_SETACCESS_DONE", "$b%s$b has now %d global access."}, /* {ARGS: "TestUser", 1000} */
305     {"NS_ADDRANK_EXISTS", "Another support ranking called '$b%s$b' already exists."},  /* {ARGS: "Supporter"} */
306     {"NS_ADDRANK_DONE", "Support ranking '$b%s$b' created."},  /* {ARGS: "Supporter"} */
307     {"NS_DELRANK_NOT_FOUND", "There is no support ranking called '$b%s$b'."},  /* {ARGS: "Supporter"} */
308     {"NS_DELRANK_DELETED", "Support ranking called '$b%s$b' removed."},  /* {ARGS: "Supporter"} */
309     {"NS_LISTRANK_ID", "Id"},
310     {"NS_LISTRANK_NAME", "Name"},
311     {"NS_LISTRANK_ASSIGNED", "Assigned to"},
312     {"NS_LISTRANK_UNRANKED", "There are also %d unranked users with global access."},  /* {ARGS: 10} */
313     {"NS_SETRANK_NOT_FOUND", "There is no support ranking with ID '$b%s$b'."},  /* {ARGS: 42} */
314     {"NS_SETRANK_HEAD", "Support ranking settings for Id %s:"},  /* {ARGS: 42} */
315     {"NS_SETRANK_UNKNOWN_SETTING", "$b%s$b is an unknown support rank setting."},  /* {ARGS: "moep"} */
316     {"NS_SETRANK_ORDER_INVALID", "%d is an invalid numeric value. (valid: 1-99)"},  /* {ARGS: 100} */
317     {"NS_ASSIGNRANK_DONE", "$b%s$b is now ranked as '$b%s$b'."},  /* {ARGS: "TestUser", "Supporter"} */
318     {"NS_INFO_HEADER", "$b%s$b Information:"}, /* {ARGS: "#TestChan"} */
319     {"NS_INFO_DEFAULTTOPIC", "Default Topic:"},
320     {"NS_INFO_MODELOCK", "Mode Lock:"},
321     {"NS_INFO_RECORD", "Record Visitors:"},
322     {"NS_INFO_OWNER", "Owner:"},
323     {"NS_INFO_USERS", "Total User Count:"},
324     {"NS_INFO_BANS", "Ban Count:"},
325     {"NS_INFO_VISITED", "Visited:"},
326     {"NS_INFO_REGISTERED", "Registered:"},
327     {"NS_INFO_REGISTRAR", "Registered by:"},
328     {"NS_INFO_OWNERLOG", "Ownership transfer history for $b%s$b:"}, /* {ARGS: "#TestChan"} */
329     {"NS_INFO_OWNERCHANGE", " from %s to %s on %s"},
330     {"NS_RENAME_DONE", "Renamed $b%s$b to $b%s$b."}, /* {ARGS: "TestUser", "TestUser2"} */
331     {"NS_RENAME_FAIL", "Failed renaming $b%s$b."}, /* {ARGS: "TestUser"} */
332     {"NS_FUN_DISABLED", "Fun commands are disabled in %s."}, /* {ARGS: "#TestChan"} */
333     {"NS_UNBIND_REQUIRED", "%1$s is a required function and there is no other command bound to %1$s. Bind another command to %1$s first."}, /* {ARGS: "bind"} */
334     {"NS_COMMANDS_NAME", "Name"},
335     {"NS_COMMANDS_ACCESS", "Access"},
336     {"NS_COMMANDS_GACCESS", "GodAccess"},
337     {"NS_COMMANDS_TRIGGERED", "Triggered"},
338     {"NS_COMMANDS_FUNCTION", "Function"},
339     {"NS_DNR_SET", "$b%s$b is do-not-register (by $b%s$b): %s" }, /* {ARGS: "#TestChan", "TestUser", "because of it is like it is"} */
340     {"NS_DNR_SET_EXPIRES", "$b%s$b is do-not-register (by $b%s$b; expires %s): %s" }, /* {ARGS: "#TestChan", "TestUser", "1 day", "because of it is like it is"} */
341     {"NS_DNR_SET_ANONYM", "$b%s$b is do-not-register. Please contact the support to get more information."}, /* {ARGS: "TestUser"} */
342     {"NS_NOREGISTER_INVALID_DURATION", "$b%s$b is not a valid duration."}, /* {ARGS: "möp"} */
343     {"NS_NOREGISTER_REGISTERED", "$b%s$b is currently registered and can't be added to the do-not-register list."}, /* {ARGS: "#TestChan"} */
344     {"NS_NOREGISTER_DONE", "added $b%s$b to the do-not-register list."}, /* {ARGS: "#TestChan"} */
345     {"NS_NOREGISTER_HEAD", "The following do-not-registers were found:"},
346     {"NS_DNR_TARGET", "Target"},
347     {"NS_DNR_USER", "Issuer"},
348     {"NS_DNR_EXPIRES", "Expires"},
349     {"NS_DNR_REASON", "Reason"},
350     {"NS_STAFF_LOGGEDIN", "Logged in as"},
351     {"NS_BOTS_ID", "Id"},
352     {"NS_BOTS_NICK", "Nick"},
353     {"NS_BOTS_SERVER", "Server:Port(:Pass)"},
354     {"NS_BOTS_CLASS", "Bot Class"},
355     {"NS_BOTS_FLAGS", "Flags"},
356     {"NS_BOTS_CHANNELS", "Channels"},
357     {"NS_BOTS_TRIGGER", "Trigger"},
358     {"NS_NICKLIST_NICK", "Nick"},
359     {"NS_NICKLIST_STATE", "State"},
360     {"NS_NICKLIST_ACCESS", "Access"},
361     {"NS_NICKLIST_SYNC", "use `nicklist sync` to fix all red and orange entrys in the list above (add opped users with %d and voiced with %d access)"},
362     {"NS_SETBOT_UNKNOWN", "`%d` is an unknown botid."}, /* {ARGS: 50} */
363     {"NS_SETBOT_HEADER", "$bSettings for botid `%d`:$b"}, /* {ARGS: 50} */
364     {"NS_SETBOT_SETTING", "$b%s$b is an unknown bot setting."}, /* {ARGS: "strangeSetting"} */
365     {"NS_SETBOT_NICK_INVALID", "`%s` is an invalid botnick."}, /* {ARGS: "-SuperMagicBananaBotWithManyFunctions"} */
366     {"NS_SETBOT_NEED_RESTART", "You need to reconnect the bot to apply this setting."},
367     {"NS_SETBOT_PORT_INVALID", "`%s` is an invalid port number."}, /* {ARGS: "-1"} */
368     {"NS_SETBOT_INVALID_CLASS", "`%s` is an invalid botclass."}, /* {ARGS: "MistColaLeer"} */
369     {"NS_SETBOT_MAXCHAN_INVALID", "`%s` is an invalid maxchan value."}, /* {ARGS: "-1"} */
370     {"NS_SETBOT_PRIORITY_INVALID", "`%s` is an invalid priority value."}, /* {ARGS: "-1"} */
371     {"NS_SETBOT_TRIGGER_INVALID", "`%s` is an invalid bot trigger."}, /* {ARGS: "tooLongTrigger"} */
372     {"NS_SETBOT_TRIGGER_NOTE", "Please note: This Setting will only affect new channels."},
373     {"NS_ADDBOT_EXISTING", "A bot with nick %s does already exist."}, /* {ARGS: "NeonServ"} */
374     {"NS_ADDBOT_DONE", "Added %s with BotID $b%d$b."}, /* {ARGS: "NeonServ", 2} */
375     {"NS_DELBOT_NOT_FOUND", "Bot with BotID / nick $b%s$b not found."}, /* {ARGS: "NeonServ"} */
376     {"NS_DELBOT_DONE", "Bot deleted."},
377     {"NS_RECONNECT_DONE", "Reconnected bot."},
378     {"NS_MODCMD_SETTING", "$b%s$b is an unknown modcmd setting."}, /* {ARGS: "strangeSetting"} */
379     {"NS_MODCMD_HEADER", "$bSettings for command %s:$b"}, /* {ARGS: "access"} */
380     {"NS_MODCMD_OUTRANKED", "$b%s$b outranks you. (required access: %d)"}, /* {ARGS: "die", 1000} */
381     {"NS_MODCMD_STATIC_FLAG", "This Flag is added statically. It can't be modified manually."},
382     {"NS_MEMINFO_DISABLED", "Memory Debugger is disabled!"},
383     {"NS_MEMINFO_NAME", "Name"},
384     {"NS_MEMINFO_COUNT", "Count"},
385     {"NS_MEMINFO_SIZE", "Size"},
386     {"NS_MEMINFO_LINE", "Line"},
387     {"NS_MEMINFO_TOTAL", "Total"},
388     {NULL, NULL}
389 };
390
391 /* TODO:
392 cmd_neonserv_open.c
393 set modelock
394 cmd_neonserv_modcmd.c
395 cmd_neonserv_allowregister.c
396 cmd_neonserv_noregister.c
397 cmd_neonserv_expire.c
398 cmd_neonserv_unvisited.c
399 cmd_neonserv_merge.c
400 cmd_neonserv_dnrsearch.c
401 cmd_neonserv_iplocate.c
402 cmd_neonserv_calc.c
403 */
404 //EVENTS
405 #include "event_neonserv_join.c"
406 #include "event_neonserv_part.c"
407 #include "event_neonserv_kick.c"
408 #include "event_neonserv_mode.c"
409 #include "event_neonserv_ctcp.c"
410 #include "event_neonserv_notice.c"
411 #include "event_neonserv_invite.c"
412 #include "event_neonserv_topic.c"
413
414
415 struct ClientSocket *getBotForChannel(struct ChanNode *chan) {
416     return getChannelBot(chan, BOTID);
417 }
418
419 static void neonserv_bot_ready(struct ClientSocket *client) {
420     if(client->botid != BOTID)
421         return;
422     MYSQL_RES *res;
423     MYSQL_ROW row;
424     
425     printf_mysql_query("SELECT `automodes`, `oper_user`, `oper_pass` FROM `bots` WHERE `id` = '%d'", client->clientid);
426     res = mysql_use();
427     if ((row = mysql_fetch_row(res)) != NULL) {
428         if(row[1] && row[2]) {
429             putsock(client, "OPER %s %s", row[1], row[2]);
430         }
431         putsock(client, "MODE %s +%s", client->user->nick, row[0]);
432     }
433     
434     printf_mysql_query("SELECT `channel_name`, `channel_key` FROM `bot_channels` LEFT JOIN `channels` ON `chanid` = `channel_id` WHERE `botid` = '%d' AND `suspended` = '0'", client->clientid);
435     res = mysql_use();
436     
437     while ((row = mysql_fetch_row(res)) != NULL) {
438         putsock(client, "JOIN %s %s", row[0], row[1]);
439     }
440 }
441
442 static void neonserv_trigger_callback(int clientid, struct ChanNode *chan, char *trigger) {
443     MYSQL_RES *res;
444     MYSQL_ROW row;
445     loadChannelSettings(chan);
446     if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) {
447         strcpy(trigger, "+");
448         return;
449     }
450     printf_mysql_query("SELECT `trigger`, `defaulttrigger` FROM `bot_channels` LEFT JOIN `bots` ON `botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chan->channel_id, BOTID);
451     res = mysql_use();
452     if(!(row = mysql_fetch_row(res))) {
453         strcpy(trigger, "+");
454         return;
455     }
456     if(row[0] && *row[0])
457         strcpy(trigger, row[0]);
458     else
459         strcpy(trigger, ((row[1] && *row[1]) ? row[1] : "~"));
460 }
461
462 static void start_bots(int type) {
463     struct ClientSocket *client;
464     MYSQL_RES *res, *res2;
465     MYSQL_ROW row;
466     
467     if(type == MODSTATE_STARTSTOP) {
468         printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue`, `ssl`, `bind` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
469         res = mysql_use();
470         while ((row = mysql_fetch_row(res)) != NULL) {
471             client = create_socket(row[3], atoi(row[4]), row[10], row[5], row[0], row[1], row[2]);
472             client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
473             client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
474             client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0);
475             client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP;
476             client->botid = BOTID;
477             client->clientid = atoi(row[7]);
478             connect_socket(client);
479         }
480     }
481     
482     printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
483     res2 = mysql_use();
484     while ((row = mysql_fetch_row(res2)) != NULL) {
485         if(bind_cmd_to_command(BOTID, row[0], row[1])) {
486             if(row[2] && strcmp(row[2], "")) {
487                 bind_set_parameters(BOTID, row[0], row[2]);
488             }
489             if(row[3]) {
490                 bind_set_global_access(BOTID, row[0], atoi(row[3]));
491             }
492             if(row[4]) {
493                 bind_set_channel_access(BOTID, row[0], row[4]);
494             }
495             if(strcmp(row[5], "0"))
496                 bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
497         }
498     }
499     bind_unbound_required_functions(BOTID);
500 }
501
502 void init_NeonServ(int type) {
503     set_bot_alias(BOTID, BOTALIAS);
504     start_bots(type);
505     
506     if(type == MODSTATE_REBIND) return;
507     
508     //register events
509     bind_bot_ready(neonserv_bot_ready, module_id);
510     bind_join(neonserv_event_join, module_id);
511     bind_part(neonserv_event_part, module_id);
512     bind_chanctcp(neonserv_event_chanctcp, module_id);
513     bind_privctcp(general_event_privctcp, module_id);
514     bind_channotice(neonserv_event_channotice, module_id);
515     bind_topic(neonserv_event_topic, module_id);
516     bind_invite(neonserv_event_invite, module_id);
517     bind_mode(neonserv_event_mode, module_id);
518     bind_kick(neonserv_event_kick, module_id);
519     
520     set_trigger_callback(BOTID, module_id, neonserv_trigger_callback);
521     
522     register_default_language_table(msgtab);
523 }
524
525 void loop_NeonServ() {
526     
527 }
528
529 void free_NeonServ(int type) {
530     unbind_allcmd(BOTID);
531     if(type == MODSTATE_STARTSTOP) {
532         //disconnect all our bots
533         struct ClientSocket *client;
534         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
535             if(client->botid == BOTID) {
536                 unbind_botwise_allcmd(0, client->clientid);
537                 close_socket(client);
538                 break;
539             }
540         }
541     }
542 }
543
544 #undef BOTID
545 #undef BOTALIAS