Advertisement
Tlams

q3_command_log_annalyse

Aug 25th, 2013
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.79 KB | None | 0 0
  1. #!/bin/bash
  2. # Auteur : Tlams
  3. # Script destiné au jeu jedi academy, afin de donner des droits de votes aux joueurs sans avoir activé le vote dans un server base.
  4. # Il est basé sur l'analyse des logs screen(apt-get install screen).
  5. # Créer pour serveur linux branche Debian. (Pas testé sur les autres)
  6. # Il faut le placer dans le même répertoire que linuxjampded
  7. # Pour utiliser JKA avec screen: screen -L -S NOM_SCREEN ./linuxjampded +set net_port 29070 +exec server.cfg  
  8. # NOM_screen correspond au nom de la fenetre screen, le même nom doit être definit pour la var "screen_name"
  9.  
  10. function contains() {
  11.     local n=$#
  12.     local value=${!n}
  13.     for ((i=1;i < $#;i++)) {
  14.         if [ "${!i}" == "${value}" ]; then
  15.             echo "y"
  16.             return 0
  17.         fi
  18.     }
  19.     echo "n"
  20.     return 1
  21. }
  22.  
  23. rcon_nb_players()
  24. {
  25.     bots_count=0
  26.     echo -e "\xff\xff\xff\xffrcon $pass status" | $nc -q $timeout -u $host $port >./status.tmp | sed -e '1d'
  27.  
  28.     for ligne in `cat ./status.tmp`
  29.     do
  30.         if [[ "$ligne" == *"$bot_flag"* ]]; then
  31.             echo "Bot trouvé - Exclu du vote"
  32.             bots_count=`expr $bots_count + 1`
  33.         fi
  34.     done
  35.     echo "Nombre de bots:"$bots_count
  36.     calc_p=$(cat ./status.tmp | wc -l) 
  37.        calc_p=$(echo "scale=2;(($calc_p-9-($bots_count*2))/2)" | bc)
  38. }
  39.  
  40.  
  41.  
  42. rcon()
  43. {
  44.         echo -e "\xff\xff\xff\xffrcon $pass $1" | $nc -q $timeout -u $host $port 2>/dev/null | sed -e '1d'
  45. }
  46.  
  47.  
  48.  
  49.  
  50. #DEF. VAR
  51. host="127.0.0.1" # JKA serveur(Normalement il n'y a pas à modifier)
  52. port="29070" #JKA port
  53. pass="rconpw" #RCON PW de votre serveur
  54.  
  55. #screen_name="siege"  #Nom fenetre screen
  56. vote_requis_bots=4  #Nombre de votes requis pour exclure les bots (fixe)
  57. percent_requis_restart=70  #POURCENTAGE MINI de votes requis pour relance la partie
  58. log_file="screenlog.0"
  59. bot_flag="^4[^3EUROPE^4]"
  60.  
  61. #INIT_VAR
  62. player_count_bots=0
  63. player_count_restart=0
  64. user_voting_bots=[]
  65. user_voting_restart=[]
  66. nc="$(which nc6 2>/dev/null || which nc)"
  67. timeout="1"
  68. vote_arrondi_restart=2
  69.  
  70. #SCRIPT START
  71. tail -f ./$log_file | while read line
  72. do
  73.     #VOTE POUR EXCLURE LES BOTS // commande: !kick_bots
  74.     if [[ "$line" == *"!kick_bots"* &&  "$line" == "say:"* && "$player_count_bots" != "$vote_requis_bots" ]]; then
  75.         user=$(echo $line | cut -c7-7) #Recupere numero client
  76.         if [ $(contains "${user_voting_bots[@]}" "$user") == "n" ]; then
  77.             echo "Ajout du vote joueur n°$user"
  78.                     user_voting_bots[$player_count_bots]="$user"
  79.                 player_count_bots=`expr $player_count_bots + 1`
  80.             rcon "svsay Vote Kick Bots "$player_count_bots"/"$vote_requis_bots" -- Vote by player:"$user
  81.             #screen -S $screen_name -X stuff 'svsay Vote Kick Bots '$player_count_bots'/'$vote_requis_bots' -- Vote by player:'$user''$'\012'
  82.             if [ "$player_count_bots" == "$vote_requis_bots" ]; then
  83.                 echo "Kick des bots!"
  84.                 #screen -S $screen_name -X stuff 'svsay VOTE ACCEPTED! The bots will be kicked !'$'\012'
  85.                 rcon "svsay VOTE ACCEPTED! The bots will be kicked !"
  86.                 mv ./bot_gestion.sh ./stop_bot_gestion.sh  #SPECIFIQUE A MON SERVER - SCRIPT DE GESTION DES BOTS
  87.                 #screen -S $screen_name  -X stuff 'kick allbots'$'\012'
  88.                 rcon "kick allbots"
  89.                 player_count_bots=0
  90.                 unset  user_voting_bots
  91.             fi
  92.         else
  93.             echo "Vote refusé: Joueur a déjà voté!"
  94.             #screen -S $screen_name -X stuff 'svsay Vote Kick Bots '$player_count_bots'/'$vote_requis_bots' -- Player '$user' has already voted'$'\012'
  95.             rcon "svsay Vote Kick Bots "$player_count_bots"/"$vote_requis_bots" -- Player "$user" has already voted"
  96.         fi
  97.     fi
  98.    
  99.     #RELOAD BOTS AU CHANGEMENT DE MAP!
  100.     if [[ "$line" == *"Server Initialization"* ]]; then
  101.         mv ./stop_bot_gestion.sh ./bot_gestion.sh #SPECIFIQUE A MON SERVER - SCRIPT DE GESTION DES BOTS
  102.         #screen -S $screen_name  -X stuff 'exec bots.cfg'$'\012'  #AJOUT CLASSIQUE DES BOTS OU UTILISER UN SCRIPT (exec) bots.cfg SPECIFIQUE
  103.         #command="exec bots.cfg"
  104.         #rcon $command
  105.         echo "Changement de carte"
  106.         unset  user_voting_bots
  107.         unset  user_voting_restart
  108.         player_count_bots=0
  109.         player_count_restart=0
  110.     fi
  111.    
  112.     if [[ "$line" == *"!restart"* &&  "$line" == "say:"* && "$player_count_restart" < "$vote_arrondi_restart" ]]; then
  113.         user=$(echo $line | cut -c7-7) #Recupere numero client
  114.         rcon_nb_players
  115.         nb_votes_requis_restart=$(echo "scale=2;(($calc_p/100)*$percent_requis_restart)" | bc)
  116.         vote_arrondi_restart=$(printf '%.0f\n' $nb_votes_requis_restart)
  117.  
  118.         if [ $(contains "${user_voting_restart[@]}" "$user") == "n" ]; then
  119.             echo "Ajout du vote joueur n°$user"
  120.                 user_voting_restart[$player_count_restart]="$user"
  121.                     player_count_restart=`expr $player_count_restart + 1`
  122.             rcon "svsay Vote to restart map "$player_count_restart"/"$vote_arrondi_restart" -- Vote by player:"$user
  123.             if [ "$player_count_restart" == "$vote_arrondi_restart" ]; then
  124.                 echo "Map restart 10s"
  125.                 rcon "svsay VOTE ACCEPTED! The map will be restarted !"
  126.                 rcon "map_restart 10"
  127.             fi
  128.         else
  129.             echo "Vote refusé: Joueur a déjà voté!"
  130.             rcon "svsay Vote to restart map "$player_count_restart"/"$vote_arrondi_restart" -- Player "$user" has already voted"
  131.         fi
  132.     fi
  133.        
  134.    
  135.     #DETECTE LA DECONNEXION CLIENT AFIN DE SUPPRIMER LE(S) VOTE(S) ET LIBERER LA PLACE
  136.     if [[ "$line" == *"ClientDisconnect:"* ]]; then
  137.         user=$(echo $line | cut -c20-20) #Recupere numero client
  138.         echo "Déconnexion joueur n°$user"
  139.         #VOTE BOTS KICK
  140.         if [ $(contains "${user_voting_bots[@]}" "$user") == "y" ]; then
  141.             echo "Liberation du vote n°$user"
  142.             player_count_bots=`expr $player_count_bots - 1`
  143.             user_voting_bots=( ${user_voting_bots[@]/"$user"/} )
  144.         fi
  145.         #VOTE RESTART
  146.         if [ $(contains "${user_voting_restart[@]}" "$user") == "y" ]; then
  147.             echo "Liberation du vote n°$user"
  148.             player_count_restart=`expr $player_count_restart - 1`
  149.             user_voting_restart=( ${user_voting_restart[@]/"$user"/} )
  150.         fi
  151.     fi
  152. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement