利用BM面板的WebHook请求,实现squad的文字交互CDK、签到、抽奖、等功能。
路径参考:/usr/local/webhook/shell
签到兑换系统,WebHook请求实例:
{ "msgtype": "val", "text":{ "content":"{{player.name}}%%{{player.steamID}}%%{{msg.body}}%%{{server.name}}%%{{server.players}}%%{{player.sessionDuration}}" } }
后端shell脚本处理:
#!/bin/bash # "content":"{{player.name}}%%{{player.steamID}}%%{{msg.body}}%%{{server.name}}%%{{server.players}}%%{{player.sessionDuration}}" # echo $[RANDOM%20+30] #name C1=`echo $1|awk -F '%%' '{print $1}'` #steamID C2=`echo $1|awk -F '%%' '{print $2}'` #mess C3=`echo $1|awk -F '%%' '{print $3}'` #players sum {{server.players}} C5=`echo $1|awk -F '%%' '{print $5}'` #在服时长 C6=`echo $1|awk -F '%%' '{print $6}'` C4=`echo $1|awk -F '%%' '{print $4}'` H4=`echo $C4 | awk -F \# '{print $2}'` S=`echo ${H4%%-*}` if [ "$S" -eq 1 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p21114' elif [ "$S" -eq 2 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p22114' elif [ "$S" -eq 3 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p23114' elif [ "$S" -eq 4 ];then SQUADCMD='/usr/bin/rcon -a4.x.x.240 -Ppswd -p21114' elif [ "$S" -eq 5 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.182 -Ppswd -p21114' fi #今日日期 DATE=`date +"%Y%m%d"` #初始化已签到人员 ls /usr/local/webhook/shell/sign/logs/$DATE if [ $? -ne 0 ];then >> /usr/local/webhook/shell/sign/logs/$DATE fi #在服时长判断是否可以签到20分钟 TIMS1=0 if [ $C6 -le 1200 ];then TIMS1=1 fi #签到功能 QD=`echo $C3 |grep -iwE 签到\|qiandao |wc -l` if [ "$QD" -eq 1 ];then if [ "$S" -eq 4 ];then $SQUADCMD AdminBroadcast $C1 签到失败,您不能在冲锋号#4进行签到。 exit elif [ "$S" -eq 5 ];then $SQUADCMD AdminBroadcast $C1 签到失败,您不能在冲锋号#5进行签到。 exit fi IFDA=`cat /usr/local/webhook/shell/sign/logs/$DATE |grep $C2 |wc -l` if [ "$IFDA" -ne 0 ];then $SQUADCMD AdminBroadcast 玩家 $C1 您今天已经签过到了。 exit fi #在服务器时长判断 if [ "$TIMS1" -eq 1 ];then $SQUADCMD AdminBroadcast $C1 签到失败,需要保持服务器在线20分钟以上。 exit fi #根据当前服务器内人数,生成随机积分 if [ "$C5" -le 20 ];then INT=`echo $[RANDOM%5+25]` elif [ "$C5" -le 40 ];then INT=`echo $[RANDOM%5+20]` elif [ "$C5" -le 55 ];then INT=`echo $[RANDOM%5+15]` elif [ "$C5" -le 75 ];then INT=`echo $[RANDOM%7+8]` elif [ "$C5" -gt 75 ];then INT=`echo $[RANDOM%5+3]` fi #积分入账功能 #入账同时判断是否存在用户,是否需要新建用户 USERINFO=`cat /usr/local/webhook/shell/sign/user.ini |grep $C2 |wc -l` if [ $USERINFO -eq 1 ];then DASS=`cat /usr/local/webhook/shell/sign/user.ini |grep $C2 |awk -F \: '{print $2}'` #生成入账内容 STSS=`expr $DASS + ${INT}` #删除原有账单,打入新的数据 sed -i "/${C2}/d" /usr/local/webhook/shell/sign/user.ini echo "${C2}:${STSS}" >> /usr/local/webhook/shell/sign/user.ini #签到成功广播 $SQUADCMD AdminBroadcast 恭喜玩家 $C1 签到获得 $INT 积分,当前已有 $STSS 分。 else echo "${C2}:${INT}" >> /usr/local/webhook/shell/sign/user.ini #签到成功广播 $SQUADCMD AdminBroadcast 恭喜玩家 $C1 签到获得 $INT 积分,当前已有 $INT 分。 fi #已签到标记 echo "$C2" >> /usr/local/webhook/shell/sign/logs/$DATE #签到完成退出脚本 exit fi #1分兑换1小时 #积分兑换预留位功能 DH1=`echo "$C3" |grep -iE ^兑换\ [0-9]*\|^duihuan\ [0-9]*\|^dh\ [0-9]* |wc -l` DH2=`echo "$C3" |grep -iE ^兑换\ [0-9]*\|^duihuan\ [0-9]*\|^dh\ [0-9]* |awk '{print $2}'` #判断传入是否为数字 if grep '^[[:digit:]]*$' <<< "$DH2";then echo "$DH2 is OK." else $SQUADCMD AdminBroadcast $C1 请在兑换积分时使用十进制数字。 exit fi if [ $DH1 -eq 1 ];then #判断需要兑换的额度是否低于20 DASS=`cat /usr/local/webhook/shell/sign/user.ini |grep $C2 |awk -F \: '{print $2}'` if [ $DH2 -lt 20 ];then $SQUADCMD AdminBroadcast $C1 低于20分不予兑换。 exit fi #判断当前积分是否足够 #积分兑换,且自动扣款 if [ $DASS -ge $DH2 ];then DHSTC=`expr $DASS - $DH2` #删除原有账单,打入新的数据 sed -i "/${C2}/d" /usr/local/webhook/shell/sign/user.ini echo "${C2}:${DHSTC}" >> /usr/local/webhook/shell/sign/user.ini #1分兑换1小时 #计算预留位时间戳 DHSTCR=`expr $DH2 \* 3600` #标记积分兑换预留位开始处理 RESE="1" else $SQUADCMD AdminBroadcast “${C1}” 您当前积分为$DASS,您的积分不足。 exit fi #开始处理预留位 QDUSERINFO=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |wc -l` if [ "$RESE" -eq 1 ];then if [ $QDUSERINFO -eq 1 ];then DASS1=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` STSS=`expr $DASS1 + $DHSTCR` sed -i "/${C2}/d" /usr/local/webhook/shell/cdk/user-cdk.ini echo "${C2}:${STSS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”预留位兑换成功,到期时间:`date -d @${STSS} +"%Y/%m/%d %H:%M"` else DAS=`date +%s` STS=`expr $DAS + $DHSTCR` echo "${C2}:${STS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini curl http://103.219.39.72:8088/cgi-bin/reserve-add.sh?add=$C2 $SQUADCMD AdminBroadcast 玩家“${C1}”预留位兑换成功,到期时间:`date -d @${STS} +"%Y/%m/%d %H:%M"` fi fi fi #查询个人信息功能 URSHOW=`echo $C3 |grep -iwE show\|查询\|chaxun |wc -l` if [ "$URSHOW" -eq 1 ];then DASS=0 DASS=`cat /usr/local/webhook/shell/sign/user.ini |grep $C2 |awk -F \: '{print $2}'` if [ "$DASS" -ne 0 ];then $SQUADCMD AdminBroadcast 玩家 $C1 当前拥有 $DASS 分。 else $SQUADCMD AdminBroadcast 未查询到玩家 $C1 的积分信息。 fi fi DH3=`echo "$C3" |grep -iE ^兑换\|^DH\|^duihuan |wc -l` if [ $DH3 -eq 1 ];then $SQUADCMD AdminBroadcast $C1,请在指令后加入您想要使用的积分数额,并使用空格隔开。 fi
CDK兑换系统脚本实例:
#!/bin/bash # "content":"{{player.name}}%%{{player.steamID}}%%{{msg.body}}%%{{server.name}}" #name C1=`echo $1|awk -F '%%' '{print $1}'` #steamID C2=`echo $1|awk -F '%%' '{print $2}'` #mess C3=`echo $1|awk -F '%%' '{print $3}'` C4=`echo $1|awk -F '%%' '{print $4}'` H4=`echo $C4 | awk -F \# '{print $2}'` S=`echo ${H4%%-*}` if [ "$S" -eq 1 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p21114' elif [ "$S" -eq 2 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p22114' elif [ "$S" -eq 3 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p23114' elif [ "$S" -eq 4 ];then SQUADCMD='/usr/bin/rcon -a4.x.x.240 -Ppswd -p21114' elif [ "$S" -eq 5 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.182 -Ppswd -p21114' fi USERINFO=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |wc -l` VIP=`echo $C3 |grep -iw vip|wc -l` if [ $VIP -eq 1 ];then if [ $USERINFO -eq 1 ];then ST1=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD AdminBroadcast 玩家“${C1}”冲锋号社区认证服预留位到期时间:`date -d @${ST1} +"%Y/%m/%d %H:%M"` else $SQUADCMD AdminBroadcast 未查询到玩家“${C1}”的预留位信息。 fi fi USERINFO5=`cat /usr/local/webhook/shell/cdk/user-5.ini |grep $C2 |wc -l` if [ $VIP -eq 1 ];then if [ $USERINFO5 -eq 1 ];then ST2=0 ST2=`cat /usr/local/webhook/shell/cdk/user-5.ini |grep $C2 |awk -F \: '{print $2}'` if [ $ST2 -ne 0 ];then $SQUADCMD AdminBroadcast 玩家“${C1}”冲锋号社区公开训练#5服飞天摄像头权限到期时间:`date -d @${ST2} +"%Y/%m/%d %H:%M"` fi exit else exit fi fi #验证CDK有效性和时间归类 YE1=`cat /usr/local/webhook/shell/cdk/cdk-1m.ini |grep -w $C3 |wc -l` YE2=`cat /usr/local/webhook/shell/cdk/cdk-3d.ini |grep -w $C3 |wc -l` YE3=`cat /usr/local/webhook/shell/cdk/cdk-7d.ini |grep -w $C3 |wc -l` YE4=`cat /usr/local/webhook/shell/cdk/cdk-hd-1m.ini |grep -w $C3 |wc -l` if [ $YE1 -eq 1 ] || [ $YE2 -eq 1 ] || [ $YE3 -eq 1 ] || [ $YE4 -eq 1 ];then if [ $USERINFO -eq 0 ];then curl http://103.219.39.72:8088/cgi-bin/reserve-add.sh?add=$C2 fi else $SQUADCMD AdminBroadcast 玩家“${C1}”输入的Cdkey不正确或已被使用。 exit fi #计算到期时间 if [ "$YE1" -eq 1 ];then #一个月加时 if [ $USERINFO -eq 1 ];then sed -i "/${C3}/d" /usr/local/webhook/shell/cdk/cdk-1m.ini DASS=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` STSS=`expr $DASS + 2700000` sed -i "/${C2}/d" /usr/local/webhook/shell/cdk/user-cdk.ini echo "${C2}:${STSS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”Cdkey激活成功,预留位到期时间:`date -d @${STSS} +"%Y/%m/%d %H:%M"` else DAS=`date +%s` STS=`expr $DAS + 2700000` echo "${C2}:${STS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”Cdkey激活成功,预留位到期时间:`date -d @${STS} +"%Y/%m/%d %H:%M"` fi elif [ "$YE2" -eq 1 ];then #3day if [ $USERINFO -eq 1 ];then sed -i "/${C3}/d" /usr/local/webhook/shell/cdk/cdk-3d.ini DASS=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` STSS=`expr $DASS + 280800` sed -i "/${C2}/d" /usr/local/webhook/shell/cdk/user-cdk.ini echo "${C2}:${STSS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”Cdkey激活成功,预留位到期时间:`date -d @${STSS} +"%Y/%m/%d %H:%M"` else DAS=`date +%s` STS=`expr $DAS + 280800` echo "${C2}:${STS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”Cdkey激活成功,预留位到期时间:`date -d @${STS} +"%Y/%m/%d %H:%M"` fi elif [ "$YE3" -eq 1 ];then #7day if [ $USERINFO -eq 1 ];then sed -i "/${C3}/d" /usr/local/webhook/shell/cdk/cdk-7d.ini DASS=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` STSS=`expr $DASS + 626400` sed -i "/${C2}/d" /usr/local/webhook/shell/cdk/user-cdk.ini echo "${C2}:${STSS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”Cdkey激活成功,预留位到期时间:`date -d @${STSS} +"%Y/%m/%d %H:%M"` else DAS=`date +%s` STS=`expr $DAS + 626400` echo "${C2}:${STS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”Cdkey激活成功,预留位到期时间:`date -d @${STS} +"%Y/%m/%d %H:%M"` fi elif [ "$YE4" -eq 1 ];then #活动渠道仅限一次 if [ $USERINFO -eq 1 ];then ST2=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |wc -l` if [ $ST2 -eq 1 ];then $SQUADCMD AdminBroadcast 玩家“${C1}”激活失败,预留位未到期不能使用活动渠道CDK。 exit fi else sed -i "/${C3}/d" /usr/local/webhook/shell/cdk/cdk-hd-1m.ini DAS=`date +%s` STS=`expr $DAS + 1317600` echo "${C2}:${STS}" >> /usr/local/webhook/shell/cdk/user-cdk.ini $SQUADCMD AdminBroadcast 玩家“${C1}”Cdkey激活成功,预留位到期时间:`date -d @${STS} +"%Y/%m/%d %H:%M"` fi fi
时长查询统一接口,由WebHook脚本预处理并调用此脚本,而不是直接使用:
#!/bin/bash #游戏时间查询集约化接口 #请求格式为 $1玩家昵称 $2steamID $3服务器序号 $4社区时长 $5当前时间 $6建队查询1 查询时长2 $7阵营ID ;处理完成在此脚本返回,不再调用请求脚本回环处理 #/usr/local/webhook/shell/Query-all.sh "" "" "" "" "" "" "" #游戏时长 #cat 76561198193670050 |jq '.response.games'| python3 -c "import sys, json; data=json.load(sys.stdin); print([d['playtime_forever'] for d in data])" #[69243, 24280, 22607, 638, 94811] #appid #cat 76561198193670050 |jq '.response.games'| python3 -c "import sys, json; data=json.load(sys.stdin); print([d['appid'] for d in data])" #[393380, 1905180, 629520, 774941, 730] #获取基础数据 #curl -s "https://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v1/?key=2731056F124EE23265879997672FFBF1&steamid=76561198193670050" > 76561198193670050 #76561198864371325 #转化时间戳 date -d "2023/06/25 17:32" +%s #功能结构 #请求格式为 $1玩家昵称 $2steamID $3服务器序号 $4社区时长 $5当前时间 $6建队查询1 查询时长2 $7阵营ID;处理完成在此脚本返回,不再调用请求脚本回环处理 #其中社区时长要求为小数格式直接引用 if [ "$S" -eq 1 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p21114' elif [ "$S" -eq 2 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p22114' elif [ "$S" -eq 3 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.72 -Ppswd -p23114' elif [ "$S" -eq 4 ];then SQUADCMD='/usr/bin/rcon -a4.x.x.240 -Ppswd -p21114' elif [ "$S" -eq 5 ];then SQUADCMD='/usr/bin/rcon -a1.x.x.182 -Ppswd -p21114' fi #1.1检查是否存在缓存,存在则直接进入2.1处理 ls /usr/local/webhook/shell/user/${2} if [ $? -ne 0 ];then #1.2steamapi拉取数据,并按小时生成本地缓存 curl -s "http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v1/?key=XXX&steamid=${2}" > /usr/local/webhook/shell/user/${2} fi #1.3先行判断是否全部为空,为空加入标记QNU=0,是否存在squad关键词再下一步处理 #1.4为空返回未公开资料 QNU=`cat /usr/local/webhook/shell/user/${2} |grep Squad |wc -l` if [ $QNU -eq 1 ];then NAME=(`cat /usr/local/webhook/shell/user/${2} |/usr/bin/jq '.response.games'| python3 -c "import sys, json; data=json.load(sys.stdin); print([d['appid'] for d in data])" | sed 's/\[\|\]\|\,//g'`) STMM=(`cat /usr/local/webhook/shell/user/${2} |/usr/bin/jq '.response.games'| python3 -c "import sys, json; data=json.load(sys.stdin); print([d['playtime_forever'] for d in data])" | sed 's/\[\|\]\|\,//g'`) fi COUNTER=0 NAMESUM=`echo ${#NAME[@]}` while true do if [ $QNU -eq 0 ];then break fi if [ $NAMESUM -eq 0 ];then break fi NAMES=`echo ${NAME[$COUNTER]} | grep -w 393380 | wc -l` if [ $NAMES -eq 1 ];then #2.1存在数据,开始处理 #2.2获得分钟数取值 #获得时间为 ${STMM[$COUNTER]} H2=`echo "scale=2;${STMM[$COUNTER]} / 60"|bc` if [ ${STMM[$COUNTER]} -gt 60 ] ;then HS2='' else HS2='0' fi break fi COUNTER=$((COUNTER+1)) if [ $COUNTER -eq $NAMESUM ];then break fi #sleep 3 done #1.5为空的资料,删除本地缓存,并黄字提示资料未公开,要求资料未公开 if [ $QNU -eq 0 ];then rm -rf /usr/local/webhook/shell/user/${2} fi #1.6资料公开的,本地缓存保留至少2小时后自动删除,进入2.1处理 #crcon + */5 * * * * find /usr/local/webhook/shell/user/ -type f -mmin +120 -delete #2.3分支判断创建队伍则提交给 3.1 查询时长提交给4.1 if [ $6 -eq 1 ];then #创建队伍3.1根据 $QNU 判断是否公开,定义提示文字。 if [ $QNU -eq 0 ];then $SQUADCMD AdminBroadcast [$5]【${7}】${1} 创建小队,steam资料未公开,已在冲锋号社区游玩 $4 小时。 else $SQUADCMD AdminBroadcast [$5]【${7}】${1} 创建小队,steam时长为 ${HS2}${H2} 小时。 fi elif [ "$6" -eq 2 ];then #查询时长4.1根据 $QNU 判断是否公开,定义提示文字。 if [ "$QNU" -eq 0 ];then $SQUADCMD AdminBroadcast 玩家 "${1}" ,steam资料未公开;已在冲锋号社区游玩 $4 小时。 else $SQUADCMD AdminBroadcast 玩家 "${1}" ,steam统计时长 ${HS2}${H2} 小时;已在冲锋号社区游玩 $4 小时。 fi fi
抽奖系统设计,根据人数降低当前的中奖率:
#!/bin/bash #积分预留位准点抽奖系统,每小时一次。 #/usr/local/webhook/shell/tmp/draw/ #程序逻辑 #查询本小时是否已经抽奖,查询对局人数,人数越少中奖率越高 #name C1=`echo $1|awk -F '%%' '{print $1}'` #steamID C2=`echo $1|awk -F '%%' '{print $2}'` #mess C3=`echo $1|awk -F '%%' '{print $3}'` #players sum {{server.players}} C5=`echo $1|awk -F '%%' '{print $5}'` #在服时长 C6=`echo $1|awk -F '%%' '{print $6}'` C4=`echo $1|awk -F '%%' '{print $4}'` H4=`echo $C4 | awk -F \# '{print $2}'` S=`echo ${H4%%-*}` if [ "$S" -eq 1 ];then SQUADCMD='/usr/local/bin/mcrcon -H 1.1.1.1 -P 21114 -p pswd' elif [ "$S" -eq 2 ];then SQUADCMD='/usr/local/bin/mcrcon -H 1.1.1.1 -P 22114 -p pswd' elif [ "$S" -eq 3 ];then SQUADCMD='/usr/local/bin/mcrcon -H 1.1.1.1 -P 23114 -p pswd' elif [ "$S" -eq 4 ];then SQUADCMD='/usr/local/bin/mcrcon -H 1.1.1.1 -P 21114 -p pswd' elif [ "$S" -eq 5 ];then SQUADCMD='/usr/local/bin/mcrcon -H 1.1.1.1 -P 21114 -p pswd' fi #小时时间 DATE=`date +"%Y%m%d%H"` #初始化已抽奖人员 ls /usr/local/webhook/shell/tmp/draw/$DATE if [ $? -ne 0 ];then >> /usr/local/webhook/shell/tmp/draw/$DATE fi IFDA=`cat /usr/local/webhook/shell/tmp/draw/$DATE |grep $C2 |wc -l` if [ "$IFDA" -ne 0 ];then $SQUADCMD "AdminBroadcast 玩家 $C1 您在本小时已经抽过奖了。" ok exit fi if [ "$S" -eq 4 ];then $SQUADCMD "AdminBroadcast $C1 抽奖失败,您不能在冲锋号#4进行抽奖。" ok exit elif [ "$S" -eq 5 ];then #转发给#5抽奖处理 #参数列表 $1steamid $2name /usr/local/webhook/shell/draw-5.sh "$C2" "$C1" exit fi #在服务器时长判断 TIMS1=0 if [ $C6 -le 600 ];then TIMS1=1 fi if [ "$TIMS1" -eq 1 ];then $SQUADCMD "AdminBroadcast $C1 抽奖失败,需要保持服务器在线10分钟以上。" ok exit fi echo $C2 >> /usr/local/webhook/shell/tmp/draw/$DATE #根据当前服务器内人数,生成随机积分 if [ "$C5" -le 35 ];then INT=`echo $[RANDOM%800+0]` elif [ "$C5" -le 55 ];then INT=`echo $[RANDOM%1200+20]` elif [ "$C5" -le 85 ];then INT=`echo $[RANDOM%1600+35]` elif [ "$C5" -gt 85 ];then INT=`echo $[RANDOM%1800+50]` fi echo "INT=$INT" #随机数中奖对应 #DASS1=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2 #`date -d @${DAT} +"%Y/%m/%d %H:%M"` if [ "$INT" -le 6 ];then #30天预留位直冲 特等奖 7 /usr/local/webhook/shell/ResPo-all.sh "$C2" "0" "2592000" "2" DAT=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中特等奖,获得30天预留位直冲,到期时间:`date -d @${DAT} +"%Y/%m/%d %H:%M"`" ok elif [ "$INT" -le 26 ];then #200积分直冲 一等奖 20 /usr/local/webhook/shell/ResPo-all.sh "$C2" "200" "0" "1" DAT=`cat /usr/local/webhook/shell/sign/user.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中一等奖,获得240积分直冲,当前积分余额 $DAT 。" ok elif [ "$INT" -le 46 ];then #14天预留位直冲 一等奖 23 /usr/local/webhook/shell/ResPo-all.sh "$C2" "0" "1209600" "2" DAT=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中一等奖,获得14天预留位直冲,到期时间:`date -d @${DAT} +"%Y/%m/%d %H:%M"`" ok elif [ "$INT" -le 69 ];then #66积分直冲 二等奖 42 /usr/local/webhook/shell/ResPo-all.sh "$C2" "66" "0" "1" DAT=`cat /usr/local/webhook/shell/sign/user.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中二等奖,获得66积分直冲,当前积分余额 $DAT 。" ok elif [ "$INT" -le 111 ];then #5天预留位直冲 二等奖 58 /usr/local/webhook/shell/ResPo-all.sh "$C2" "0" "432000" "2" DAT=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中二等奖,获得5天预留位直冲,到期时间:`date -d @${DAT} +"%Y/%m/%d %H:%M"`" ok elif [ "$INT" -le 208 ];then #12小时预留位直冲 三等奖 97 /usr/local/webhook/shell/ResPo-all.sh "$C2" "0" "43200" "2" DAT=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中三等奖,获得12小时预留位直冲,到期时间:`date -d @${DAT} +"%Y/%m/%d %H:%M"`" ok elif [ "$INT" -le 286 ];then #1天预留位直冲 三等奖 78 /usr/local/webhook/shell/ResPo-all.sh "$C2" "0" "86400" "2" DAT=`cat /usr/local/webhook/shell/cdk/user-cdk.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中三等奖,获得24小时预留位直冲,到期时间:`date -d @${DAT} +"%Y/%m/%d %H:%M"`" ok elif [ "$INT" -le 666 ];then #1-3分 50% 安慰奖 380 JIF=`echo $[RANDOM%2+1]` /usr/local/webhook/shell/ResPo-all.sh "$C2" "$JIF" "0" "1" DAT=`cat /usr/local/webhook/shell/sign/user.ini |grep $C2 |awk -F \: '{print $2}'` $SQUADCMD "AdminBroadcast 恭喜玩家 $C1 ,抽中安慰奖,获得${JIF}积分,当前积分余额 $DAT 。" ok elif [ "$INT" -gt 666 ];then #没中奖 $SQUADCMD "AdminBroadcast $C1 很抱歉,您没有中奖。" ok fi
通过steamAPI调用数据,查询玩家时长:
#!/bin/bash #战队服检测时间,要求公开资料,200小时数限制,或社区时长大于120 #GameDur.sh # "content":"{{player.org.timePlayed}}%%{{player.steamID}}" SQUADCMD='/usr/bin/rcon -ax.x.x.x -Ppswd -p23114' #timePlayed org C1=`echo $1|awk -F '%%' '{print $1}'` #steamID C2=`echo $1|awk -F '%%' '{print $2}'` #查询组织时长是否大于或等于120小时,满足则退出脚本。 //432000 if [ "$C1" -ge "432000" ];then echo "社区时长大于120小时,退出脚本。" exit fi IDCOUNTER=0 #取值userid while true do USERID=`$SQUADCMD listplayers|grep $C2 |awk '{print $2}'` if [ "$USERID" = "" ];then echo "$USERID is null." else break fi IDCOUNTER=$((IDCOUNTER+1)) if [ "$IDCOUNTER" -eq 15 ];then echo "获取${C2}对局ID超时,不再查询此玩家。" exit fi sleep 1 done #1.1检查是否存在缓存,存在则直接进入2.1处理 ls /usr/local/webhook/shell/user/$C2 if [ $? -ne 0 ];then #1.2steamapi拉取数据,并按小时生成本地缓存 curl -s "http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v1/?key=52A12DEE9B7C371AF6DC98D71CDD3D74&steamid=$C2" > /usr/local/webhook/shell/user/$C2 fi #1.3先行判断是否全部为空,为空加入标记QNU=0,是否存在squad关键词再下一步处理 #1.4为空返回未公开资料 QNU=`cat /usr/local/webhook/shell/user/$C2 |grep Squad |wc -l` if [ $QNU -eq 0 ];then rm -rf /usr/local/webhook/shell/user/$C2 sleep 1 $SQUADCMD AdminKickById $USERID 请公开steam资料以查询时长[个人资料-编辑个人资料-隐私设置-公开],且此为老兵服,低于200小时禁入。 exit fi if [ $QNU -eq 1 ];then NAME=(`cat /usr/local/webhook/shell/user/$C2 |/usr/bin/jq '.response.games'| python3 -c "import sys, json; data=json.load(sys.stdin); print([d['appid'] for d in data])" | sed 's/\[\|\]\|\,//g'`) STMM=(`cat /usr/local/webhook/shell/user/$C2 |/usr/bin/jq '.response.games'| python3 -c "import sys, json; data=json.load(sys.stdin); print([d['playtime_forever'] for d in data])" | sed 's/\[\|\]\|\,//g'`) fi COUNTER=0 NAMESUM=`echo ${#NAME[@]}` while true do if [ $QNU -eq 0 ];then break fi if [ $NAMESUM -eq 0 ];then break fi NAMES=`echo ${NAME[$COUNTER]} | grep -w 393380 | wc -l` if [ $NAMES -eq 1 ];then #获得时间为 ${STMM[$COUNTER]} DUR=0 if [ ${STMM[$COUNTER]} -lt 12000 ] ;then DUR=1 fi break fi COUNTER=$((COUNTER+1)) if [ $COUNTER -eq $NAMESUM ];then break fi #sleep 3 done if [ $DUR -eq 1 ];then sleep 1 $SQUADCMD AdminKickById $USERID 此为老兵服务器,低于200小时禁入;您可以选择有新手标识的服务器进入,欢迎以后再来。 fi echo "$C2 Check ok!"
查询当前服务器内有多少特定的用户:
#teamID C1=`echo $1|awk -F '%%' '{print $1}'` #steamID C2=`echo $1|awk -F '%%' '{print $2}'` #server C4=`echo $1|awk -F '%%' '{print $3}'` H4=`echo $C4 | awk -F \# '{print $2}'` S=`echo ${H4%%-*}` #获取在线用户列表 #ListPlayers|grep "Team ID" |awk '{print $5}' URLST=(`$SQUADCMD ListPlayers|grep "Team ID" |awk '{print $5}'`) #获取OP列表 OPLST=(`cat /usr/local/webhook/shell/txt/oplist`) #获取OP数量 COUNTER=0 OPLSTSUM=`echo ${#OPLST[@]}` URLSTSUM=`echo ${#URLST[@]}` OPCOUNT=0 while true do if [ $URLSTSUM -eq 0 ];then break fi OPCOUNTER=0 while true do SU=`echo ${URLST[$COUNTER]} | grep -w ${OPLST[$OPCOUNTER]} | wc -l` if [ $SU -eq 1 ];then OPCOUNT=$((OPCOUNT+1)) fi OPCOUNTER=$((OPCOUNTER+1)) if [ $OPCOUNTER -eq $OPLSTSUM ];then break fi done COUNTER=$((COUNTER+1)) if [ $COUNTER -eq $URLSTSUM ];then break fi done echo $OPCOUNT
发表评论