Commit d53a0088 authored by doebi's avatar doebi
Browse files

added simple spamprotection and auto-update

parent 2f405bbf
......@@ -4,6 +4,7 @@ import badge
import wifi
import appglue
from hashlib import sha1
import woezel
import uos
import ubinascii
......@@ -67,23 +68,30 @@ class WinkeKatze:
def sub_cb(self,topic,msg):
print ("received mqtt message topic: %s, payload: %s" % (topic,msg))
if topic.endswith('/nick'):
print ("setting received nick to %s" % msg.decode("utf-8"))
self.new_wink(msg)
list = []
hash = ubinascii.hexlify(sha1(self.nick).digest())
for i in range(6):
# reverse because of reverse()
list.append(0)
list.append(int(int(hash[i*6+4:i*6+6], 16)/7))
list.append(int(int(hash[i*6+2:i*6+4], 16)/7))
list.append(int(int(hash[i*6:i*6+2], 16)/7))
list.reverse()
colors = bytes(list)
self.wink(colors)
if msg.decode("utf-8") == self.nick:
pass
else:
print ("setting received nick to %s" % msg.decode("utf-8"))
self.new_wink(msg)
list = []
hash = ubinascii.hexlify(sha1(self.nick).digest())
for i in range(6):
# reverse because of reverse()
list.append(0)
list.append(int(int(hash[i*6+4:i*6+6], 16)/7))
list.append(int(int(hash[i*6+2:i*6+4], 16)/7))
list.append(int(int(hash[i*6:i*6+2], 16)/7))
list.reverse()
colors = bytes(list)
self.wink(colors)
if topic.endswith('/motd'):
self.motd = msg.decode("utf-8")
self.wink(''.join(['\0\0\0\50' for i in range(6)]))
self.wink(''.join(['\50\0\0\0' for i in range(6)]))
if topic.endswith('/version'):
nv = int(msg.decode("utf-8"))
if nv > self.version:
woezel.install("Winkekatze")
def wink(self, colors):
for count in [1,2,3]:
......@@ -129,6 +137,7 @@ class WinkeKatze:
self.clientname = 'SHA2017Badge' + str(ubinascii.hexlify(uos.urandom(5)))
self.server = server
self.topic = topic
self.version = 18
self.nick = ''
self.nick1 = ''
self.nick2 = ''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment