aboutsummaryrefslogtreecommitdiffstats
path: root/UDP/index
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-09-17 13:43:22 +0200
committermakefu <github@syntax-fehler.de>2011-09-17 13:43:22 +0200
commit9f0685f7d6dd8d84ddb00dc96472dd026596eb42 (patch)
tree48f6c1a25d4f99496d8a6024a6fb61ba50d6ab6d /UDP/index
parentd581793fa3418e89aaa747889989438271016968 (diff)
Reaktor/UDP: rewrite ubot
replace the ubot code with acutally working code
Diffstat (limited to 'UDP/index')
-rwxr-xr-xUDP/index49
1 files changed, 27 insertions, 22 deletions
diff --git a/UDP/index b/UDP/index
index 950f0d2..c46202b 100755
--- a/UDP/index
+++ b/UDP/index
@@ -1,6 +1,6 @@
#!/usr/bin/python
-from asycore import asychat
+import asyncore, socket
import logging
import sys
log = logging.getLogger('asybot')
@@ -15,43 +15,48 @@ def enable_syslog(logger):
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
-class ubot(asychat):
+class ubot(asyncore.dispatcher):
""" UDP Bot """
- def __init__(self, port,pattern,action,bind="0.0.0.0",terminator='\r\n'):
- asychat.__init__(self)
- self.bind = bind
+ def __init__(self, port,pattern,action,bind_addr="",):
+ asyncore.dispatcher.__init__(self)
+ self.bind_addr = bind_addr
self.port = port
self.data = ''
- self.set_terminator('\r\n')
self.bind_socket()
def bind_socket(self):
"""
if the socket is already bound we want to reuse this socket anyway
"""
- log.error("not yet implemented")
- sys.exit(23)
- def collect_incoming_data(self,data):
- self.data += data
-
- def found_terminator(self):
- """
- TODO what happens if, for example in an html message we find our pattern a hundred times.
- should the actions been called a hundred times or just once for the connect?
- """
+
+ self.create_socket(socket.AF_INET,socket.SOCK_DGRAM)
+ self.set_reuse_addr()
+ self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
+ log.info("Binding Socket at %s:%d" %(self.bind_addr,self.port))
+ self.bind( (self.bind_addr,self.port) )
+
+ def handle_connect(self):
+ log.info("Server Started")
+ def handle_read(self):
+ self.data,addr = self.recvfrom(2048)
log.debug('<< %s' % self.data)
- message = self.data
- self.data = ''
- if self.find_pattern(message):
- self.start_action(message)
+ if self.find_pattern():
+ self.start_action()
- def find_pattern(self,message):
+ def find_pattern(self):
""" returns true if own pattern is found"""
log.error("not yet implemented")
sys.exit(23)
- def start_action(self,message):
+ def start_action(self):
""" runs all the defined actions"""
log.error("not yet implemented")
sys.exit(23)
+
+if __name__ == "__main__":
+ import os
+ lol = logging.DEBUG if os.environ.get('debug',False) else logging.INFO
+ logging.basicConfig(level=lol)
+ ubot(1337,r'',{})
+ asyncore.loop()