Skip to content

Commit

Permalink
Merge pull request #1027 from ZarothYe/prevent-whitespace-ki-messages
Browse files Browse the repository at this point in the history
Prevent sending blank/space KI messages in variety of contexts; Fix /invite so it doesn't silently crash
  • Loading branch information
Hoikas committed Nov 26, 2021
2 parents 78c442f + eaf42c5 commit 2c186e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion Scripts/Python/ki/xKIChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,27 +866,38 @@ def __call__(self, message):
else:
statusMsg = PtGetLocalizedString(emote[1], [PtGetLocalPlayer().getPlayerName()])
self.chatMgr.DisplayStatusMessage(statusMsg, 1)

# Get remaining message string after emote command
message = message[len(words[0]):]
if message == "":
if message == "" or message.isspace():
return None
return message[1:]
except LookupError:
try:
command = xKIExtChatCommands.xChatExtendedChat[str(words[0][1:].casefold())]
if isinstance(command, str):
# Retrieved command is just a plain string
args = message[len(words[0]):]
PtConsole(command + args)
else:
# Retrieved command is not a string (it's a function)
try:
# Get remaining message string after chat command
args = message[len(words[0]) + 1:]
if args:
try:
retDisp = command(args)
except TypeError:
retDisp = command()

# Command took no args, so return args as new message
if args == "" or args.isspace():
return None
return args
else:
retDisp = command()

# Check type of return value from command and display appropriately
if isinstance(retDisp, str):
self.chatMgr.DisplayStatusMessage(retDisp)
elif isinstance(retDisp, tuple):
Expand All @@ -898,11 +909,19 @@ def __call__(self, message):
PtDebugPrint("xKIChat.commandsProcessor(): Chat command function did not run.", command, level=kErrorLevel)
except LookupError:
if str(words[0].casefold()) in xKIExtChatCommands.xChatSpecialHandledCommands:
# Get remaining message string after special chat command
remainingMsg = message[len(words[0]):]
if remainingMsg == "" or remainingMsg.isspace():
return None
# Return full message with special command still prefixed
return message
else:
self.chatMgr.AddChatLine(None, PtGetLocalizedString("KI.Errors.CommandError", [message]), kChat.SystemMessage)
return None

# Prevent sending blank/whitespace message
if message == "" or message.isspace():
return None
return message

## Extract the player ID from a chat's params.
Expand Down
4 changes: 2 additions & 2 deletions Scripts/Python/xInvite.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def CreateInvitation(params=None):
if invites is not None:
if invites.getChildNodeCount() <= gMaxInviteCount:
# create the note
note = ptVaultTextNoteNode(PtVaultNodePermissionFlags.kDefaultPermissions)
note = ptVaultTextNoteNode()
note.noteSetTitle(passkey)
invites.addNode(note)
return PtGetLocalizedString("KI.Invitation.InviteKeyAdded", [str(passkey)])
Expand Down Expand Up @@ -172,7 +172,7 @@ def DeleteInvitation(params=None):
return PtGetLocalizedString("KI.Invitation.DeletedInvitation") + str(passkey)

def MeChat(params=None):
if (params == None):
if (not params or params.isspace()):
PtDebugPrint('xChatExtend:MeCmd: If you have nothing to say, why say anything at all?')
return
PtSendKIMessage(kKIChatStatusMsg, ('%s %s' % (PtGetLocalPlayer().getPlayerName(), params)))

0 comments on commit 2c186e3

Please sign in to comment.