Skip to content

Commit

Permalink
improved dialog response checking (#902)
Browse files Browse the repository at this point in the history
* new listitem validation

* limit the answer value from 0 to 1

* review changes
  • Loading branch information
atomlin-git authored Jun 28, 2024
1 parent 833af23 commit 6c58ec6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Server/Components/Dialogs/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,27 @@ class DialogsComponent final : public IDialogsComponent, public PlayerConnectEve
// If the dialog id doesn't match what the server is expecting, ignore it
PlayerDialogData* data = queryExtension<PlayerDialogData>(peer);
if (!data || data->getActiveID() == INVALID_DIALOG_ID || data->getActiveID() != sendDialogResponse.ID)
{
return false;
}

// If dialog type is one of the lists and list item is invalid, ignore it
if (sendDialogResponse.ListItem < 0 && (data->style_ == DialogStyle_LIST || data->style_ == DialogStyle_TABLIST || data->style_ == DialogStyle_TABLIST_HEADERS))
{
if(sendDialogResponse.Response < 0 || sendDialogResponse.Response > 1)
return false;

if((data->style_ == DialogStyle_PASSWORD || data->style_ == DialogStyle_INPUT || data->style_ == DialogStyle_MSGBOX) && sendDialogResponse.ListItem != -1)
return false;

if((data->style_ == DialogStyle_LIST || data->style_ == DialogStyle_TABLIST || data->style_ == DialogStyle_TABLIST_HEADERS) && data->body_.length() > 0)
{
unsigned int lines = 0;

for(unsigned int i = 0 ; i < data->body_.length() - 1; i++)
if(data->body_[i] == '\n')
lines++;

if(data->style_ == DialogStyle_TABLIST_HEADERS && lines > 0)
lines--;

if(sendDialogResponse.ListItem < 0 || sendDialogResponse.ListItem > lines)
return false;
}

data->activeId = INVALID_DIALOG_ID;
Expand Down

0 comments on commit 6c58ec6

Please sign in to comment.