diff --git a/clientBlaster.py b/clientBlaster.py index 53e7eb2..a87bae0 100644 --- a/clientBlaster.py +++ b/clientBlaster.py @@ -82,7 +82,7 @@ def sendResponse(connection,data): senderThreadSleepMin = 0.0333 senderThreadSleepMax = 1.0 -senderThreadSleepIncr = 0.05 +senderThreadSleepIncr = 0.01 class senderThread(threading.Thread): def __init__(self,connectionThread): @@ -110,7 +110,7 @@ class senderThread(threading.Thread): with self.lock: sleepTime = self.sleep - print(sleepTime) + #print(sleepTime) time.sleep(sleepTime) with self.lock: @@ -153,8 +153,11 @@ class connectionThread(threading.Thread): print("thread closed: " +str(self.threadId)+ " (open: " +str(len(threads))+ ")") self.closed = True - def sendResponse(self,data): - with self.lock: + def sendResponse(self,data,lock = True): + if lock == True: + with self.lock: + self.senderThread.addToQueue([sendResponse,[self.connection,data],{}]) + else: self.senderThread.addToQueue([sendResponse,[self.connection,data],{}]) def run(self): diff --git a/modules/[text server]/[api]/communication/module.py b/modules/[text server]/[api]/communication/module.py new file mode 100644 index 0000000..3bd9e09 --- /dev/null +++ b/modules/[text server]/[api]/communication/module.py @@ -0,0 +1,29 @@ +moduleDepends([ + p("[text server]","[api]","commands"), +]) + +global textSend +def textSend(self,command,args): + if len(args) < 2: + return ["error","nonfatal","syntax","Correct syntax: " +command+ ",,,[argument 1],[argument 2],..."] + + user = args[0].lower() + if len(user) < 1: + return ["error","nonfatal","name_too_short","Needs to be at least 1 character in length."] + + me = "" + with self.lock: + me = self.user + + if not me: + return ["error","nonfatal","not_logged_in"] + + with threadsLock: + for threadId in threads: + thread = threads[threadId] + with thread.lock: + if thread.user != user: continue + thread.sendResponse(textListToCommand(["send",me] + args[1:]).encode("utf-8"),lock = False) + + return ["ok"] +textCommandAddHandler("send",textSend) \ No newline at end of file diff --git a/modules/[text server]/main/module.py b/modules/[text server]/main/module.py index 0779762..220d77c 100644 --- a/modules/[text server]/main/module.py +++ b/modules/[text server]/main/module.py @@ -33,14 +33,6 @@ def textOnRequest(event,self,requestLength): text = data.decode("utf-8") print(":".join(map(str,self.address))+ " > " +text) - if text == "close": - with threadsLock: - global close - close = True - - self.closeThread() - return True - response = textCommandRun(self,textCommandToList(text)) print("response: " +textListToCommand(response)) self.sendResponse(textListToCommand(response).encode("utf-8"))