Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Auteur : Tlams
- # Script destiné au jeu jedi academy, afin de donner des droits de votes aux joueurs sans avoir activé le vote dans un server base.
- # Il est basé sur l'analyse des logs screen(apt-get install screen).
- # Créer pour serveur linux branche Debian. (Pas testé sur les autres)
- # Il faut le placer dans le même répertoire que linuxjampded
- # Pour utiliser JKA avec screen: screen -L -S NOM_SCREEN ./linuxjampded +set net_port 29070 +exec server.cfg
- # NOM_screen correspond au nom de la fenetre screen, le même nom doit être definit pour la var "screen_name"
- function contains() {
- local n=$#
- local value=${!n}
- for ((i=1;i < $#;i++)) {
- if [ "${!i}" == "${value}" ]; then
- echo "y"
- return 0
- fi
- }
- echo "n"
- return 1
- }
- rcon_nb_players()
- {
- bots_count=0
- echo -e "\xff\xff\xff\xffrcon $pass status" | $nc -q $timeout -u $host $port >./status.tmp | sed -e '1d'
- for ligne in `cat ./status.tmp`
- do
- if [[ "$ligne" == *"$bot_flag"* ]]; then
- echo "Bot trouvé - Exclu du vote"
- bots_count=`expr $bots_count + 1`
- fi
- done
- echo "Nombre de bots:"$bots_count
- calc_p=$(cat ./status.tmp | wc -l)
- calc_p=$(echo "scale=2;(($calc_p-9-($bots_count*2))/2)" | bc)
- }
- rcon()
- {
- echo -e "\xff\xff\xff\xffrcon $pass $1" | $nc -q $timeout -u $host $port 2>/dev/null | sed -e '1d'
- }
- #DEF. VAR
- host="127.0.0.1" # JKA serveur(Normalement il n'y a pas à modifier)
- port="29070" #JKA port
- pass="rconpw" #RCON PW de votre serveur
- #screen_name="siege" #Nom fenetre screen
- vote_requis_bots=4 #Nombre de votes requis pour exclure les bots (fixe)
- percent_requis_restart=70 #POURCENTAGE MINI de votes requis pour relance la partie
- log_file="screenlog.0"
- bot_flag="^4[^3EUROPE^4]"
- #INIT_VAR
- player_count_bots=0
- player_count_restart=0
- user_voting_bots=[]
- user_voting_restart=[]
- nc="$(which nc6 2>/dev/null || which nc)"
- timeout="1"
- vote_arrondi_restart=2
- #SCRIPT START
- tail -f ./$log_file | while read line
- do
- #VOTE POUR EXCLURE LES BOTS // commande: !kick_bots
- if [[ "$line" == *"!kick_bots"* && "$line" == "say:"* && "$player_count_bots" != "$vote_requis_bots" ]]; then
- user=$(echo $line | cut -c7-7) #Recupere numero client
- if [ $(contains "${user_voting_bots[@]}" "$user") == "n" ]; then
- echo "Ajout du vote joueur n°$user"
- user_voting_bots[$player_count_bots]="$user"
- player_count_bots=`expr $player_count_bots + 1`
- rcon "svsay Vote Kick Bots "$player_count_bots"/"$vote_requis_bots" -- Vote by player:"$user
- #screen -S $screen_name -X stuff 'svsay Vote Kick Bots '$player_count_bots'/'$vote_requis_bots' -- Vote by player:'$user''$'\012'
- if [ "$player_count_bots" == "$vote_requis_bots" ]; then
- echo "Kick des bots!"
- #screen -S $screen_name -X stuff 'svsay VOTE ACCEPTED! The bots will be kicked !'$'\012'
- rcon "svsay VOTE ACCEPTED! The bots will be kicked !"
- mv ./bot_gestion.sh ./stop_bot_gestion.sh #SPECIFIQUE A MON SERVER - SCRIPT DE GESTION DES BOTS
- #screen -S $screen_name -X stuff 'kick allbots'$'\012'
- rcon "kick allbots"
- player_count_bots=0
- unset user_voting_bots
- fi
- else
- echo "Vote refusé: Joueur a déjà voté!"
- #screen -S $screen_name -X stuff 'svsay Vote Kick Bots '$player_count_bots'/'$vote_requis_bots' -- Player '$user' has already voted'$'\012'
- rcon "svsay Vote Kick Bots "$player_count_bots"/"$vote_requis_bots" -- Player "$user" has already voted"
- fi
- fi
- #RELOAD BOTS AU CHANGEMENT DE MAP!
- if [[ "$line" == *"Server Initialization"* ]]; then
- mv ./stop_bot_gestion.sh ./bot_gestion.sh #SPECIFIQUE A MON SERVER - SCRIPT DE GESTION DES BOTS
- #screen -S $screen_name -X stuff 'exec bots.cfg'$'\012' #AJOUT CLASSIQUE DES BOTS OU UTILISER UN SCRIPT (exec) bots.cfg SPECIFIQUE
- #command="exec bots.cfg"
- #rcon $command
- echo "Changement de carte"
- unset user_voting_bots
- unset user_voting_restart
- player_count_bots=0
- player_count_restart=0
- fi
- if [[ "$line" == *"!restart"* && "$line" == "say:"* && "$player_count_restart" < "$vote_arrondi_restart" ]]; then
- user=$(echo $line | cut -c7-7) #Recupere numero client
- rcon_nb_players
- nb_votes_requis_restart=$(echo "scale=2;(($calc_p/100)*$percent_requis_restart)" | bc)
- vote_arrondi_restart=$(printf '%.0f\n' $nb_votes_requis_restart)
- if [ $(contains "${user_voting_restart[@]}" "$user") == "n" ]; then
- echo "Ajout du vote joueur n°$user"
- user_voting_restart[$player_count_restart]="$user"
- player_count_restart=`expr $player_count_restart + 1`
- rcon "svsay Vote to restart map "$player_count_restart"/"$vote_arrondi_restart" -- Vote by player:"$user
- if [ "$player_count_restart" == "$vote_arrondi_restart" ]; then
- echo "Map restart 10s"
- rcon "svsay VOTE ACCEPTED! The map will be restarted !"
- rcon "map_restart 10"
- fi
- else
- echo "Vote refusé: Joueur a déjà voté!"
- rcon "svsay Vote to restart map "$player_count_restart"/"$vote_arrondi_restart" -- Player "$user" has already voted"
- fi
- fi
- #DETECTE LA DECONNEXION CLIENT AFIN DE SUPPRIMER LE(S) VOTE(S) ET LIBERER LA PLACE
- if [[ "$line" == *"ClientDisconnect:"* ]]; then
- user=$(echo $line | cut -c20-20) #Recupere numero client
- echo "Déconnexion joueur n°$user"
- #VOTE BOTS KICK
- if [ $(contains "${user_voting_bots[@]}" "$user") == "y" ]; then
- echo "Liberation du vote n°$user"
- player_count_bots=`expr $player_count_bots - 1`
- user_voting_bots=( ${user_voting_bots[@]/"$user"/} )
- fi
- #VOTE RESTART
- if [ $(contains "${user_voting_restart[@]}" "$user") == "y" ]; then
- echo "Liberation du vote n°$user"
- player_count_restart=`expr $player_count_restart - 1`
- user_voting_restart=( ${user_voting_restart[@]/"$user"/} )
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement