diff --git a/adm/style/acp_mchat_globalsettings.html b/adm/style/acp_mchat_globalsettings.html
index 53402be..d82744c 100644
--- a/adm/style/acp_mchat_globalsettings.html
+++ b/adm/style/acp_mchat_globalsettings.html
@@ -117,6 +117,11 @@
{{ lang('MCHAT_FLOOD_TIME_EXPLAIN') }}
{{ lang('MCHAT_ACP_SECONDS') }}
+
+
+ {{ lang('MCHAT_FLOOD_MESSAGES_EXPLAIN') }}
+ - {{ lang('MCHAT_ACP_MESSAGES') }}
+
{{ lang('MCHAT_MAX_MESSAGE_LENGTH_EXPLAIN') }}
diff --git a/composer.json b/composer.json
index 77a25a9..12ed4ab 100644
--- a/composer.json
+++ b/composer.json
@@ -1,52 +1,52 @@
{
- "name": "dmzx/mchat",
- "type": "phpbb-extension",
- "description": "mChat",
- "homepage": "https://www.phpbb.com/customise/db/extension/mchat_extension/",
- "version": "2.1.2",
- "time": "2018-12-25",
- "keywords": [
- "phpbb",
- "extension",
- "mchat"
- ],
- "license": "GPL-2.0-only",
- "authors": [
- {
- "name": "kasimi",
- "homepage": "https://kasimi.net",
- "email": "mail@kasimi.net",
- "role": "Lead Developer"
- },
- {
- "name": "dmzx",
- "homepage": "http://www.dmzx-web.net",
- "email": "info@dmzx-web.net",
- "role": "Former Developer"
- },
- {
- "name": "RMcGirr83",
- "homepage": "http://rmcgirr83.org",
- "role": "Original MOD author"
- }
- ],
- "require": {
- "php": ">=5.4.7",
- "composer/installers": "~1.0.0",
- "phpbb/phpbb": ">=3.2.0"
- },
- "require-dev": {
- "phpbb/epv": "dev-master"
- },
- "extra": {
- "display-name": "mChat",
- "soft-require": {
- "phpbb/phpbb": ">=3.2.0"
- },
- "version-check": {
- "host": "www.phpbb.com",
- "directory": "/customise/db/extension/mchat_extension",
- "filename": "version_check"
- }
- }
+ "name": "dmzx/mchat",
+ "type": "phpbb-extension",
+ "description": "mChat",
+ "homepage": "https://www.phpbb.com/customise/db/extension/mchat_extension/",
+ "version": "2.1.3",
+ "time": "2019-06-06",
+ "keywords": [
+ "phpbb",
+ "extension",
+ "mchat"
+ ],
+ "license": "GPL-2.0-only",
+ "authors": [
+ {
+ "name": "kasimi",
+ "homepage": "https://kasimi.net",
+ "email": "mail@kasimi.net",
+ "role": "Lead Developer"
+ },
+ {
+ "name": "dmzx",
+ "homepage": "http://www.dmzx-web.net",
+ "email": "info@dmzx-web.net",
+ "role": "Former Developer"
+ },
+ {
+ "name": "RMcGirr83",
+ "homepage": "http://rmcgirr83.org",
+ "role": "Original MOD author"
+ }
+ ],
+ "require": {
+ "php": ">=5.4.7",
+ "composer/installers": "~1.0.0",
+ "phpbb/phpbb": ">=3.2.0"
+ },
+ "require-dev": {
+ "phpbb/epv": "dev-master"
+ },
+ "extra": {
+ "display-name": "mChat",
+ "soft-require": {
+ "phpbb/phpbb": ">=3.2.0"
+ },
+ "version-check": {
+ "host": "www.phpbb.com",
+ "directory": "/customise/db/extension/mchat_extension",
+ "filename": "version_check"
+ }
+ }
}
\ No newline at end of file
diff --git a/config/services.yml b/config/services.yml
index 0d6c01e..eae2e91 100644
--- a/config/services.yml
+++ b/config/services.yml
@@ -83,7 +83,6 @@ services:
- '@cache.driver'
- '@dispatcher'
- '@group_helper'
- - '@text_formatter.parser'
dmzx.mchat.settings:
class: dmzx\mchat\core\settings
diff --git a/core/functions.php b/core/functions.php
index afff00d..0ab786b 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -631,24 +631,62 @@ class functions
*/
public function mchat_is_user_flooding()
{
- if (!$this->mchat_settings->cfg('mchat_flood_time') || $this->auth->acl_get('u_mchat_flood_ignore'))
+ if ($this->auth->acl_get('u_mchat_flood_ignore'))
{
return false;
}
+ $sql_queries = [];
+
$sql_array = [
- 'SELECT' => 'm.message_time',
+ 'SELECT' => 'm.user_id',
'FROM' => [$this->mchat_settings->get_table_mchat() => 'm'],
- 'WHERE' => 'm.user_id = ' . (int) $this->user->data['user_id'],
- 'ORDER_BY' => 'm.message_time DESC',
+ 'ORDER_BY' => 'm.message_time DESC, m.message_id DESC',
];
- $sql = $this->db->sql_build_query('SELECT', $sql_array);
- $result = $this->db->sql_query_limit($sql, 1);
- $message_time = (int) $this->db->sql_fetchfield('message_time');
- $this->db->sql_freeresult($result);
+ if ($this->mchat_settings->cfg('mchat_flood_time'))
+ {
+ $sql = $this->db->sql_build_query('SELECT', array_merge($sql_array, [
+ 'WHERE' => implode(' AND ', [
+ 'm.user_id = ' . (int) $this->user->data['user_id'],
+ 'message_time > ' . time() . ' - ' . (int) $this->mchat_settings->cfg('mchat_flood_time'),
+ $this->mchat_notifications->get_sql_where('exclude'),
+ ]),
+ ]));
- return $message_time && time() - $message_time < $this->mchat_settings->cfg('mchat_flood_time');
+ $sql_queries[$sql] = 1;
+ }
+
+ if ($this->mchat_settings->cfg('mchat_flood_messages'))
+ {
+ $sql = $this->db->sql_build_query('SELECT', array_merge($sql_array, [
+ 'WHERE' => $this->mchat_notifications->get_sql_where('exclude'),
+ ]));
+
+ $sql_queries[$sql] = $this->mchat_settings->cfg('mchat_flood_messages');
+ }
+
+ foreach ($sql_queries as $sql => $limit)
+ {
+ $result = $this->db->sql_query_limit($sql, $limit);
+ $rows = $this->db->sql_fetchrowset($result);
+ $this->db->sql_freeresult($result);
+
+ if ($rows)
+ {
+ foreach ($rows as $row)
+ {
+ if ($row['user_id'] != $this->user->data['user_id'])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ }
+
+ return false;
}
/**
diff --git a/core/notifications.php b/core/notifications.php
index 07d705b..89c8d57 100644
--- a/core/notifications.php
+++ b/core/notifications.php
@@ -208,6 +208,7 @@ class notifications
return $post_subjects + $missing_post_subjects;
}
+
/**
* Converts the message field of the post row so that it can be passed to generate_text_for_display()
*
@@ -374,12 +375,14 @@ class notifications
* Generates an SQL WHERE condition to include or exlude notifacation
* messages based on the current user's settings and permissions
*
+ * @param string $mode One of user|exclude. user mode uses the current user's settings to decide which notifications
+ * to exclude. exclude mode always excludes all notifications.
* @return string
*/
- public function get_sql_where()
+ public function get_sql_where($mode = 'user')
{
// Exclude all post notifications
- if (!$this->mchat_settings->cfg('mchat_posts'))
+ if ($mode == 'exclude' || !$this->mchat_settings->cfg('mchat_posts'))
{
return 'm.post_id = 0';
}
diff --git a/core/settings.php b/core/settings.php
index 467e98f..f3c341b 100644
--- a/core/settings.php
+++ b/core/settings.php
@@ -163,7 +163,8 @@ class settings
'mchat_custom_height' => ['default' => 350, 'validation' => ['num', false, 50, 1000]],
'mchat_custom_page' => ['default' => 1],
'mchat_edit_delete_limit' => ['default' => 0],
- 'mchat_flood_time' => ['default' => 0, 'validation' => ['num', false, 0, 60]],
+ 'mchat_flood_time' => ['default' => 0, 'validation' => ['num', false, 0, 3600]],
+ 'mchat_flood_messages' => ['default' => 0, 'validation' => ['num', false, 0, 100]],
'mchat_index_height' => ['default' => 250, 'validation' => ['num', false, 50, 1000]],
'mchat_live_updates' => ['default' => 1],
'mchat_log_enabled' => ['default' => 1],
diff --git a/language/en/mchat_acp.php b/language/en/mchat_acp.php
index daea4ca..4b16bad 100644
--- a/language/en/mchat_acp.php
+++ b/language/en/mchat_acp.php
@@ -96,7 +96,9 @@ $lang = array_merge($lang, [
'MCHAT_ARCHIVE_SORT_BOTTOM_TOP' => 'Always sort messages newest to oldest',
'MCHAT_ARCHIVE_SORT_USER' => 'Sort messages depending on the user’s Location of new messages preference',
'MCHAT_FLOOD_TIME' => 'Flood time',
- 'MCHAT_FLOOD_TIME_EXPLAIN' => 'The number of seconds a user must wait before posting another message in the chat.
You are limited from 0 to 60 seconds. Default is 0. Set to 0 to disable.',
+ 'MCHAT_FLOOD_TIME_EXPLAIN' => 'The number of seconds a user must wait before posting another message in the chat.
You are limited from 0 to 3600 seconds (1 hour). Default is 0. Set to 0 to disable.',
+ 'MCHAT_FLOOD_MESSAGES' => 'Flood messages',
+ 'MCHAT_FLOOD_MESSAGES_EXPLAIN' => 'The number of messages a user can send consecutively before another user is required to post in the chat.
You are limited from 0 to 100 messages. Default is 0. Set to 0 to disable.',
'MCHAT_EDIT_DELETE_LIMIT' => 'Time limit for editing and deleting messages',
'MCHAT_EDIT_DELETE_LIMIT_EXPLAIN' => 'Messages older than the specified number of seconds cannot be edited or deleted by the author any more.
Users who have edit/delete permission as well as moderator permission are exempt from this time limit.
Set to 0 to allow unlimited editing and deleting.',
'MCHAT_MAX_MESSAGE_LENGTH' => 'Maximum message length',
@@ -106,7 +108,7 @@ $lang = array_merge($lang, [
'MCHAT_CUSTOM_PAGE' => 'Enable mChat page',
'MCHAT_CUSTOM_HEIGHT' => 'mChat page height',
'MCHAT_CUSTOM_HEIGHT_EXPLAIN' => 'You are limited from 50 to 1000. Default is 350.',
- 'MCHAT_BBCODES_DISALLOWED' => 'Disallowed BBCdes',
+ 'MCHAT_BBCODES_DISALLOWED' => 'Disallowed BBCodes',
'MCHAT_BBCODES_DISALLOWED_EXPLAIN' => 'Here you can input the BBCodes that are not to be used in a message.
Separate BBCodes with a vertical bar, for example:
b|i|u|code|list|list=|flash|quote and/or a %1$scustom BBCode tag name%2$s.',
'MCHAT_STATIC_MESSAGE' => 'Static message',
'MCHAT_STATIC_MESSAGE_EXPLAIN' => 'Here you can define a static message. HTML code is allowed. Set to empty to disable the display.
This message can be translated: edit the MCHAT_STATIC_MESSAGE language key in /ext/dmzx/mchat/language/XX/mchat.php.',
@@ -140,6 +142,7 @@ $lang = array_merge($lang, [
'TOO_LONG_MCHAT_DATE' => 'The date format you entered is too long.',
'TOO_SHORT_MCHAT_DATE' => 'The date format you entered is too short.',
'TOO_LARGE_MCHAT_FLOOD_TIME' => 'The flood time value is too large.',
+ 'TOO_LARGE_MCHAT_FLOOD_MESSAGES' => 'The flood messages value is too large.',
'TOO_SMALL_MCHAT_INDEX_HEIGHT' => 'The index height value is too small.',
'TOO_LARGE_MCHAT_INDEX_HEIGHT' => 'The index height value is too large.',
'TOO_LARGE_MCHAT_MAX_INPUT_HEIGHT' => 'The max input height value is too large.',
diff --git a/language/en/permissions_mchat.php b/language/en/permissions_mchat.php
index 53b64c5..76a27ad 100644
--- a/language/en/permissions_mchat.php
+++ b/language/en/permissions_mchat.php
@@ -45,7 +45,7 @@ $lang = array_merge($lang, [
'ACL_U_MCHAT_PM' => 'Can use private message',
'ACL_U_MCHAT_LIKE' => 'Can see like icon (requires BBCode permission)',
'ACL_U_MCHAT_QUOTE' => 'Can see quote icon (requires BBCode permission)',
- 'ACL_U_MCHAT_FLOOD_IGNORE' => 'Can ignore flood limit',
+ 'ACL_U_MCHAT_FLOOD_IGNORE' => 'Can ignore flood limits',
'ACL_U_MCHAT_ARCHIVE' => 'Can view the archive',
'ACL_U_MCHAT_BBCODE' => 'Can use BBCodes',
'ACL_U_MCHAT_SMILIES' => 'Can use smilies',
diff --git a/migrations/mchat_2_1_3.php b/migrations/mchat_2_1_3.php
new file mode 100644
index 0000000..6dc87ff
--- /dev/null
+++ b/migrations/mchat_2_1_3.php
@@ -0,0 +1,31 @@
+
+
{% if S_MCHAT_AVATARS %}