Skip to content

Commit c11404d

Browse files
committed
fix to dice roll regex, added error output when invalid dice roll
strings are sent by plugins
1 parent b6dba1e commit c11404d

12 files changed

Lines changed: 20 additions & 3 deletions

OmegaRPG/omegarpgmainwindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ OmegaRpgMainWindow::OmegaRpgMainWindow()
187187
connect(playerList,&PlayerListAreaWidget::openWhisper,chat,&ChatAreaWidget::openWhisperTab);
188188
connect(playerList,&PlayerListAreaWidget::bootFromRoom,control,&orpg::ClientControl::kick);
189189
connect(playerList,&PlayerListAreaWidget::chat,chat,&ChatAreaWidget::chatPrivate);
190+
connect(playerList,&PlayerListAreaWidget::error,chat,&ChatAreaWidget::printErrorMessage);
190191

191192
//settings window signals
192193
connect(settingsWindow,&OmegaRpgSettingsWindow::demandSettings,this,&OmegaRpgMainWindow::updateSettingsWindow);

core/client/util/diceroll.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const QRegularExpression DiceRoll::completeStringRegEx_ =
1414
"(?<"+signString_+">[+-]?)[\\s\\t]*" /// sign of first roll
1515
"(((?<"+numString_+">\\d+)?(?<"+diceString_+">d))?(?<"+valueString_+">\\d+))[\\s\\t]*" /// dice of first roll
1616
"(\\((?<"+nameString_+">.*?)\\))?[\\s\\t]*" /// name of first roll
17-
"(?<"+remainingString_+">([+-][\\s\\t]*((\\d+)?(d))?(\\d+)[\\s\\t]*(.*?)[\\s\\t]*?)*)" ///remaining rolls
17+
"(?<"+remainingString_+">([+-][\\s\\t]*((\\d+)?(d))?(\\d+)[\\s\\t]*(\\(.*?\\))?[\\s\\t]*)*)" ///remaining rolls
1818
"$");
1919

2020
QString DiceRoll::rawString() const

gui/client/plugins/plugin.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "plugin.h"
22
#include "core/client/util/diceroll.h"
3+
#include "core/client/util/dice.h"
34

45
Plugin::Plugin(QQuickItem *parent) : QQuickItem(parent)
56
{
@@ -51,7 +52,14 @@ void Plugin::setEditable(bool editable)
5152
void Plugin::roll(const QString& rollString)
5253
{
5354
DiceRoll diceRoll(rollString);
54-
chat(diceRoll.roll());
55+
if(diceRoll.valid())
56+
{
57+
chat(diceRoll.roll());
58+
}
59+
else
60+
{
61+
error("Malformed dice roll string: "+diceRoll.rawString());
62+
}
5563
}
5664

5765

gui/client/plugins/plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Plugin : public QQuickItem
2828
void pluginDataSet();
2929
void pluginDataChanged(const QJsonObject& data);
3030
void chat(const QString& text);
31+
void error(const QString& text);
3132
public slots:
3233
private:
3334
bool editable_;

gui/client/widgets/alias/aliassheetbinderwidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void AliasSheetBinderWidget::addSheetWidget(AliasSheetWidget *sheet)
5757
tabs->addTab(sheet,sheet->getSheetName());
5858
sheet->setNightMode(nightMode);
5959
connect(sheet,&AliasSheetWidget::chat,this,&AliasSheetBinderWidget::chat);
60+
connect(sheet,&AliasSheetWidget::error,this,&AliasSheetBinderWidget::error);
6061
connect(sheet,&AliasSheetWidget::changed,this,&AliasSheetBinderWidget::changed);
6162
}
6263
}

gui/client/widgets/alias/aliassheetpluginwidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ AliasSheetPluginWidget::AliasSheetPluginWidget(const AliasSheetPlugin* sheet, bo
2020
data_ = sheet_->pluginData();
2121
connect(pluginWidget,&Plugin::pluginDataChanged,this,&AliasSheetPluginWidget::pluginDataChanged);
2222
connect(pluginWidget,&Plugin::chat,this,&AliasSheetWidget::chat);
23+
connect(pluginWidget,&Plugin::error,this,&AliasSheetWidget::error);
2324
}
2425
}
2526
else

gui/client/widgets/alias/aliassheetreadwidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void AliasSheetReadWidget::currentChanged(const Alias *alias)
4444
updateNightMode();
4545
connect(binder,&AliasSheetBinderWidget::changed,this,&AliasSheetReadWidget::changed);
4646
connect(binder,&AliasSheetBinderWidget::chat,this,&AliasSheetReadWidget::chat);
47+
connect(binder,&AliasSheetBinderWidget::error,this,&AliasSheetReadWidget::error);
4748
}
4849
}
4950

gui/client/widgets/alias/aliassheetreadwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class AliasSheetReadWidget : public QWidget
2222
signals:
2323
void editedAlias(Alias* alias);
2424
void chat(const QString& text);
25+
void error(const QString& text);
2526
public slots:
2627
void setNightMode(bool value);
2728
private slots:

gui/client/widgets/alias/aliassheetwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class AliasSheetWidget : public QWidget
2323
signals:
2424
void changed();
2525
void chat(const QString& text);
26+
void error(const QString& text);
2627
public slots:
2728
void exportSheet();
2829
virtual void setNightMode(bool value);

gui/client/widgets/chatareawidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void ChatAreaWidget::printStatusMessage(QString text)
474474
void ChatAreaWidget::printChatMessage(const orpg::ChatMessage& chatMessage)
475475
{
476476
QTextBrowser* tb = getChatBrowser(chatMessage.senderId(),chatMessage.to());
477-
if(tb==NULL)
477+
if(tb==nullptr)
478478
return;
479479
QString idpart;
480480
if(chatMessage.hasSenderId())

0 commit comments

Comments
 (0)