Skip to content

Commit

Permalink
GH-230 Move referral multi account detection handling to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 2, 2022
1 parent 028c980 commit dc1738e
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 57 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

include($includePath . './screens/FirstLogin/FirstLogin.screen.php');
include($includePath . './screens/FirstLogin/utils/effects/handleProxyDetection.effect.php');
include($includePath . './screens/FirstLogin/utils/effects/handleReferralMultiAccountDetection.effect.php');

});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\FirstLogin\Utils\Effects;

/**
* @param array $params
* @param arrayRef $params['user']
* @param number $params['referredById']
* @param arrayRef $params['referringUserWithTasksData']
* @param number $params['currentTimestamp']
*/
function handleReferralMultiAccountDetection($props) {
global $_EnginePath, $_Included_AlertSystemUtilities;

$user = &$props['user'];
$userId = $user['id'];
$referredById = $props['referredById'];
$referringUserWithTasksData = &$props['referringUserWithTasksData'];
$currentTimestamp = $props['currentTimestamp'];

$_Included_AlertSystemUtilities = true;
include($_EnginePath.'includes/functions/AlertSystemUtilities.php');

$CheckIntersection = AlertUtils_IPIntersect($userId, $referredById, array
(
'LastTimeDiff' => (TIME_DAY * 60),
'ThisTimeDiff' => (TIME_DAY * 60),
'ThisTimeStamp' => ($currentTimestamp - SERVER_MAINOPEN_TSTAMP)
));

if($CheckIntersection !== false)
{
$FiltersData = array();
$FiltersData['place'] = 4;
$FiltersData['alertsender'] = 4;
$FiltersData['users'] = array($userId, $referredById);
$FiltersData['ips'] = $CheckIntersection['Intersect'];
$FiltersData['newuser'] = $userId;
$FiltersData['referrer'] = $referredById;
foreach($CheckIntersection['Intersect'] as $IP)
{
$FiltersData['logcount'][$IP][$userId] = $CheckIntersection['IPLogData'][$userId][$IP]['Count'];
$FiltersData['logcount'][$IP][$referredById] = $CheckIntersection['IPLogData'][$referredById][$IP]['Count'];
}

$FilterResult = AlertUtils_CheckFilters($FiltersData, array('Save' => true));
if($FilterResult['SendAlert'])
{
$_Alert['Data']['ReferrerID'] = $referredById;
foreach($CheckIntersection['Intersect'] as $ThisIPID)
{
$_Alert['Data']['Intersect'][] = array
(
'IPID' => $ThisIPID,
'NewUser' => $CheckIntersection['IPLogData'][$userId][$ThisIPID],
'OldUser' => $CheckIntersection['IPLogData'][$referredById][$ThisIPID]
);
}
if(!empty($referringUserWithTasksData['TaskData']))
{
$_Alert['Data']['Tasks'] = $referringUserWithTasksData['TaskData'];
}

$Query_AlertOtherUsers .= "SELECT DISTINCT `User_ID` FROM {{table}} WHERE ";
$Query_AlertOtherUsers .= "`User_ID` NOT IN ({$userId}, {$referredById}) AND ";
$Query_AlertOtherUsers .= "`IP_ID` IN (".implode(', ', $CheckIntersection['Intersect']).") AND ";
$Query_AlertOtherUsers .= "`Count` > `FailCount`;";
$Result_AlertOtherUsers = doquery($Query_AlertOtherUsers, 'user_enterlog');
if($Result_AlertOtherUsers->num_rows > 0)
{
while($FetchData = $Result_AlertOtherUsers->fetch_assoc())
{
$_Alert['Data']['OtherUsers'][] = $FetchData['User_ID'];
}
}

Alerts_Add(4, $currentTimestamp, 1, 2, 8, $userId, $_Alert['Data']);
}
}
}

?>
63 changes: 6 additions & 57 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,63 +101,12 @@
}

// Check IP Intersection
$_Included_AlertSystemUtilities = true;
include($_EnginePath.'includes/functions/AlertSystemUtilities.php');
$CheckIntersection = AlertUtils_IPIntersect($_User['id'], $_User['referred'], array
(
'LastTimeDiff' => (TIME_DAY * 60),
'ThisTimeDiff' => (TIME_DAY * 60),
'ThisTimeStamp' => ($Now - SERVER_MAINOPEN_TSTAMP)
));
if($CheckIntersection !== false)
{
$FiltersData = array();
$FiltersData['place'] = 4;
$FiltersData['alertsender'] = 4;
$FiltersData['users'] = array($_User['id'], $_User['referred']);
$FiltersData['ips'] = $CheckIntersection['Intersect'];
$FiltersData['newuser'] = $_User['id'];
$FiltersData['referrer'] = $_User['referred'];
foreach($CheckIntersection['Intersect'] as $IP)
{
$FiltersData['logcount'][$IP][$_User['id']] = $CheckIntersection['IPLogData'][$_User['id']][$IP]['Count'];
$FiltersData['logcount'][$IP][$_User['referred']] = $CheckIntersection['IPLogData'][$_User['referred']][$IP]['Count'];
}

$FilterResult = AlertUtils_CheckFilters($FiltersData, array('Save' => true));
if($FilterResult['SendAlert'])
{
$_Alert['Data']['ReferrerID'] = $_User['referred'];
foreach($CheckIntersection['Intersect'] as $ThisIPID)
{
$_Alert['Data']['Intersect'][] = array
(
'IPID' => $ThisIPID,
'NewUser' => $CheckIntersection['IPLogData'][$_User['id']][$ThisIPID],
'OldUser' => $CheckIntersection['IPLogData'][$_User['referred']][$ThisIPID]
);
}
if(!empty($ThisTaskUser['TaskData']))
{
$_Alert['Data']['Tasks'] = $ThisTaskUser['TaskData'];
}

$Query_AlertOtherUsers .= "SELECT DISTINCT `User_ID` FROM {{table}} WHERE ";
$Query_AlertOtherUsers .= "`User_ID` NOT IN ({$_User['id']}, {$_User['referred']}) AND ";
$Query_AlertOtherUsers .= "`IP_ID` IN (".implode(', ', $CheckIntersection['Intersect']).") AND ";
$Query_AlertOtherUsers .= "`Count` > `FailCount`;";
$Result_AlertOtherUsers = doquery($Query_AlertOtherUsers, 'user_enterlog');
if($Result_AlertOtherUsers->num_rows > 0)
{
while($FetchData = $Result_AlertOtherUsers->fetch_assoc())
{
$_Alert['Data']['OtherUsers'][] = $FetchData['User_ID'];
}
}

Alerts_Add(4, $Now, 1, 2, 8, $_User['id'], $_Alert['Data']);
}
}
Overview\Screens\FirstLogin\Utils\Effects\handleReferralMultiAccountDetection([
'user' => &$_User,
'referredById' => $_User['referred'],
'referringUserWithTasksData' => &$ThisTaskUser,
'currentTimestamp' => $Now,
]);
}

// Check, if this IP is Proxy
Expand Down

0 comments on commit dc1738e

Please sign in to comment.