Skip to content

Commit

Permalink
Merge pull request #1054 from proditis/master
Browse files Browse the repository at this point in the history
make sure team instances respect approved players all around
  • Loading branch information
proditis authored Nov 17, 2023
2 parents 8f80d4b + e9a7326 commit e065592
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions contrib/echoctf_updown_mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ if [ "$script_type" == "client-connect" ]; then
done
# Add to private instances of our own and our team mates
TEAM_VISIBLE_INSTANCES=$(echo "get sysconfig:team_visible_instances"|nc ${NCOPTS} ${MEMD} 11211 |egrep -v "(VALUE|END)")
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name} and approved=1))"
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name}) and approved=1)"
if [ "$TEAM_VISIBLE_INSTANCES" == "" ]; then
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or (player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name} and approved=1)) AND team_allowed=1)"
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or (player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name}) and approved=1) AND team_allowed=1)"
fi
for network in $(mysql -h ${DBHOST} -u"${DBUSER}" -p"${DBPASS}" echoCTF -NBe "$TEAMS_QUERY");do
/sbin/pfctl -t "${network}_clients" -T add ${ifconfig_pool_remote_ip}
Expand All @@ -50,9 +50,9 @@ elif [ "$script_type" == "client-disconnect" ]; then
/sbin/pfctl -t "${network}_clients" -T delete ${ifconfig_pool_remote_ip}
done
TEAM_VISIBLE_INSTANCES=$(echo "get sysconfig:team_visible_instances"|nc ${NCOPTS} ${MEMD} 11211 |egrep -v "(VALUE|END)")
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name} and approved=1))"
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name}) and approved=1)"
if [ "$TEAM_VISIBLE_INSTANCES" == "" ]; then
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or (player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name} and approved=1)) AND team_allowed=1)"
TEAMS_QUERY="SELECT LOWER(CONCAT(t2.name,'_',player_id)) AS net FROM target_instance as t1 LEFT JOIN target as t2 on t1.target_id=t2.id WHERE player_id=${common_name} or (player_id IN (SELECT player_id from team_player WHERE team_id IN (SELECT team_id FROM team_player where player_id=${common_name}) and approved=1) AND team_allowed=1)"
fi

for network in $(mysql -h ${DBHOST} -u"${DBUSER}" -p"${DBPASS}" echoCTF -NBe "$TEAMS_QUERY");do
Expand Down
9 changes: 7 additions & 2 deletions frontend/modules/team/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ public function actionView($token)
'pagination' => false,
]);
$teamPlayers = ArrayHelper::getColumn($TP->all(),'player_id');
$teamInstances = \app\modules\target\models\TargetInstance::find()->andFilterWhere(['player_id'=>$teamPlayers]);
$teamInstances = \app\modules\target\models\TargetInstance::find()->leftJoin('team_player','target_instance.player_id=team_player.player_id')
->andFilterWhere(['in','target_instance.player_id',$teamPlayers])
->andFilterWhere(['team_player.approved'=>1]);
if(\Yii::$app->sys->team_visible_instances!==true)
{
$teamInstances->andFilterWhere(['team_allowed'=>1]);
Expand Down Expand Up @@ -193,7 +195,10 @@ public function actionMine()
'pagination' => false,
]);
$teamPlayers = ArrayHelper::getColumn(Yii::$app->user->identity->team->players,'id');
$teamInstances = \app\modules\target\models\TargetInstance::find()->andFilterWhere(['player_id'=>$teamPlayers]);
$teamInstances = \app\modules\target\models\TargetInstance::find()->leftJoin('team_player','target_instance.player_id=team_player.player_id')
->andFilterWhere(['player_id'=>$teamPlayers])
->andFilterWhere(['team_player.approved'=>1]);

if(\Yii::$app->sys->team_visible_instances!==true)
{
$teamInstances->andFilterWhere(['team_allowed'=>1]);
Expand Down

0 comments on commit e065592

Please sign in to comment.