Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent sending blank/space KI messages in variety of contexts; Fix /invite so it doesn't silently crash #1027

Merged
merged 3 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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():
ZarothYe marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions Scripts/Python/xCheat.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ def ImportMarkers(args):
if jnode.folderGetName() == mg[1]:
# yes, add the markers to this game
for marker in mg[0][4]:
# TODO: PlasmaVaultConstants.PtVaultNodePermissionFlags does not exist
ZarothYe marked this conversation as resolved.
Show resolved Hide resolved
nMarker = Plasma.ptVaultMarkerNode(PlasmaVaultConstants.PtVaultNodePermissionFlags.kDefaultPermissions)
nMarker.markerSetText(marker[0])
pos = Plasma.ptPoint3(marker[1],marker[2],marker[3])
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 (params == None or params == "" or params.isspace()):
ZarothYe marked this conversation as resolved.
Show resolved Hide resolved
PtDebugPrint('xChatExtend:MeCmd: If you have nothing to say, why say anything at all?')
return
PtSendKIMessage(kKIChatStatusMsg, ('%s %s' % (PtGetLocalPlayer().getPlayerName(), params)))