aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2013-04-16 07:19:55 -0400
committerEric S. Raymond <esr@thyrsus.com>2013-04-16 07:19:55 -0400
commitbf72620f61f1a313e6afe0b20055c52683e248bc (patch)
tree47a457dd30bf4331e8c3635e1793c1cab270d024
parentTypo fixes. (diff)
downloadirker-bf72620f61f1a313e6afe0b20055c52683e248bc.tar.xz
Added option to force nick.
-rw-r--r--NEWS1
-rwxr-xr-xirkerd30
-rw-r--r--irkerd.xml8
3 files changed, 29 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 8381509..f72b883 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@
1.18
Added -l option; irker can now be used as a channel monitor.
+ Added -n option: the nick can be forced.
1.17 @ 2013-02-03
Various minor fixes and bulletproofing.
diff --git a/irkerd b/irkerd
index a0231f4..d3ea230 100755
--- a/irkerd
+++ b/irkerd
@@ -28,7 +28,6 @@ http://pypi.python.org/pypi/irc/
HOST = "localhost"
PORT = 6659
-NAMESTYLE = "irker%03d" # IRC nick template - must contain '%d'
XMIT_TTL = (3 * 60 * 60) # Time to live, seconds from last transmit
PING_TTL = (15 * 60) # Time to live, seconds from last PING
HANDSHAKE_TTL = 60 # Time to live, seconds from nick transmit
@@ -44,7 +43,7 @@ CONNECTION_MAX = 200 # To avoid hitting a thread limit
version = "1.17"
-import sys, getopt, urlparse, time, random, socket, signal
+import sys, getopt, urlparse, time, random, socket, signal, re
import threading, Queue, SocketServer
import irc.client, logging
try:
@@ -112,7 +111,10 @@ class Connection:
"Return a name for the nth server connection."
if n is None:
n = self.nick_trial
- return (NAMESTYLE % n)
+ if fallback:
+ return (namestyle % n)
+ else:
+ return namestyle
def handle_ping(self):
"Register the fact that the server has pinged this connection."
self.last_ping = time.time()
@@ -121,13 +123,17 @@ class Connection:
self.status = "ready"
self.irker.debug(1, "nick %s accepted" % self.nickname())
def handle_badnick(self):
- "The server says our nick has a conflict."
+ "The server says our nick is ill-formed or has a conflict."
self.irker.debug(1, "nick %s rejected" % self.nickname())
- # Randomness prevents a malicious user or bot from anticipating the
- # next trial name in order to block us from completing the handshake.
- self.nick_trial += random.randint(1, 3)
- self.last_xmit = time.time()
- self.connection.nick(self.nickname())
+ if fallback:
+ # Randomness prevents a malicious user or bot from
+ # anticipating the next trial name in order to block us
+ # from completing the handshake.
+ self.nick_trial += random.randint(1, 3)
+ self.last_xmit = time.time()
+ self.connection.nick(self.nickname())
+ # Otherwise fall through, it might be possible to
+ # recover manually.
def handle_disconnect(self):
"Server disconnected us for flooding or some other reason."
self.connection = None
@@ -538,8 +544,9 @@ class IrkerUDPHandler(SocketServer.BaseRequestHandler):
if __name__ == '__main__':
debuglvl = 0
+ namestyle = "irker%03d"
logfile = None
- (options, arguments) = getopt.getopt(sys.argv[1:], "d:l:V:")
+ (options, arguments) = getopt.getopt(sys.argv[1:], "d:l:n:V:")
for (opt, val) in options:
if opt == '-d': # Enable debug/progress messages
debuglvl = int(val)
@@ -547,9 +554,12 @@ if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
elif opt == '-l': # Logfile mode - report traffic read in
logfile = val
+ elif opt == '-n': # Force the nick
+ namestyle = val
elif opt == '-V': # Emit version and exit
sys.stdout.write("irkerd version %s\n" % version)
sys.exit(0)
+ fallback = re.search("%.*d", namestyle)
irker = Irker(debuglevel=debuglvl)
irker.debug(1, "irkerd version %s" % version)
try:
diff --git a/irkerd.xml b/irkerd.xml
index 795b367..54d2ffb 100644
--- a/irkerd.xml
+++ b/irkerd.xml
@@ -20,6 +20,7 @@
<command>irkerd</command>
<arg>-d <replaceable>debuglevel</replaceable></arg>
<arg>-l <replaceable>logfile</replaceable></arg>
+ <arg>-n <replaceable>nick</replaceable></arg>
<arg>-V</arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -80,6 +81,13 @@ timestamp in Unix time, the fqdn of the sending server, and the
message data.</para></listitem>
</varlistentry>
<varlistentry>
+<term>-n</term>
+<listitem><para>Takes a following value, setting the nick
+to be used. If the nick contains a numeric format element
+(such as %03d) it is used to generate suffixed fallback names
+in the event of a nick collision.</para></listitem>
+</varlistentry>
+<varlistentry>
<term>-V</term>
<listitem><para>Write the program version to stdout and
terminate.</para></listitem>