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

23 lines
647 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":
threadsLock.acquire()
global close
close = True
threadsLock.release()
self.closeThread()
return True
addEventHandler("onRequest",textRequest)