lickthecoin/server.py

35 lines
829 B
Python
Raw Normal View History

2020-03-11 03:13:56 +00:00
#!/usr/bin/env python3
from twisted.internet import protocol, reactor, endpoints
2020-03-11 15:53:05 +00:00
import bcrypt
2020-03-11 22:18:56 +00:00
salt = b'$2b$12$mvJMOyxLJid1jFLgaU1s0.'
2020-03-11 15:53:05 +00:00
def hash(inp):
2020-03-11 22:18:56 +00:00
return bcrypt.hashpw(inp.encode('utf-8'), salt).decode('utf-8')
actions = []
2020-03-11 03:13:56 +00:00
2020-03-11 15:43:39 +00:00
class Reply(protocol.Protocol):
2020-03-11 03:13:56 +00:00
def dataReceived(self, data):
2020-03-11 22:18:56 +00:00
output = 'ERROR:INVALID_INP'
data = data.decode('utf-8').split(':')
2020-03-11 15:53:05 +00:00
if len(data) > 4:
data.pop(0)
2020-03-11 22:18:56 +00:00
if data[0] in actions:
output = actions[data[0]](data[1:])
#output=hash(data[0])
2020-03-11 15:43:39 +00:00
else:
2020-03-11 15:53:05 +00:00
self.transport.write('LICKTHECOIN:{}\n'.format(output).encode('utf-8'))
2020-03-11 03:13:56 +00:00
2020-03-11 15:43:39 +00:00
class Factory(protocol.Factory):
2020-03-11 03:13:56 +00:00
def buildProtocol(self, addr):
2020-03-11 15:43:39 +00:00
return Reply()
2020-03-11 03:13:56 +00:00
2020-03-11 15:43:39 +00:00
endpoints.serverFromString(reactor, "tcp:13327").listen(Factory())
2020-03-11 03:13:56 +00:00
reactor.run()