feat: forum post notifications into mailbox

This commit is contained in:
Martin Ambrus
2017-10-22 19:16:43 +02:00
parent 2fcaaa3ee8
commit a163206782
8 changed files with 57 additions and 17 deletions
+35 -6
View File
@@ -1471,13 +1471,40 @@ class MYSQLi_DB {
FORUM SUREY FORUM SUREY
*************************/ *************************/
function CreatPost($post, $tids, $owner, $alliance, $player, $coor, $report) { function CreatPost($post, $tids, $owner, $alliance, $player, $coor, $report, $fid2 = 0) {
list($post, $tids, $owner, $alliance, $player, $coor, $report) = $this->escape_input($post, $tids, $owner, (int) $alliance, (int) $player, (int) $coor, (int) $report); global $message, $session;
list($post, $tids, $owner, $alliance, $player, $coor, $report, $fid2) = $this->escape_input($post, (int) $tids, $owner, (int) $alliance, (int) $player, (int) $coor, (int) $report, (int) $fid2);
$date = time(); $date = time();
$q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date',$alliance,$player,$coor,$report)"; $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post',$tids,'$owner','$date',$alliance,$player,$coor,$report)";
mysqli_query($this->dblink,$q); mysqli_query($this->dblink,$q);
return mysqli_insert_id($this->dblink); $postID = mysqli_insert_id($this->dblink);
// create a message notification for each person subscribed to this topic
// ... for now it's everyone who ever posted there, there is no real un/subscription yet
if ($fid2 !== 0) {
$q = "SELECT DISTINCT owner FROM ".TB_PREFIX . "forum_post WHERE topic = $tids";
$result = mysqli_query($this->dblink, $q);
if ($result->num_rows) {
while ($row = mysqli_fetch_assoc($result)) {
if ($row['owner'] != $owner) {
$this->sendMessage(
(int) $row['owner'],
2,
'New Message in Alliance Forum',
"Hi!\n\n".$this->escape($session->username)." posted a new message into your common topic. Here\\'s a link that will get you there: <a href=\"".rtrim(SERVER, '/')."/allianz.php?s=2&amp;pid=2&amp;fid2=$fid2&amp;tid=$tids\">forum link</a>\n\nYours sincerely,\n<i>Server Robot :)</i>",
0,
0,
0,
0,
0,
true);
}
}
}
}
return $postID;
} }
function UpdatePostDate($id) { function UpdatePostDate($id) {
@@ -2206,8 +2233,10 @@ class MYSQLi_DB {
return mysqli_query($this->dblink,$q); return mysqli_query($this->dblink,$q);
} }
function sendMessage($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report) { function sendMessage($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report, $skip_escaping = false) {
list($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report) = $this->escape_input((int) $client, (int) $owner, $topic, $message, (int) $send, (int) $alliance, (int) $player, (int) $coor, (int) $report); if (!$skip_escaping) {
list($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report) = $this->escape_input((int) $client, (int) $owner, $topic, $message, (int) $send, (int) $alliance, (int) $player, (int) $coor, (int) $report);
}
$time = time(); $time = time();
$q = "INSERT INTO " . TB_PREFIX . "mdata values (0,$client,$owner,'$topic','$message',0,0,$send,$time,0,0,$alliance,$player,$coor,$report)"; $q = "INSERT INTO " . TB_PREFIX . "mdata values (0,$client,$owner,'$topic','$message',0,0,$send,$time,0,0,$alliance,$player,$coor,$report)";
+8 -6
View File
@@ -418,17 +418,19 @@ class Message {
} }
} }
private function sendMessage($recieve, $topic, $text) { private function sendMessage($recieve, $topic, $text, $security_check = true) {
global $session, $database; global $session, $database;
$user = $database->getUserField($recieve, "id", 1); $user = $database->getUserField($recieve, "id", 1);
// Vulnerability closed by Shadow // Vulnerability closed by Shadow
$q = "SELECT * FROM ".TB_PREFIX."mdata WHERE owner='".$session->uid."' AND time > ".time()." - 60"; if ($security_check) {
$res = mysqli_query($GLOBALS['link'],$q) or die(mysqli_error($database->dblink). " query ".$q); $q = "SELECT * FROM ".TB_PREFIX."mdata WHERE owner='".$session->uid."' AND time > ".time()." - 60";
$flood = mysqli_num_rows($res); $res = mysqli_query($GLOBALS['link'],$q) or die(mysqli_error($database->dblink). " query ".$q);
if($flood > 5) $flood = mysqli_num_rows($res);
return; //flood if($flood > 5)
return; //flood
}
// Vulnerability closed by Shadow // Vulnerability closed by Shadow
+2 -1
View File
@@ -51,7 +51,8 @@ martinambrus changes:
39. not allowing installation if old data are still in database to prevent multiple worlds generation and game misbehavior 39. not allowing installation if old data are still in database to prevent multiple worlds generation and game misbehavior
40. fixed quest 1 to reload the page and allow for immediate completion of the woodcutter 40. fixed quest 1 to reload the page and allow for immediate completion of the woodcutter
41. NPC links added to units in Hero Mansion 41. NPC links added to units in Hero Mansion
42. fixed random attacks attacker tribe (Natars) when building Wonder of the World 42. fixed random attacks attacker tribe (Natars) when building Wonder of the World
43. players who post in an Alliance forum are now notified of each subsequent post in that topic via messages
Shadowss changes: Shadowss changes:
+1
View File
@@ -11,6 +11,7 @@ foreach($topics as $arr) {
<input type="hidden" name="s" value="2"> <input type="hidden" name="s" value="2">
<input type="hidden" name="pid" value="<?php echo $_GET['pid']; ?>"> <input type="hidden" name="pid" value="<?php echo $_GET['pid']; ?>">
<input type="hidden" name="tid" value="<?php echo $_GET['tid']; ?>"> <input type="hidden" name="tid" value="<?php echo $_GET['tid']; ?>">
<input type="hidden" name="fid2" value="<?php echo $_GET['fid2']; ?>">
<input type="hidden" name="newpost" value="1"> <input type="hidden" name="newpost" value="1">
<input type="hidden" name="checkstr" value="c0d"><table cellpadding="1" cellspacing="1" id="new_post"><thead> <input type="hidden" name="checkstr" value="c0d"><table cellpadding="1" cellspacing="1" id="new_post"><thead>
+2 -1
View File
@@ -136,6 +136,7 @@ if(isset($_POST['newtopic'])){
if(isset($_POST['newpost'])){ if(isset($_POST['newpost'])){
$text = $_POST['text']; $text = $_POST['text'];
$tids = $_POST['tid']; $tids = $_POST['tid'];
$fid2 = $_POST['fid2'];
$owner = $session->uid; $owner = $session->uid;
if($text != ""){ if($text != ""){
if(!preg_match('/\[message\]/',$text) && !preg_match('/\[\/message\]/',$text)){ if(!preg_match('/\[message\]/',$text) && !preg_match('/\[\/message\]/',$text)){
@@ -194,7 +195,7 @@ if(isset($_POST['newpost'])){
} }
} }
$database->UpdatePostDate($tids); $database->UpdatePostDate($tids);
$database->CreatPost($text,$tids,$owner,$alliance,$player,$coor,$report); $database->CreatPost($text,$tids,$owner,$alliance,$player,$coor,$report,$fid2);
} }
} }
} }
+3 -2
View File
@@ -743,14 +743,15 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%forum_edit` (
CREATE TABLE IF NOT EXISTS `%PREFIX%forum_post` ( CREATE TABLE IF NOT EXISTS `%PREFIX%forum_post` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`post` longtext NULL, `post` longtext NULL,
`topic` varchar(255) NULL, `topic` int(11) DEFAULT NULL,
`owner` varchar(255) NULL, `owner` varchar(255) NULL,
`date` varchar(255) NULL, `date` varchar(255) NULL,
`alliance0` int(11) NULL, `alliance0` int(11) NULL,
`player0` int(11) NULL, `player0` int(11) NULL,
`coor0` int(11) NULL, `coor0` int(11) NULL,
`report0` int(11) NULL, `report0` int(11) NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`),
KEY `topic-owner` (`topic`,`owner`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --
+5
View File
@@ -1,2 +1,7 @@
-- 22.10.2017 -> forum topics table and indexe changes
ALTER TABLE `s1_forum_post` CHANGE `topic` `topic` INT NULL DEFAULT NULL;
ALTER TABLE `s1_forum_post` CHANGE `owner` `owner` INT NULL DEFAULT NULL;
ALTER TABLE `travian`.`s1_forum_post` ADD INDEX `topic-owner` (`topic`, `owner`);
-- 20.10.2017 -> changing MD5 for bcrypt password hashing algo -- 20.10.2017 -> changing MD5 for bcrypt password hashing algo
ALTER TABLE `s1_users` ADD `is_bcrypt` TINYINT(1) NOT NULL DEFAULT '0' AFTER `vactwoweeks`; ALTER TABLE `s1_users` ADD `is_bcrypt` TINYINT(1) NOT NULL DEFAULT '0' AFTER `vactwoweeks`;
+1 -1
View File
@@ -1,5 +1,5 @@
- normalize forum tables - varchar is used for numeric values and is joined with int field - normalize forum tables - varchar is used for numeric values and is joined with int field
- send forum replies in a forum where a user is active also to that user's mailbox
- make an option for admin to be raidable (in profile?) - make an option for admin to be raidable (in profile?)
- finish parts in Admin that are unfinished (mostly delete -X- buttons and Alliance settings) - finish parts in Admin that are unfinished (mostly delete -X- buttons and Alliance settings)
- add batching logic to mehods which get called too frequently and multiple times (example - Message::sendMessage() now that is sends messages for each forum post)
- add PayPal listener to verify gold transactions imediatelly - add PayPal listener to verify gold transactions imediatelly