Ensure that a DataTLV is not too long
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
@ -109,7 +109,10 @@ class Squirrel(Hazelnut):
|
||||
self.refresh_input()
|
||||
if not self.squinnondation.no_emoji:
|
||||
self.refresh_emoji_pad()
|
||||
key = self.squinnondation.screen.getkey(curses.LINES - 1, 3 + len(self.nickname) + self.input_index)
|
||||
try:
|
||||
key = self.squinnondation.screen.getkey(curses.LINES - 1, 3 + len(self.nickname) + self.input_index)
|
||||
except curses.error:
|
||||
continue
|
||||
|
||||
if key == "KEY_MOUSE":
|
||||
try:
|
||||
@ -169,7 +172,12 @@ class Squirrel(Hazelnut):
|
||||
return
|
||||
elif key != "\n":
|
||||
# Insert the pressed key in the current message
|
||||
self.input_buffer = self.input_buffer[:self.input_index] + key + self.input_buffer[self.input_index:]
|
||||
new_buffer = self.input_buffer[:self.input_index] + key + self.input_buffer[self.input_index:]
|
||||
if len(DataTLV.construct(f"<{self.nickname}> {new_buffer}")) > 255 - 8 - 4:
|
||||
# The message is too long to be sent once. We don't allow the user to type any other character.
|
||||
curses.beep()
|
||||
return
|
||||
self.input_buffer = new_buffer
|
||||
self.input_index += 1
|
||||
return
|
||||
|
||||
|
Reference in New Issue
Block a user