chatServer/modules/-[example modules]/parrot text server/module.py
2021-04-09 16:42:52 +02:00

22 lines
621 B
Python

global textPreRequest
def textPreRequest(event,self,requestLength):
if requestLength <= 128: return
sendResponse(self.connection,"error: too long".encode("utf-8"))
self.closeThread()
return True
addEventHandler("onPreRequest",textPreRequest)
global textRequest
def textRequest(event,self,requestLength):
data = self.connection.recv(requestLength)
sendResponse(self.connection,data)
text = data.decode("utf-8")
print(":".join(map(str,self.address))+ " > " +text)
if text == "exit":
with threadsLock:
global close
close = True
self.closeThread()
return True
addEventHandler("onRequest",textRequest)