SHARE
TWEET

Untitled

a guest Nov 15th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const game = {
  2.     roomName: "👑 [24/7] PWRHAX.EU - POWER 2v2 👑",
  3.     maxPlayers: 12,
  4.     playerName: "Admin",
  5.     public: true,
  6.     geo: {
  7.       code: "PL",
  8.       lat: 52.232544,
  9.       lon: 20.997543
  10.     }
  11.   };
  12.  
  13.   let infoPlayers = [];
  14.  
  15.   let connections = [];
  16.   let arrUsers = [];
  17.   let allUsers = {};
  18.  
  19.  
  20.   let loginUsers = [];
  21.  
  22.  
  23.  
  24.   let admins = ['Shaw','Kris','♛𝔎⓽𝓡𝐼𝓒𝓐𝓡𝓓♛','Yezzy>!','Niezłykinol','mbape','xPsc1','Mαנοя'];
  25.   let blackListAccess = ['zax'];
  26.  
  27.   let duplicateMsg = {};
  28.   let decisionPlayer = {};
  29.  
  30.   const config = {
  31.     showGoalInfo: true,
  32.     chatEnabled: true,
  33.     muteNewPlayers: false,
  34.     adminPassword: "cyk"
  35.   };
  36.  
  37.   const prefixes = {
  38.     message: "⏩  ",
  39.     cmd: "!"
  40.   };
  41.  
  42.   let goalsMVP = {};
  43.   let assistsMVP = {};
  44.  
  45.   let arrGoalsMVP = [];
  46.   let arrAssistsMVP = [];
  47.  
  48.   let adminAccess = {};
  49.  
  50.   let superAdmins = [0];
  51.   let mutedPlayers = [];
  52.   let noCmdPlayers = [];
  53.   let afkPlayers = [];
  54.  
  55.   //Bets
  56.   let betStatus = true;
  57.  
  58.   let allBets = {};
  59.   let currentBets = {};
  60.   let arrBets = [];
  61.   //
  62.  
  63.   let authenticatedAdmins = [];
  64.   let adminLogs = {};
  65.  
  66.   let ball = {
  67.     kickedBy: {
  68.       player: null,
  69.       time: null,
  70.     },
  71.     touchedBy: {
  72.       player: null,
  73.       time: null
  74.     },
  75.     assistingPlayer: null
  76.   };
  77.  
  78.   let redWin = 1;
  79.   let blueWin = 1;
  80.  
  81.  
  82.   function getSpec() {
  83.     return room.getPlayerList().filter((player) => player.team === 0 && afkPlayers.indexOf(player.name) < 0 && player.id != 0);
  84.   }
  85.  
  86.   function getBlue() {
  87.     return room.getPlayerList().filter((player) => player.team === 2);
  88.   }
  89.  
  90.   function getRed() {
  91.     return room.getPlayerList().filter((player) => player.team === 1);
  92.   }
  93.  
  94.  
  95.   let goals = {};
  96.   let ownGoals = {};
  97.   let assists = {};
  98.  
  99.   let match = {};
  100.  
  101.   let cmdManager;
  102.   let nextPauseAction = true;
  103.  
  104.   const room = new HBInit(game);
  105.  
  106.   let bans = {};
  107.  
  108.   room.onPlayerBallKick = player => {
  109.     updateAssistingPlayer(player);
  110.  
  111.     let time = Date.now();
  112.     let kick = {
  113.       time,
  114.       player
  115.     };
  116.     ball.kickedBy = kick;
  117.   };
  118.  
  119.   function createArrGoalsMVP() {
  120.  
  121.     arrGoalsMVP = [];
  122.  
  123.     /*Stworzenie tablicy obiektów opartą o obiekt 'wins'*/
  124.     for (let x in goalsMVP) {
  125.       arrGoalsMVP.push([x, goalsMVP[x]]);
  126.     };
  127.  
  128.     /*Sortowanie tablicy arrWins*/
  129.     arrGoalsMVP.sort(function (a, b) {
  130.       return b[1] - a[1];
  131.     })
  132.  
  133.   };
  134.  
  135.   function createArrAssistsMVP() {
  136.  
  137.     arrAssistsMVP = [];
  138.  
  139.     /*Stworzenie tablicy obiektów opartą o obiekt 'wins'*/
  140.     for (let x in assistsMVP) {
  141.       arrAssistsMVP.push([x, assistsMVP[x]]);
  142.     };
  143.  
  144.     /*Sortowanie tablicy arrWins*/
  145.     arrAssistsMVP.sort(function (a, b) {
  146.       return b[1] - a[1];
  147.     })
  148.  
  149.   };
  150.  
  151.  
  152.  
  153.   room.onTeamVictory = function (scores) {
  154.  
  155.     createArrAssistsMVP();
  156.     createArrGoalsMVP();
  157.     let bestGoals
  158.     if (arrGoalsMVP.length != 0) {
  159.       bestGoals = arrGoalsMVP[0][0];
  160.     }
  161.  
  162.     if (scores.blue > scores.red) {
  163.       if (arrGoalsMVP.length != 0) {
  164.         room.sendChat(`🏆 🔵 won ${blueWin} matches in a row. 🏆  ⭐ MVP: ${bestGoals}, Goals: ${arrGoalsMVP[0][1]} Assists: ${assistsMVP[bestGoals] || 0} ⭐`);
  165.       } else {
  166.         room.sendChat(`🏆 🔵 won ${blueWin} matches in a row. 🏆  ⭐ MVP: Niezalogowany gracz.`);
  167.       }
  168.       redWin = 1;
  169.       blueWin++;
  170.     } else {
  171.       if (arrGoalsMVP.length != 0) {
  172.  
  173.         room.sendChat(`🏆 🔴 won ${redWin} matches in a row. 🏆   ⭐ MVP: ${bestGoals}, Goals: ${arrGoalsMVP[0][1]} Assists: ${assistsMVP[bestGoals] || 0} ⭐`);
  174.       } else {
  175.         room.sendChat(`🏆 🔴 won ${redWin} matches in a row. 🏆   ⭐ MVP: Niezalogowany gracz. ⭐`);
  176.       }
  177.       blueWin = 1;
  178.       redWin++;
  179.     }
  180.  
  181.     if (scores.blue > scores.red) {
  182.       for (let x in currentBets) {
  183.         const team = currentBets[x][0];
  184.         if (team === 2) {
  185.           let bet = allBets[x] || 0;
  186.           allBets[x] = bet + currentBets[x][1];
  187.         } else {
  188.           let bet = allBets[x] || 0;
  189.           allBets[x] = bet - currentBets[x][1];
  190.         }
  191.       }
  192.     } else {
  193.       for (let x in currentBets) {
  194.         const team = currentBets[x][0];
  195.         if (team === 1) {
  196.           let bet = allBets[x] || 0;
  197.           allBets[x] = bet + currentBets[x][1];
  198.         } else {
  199.           let bet = allBets[x] || 0;
  200.           allBets[x] = bet - currentBets[x][1];
  201.         }
  202.       }
  203.     }
  204.  
  205.     currentBets = {};
  206.     goalsMVP = {};
  207.     assistsMVP = {};
  208.  
  209.     room.getPlayerList().map((p)=>{
  210.       if(p.team != 0){
  211.         let score = match[p.name] || 0;
  212.         match[p.name] = score + 1;
  213.       }
  214.     })
  215.    
  216.   }
  217.  
  218.   room.onTeamGoal = team => {
  219.     let scorer;
  220.  
  221.     if (ball.kickedBy && ball.touchedBy) {
  222.       if (ball.kickedBy.time > ball.touchedBy.time) {
  223.         scorer = ball.kickedBy.player;
  224.       } else {
  225.         scorer = ball.touchedBy.player;
  226.       }
  227.     } else if (ball.kickedBy) {
  228.       scorer = ball.kickedBy.player;
  229.     } else if (ball.touchedBy) {
  230.       scorer = ball.touchedBy.player;
  231.     }
  232.  
  233.     if (scorer) {
  234.       let ownGoal = scorer.team !== team;
  235.       let assistOccured = ball.assistingPlayer && !ownGoal && ball.assistingPlayer.team === team && ball.assistingPlayer.id !== scorer.id;
  236.  
  237.       if (config.showGoalInfo) {
  238.         let message = `Gola ${ownGoal ? "samobójczego" : ""} zdobył gracz ${scorer.name}`;
  239.         if (assistOccured) {
  240.           message += ` (${ball.assistingPlayer.name})`;
  241.         }
  242.         sendMessage(message);
  243.       }
  244.  
  245.       if (ownGoal && arrUsers.includes(scorer.name)) {
  246.         let score = ownGoals[scorer.name] || 0;
  247.         ownGoals[scorer.name] = score + 1;
  248.       } else {
  249.         if (arrUsers.includes(scorer.name)) {
  250.           let score = goals[scorer.name] || 0;
  251.           goals[scorer.name] = score + 1;
  252.  
  253.           let scoreMVP = goalsMVP[scorer.name] || 0;
  254.           goalsMVP[scorer.name] = scoreMVP + 1;
  255.         }
  256.       }
  257.  
  258.       if (assistOccured) {
  259.         let score = assists[ball.assistingPlayer.name] || 0;
  260.         assists[ball.assistingPlayer.name] = score + 1;
  261.  
  262.         let scoreMVP = assistsMVP[ball.assistingPlayer.name] || 0;
  263.         assistsMVP[ball.assistingPlayer.name] = scoreMVP + 1;
  264.       }
  265.     }
  266.  
  267.     ball.kickedBy = null;
  268.     ball.touchedBy = null;
  269.   };
  270.  
  271.   let code = (str) => {
  272.     var input     = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  273.     var output    = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm';
  274.     var index     = x => input.indexOf(x);
  275.     var translate = x => index(x) > -1 ? output[index(x)] : x;
  276.     return str.split('').map(translate).join('');
  277.   }
  278.  
  279.  
  280.   function registerPlayer(p, message) {
  281.     exportUsers();
  282.         setTimeout(() => {
  283.           putMethod();
  284.         }, 2000)
  285.     for (name in users) {
  286.       if (!Object.keys(users).includes(code(p.name)) && message.substr(10).length > 2) {
  287.         room.sendChat(`❗Zostałeś zarejestrowany oraz automatycznie zalogowany.`, p.id);
  288.         room.sendChat(`❗${p.name}, Twoje hasło: '${message.substr(10)}' Komenda do logowania: '!login ${message.substr(10)}'`, p.id);
  289.         room.sendChat(`❗Do czasu zalogowania twoje gole,asysty,bety nie będa dodawane.`, p.id);
  290.         //
  291.         users[code(p.name)] = code(message.substr(10));
  292.         arrUsers.push(p.name);
  293.  
  294.         break;
  295.       } else if (message.substr(10).length < 2) {
  296.         room.sendChat(`Twoje hasło musi składać się min. 3 znaków❗`, p.id);
  297.         break;
  298.       } else {
  299.         room.sendChat('❗Gracz o takim nicku jest już zarejestrowany. To nie ty? Napisz: HTTP://PWRHAX.EU', p.id);
  300.         break;
  301.       }
  302.     }
  303.   };
  304.  
  305.   function loginPlayer(p, message) {
  306.     exportUsers();
  307.     setTimeout(() => {
  308.       putMethod();
  309.     }, 2000)
  310.  
  311.     const players = Object.keys(users);
  312.     const idxPlayer = players.indexOf(code(p.name));
  313.  
  314.     if (idxPlayer === -1) {
  315.       room.sendChat(`Twój nick nie jest zarejestrowany❗ Użyj '!register password' aby go zarejestrować.`, p.id);
  316.     } else if (idxPlayer != -1 && arrUsers.includes(p.name)) {
  317.       room.sendChat(`${p.name}, jesteś już zalogowany❗ (Zostaniesz zautomatycznie wylogowany po opuszczeniu rooma.)❗`, p.id);
  318.     } else if (idxPlayer != -1 && code(message.substr(7)) != users[players[idxPlayer]]) {
  319.       room.sendChat(`Błędne hasło❗ Zapomniałeś hasła❓ Pisz: HTTP://PWRHAX.EU`, p.id);
  320.     } else if (idxPlayer != -1 && code(message.substr(7)) == users[players[idxPlayer]]) {
  321.       room.sendChat(`${p.name}, zalogowany❗`, p.id);
  322.       if (admins.includes(p.name)) {
  323.         room.setPlayerAdmin(p.id, true);
  324.         room.sendChat(`${p.name} jest super-adminem ❗`)
  325.         authenticatedAdmins.push(p.id);
  326.       }
  327.       arrUsers.push(p.name);
  328.     }
  329.   };
  330.  
  331.  
  332.  
  333.   room.onPlayerChat = (player, msg) => {
  334.   if(msg != duplicateMsg[player.name]){
  335.       decisionPlayer[player.id] = 0;
  336.    }
  337.  
  338.   duplicateMsg[player.name] = msg;
  339.  
  340.  
  341.   if(msg === duplicateMsg[player.name]){
  342.      let dec = decisionPlayer[player.id] || 0;
  343.      decisionPlayer[player.id] = dec + 1;
  344.   }
  345.  
  346.   if(decisionPlayer[player.id] > 3){
  347.       return false;
  348.   }
  349.     getSpec();
  350.     getRed();
  351.     getBlue();
  352.  
  353.     if (msg.startsWith('!register')) {
  354.       registerPlayer(player, msg);
  355.       return false;
  356.     }
  357.     if (msg.startsWith('!login')) {
  358.       loginPlayer(player, msg);
  359.       return false;
  360.     }
  361.     if (msg.startsWith('!bet') && betStatus && arrUsers.includes(player.name)) {
  362.       const betText = msg.split(" ");
  363.  
  364.       let teamValidRed = new RegExp(/red/i);
  365.       let teamValidBlue = new RegExp(/blue/i);
  366.       let teamValidBlueRed = new RegExp(/blue|red/i);
  367.  
  368.       let valueValid = new RegExp(/\d{1,}/);
  369.  
  370.       let currentBetsKeys = Object.keys(currentBets);
  371.       let filterCurrentBets = currentBetsKeys.filter((p) => p === player.name);
  372.  
  373.       if (filterCurrentBets.length === 1) {
  374.         room.sendChat(`🖕 Możesz obstawić tylko 1 mecz.`, player.id);
  375.       } else if (teamValidRed.test(betText[1]) && valueValid.test(msg) && player.team === 0 && betText.length === 3 && allBets[player.name] >= betText[2] && betText[2] >=0 && betText[2].indexOf('.')=== -1&& getRed().length === 2) {
  376.         betText[1] = 1;
  377.  
  378.         room.sendChat(`Postawiłeś ${betText[2]}💲 na Red.`, player.id);
  379.         //
  380.         room.sendChat(`${player.name} postawił na twoją drużynę ${betText[2]}💲.`, getRed()[0].id);
  381.         room.sendChat(`${player.name} postawił na twoją drużynę ${betText[2]}💲.`, getRed()[1].id);
  382.  
  383.         currentBets[player.name] = [betText[1], parseFloat(valueValid.exec(msg)[0])];
  384.       } else if (teamValidBlue.test(betText[1]) && valueValid.test(msg) && player.team === 0 && betText.length === 3 && allBets[player.name] >= betText[2] && betText[2] >=0 && betText[2].indexOf('.')=== -1&&getBlue().length === 2) {
  385.  
  386.         betText[1] = 2;
  387.         room.sendChat(`Postawiłeś ${betText[2]}💲 na Blue.`, player.id);
  388.  
  389.         room.sendChat(`${player.name} postawił na twoją drużynę ${betText[2]}💲.`, getBlue()[0].id);
  390.         room.sendChat(`${player.name} postawił na twoją drużynę ${betText[2]}💲.`, getBlue()[1].id);
  391.  
  392.         currentBets[player.name] = [betText[1], parseFloat(valueValid.exec(msg)[0])];
  393.       } else if (allBets[player.name] < betText[2]) {
  394.  
  395.         room.sendChat(`Nie masz tyle 💲`, player.id);
  396.  
  397.       } else if (betText.length != 3) {
  398.         room.sendChat(`Zastosuj się do wzorca: !bet team value`, player.id);
  399.       } else if (!teamValidBlueRed.test(betText[1])) {
  400.         room.sendChat(`Nie znaleziono ${betText[1]} , użyj red/blue.`, player.id);
  401.       } else if (player.team != 0) {
  402.         room.sendChat(`Nie możesz obstawiać swoich meczy.`, player.id);
  403.       }
  404.  
  405.       return false;
  406.     }
  407.  
  408.     if (msg.startsWith('!bet') && betStatus && !arrUsers.includes(player.name)) {
  409.       room.sendChat(`Bety są tylko i wyłącznie dla zarejestrowanych graczy.`, player.id);
  410.       return false;
  411.     }
  412.  
  413.  
  414.     if (msg.startsWith('!bet') && !betStatus) {
  415.       room.sendChat(`Bety są obecnie wyłączone po rozpoczęciu gry masz 15s aby obstawić dowolną drużynę.`, player.id);
  416.       return false;
  417.     }
  418.  
  419.  
  420.     if (msg.startsWith(prefixes.cmd)) {
  421.       if (!canPlayerInvokeCmd(player)) return false;
  422.  
  423.       let showMessage = parseCmd(player, msg.substring(1));
  424.       return showMessage && (!isPlayerMuted(player) && config.chatEnabled || isSuperAdmin(player));
  425.     }
  426.  
  427.     return !isPlayerMuted(player) && config.chatEnabled || isSuperAdmin(player);
  428.   };
  429.  
  430.   const sendBan = (data) =>{
  431.     const xhr = new XMLHttpRequest();
  432.  
  433.     xhr.open('POST','http://217.182.79.39:5000/ban')
  434.     xhr.setRequestHeader('Content-Type','application/json')
  435.     xhr.send(JSON.stringify(data))
  436. }
  437.  
  438.   room.onPlayerKicked = (kickedPlayer, reason, ban, byPlayer) => {
  439.  
  440.     sendUsers();
  441.  
  442.     if(ban) {addBan(byPlayer.name)};
  443.  
  444.     if(ban) sendBan({name: game.roomName,banned:kickedPlayer.name,byPlayer: byPlayer.name,reason: reason});
  445.  
  446.  
  447.     if (isSuperAdmin(kickedPlayer) || authenticatedAdmins.includes(kickedPlayer.id) && !isSuperAdmin(byPlayer)) {
  448.       if (ban)
  449.         room.clearBans();
  450.  
  451.       room.kickPlayer(byPlayer.id, "Tak się bawić nie będziemy", true);
  452.     }
  453.  
  454.    
  455.  
  456.     if (blackListAccess.includes(byPlayer.name) && reason === 'won') {
  457.       downloadBl();
  458.  
  459.       let bl = infoPlayers.filter((p)=> p.name === kickedPlayer.name)[0];
  460.      
  461.       blContent.push(bl);
  462.  
  463.       const xhr = new XMLHttpRequest();
  464.       xhr.open('PUT','https://api.myjson.com/bins/v81fc');
  465.       xhr.setRequestHeader('Content-Type', 'application/json');
  466.       xhr.send(JSON.stringify(blContent));
  467.      
  468.     }
  469.  
  470.     let banInfo = {};
  471.     banInfo.banned = kickedPlayer.name;
  472.     banInfo.admin = byPlayer.name;
  473.     banInfo.reason = reason;
  474.     banInfo.isBan = ban;
  475.     banInfo.time = new Date();
  476.  
  477.     if (!bans[byPlayer.id]) {
  478.       bans[byPlayer.id] = [];
  479.     }
  480.     bans[byPlayer.id].unshift(banInfo);
  481.  
  482.     if (!authenticatedAdmins.includes(byPlayer.id) && !isSuperAdmin(byPlayer)) {
  483.       let playerBans = bans[byPlayer.id].filter(ban => ban.isBan);
  484.  
  485.       if (playerBans.length >= 5) {
  486.         let lastBan = playerBans[0];
  487.         let banToCompare = playerBans[4];
  488.         let dateDiff = lastBan.time - banToCompare.time;
  489.         if (dateDiff <= 1000 * 60 * 5) {
  490.           clearAllBans("Admina");
  491.           room.kickPlayer(byPlayer.id, "żegnaj trollu", true);
  492.         }
  493.       }
  494.     }
  495.  
  496.   };
  497.  
  498.   room.onPlayerAdminChange = (changedPlayer, byPlayer) => {
  499.     updateAdmins();
  500.     if (!changedPlayer.admin && (isSuperAdmin(changedPlayer) || authenticatedAdmins.includes(changedPlayer.id) && !isSuperAdmin(byPlayer))) {
  501.       if (byPlayer !== null && byPlayer.name !== game.playerName) {
  502.         room.setPlayerAdmin(changedPlayer.id, true);
  503.         room.setPlayerAdmin(byPlayer.id, false);
  504.  
  505.         sendMessage("Próba odebrania uprawnień adminowi wyższej rangi!");
  506.       }
  507.     }
  508.  
  509.     let FalAdmin = new RegExp(/zax/i);
  510.     let LmaAdmin = new RegExp(/zax/i);
  511.  
  512.     if (byPlayer.id != 0 && FalAdmin.test(changedPlayer.name)) {
  513.       room.setPlayerAdmin(changedPlayer.id, false);
  514.       room.sendChat('❗❗ Nie dawaj admina nikomu o nicku Zdun ❗❗');
  515.     }
  516.  
  517.     if (byPlayer.id != 0 && LmaAdmin.test(changedPlayer.name)) {
  518.       room.setPlayerAdmin(changedPlayer.id, false);
  519.       room.sendChat('❗❗ Nie dawaj admina nikomu o nicku zax ❗❗');
  520.     }
  521.   };
  522.  
  523.   function valid(player){
  524.     const xhr = new XMLHttpRequest();
  525.  
  526.     xhr.open('GET','https://api.myjson.com/bins/176yok',true)
  527.     xhr.onload = function(){
  528.       if(xhr.status === 200){
  529.         let x = JSON.parse(xhr.responseText);
  530.           if(x[player.name] === false){
  531.             room.kickPlayer(player.id,'Fejk',true)
  532.           }
  533.       }
  534.     }
  535.     xhr.send()
  536.   }
  537.  
  538.   let blContent = [];
  539.  
  540.   const downloadBl = () =>{
  541.     const xhr = new XMLHttpRequest();
  542.  
  543.     xhr.open('GET','https://api.myjson.com/bins/v81fc')
  544.     xhr.onload = function(){
  545.       if(xhr.status === 200){
  546.         blContent = JSON.parse(xhr.responseText);
  547.       }
  548.     }
  549.  
  550.     xhr.send();
  551.   }
  552.  
  553.  
  554.   const validateBl = (player) =>{
  555.     const xhr = new XMLHttpRequest();
  556.  
  557.     xhr.open('GET','https://api.myjson.com/bins/v81fc')
  558.     xhr.onload = function(){
  559.       if(xhr.status === 200){
  560.         let x = JSON.parse(xhr.responseText);
  561.         if(x.length){
  562.           for(p of x){
  563.             if(p.auth === player.auth || p.conn === player.conn){
  564.               room.kickPlayer(player.id,'🏴 Czarna lista 🏴',true)
  565.             }
  566.           }
  567.         }
  568.       }
  569.     }
  570.  
  571.     xhr.send();
  572.   }
  573.  
  574.   const ip = (player) =>{
  575.     const xhr = new XMLHttpRequest();
  576.  
  577.     xhr.open('GET',`http://check.getipintel.net/check.php?ip=${player.ip.Nb.Cb[0]}&contact=`)
  578.     xhr.onload = function(){
  579.         if(xhr.status===200){
  580.             if(xhr.responseText === "1"){
  581.           room.kickPlayer(player.id,'😂VPN😂',true)
  582.         }
  583.         }
  584.     }
  585.  
  586.     xhr.send()
  587.    
  588.   }
  589.  
  590.   room.onPlayerJoin = player => {
  591.     room.sendAnnouncement('Zapraszamy do odwiedzenia naszej strony HTTP://PWRHAX.EU', player.id, 0xd9db6e, "bold", 2)
  592.     if(player.name === 'lutentokot'){
  593.         downloadBl();
  594.  
  595.       let bl = infoPlayers.filter((p)=> p.name === player.name)[0];
  596.      
  597.       blContent.push(bl);
  598.  
  599.       const xhr = new XMLHttpRequest();
  600.       xhr.open('PUT','https://api.myjson.com/bins/v81fc');
  601.       xhr.setRequestHeader('Content-Type', 'application/json');
  602.       xhr.send(JSON.stringify(blContent));
  603.     }
  604.     // valid(player);
  605.     downloadBl();
  606.     validateBl(player)
  607.     // ip(player)  
  608.    
  609.     room.sendChat("Welcome " + player.name + ', wpisz !komendy by poznać funkcje rooma!', player.id)
  610.     room.sendChat("Użyj '!register password' aby się zarejestrować lub '!login password' aby się zalogować.", player.id);
  611.  
  612.     updateAdmins();
  613.  
  614.     if (config.muteNewPlayers) {
  615.       mutePlayer(player);
  616.     }
  617.  
  618.  
  619.     let conn = connections.find(a => a[1] === player.conn)
  620.     if (conn) {
  621.       // room.kickPlayer(player.id, "1 gracz = 1 karta", false);
  622.     } else {
  623.       connections.push([player.id, player.conn])
  624.     }
  625.    
  626.     let bets = allBets[player.name] || 97;
  627.  
  628.     allBets[player.name] = bets + 3;
  629.  
  630.     infoPlayers.push({
  631.       name: player.name,
  632.       auth: player.auth,
  633.       conn: player.conn
  634.     });
  635.     sendUsers();
  636.   };
  637.  
  638.   room.onPlayerLeave = player => {
  639.  
  640.     if (arrUsers.indexOf(player.name) != -1) {
  641.       arrUsers.splice(arrUsers.indexOf(player.name), 1);
  642.     }
  643.     unsetPlayerAfk(player);
  644.     unsetSuperAdmin(player);
  645.     updateAdmins();
  646.     if (player.team !== 0 && room.getScores()) {
  647.       let players = room.getPlayerList().filter(player => player.team === 0 && !isPlayerAfk(player));
  648.       players = players.filter(player => player.id !== 0);
  649.       if (players.length) {
  650.         room.pauseGame(true);
  651.         sendMessage("Gracz z boiska opuścił serwer. Są dostępni gracze na ławce.");
  652.       }
  653.     }
  654.     setTimeout(() => {
  655.       infoPlayers = infoPlayers.filter((p) => p.name != player.name);
  656.     }, 1000)
  657.  
  658.     connections = connections.filter(a => a[0] !== player.id);
  659.  
  660.     setTimeout(() => {
  661.       infoPlayers = infoPlayers.filter((p) => p.name != player.name);
  662.     }, 1000)
  663.    
  664.     sendUsers()
  665.   };
  666.  
  667.  
  668.  
  669.  
  670.   room.onPlayerTeamChange = player => {
  671.     if (player.id === 0) {
  672.       room.setPlayerTeam(0, 0);
  673.     }
  674.  
  675.   sendUsers()
  676.     if (player.team !== 0 && isPlayerAfk(player)) {
  677.       sendMessage(`Gracz ${player.name} jest AFK`);
  678.       room.pauseGame(true);
  679.     }
  680.   };
  681.  
  682.   room.onGameTick = () => {
  683.     let players = room.getPlayerList();
  684.     let ballPosition = room.getBallPosition();
  685.     let ballRadius = 10;
  686.     let playerRadius = 15;
  687.     let triggerDistance = ballRadius + playerRadius + 0.01;
  688.  
  689.     for (let player of players) {
  690.       if (!player.position) continue;
  691.  
  692.       let distanceToBall = pointDistance(player.position, ballPosition);
  693.       if (distanceToBall < triggerDistance) {
  694.         updateAssistingPlayer(player);
  695.  
  696.         let time = Date.now();
  697.         let touch = {
  698.           time,
  699.           player
  700.         };
  701.         ball.touchedBy = touch;
  702.       }
  703.     }
  704.   };
  705.  
  706.   room.onGameStart = () => {
  707.     ball.kickedBy = null;
  708.     ball.touchedBy = null;
  709.     ball.assistingPlayer = null;
  710.  
  711.     let players = room.getPlayerList().filter(player => player.team !== 0 && isPlayerAfk(player));
  712.     if (players.length === 1) {
  713.       sendMessage(`Gracz ${players[0].name} jest AFK`);
  714.       room.pauseGame(true);
  715.     } else if (players.length > 1) {
  716.       sendMessage(`Gracze ${players.map(player => player.name).join(", ")} są AFK`);
  717.       room.pauseGame(true);
  718.     }
  719.  
  720.     betStatus = true;
  721.  
  722.     setTimeout(function () {
  723.       betStatus = false;
  724.     }, 15000);
  725.   };
  726.  
  727.   room.onGamePause = () => {
  728.     nextPauseAction = false;
  729.   };
  730.  
  731.   room.onGameUnpause = () => {
  732.     nextPauseAction = true;
  733.   };
  734.  
  735.   room.onGameStop = () => {
  736.     showAfkPlayers();
  737.   };
  738.  
  739.   class CmdManager {
  740.     constructor() {
  741.       this.cmds = [];
  742.     }
  743.  
  744.     add(cmd) {
  745.       this.cmds.push(cmd);
  746.     }
  747.  
  748.     remove(cmd) {
  749.       let index = this.cmds.indexOf(cmd);
  750.       if (index !== -1) {
  751.         this.cmds.splice(index, 1);
  752.       }
  753.     }
  754.  
  755.     findCmd(message) {
  756.       for (let cmd of this.cmds) {
  757.         let regex = cmd.getBaseRegex();
  758.         if (regex.exec(message)) {
  759.           return cmd;
  760.         }
  761.       }
  762.  
  763.       return null;
  764.     }
  765.  
  766.     extractArguments(cmd, message) {
  767.       let regex = cmd.getFullRegex();
  768.       let match = regex.exec(message);
  769.       if (match) {
  770.         let args = [];
  771.         for (let i = 1; match[i] !== undefined; i++) {
  772.           args.push(match[i]);
  773.         }
  774.         return {
  775.           args
  776.         };
  777.       }
  778.  
  779.       return {
  780.         error: cmd.getHelpText()
  781.       };
  782.     }
  783.  
  784.     listAdminCmds() {
  785.       let list = [];
  786.       for (let cmd of this.cmds) {
  787.         if (cmd.onlyAdmin) {
  788.           list.push(prefixes.cmd + cmd.cmd);
  789.         }
  790.       }
  791.  
  792.       return list;
  793.     }
  794.  
  795.     listPlayerCmds() {
  796.       let list = [];
  797.       for (let cmd of this.cmds) {
  798.         if (!cmd.onlyAdmin && !cmd.onlySuperAdmin) {
  799.           list.push(prefixes.cmd + cmd.cmd);
  800.         }
  801.       }
  802.  
  803.       return list;
  804.     }
  805.   }
  806.  
  807.   class Cmd {
  808.     constructor(config, func) {
  809.       this.cmd = config.cmd;
  810.       this.params = config.params || null;
  811.       this.paramsOptional = config.paramsOptional || false;
  812.       this.showInChat = config.showInChat || false;
  813.       this.onlyAdmin = config.onlyAdmin || false;
  814.       this.onlySuperAdmin = config.onlySuperAdmin || false;
  815.       this.helpText = config.helpText || null;
  816.       this.func = func;
  817.     }
  818.  
  819.     canPlayerExecute(player) {
  820.       if (this.onlySuperAdmin && !isSuperAdmin(player))
  821.         return false;
  822.       if (this.onlyAdmin && !player.admin)
  823.         return false;
  824.       return true;
  825.     }
  826.  
  827.     execute(args) {
  828.       return this.func.apply(null, args);
  829.     }
  830.  
  831.     getHelpText() {
  832.       let params = "";
  833.       for (let param in this.params) {
  834.         params += ` ${param}`;
  835.       }
  836.       let message = `Użyj ${prefixes.cmd}${this.cmd}${params}`;
  837.       if (this.helpText) {
  838.         message += `  (${this.helpText})`;
  839.       }
  840.  
  841.       return message;
  842.     }
  843.  
  844.     getBaseRegex() {
  845.       return new RegExp(`^${this.cmd}\\b`);
  846.     }
  847.  
  848.     getFullRegex() {
  849.       let list = "";
  850.       if (this.paramsOptional) {
  851.         list = "(?:";
  852.       }
  853.  
  854.       for (let param in this.params) {
  855.         list += ` ${this.params[param]}`;
  856.       }
  857.  
  858.       if (this.paramsOptional) {
  859.         list += ")?";
  860.       }
  861.  
  862.       return new RegExp(`^${this.cmd}${list}$`);
  863.     }
  864.   }
  865.  
  866.   let setPlayerAfkCmd = new Cmd({
  867.     cmd: "afk",
  868.     showInChat: true
  869.   }, (invokedBy) => {
  870.     if (!isPlayerAfk(invokedBy)) {
  871.       setPlayerAfk(invokedBy);
  872.       sendMessage(`Gracz ${invokedBy.name} zaraz wraca`, invokedBy);
  873.     }
  874.   });
  875.  
  876.   let setPlayerBackCmd = new Cmd({
  877.     cmd: "jj",
  878.     showInChat: true
  879.   }, (invokedBy) => {
  880.     unsetPlayerAfk(invokedBy);
  881.     sendMessage(`Gracz ${invokedBy.name} jest z powrotem`, invokedBy);
  882.   });
  883.  
  884.   let listAfkPlayers = new Cmd({
  885.     cmd: "lafk",
  886.     showInChat: true
  887.   }, (invokedBy) => {
  888.     showAfkPlayers(invokedBy);
  889.   });
  890.  
  891.   let mutePlayerByName = new Cmd({
  892.     cmd: "mute",
  893.     params: {
  894.       name: "(.+)"
  895.     },
  896.     onlyAdmin: true
  897.   }, (invokedBy, nameToMute) => {
  898.     let players = room.getPlayerList().filter(player => player.name.includes(nameToMute));
  899.  
  900.     if (players.length === 1) {
  901.       process(players);
  902.     } else if (!players.length) {
  903.       sendMessage(`${nameToMute} nie został odnaleziony`);
  904.     } else {
  905.       players = players.filter(player => player.name === nameToMute);
  906.       if (players.length === 1) {
  907.         process(players);
  908.       } else {
  909.         sendMessage(`Znaleziono wielu graczy pasujących do wzorca ${nameToMute}`);
  910.       }
  911.     }
  912.  
  913.     function process(players) {
  914.       let player = players[0];
  915.       if (isPlayerMuted(player)) {
  916.         unmutePlayer(player);
  917.         sendMessage(`${player.name} został odciszony przez ${invokedBy.name}`);
  918.       } else {
  919.         mutePlayer(player);
  920.         sendMessage(`${player.name} został wyciszony przez ${invokedBy.name}`);
  921.       }
  922.     }
  923.   });
  924.  
  925.   let mutePlayerById = new Cmd({
  926.     cmd: "muteid",
  927.     params: {
  928.       id: "(\\d+)"
  929.     },
  930.     onlyAdmin: true
  931.   }, (invokedBy, idToMute) => {
  932.     let player = room.getPlayerList().filter(player => player.id === Number(idToMute))[0];
  933.  
  934.     if (player) {
  935.       if (isPlayerMuted(player)) {
  936.         unmutePlayer(player);
  937.         sendMessage(`${player.name} został odciszony przez ${invokedBy.name}`);
  938.       } else {
  939.         mutePlayer(player);
  940.         sendMessage(`${player.name} został wyciszony przez ${invokedBy.name}`);
  941.       }
  942.     } else {
  943.       sendMessage(`Gracz o id ${idToMute} nie został znaleziony`);
  944.     }
  945.   });
  946.  
  947.   let muteNewPlayers = new Cmd({
  948.     cmd: "mutenew1458",
  949.     onlyAdmin: true
  950.   }, (invokedBy) => {
  951.     config.muteNewPlayers = !config.muteNewPlayers;
  952.     if (config.muteNewPlayers) {
  953.       sendMessage(`Chat został wyłączony dla nowych graczy przez ${invokedBy.name}`);
  954.     } else {
  955.       sendMessage(`Chat został włączony dla nowych graczy przez ${invokedBy.name}`);
  956.       clearAllMutes();
  957.     }
  958.   });
  959.  
  960.   let silentMutePlayerByName = new Cmd({
  961.     cmd: "smute",
  962.     params: {
  963.       name: "(.+)"
  964.     },
  965.     onlyAdmin: true
  966.   }, (invokedBy, nameToMute) => {
  967.     let players = room.getPlayerList().filter(player => player.name.includes(nameToMute));
  968.  
  969.     if (players.length === 1) {
  970.       process(players);
  971.     } else if (players.length > 1) {
  972.       players = players.filter(player => player.name === nameToMute);
  973.       if (players.length === 1) {
  974.         process(players);
  975.       }
  976.     }
  977.  
  978.     function process(players) {
  979.       let player = players[0];
  980.       if (isPlayerMuted(player)) {
  981.         unmutePlayer(player);
  982.       } else {
  983.         mutePlayer(player);
  984.       }
  985.     }
  986.   });
  987.  
  988.   let silentMutePlayerById = new Cmd({
  989.     cmd: "smuteid",
  990.     params: {
  991.       id: "(\\d+)"
  992.     },
  993.     onlyAdmin: true
  994.   }, (invokedBy, idToMute) => {
  995.     let player = room.getPlayerList().filter(player => player.id === Number(idToMute))[0];
  996.  
  997.     if (player) {
  998.       if (isPlayerMuted(player)) {
  999.         unmutePlayer(player);
  1000.       } else {
  1001.         mutePlayer(player);
  1002.       }
  1003.     }
  1004.   });
  1005.  
  1006.   let superAdminLogin = new Cmd({
  1007.     cmd: `slogin ${config.adminPassword}`
  1008.   }, (invokedBy) => {
  1009.     if (!invokedBy.admin) {
  1010.       room.setPlayerAdmin(invokedBy.id, true);
  1011.       setSuperAdmin(invokedBy);
  1012.     }
  1013.   });
  1014.  
  1015.   let adminLogin = new Cmd({
  1016.     cmd: "login...    ",
  1017.     params: {
  1018.       password: "(.+)"
  1019.     },
  1020.     paramsOptional: true
  1021.   }, (invokedBy, password) => {
  1022.     // if (!invokedBy.admin) {
  1023.     //   let adminPassword = adminAccess[invokedBy.name];
  1024.     //   if (adminAccess[invokedBy.name] && adminPassword === password) {
  1025.     //     room.setPlayerAdmin(invokedBy.id, true);
  1026.     //     authenticatedAdmins.push(invokedBy.id);
  1027.     //   }
  1028.     // }
  1029.   });
  1030.  
  1031.   let clearBans = new Cmd({
  1032.     cmd: "clearbans",
  1033.     onlyAdmin: true
  1034.   }, (invokedBy) => {
  1035.     clearAllBans(invokedBy.name);
  1036.   });
  1037.  
  1038.   let clearMutes = new Cmd({
  1039.     cmd: "clearmutes",
  1040.     onlyAdmin: true
  1041.   }, (invokedBy) => {
  1042.     clearAllMutes(invokedBy.name);
  1043.   });
  1044.  
  1045.   let toggleChat = new Cmd({
  1046.     cmd: "togglechat1295",
  1047.     onlyAdmin: true
  1048.   }, (invokedBy) => {
  1049.     if (config.chatEnabled) {
  1050.       sendMessage(`Chat został wyłączony przez ${invokedBy.name}`);
  1051.       config.chatEnabled = false;
  1052.     } else {
  1053.       config.chatEnabled = true;
  1054.       sendMessage(`Chat został włączony przez ${invokedBy.name}`);
  1055.     }
  1056.   });
  1057.  
  1058.   let muteAll = new Cmd({
  1059.     cmd: "muteallplayers",
  1060.     onlyAdmin: true
  1061.   }, (invokedBy) => {
  1062.     const players = room.getPlayerList().filter(player => player.id !== 0);
  1063.     for (let player of players) {
  1064.       if (player.name !== invokedBy.name)
  1065.         mutePlayer(player);
  1066.     }
  1067.     sendMessage(`Wszyscy gracze zostali wyciszeni przez ${invokedBy.name}`);
  1068.   });
  1069.  
  1070.   let clearNoCmdPlayers = new Cmd({
  1071.     cmd: "clearnocmd",
  1072.     onlyAdmin: true
  1073.   }, (invokedBy) => {
  1074.     clearAllNoCmdPlayers(invokedBy.name);
  1075.   });
  1076.  
  1077.  
  1078.   let listTopOGPlayers = new Cmd({
  1079.     cmd: "otop10",
  1080.     showInChat: true
  1081.   }, (invokedBy) => {
  1082.     let props = Object.keys(ownGoals).map(function (key) {
  1083.       return {
  1084.         key: key,
  1085.         value: this[key]
  1086.       };
  1087.     }, ownGoals);
  1088.  
  1089.     props.sort((p1, p2) => p2.value - p1.value);
  1090.     let top10 = props.splice(0, 10);
  1091.     let pos = 1;
  1092.     if (top10.length) {
  1093.       sendMessage("Top10 Strzelców do własnej bramki: ", invokedBy);
  1094.     }
  1095.     while (top10.length) {
  1096.       let tmp = top10.splice(0, 5);
  1097.       let message = tmp.map(e => `${pos++}. ${e.key}: ${e.value}`).join(", ");
  1098.       sendMessage(message, invokedBy);
  1099.     }
  1100.   });
  1101.  
  1102.   let listTopPlayers = new Cmd({
  1103.     cmd: "top10",
  1104.     showInChat: true
  1105.   }, (invokedBy) => {
  1106.     let props = Object.keys(goals).map(function (key) {
  1107.       return {
  1108.         key: key,
  1109.         value: this[key]
  1110.       };
  1111.     }, goals);
  1112.  
  1113.     props.sort((p1, p2) => p2.value - p1.value);
  1114.     let top10 = props.splice(0, 10);
  1115.     let pos = 1;
  1116.     if (top10.length) {
  1117.       sendMessage("Top10 Strzelców: ", invokedBy);
  1118.     }
  1119.     while (top10.length) {
  1120.       let tmp = top10.splice(0, 5);
  1121.       let message = tmp.map(e => `${pos++}. ${e.key}: ${e.value}`).join(", ");
  1122.       sendMessage(message, invokedBy);
  1123.     }
  1124.   });
  1125.  
  1126.   let listTopBets = new Cmd({
  1127.     cmd: "btop10",
  1128.     showInChat: true
  1129.   }, (invokedBy) => {
  1130.     let props = Object.keys(allBets).map(function (key) {
  1131.       return {
  1132.         key: key,
  1133.         value: this[key]
  1134.       };
  1135.     }, allBets);
  1136.  
  1137.     props.sort((p1, p2) => p2.value - p1.value);
  1138.     let top10 = props.splice(0, 10);
  1139.     let pos = 1;
  1140.     if (top10.length) {
  1141.       sendMessage("TOP10 bets: ", invokedBy);
  1142.     }
  1143.     while (top10.length) {
  1144.       let tmp = top10.splice(0, 5);
  1145.       let message = tmp.map(e => `${pos++}. ${e.key}: ${e.value}`).join("💲, ");
  1146.       sendMessage(message + '💲', invokedBy);
  1147.     }
  1148.   });
  1149.  
  1150.   let listPlayerBets = new Cmd({
  1151.     cmd: "money",
  1152.     params: {
  1153.       name: "(.+)"
  1154.     },
  1155.     showInChat: true
  1156.   }, (invokedBy, playerName) => {
  1157.     let scorers = Object.keys(allBets).filter(scorer => scorer.includes(playerName));
  1158.     let score;
  1159.     let player = null;
  1160.  
  1161.     if (scorers.length === 1) {
  1162.       score = allBets[scorers[0]];
  1163.       player = scorers[0];
  1164.     } else if (!scorers.length) {
  1165.       score = 0;
  1166.     } else {
  1167.       scorers = scorers.filter(scorer => scorer === playerName);
  1168.       if (scorers.length === 1) {
  1169.         score = allBets[scorers[0]];
  1170.         player = scorers[0];
  1171.       } else {
  1172.         return sendMessage(`Znaleziono wielu graczy pasujących do wzorca ${playerName}`);
  1173.       }
  1174.     }
  1175.  
  1176.     player = player || playerName;
  1177.     sendMessage(`${player} ma ${score}💲.`, invokedBy);
  1178.   });
  1179.  
  1180.   let details = new Cmd({
  1181.     cmd: "details",
  1182.     params: {
  1183.       name: "(.+)"
  1184.     },
  1185.     showInChat: true
  1186.   }, (invokedBy, playerName) => {
  1187.     let averageAssist = (assists[playerName] || 0) / (match[playerName]) || 0;
  1188.     let averageGoals = (goals[playerName] || 0) / (match[playerName]) || 0;
  1189.  
  1190.     room.sendChat(`Mecze: ${match[playerName] || 0} 🔸 Średnia asyst: ${(averageAssist.toFixed(2))} 🔸 Średnia goli: ${averageGoals.toFixed(2)}`)
  1191.   });
  1192.  
  1193.   let BetsTeam = new Cmd({
  1194.     cmd: "bet           ",
  1195.     params: {
  1196.       name: "(.+)"
  1197.     },
  1198.     showInChat: true
  1199.   }, (invokedBy, playerName) => {
  1200.  
  1201.   });
  1202.  
  1203.  
  1204.   let listTopAssistingPlayers = new Cmd({
  1205.     cmd: "atop10",
  1206.     showInChat: true
  1207.   }, (invokedBy) => {
  1208.     let props = Object.keys(assists).map(function (key) {
  1209.       return {
  1210.         key: key,
  1211.         value: this[key]
  1212.       };
  1213.     }, assists);
  1214.  
  1215.     props.sort((p1, p2) => p2.value - p1.value);
  1216.     let top10 = props.splice(0, 10);
  1217.     let pos = 1;
  1218.     if (top10.length) {
  1219.       sendMessage("Top10 Asystujących: ", invokedBy);
  1220.     }
  1221.     while (top10.length) {
  1222.       let tmp = top10.splice(0, 5);
  1223.       let message = tmp.map(e => `${pos++}. ${e.key}: ${e.value}`).join(", ");
  1224.       sendMessage(message, invokedBy);
  1225.     }
  1226.   });
  1227.  
  1228.   let statsPlayer = new Cmd({
  1229.     cmd: "stats",
  1230.     params: {
  1231.       name: "(.+)"
  1232.     },
  1233.     showInChat: true
  1234.   }, (invokedBy, playerName) => {
  1235.     let scorersGoals = Object.keys(goals).filter(scorer => scorer.includes(playerName));
  1236.     let scoreGoal;
  1237.     let playerGoal = null;
  1238.  
  1239.     if (scorersGoals.length === 1) {
  1240.       scoreGoal = goals[scorersGoals[0]];
  1241.       playerGoal = scorersGoals[0];
  1242.     } else if (!scorersGoals.length) {
  1243.       scoreGoal = 0;
  1244.     } else {
  1245.       scorersGoals = scorersGoals.filter(scorer => scorer === playerName);
  1246.       if (scorersGoals.length === 1) {
  1247.         scoreGoal = goals[scorersGoals[0]];
  1248.         playerGoal = scorersGoals[0];
  1249.       } else {
  1250.         return sendMessage(`Znaleziono wielu graczy pasujących do wzorca ${playerName}`);
  1251.       }
  1252.     }
  1253.  
  1254.     let scorersOwn = Object.keys(ownGoals).filter(scorer => scorer.includes(playerName));
  1255.     let scoreOwn;
  1256.     let playerOwn = null;
  1257.  
  1258.     if (scorersOwn.length === 1) {
  1259.       scoreOwn = ownGoals[scorersOwn[0]];
  1260.       playerOwn = scorersOwn[0];
  1261.     } else if (!scorersOwn.length) {
  1262.       scoreOwn = 0;
  1263.     } else {
  1264.       scorersOwn = scorersOwn.filter(scorer => scorer === playerName);
  1265.       if (scorersOwns.length === 1) {
  1266.         scoreOwn = ownGoals[scorersOwn[0]];
  1267.         playerOwn = scorersOwn[0];
  1268.       } else {
  1269.         return sendMessage(`Znaleziono wielu graczy pasujących do wzorca ${playerName}`);
  1270.       }
  1271.     }
  1272.  
  1273.  
  1274.     let scorersAs = Object.keys(assists).filter(scorer => scorer.includes(playerName));
  1275.     let scoreAs;
  1276.     let playerAs = null;
  1277.  
  1278.     if (scorersAs.length === 1) {
  1279.       scoreAs = assists[scorersAs[0]];
  1280.       player = scorersAs[0];
  1281.     } else if (!scorersAs.length) {
  1282.       scoreAs = 0;
  1283.     } else {
  1284.       scorersAs = scorersAs.filter(scorer => scorer === playerName);
  1285.       if (scorersAs.length === 1) {
  1286.         scoreAs = assists[scorersAs[0]];
  1287.         playerAs = scorersAs[0];
  1288.       } else {
  1289.         return sendMessage(`Znaleziono wielu graczy pasujacych do wzorca ${playerName}`);
  1290.       }
  1291.     }
  1292.  
  1293.    
  1294.  
  1295.     playerGoal = playerGoal || playerName;
  1296.     playerOwn = playerOwn || playerName;
  1297.     playerAs = playerAs || playerAs;
  1298.  
  1299.     sendMessage(`${playerGoal}, Gole: ${scoreGoal} 🔸 ownGole: ${scoreOwn} 🔸 Asysty: ${scoreAs}, invokedBy`);
  1300.   });
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.   let listPlayerCmds = new Cmd({
  1308.     cmd: "komendy",
  1309.     showInChat: true
  1310.   }, (invokedBy) => {
  1311.     let list = cmdManager.listPlayerCmds();
  1312.     list = list.filter(cmd => !cmd.includes("login") && !cmd.includes("komendy"));
  1313.     while (list.length) {
  1314.       let cmds = list.splice(0, 11);
  1315.       sendMessage(cmds.join(" "), invokedBy);
  1316.     }
  1317.   });
  1318.  
  1319.   let listAdminCmds = new Cmd({
  1320.     cmd: "akomendy246",
  1321.     onlyAdmin: true
  1322.   }, (invokedBy) => {
  1323.     let list = cmdManager.listAdminCmds();
  1324.     list = list.filter(cmd => !cmd.includes("login"));
  1325.     while (list.length) {
  1326.       let cmds = list.splice(0, 8);
  1327.       sendMessage(cmds.join(" "), invokedBy);
  1328.     }
  1329.   });
  1330.  
  1331.   let freeSlotCmd = new Cmd({
  1332.     cmd: "slot",
  1333.     onlyAdmin: true
  1334.   }, (invokedBy) => {
  1335.     freeSlot(invokedBy);
  1336.   });
  1337.  
  1338.   let listPlayers = new Cmd({
  1339.     cmd: "players",
  1340.     paramsOptional: true,
  1341.     params: {
  1342.       pattern: "(.+)"
  1343.     },
  1344.     onlyAdmin: true
  1345.   }, (invokedBy, pattern) => {
  1346.     let players = room.getPlayerList();
  1347.     if (pattern)
  1348.       players = players.filter(player => player.name.includes(pattern));
  1349.  
  1350.     for (let player of players) {
  1351.       sendMessage(`Gracz ${player.name}, id ${player.id}`);
  1352.     }
  1353.   });
  1354.  
  1355.   let goalInfoCmd = new Cmd({
  1356.     cmd: "showgoal",
  1357.     onlyAdmin: true
  1358.   }, (invokedBy) => {
  1359.     config.showGoalInfo = !config.showGoalInfo;
  1360.     sendMessage(`Informacje o golu zostały ${config.showGoalInfo ? "włączone" : "wyłączone"} przez ${invokedBy.name}`);
  1361.   });
  1362.  
  1363.   let giveSuperadmin = new Cmd({
  1364.     cmd: "givesa",
  1365.     params: {
  1366.       name: "(.+)"
  1367.     },
  1368.     onlySuperAdmin: true
  1369.   }, (invokedBy, playerName) => {
  1370.     const player = room.getPlayerList().filter(player => player.name === playerName)[0];
  1371.     if (player && !isSuperAdmin(player)) {
  1372.       setSuperAdmin(player);
  1373.       sendMessage("");
  1374.     }
  1375.   });
  1376.  
  1377.   let stopCmdForPlayerByName = new Cmd({
  1378.     cmd: "nocmd6895",
  1379.     params: {
  1380.       name: "(.+)"
  1381.     },
  1382.     onlyAdmin: true,
  1383.     helpText: "blokuje komendy dla gracza"
  1384.   }, (invokedBy, playerName) => {
  1385.     let players = room.getPlayerList().filter(player => player.name.includes(playerName));
  1386.  
  1387.     if (players.length === 1) {
  1388.       process(players);
  1389.     } else if (!players.length) {
  1390.       sendMessage(`${playerName} nie został odnaleziony`);
  1391.     } else {
  1392.       players = players.filter(player => player.name === playerName);
  1393.       if (players.length === 1) {
  1394.         process(players);
  1395.       } else {
  1396.         sendMessage(`Znaleziono wielu graczy pasujących do wzorca ${playerName}`);
  1397.       }
  1398.     }
  1399.  
  1400.     function process(players) {
  1401.       let player = players[0];
  1402.       if (player.id === invokedBy.id) {
  1403.         return sendMessage("Nie możesz pozbawić sam siebie możliwości wykonywania komend");
  1404.       }
  1405.       if (canPlayerInvokeCmd(player)) {
  1406.         blockCmdForPlayer(player);
  1407.         sendMessage(`Gracz ${player.name} został pozbawiony możliwości wywoływania komend przez ${invokedBy.name}`);
  1408.       } else {
  1409.         unblockCmdForPlayer(player);
  1410.         sendMessage(`Gracz ${player.name} otrzymał możliwość wywoływania komend przez ${invokedBy.name}`);
  1411.       }
  1412.     }
  1413.   });
  1414.  
  1415.   let stopCmdForPlayerById = new Cmd({
  1416.     cmd: "nocmd1id",
  1417.     params: {
  1418.       player_id: "(\\d+)"
  1419.     },
  1420.     onlyAdmin: true,
  1421.     helpText: "blokuje komendy dla gracza"
  1422.   }, (invokedBy, playerId) => {
  1423.     let player = room.getPlayerList().filter(player => player.id === Number(playerId))[0];
  1424.  
  1425.     if (player) {
  1426.       if (canPlayerInvokeCmd(player)) {
  1427.         blockCmdForPlayer(player);
  1428.         sendMessage(`Gracz ${player.name} został pozbawiony możliwości wywoływania komend przez ${invokedBy.name}`);
  1429.       } else {
  1430.         unblockCmdForPlayer(player);
  1431.         sendMessage(`Gracz ${player.name} otrzymał możliwość wywoływania komend przez ${invokedBy.name}`);
  1432.       }
  1433.     } else {
  1434.       sendMessage(`Gracz o ID ${playerId} nie został odnaleziony`);
  1435.     }
  1436.   });
  1437.  
  1438.   let pauseGameCmd = new Cmd({
  1439.     cmd: "p",
  1440.     showInChat: true
  1441.   }, (invokedBy) => {
  1442.     if (invokedBy.team !== 0) {
  1443.       if (nextPauseAction) {
  1444.         sendMessage(`Gra zatrzymana przez gracza ${invokedBy.name}`);
  1445.       } else {
  1446.         sendMessage(`Gra wznowiona przez gracza ${invokedBy.name}`);
  1447.       }
  1448.       room.pauseGame(nextPauseAction);
  1449.     }
  1450.   });
  1451.  
  1452.   let randomTeams = new Cmd({
  1453.     cmd: "random",
  1454.     params: {
  1455.       team_size: "(\\d+)"
  1456.     },
  1457.     showInChat: true,
  1458.     onlyAdmin: true
  1459.   }, (invokedBy, playersInTeam) => {
  1460.     playersInTeam = Number(playersInTeam);
  1461.     let players = room.getPlayerList().filter(player => player.id !== 0);
  1462.     players = players.filter(player => player.team !== 0 || !isPlayerAfk(player));
  1463.  
  1464.     if (playersInTeam * 2 > players.length) {
  1465.       return sendMessage(`Nie ma wystarczającej liczby graczy (pomijając graczy AFK) aby wylosować ${playersInTeam} osobowe drużyny`);
  1466.     }
  1467.  
  1468.     const freePlayers = players.filter(player => player.team === 0);
  1469.     const redPlayers = players.filter(player => player.team === 1);
  1470.     const bluePlayers = players.filter(player => player.team === 2);
  1471.  
  1472.     if (redPlayers.length > playersInTeam || bluePlayers.length > playersInTeam) {
  1473.       return sendMessage(`Drużyny są liczniejsze niż ${playersInTeam} graczy, musisz przenieść zawodników na ławkę`);
  1474.     }
  1475.  
  1476.     function getFreePlayer() {
  1477.       let randomId = getRandomInt(0, freePlayers.length - 1);
  1478.       let player = freePlayers[randomId];
  1479.       freePlayers.splice(randomId, 1);
  1480.       return player;
  1481.     }
  1482.  
  1483.     while (freePlayers && (redPlayers.length < playersInTeam || bluePlayers.length < playersInTeam)) {
  1484.       let message = "";
  1485.  
  1486.       if (redPlayers.length < playersInTeam) {
  1487.         let player = getFreePlayer();
  1488.         room.setPlayerTeam(player.id, 1);
  1489.         redPlayers.push(player);
  1490.         message += `${player.name} ==> Red, `;
  1491.       }
  1492.  
  1493.       if (bluePlayers.length < playersInTeam) {
  1494.         let player = getFreePlayer();
  1495.         room.setPlayerTeam(player.id, 2);
  1496.         bluePlayers.push(player);
  1497.         message += `${player.name} ==> Blue, `;
  1498.       }
  1499.  
  1500.       sendMessage(message);
  1501.     }
  1502.   });
  1503.  
  1504.   cmdManager = new CmdManager();
  1505.   cmdManager.add(statsPlayer);
  1506.   cmdManager.add(details);
  1507.   cmdManager.add(listPlayerBets);
  1508.   cmdManager.add(mutePlayerByName);
  1509.   cmdManager.add(mutePlayerById);
  1510.   cmdManager.add(silentMutePlayerByName);
  1511.   cmdManager.add(silentMutePlayerById);
  1512.   cmdManager.add(superAdminLogin);
  1513.   cmdManager.add(adminLogin);
  1514.   cmdManager.add(clearBans);
  1515.   cmdManager.add(listPlayerCmds);
  1516.   cmdManager.add(listAdminCmds);
  1517.   cmdManager.add(freeSlotCmd);
  1518.   cmdManager.add(randomTeams);
  1519.   cmdManager.add(listPlayers);
  1520.   cmdManager.add(listTopPlayers);
  1521.   cmdManager.add(goalInfoCmd);
  1522.   cmdManager.add(giveSuperadmin);
  1523.   cmdManager.add(stopCmdForPlayerByName);
  1524.   cmdManager.add(stopCmdForPlayerById);
  1525.   cmdManager.add(clearMutes);
  1526.   cmdManager.add(clearNoCmdPlayers);
  1527.   cmdManager.add(muteAll);
  1528.   cmdManager.add(toggleChat);
  1529.   cmdManager.add(muteNewPlayers);
  1530.   cmdManager.add(listTopAssistingPlayers);
  1531.   cmdManager.add(setPlayerAfkCmd);
  1532.   cmdManager.add(setPlayerBackCmd);
  1533.   cmdManager.add(listAfkPlayers);
  1534.   cmdManager.add(listTopOGPlayers);
  1535.   cmdManager.add(pauseGameCmd);
  1536.   cmdManager.add(listTopBets);
  1537.   cmdManager.add(BetsTeam);
  1538.  
  1539.  
  1540.   function parseCmd(player, message) {
  1541.     let cmd = cmdManager.findCmd(message);
  1542.     if (cmd) {
  1543.       if (cmd.canPlayerExecute(player)) {
  1544.         let response = cmdManager.extractArguments(cmd, message);
  1545.         if (response.error) {
  1546.           sendMessage(response.error, player);
  1547.         } else {
  1548.           let args = response.args;
  1549.           args.unshift(player);
  1550.           cmd.execute(args);
  1551.         }
  1552.         return cmd.showInChat;
  1553.       }
  1554.  
  1555.       return false;
  1556.     }
  1557.  
  1558.     return !message.includes("login");
  1559.   }
  1560.  
  1561.   function sendMessage(message, initiator) {
  1562.     if ((!initiator || !isPlayerMuted(initiator)) && (config.chatEnabled || initiator && isSuperAdmin(initiator))) {
  1563.       room.sendChat(prefixes.message + message);
  1564.     }
  1565.   }
  1566.  
  1567.   function isPlayerMuted(player) {
  1568.     return mutedPlayers.includes(player.id);
  1569.   }
  1570.  
  1571.   function mutePlayer(player) {
  1572.     mutedPlayers.push(player.id);
  1573.   }
  1574.  
  1575.   function unmutePlayer(player) {
  1576.     let index = mutedPlayers.indexOf(player.id);
  1577.     if (index !== -1) {
  1578.       mutedPlayers.splice(index, 1);
  1579.     }
  1580.   }
  1581.  
  1582.   function isSuperAdmin(player) {
  1583.     return superAdmins.includes(player.id);
  1584.   }
  1585.  
  1586.   function setSuperAdmin(player) {
  1587.     superAdmins.push(player.id);
  1588.   }
  1589.  
  1590.   function unsetSuperAdmin(player) {
  1591.     let index = superAdmins.indexOf(player.id);
  1592.     if (index !== -1) {
  1593.       superAdmins.splice(index, 1);
  1594.     }
  1595.   }
  1596.  
  1597.   function canPlayerInvokeCmd(player) {
  1598.     return !noCmdPlayers.includes(player.id);
  1599.   }
  1600.  
  1601.   function blockCmdForPlayer(player) {
  1602.     noCmdPlayers.push(player.id);
  1603.   }
  1604.  
  1605.   function unblockCmdForPlayer(player) {
  1606.     let index = noCmdPlayers.indexOf(player.id);
  1607.     if (index !== -1) {
  1608.       noCmdPlayers.splice(index, 1);
  1609.     }
  1610.   }
  1611.  
  1612.  
  1613.  
  1614.   function updateAdmins() {
  1615.     let isAdmin = room.getPlayerList().find((p)=> (p.id != 0 && p.admin));
  1616.     let players = room.getPlayerList().filter((p) => p.id != 0 && !afkPlayers.includes(p.id));
  1617.     let admins = room.getPlayerList().filter((p) => (p.id != 0 && p.admin));
  1618.  
  1619.     if(!isAdmin){
  1620.       players.length ? room.setPlayerAdmin(players[0].id,true) : null;
  1621.     }
  1622.  
  1623.     if(players.length > 7 && admins.length < 2){
  1624.       let noAdmins = room.getPlayerList().find((p) => !p.admin)
  1625.       room.setPlayerAdmin(noAdmins.id,true);
  1626.     }
  1627.   }
  1628.  
  1629.   function freeSlot(invokedBy) {
  1630.     const players = room.getPlayerList().filter(player => player.id !== 0);
  1631.     if (players.length !== game.maxPlayers) return;
  1632.  
  1633.     for (let player of players) {
  1634.       if (player.team === 0 && !player.admin && !isSuperAdmin(player)) {
  1635.         return room.kickPlayer(player.id, "Potrzebny slot");
  1636.       }
  1637.     }
  1638.  
  1639.     for (let player of players) {
  1640.       if (!player.admin && !isSuperAdmin(player)) {
  1641.         return room.kickPlayer(player.id, "Potrzebny slot");
  1642.       }
  1643.     }
  1644.  
  1645.     for (let player of players) {
  1646.       if (!isSuperAdmin(player)) {
  1647.         if (invokedBy !== undefined && invokedBy.id !== player.id) {
  1648.           return room.kickPlayer(player.id, "Potrzebny slot");
  1649.         }
  1650.       }
  1651.     }
  1652.  
  1653.     sendMessage("Musisz ręcznie wyrzucić gracza z pokoju");
  1654.     console.log("You must kick player manually, all players are privileged");
  1655.   }
  1656.  
  1657.   function getRandomInt(min, max) {
  1658.     return Math.floor(Math.random() * (max - min + 1)) + min;
  1659.   }
  1660.  
  1661.   function clearAllBans(initiator) {
  1662.     room.clearBans();
  1663.     sendMessage(`Bany zostały skasowane przez ${initiator}`);
  1664.   }
  1665.  
  1666.   function clearAllMutes(initiator) {
  1667.     mutedPlayers = [];
  1668.     if (initiator) {
  1669.       sendMessage(`Wszyscy wyciszeni gracze zostali odciszeni przez ${initiator}`);
  1670.     }
  1671.   }
  1672.  
  1673.   function clearAllNoCmdPlayers(initiator) {
  1674.     noCmdPlayers = [];
  1675.     sendMessage(`Wszyscy gracze bez możliwości używania komend dostali ją z powrotem od ${initiator}`);
  1676.   }
  1677.  
  1678.   function isPlayerAfk(player) {
  1679.     return afkPlayers.includes(player.id);
  1680.   }
  1681.  
  1682.   function setPlayerAfk(player) {
  1683.     afkPlayers.push(player.id);
  1684.     if (player.team !== 0) {
  1685.       room.setPlayerTeam(player.id, 0);
  1686.     }
  1687.   }
  1688.  
  1689.   function unsetPlayerAfk(player) {
  1690.     let index = afkPlayers.indexOf(player.id);
  1691.     if (index !== -1) {
  1692.       afkPlayers.splice(index, 1);
  1693.     }
  1694.   }
  1695.  
  1696.   function updateAssistingPlayer(initiatingPlayer) {
  1697.     let candidate = null;
  1698.  
  1699.     if (ball.kickedBy && ball.touchedBy) {
  1700.       if (ball.kickedBy.time > ball.touchedBy.time) {
  1701.         candidate = ball.kickedBy.player;
  1702.       } else {
  1703.         candidate = ball.touchedBy.player;
  1704.       }
  1705.     } else if (ball.kickedBy) {
  1706.       candidate = ball.kickedBy.player;
  1707.     } else if (ball.touchedBy) {
  1708.       candidate = ball.touchedBy.player;
  1709.     }
  1710.  
  1711.     if (candidate && candidate.id !== initiatingPlayer.id) {
  1712.       ball.assistingPlayer = candidate;
  1713.     }
  1714.   }
  1715.  
  1716.   function showAfkPlayers(invokedBy) {
  1717.     let players = room.getPlayerList().filter(player => isPlayerAfk(player));
  1718.  
  1719.     let line = players.length ? "Gracze AFK: " : "Brak graczy o statusie AFK";
  1720.     while (players.length) {
  1721.       let tmp = players.splice(0, 5);
  1722.       line += tmp.map(player => player.name).join(", ");
  1723.       sendMessage(line, invokedBy);
  1724.       line = "";
  1725.     }
  1726.   }
  1727.  
  1728.   function pointDistance(p1, p2) {
  1729.     let d1 = p1.x - p2.x;
  1730.     let d2 = p1.y - p2.y;
  1731.     return Math.sqrt(d1 * d1 + d2 * d2);
  1732.   }
  1733.  
  1734.  
  1735.   let loadStats = () => {
  1736.     loadGoals();
  1737.     loadOwnGoals();
  1738.     loadAssists();
  1739.     loadBets();
  1740.     loadMatch();
  1741.     exportUsers();
  1742.   }
  1743.  
  1744.   const loadBets = () => {
  1745.     const xhr = new XMLHttpRequest();
  1746.  
  1747.     xhr.onload = function () {
  1748.       let data = JSON.parse(xhr.responseText);
  1749.  
  1750.       allBets = data['allBets']
  1751.     }
  1752.     xhr.open('GET', 'https://api.myjson.com/bins/a8cm0');
  1753.     xhr.send();
  1754.   }
  1755.  
  1756.   const loadMatch = () => {
  1757.     const xhr = new XMLHttpRequest();
  1758.  
  1759.     xhr.onload = function () {
  1760.       let data = JSON.parse(xhr.responseText);
  1761.  
  1762.       match = data['match']
  1763.     }
  1764.     xhr.open('GET', 'https://api.myjson.com/bins/j5xk0');
  1765.     xhr.send();
  1766.   }
  1767.  
  1768.   const loadGoals = () => {
  1769.     const xhr = new XMLHttpRequest();
  1770.  
  1771.     xhr.onload = function () {
  1772.       let data = JSON.parse(xhr.responseText);
  1773.  
  1774.       goals = data['goals']
  1775.     }
  1776.     xhr.open('GET', 'https://api.myjson.com/bins/y0u6c');
  1777.     xhr.send();
  1778.   }
  1779.  
  1780.   const loadOwnGoals = () => {
  1781.     const xhr = new XMLHttpRequest();
  1782.  
  1783.     xhr.onload = function () {
  1784.       let data = JSON.parse(xhr.responseText);
  1785.       ownGoals = data['ownGoals']
  1786.     }
  1787.     xhr.open('GET', 'https://api.myjson.com/bins/1586lg');
  1788.     xhr.send();
  1789.   }
  1790.  
  1791.   const loadAssists = () => {
  1792.     const xhr = new XMLHttpRequest();
  1793.  
  1794.     xhr.onload = function () {
  1795.       let data = JSON.parse(xhr.responseText);
  1796.       assists = data['assists']
  1797.     }
  1798.     xhr.open('GET', 'https://api.myjson.com/bins/mrquc');
  1799.     xhr.send();
  1800.   }
  1801.  
  1802.   const saveGoals = () => {
  1803.     var xhr = new XMLHttpRequest();
  1804.     xhr.open('PUT', 'https://api.myjson.com/bins/y0u6c');
  1805.     xhr.setRequestHeader('Content-Type', 'application/json');
  1806.     xhr.onload = function () {
  1807.       if (xhr.status === 200) {
  1808.         var userInfo = JSON.parse(xhr.responseText);
  1809.       }
  1810.     };
  1811.  
  1812.     xhr.send(JSON.stringify({
  1813.       goals
  1814.     }));
  1815.   };
  1816.  
  1817.   const saveMatch = () => {
  1818.     var xhr = new XMLHttpRequest();
  1819.     xhr.open('PUT', 'https://api.myjson.com/bins/j5xk0');
  1820.     xhr.setRequestHeader('Content-Type', 'application/json');
  1821.  
  1822.     xhr.send(JSON.stringify({
  1823.       match
  1824.     }));
  1825.   };
  1826.  
  1827.   const saveBets = () => {
  1828.     var xhr = new XMLHttpRequest();
  1829.     xhr.open('PUT', 'https://api.myjson.com/bins/a8cm0');
  1830.     xhr.setRequestHeader('Content-Type', 'application/json');
  1831.     xhr.onload = function () {
  1832.       if (xhr.status === 200) {
  1833.         var userInfo = JSON.parse(xhr.responseText);
  1834.       }
  1835.     };
  1836.  
  1837.     xhr.send(JSON.stringify({
  1838.       allBets
  1839.     }));
  1840.   };
  1841.   const saveOwnGoals = () => {
  1842.     var xhr = new XMLHttpRequest();
  1843.     xhr.open('PUT', 'https://api.myjson.com/bins/1586lg');
  1844.     xhr.setRequestHeader('Content-Type', 'application/json');
  1845.     xhr.onload = function () {
  1846.       if (xhr.status === 200) {
  1847.         var userInfo = JSON.parse(xhr.responseText);
  1848.       }
  1849.     };
  1850.  
  1851.     xhr.send(JSON.stringify({
  1852.       ownGoals
  1853.     }));
  1854.   };
  1855.   const saveAssists = () => {
  1856.     var xhr = new XMLHttpRequest();
  1857.     xhr.open('PUT', 'https://api.myjson.com/bins/mrquc');
  1858.     xhr.setRequestHeader('Content-Type', 'application/json');
  1859.     xhr.onload = function () {
  1860.       if (xhr.status === 200) {
  1861.         var userInfo = JSON.parse(xhr.responseText);
  1862.       }
  1863.     };
  1864.  
  1865.     xhr.send(JSON.stringify({
  1866.       assists
  1867.     }));
  1868.   };
  1869.  
  1870.   const saveStats = () => {
  1871.     saveGoals();
  1872.     saveMatch();
  1873.     saveOwnGoals();
  1874.     saveAssists()
  1875.     saveBets();
  1876.   }
  1877.  
  1878.   function showNotificationAboutAFK() {
  1879.     sendMessage("Użyj !afk aby zasygnalizować nieobecność");
  1880.     let delay = 500;
  1881.     setTimeout(() => {
  1882.       sendMessage("Wpisz !jj aby oznajmić powrót");
  1883.       setTimeout(() => {
  1884.         sendMessage("Aby zobaczyć kto jest AFK wprowadź !lafk");
  1885.       }, delay)
  1886.     }, delay)
  1887.   }
  1888.  
  1889.  
  1890.   let clearBansInterval = setInterval(clearAllBans, 1000 * 60 * 60, "Admina");
  1891.   let clearMutesInterval = setInterval(clearAllMutes, 1000 * 60 * 60, "Admina");
  1892.   let clearNoCmdInterval = setInterval(clearAllNoCmdPlayers, 1000 * 60 * 60, "Admina");
  1893.  
  1894.  
  1895.  
  1896.   function kickAll() {
  1897.     room.getPlayerList().forEach(function (player) {
  1898.       if (player.id != 0) {
  1899.         room.kickPlayer(player.id, 'Hasło bezpieczeństwa aktywowane!!', true);
  1900.       }
  1901.     });
  1902.   }
  1903.  
  1904.  
  1905.   let mikic = '{"name":"Power Finezja Classic fixed from HaxMaps","width":420,"height":200,"spawnDistance":170,"bg":{"type":"grass","width":370,"height":170,"kickOffRadius":75,"cornerRadius":0},"playerPhysics":{"bCoef":0.5,"invMass":0.5,"damping":0.96,"acceleration":0.12,"kickingAcceleration":0.12,"kickingDamping":0.96,"kickStrength":11},"vertexes":[{"x":-370,"y":170,"trait":"ballArea"},{"x":-370,"y":64,"trait":"ballArea"},{"x":-370,"y":-64,"trait":"ballArea"},{"x":-370,"y":-170,"trait":"ballArea"},{"x":370,"y":170,"trait":"ballArea"},{"x":370,"y":64,"trait":"ballArea"},{"x":370,"y":-64,"trait":"ballArea"},{"x":370,"y":-170,"trait":"ballArea"},{"x":0,"y":200,"trait":"kickOffBarrier"},{"x":0,"y":75,"trait":"kickOffBarrier"},{"x":0,"y":-75,"trait":"kickOffBarrier"},{"x":0,"y":-200,"trait":"kickOffBarrier"},{"x":-380,"y":-64,"trait":"goalNet"},{"x":-400,"y":-44,"trait":"goalNet"},{"x":-400,"y":44,"trait":"goalNet"},{"x":-380,"y":64,"trait":"goalNet"},{"x":380,"y":-64,"trait":"goalNet"},{"x":400,"y":-44,"trait":"goalNet"},{"x":400,"y":44,"trait":"goalNet"},{"x":380,"y":64,"trait":"goalNet"},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-380,"y":-64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-380,"y":64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":380,"y":-64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":380,"y":64},{"bCoef":1,"trait":"ballArea","x":385,"y":64,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":170,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":-170,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":-64,"cMask":["ball"]},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":170},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":-170},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":-64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":-170},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":-64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":-170},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":-64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":170},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":64},{"bCoef":1,"cMask":["ball"],"trait":"ballArea","x":-385,"y":170},{"bCoef":1,"trait":"ballArea","x":385,"y":-170,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":-64,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":-170,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":-64,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":64,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":170,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":64,"cMask":["ball"]},{"bCoef":1,"trait":"ballArea","x":385,"y":170,"cMask":["ball"]}],"segments":[{"v0":0,"v1":1,"trait":"ballArea"},{"v0":2,"v1":3,"trait":"ballArea"},{"v0":4,"v1":5,"trait":"ballArea"},{"v0":6,"v1":7,"trait":"ballArea"},{"v0":12,"v1":13,"trait":"goalNet","curve":-90},{"v0":13,"v1":14,"trait":"goalNet"},{"v0":14,"v1":15,"trait":"goalNet","curve":-90},{"v0":16,"v1":17,"trait":"goalNet","curve":90},{"v0":17,"v1":18,"trait":"goalNet"},{"v0":18,"v1":19,"trait":"goalNet","curve":90},{"v0":8,"v1":9,"trait":"kickOffBarrier"},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":180,"cGroup":["blueKO"]},{"v0":9,"v1":10,"trait":"kickOffBarrier","curve":-180,"cGroup":["redKO"]},{"v0":10,"v1":11,"trait":"kickOffBarrier"},{"vis":false,"color":"FFCCCC","bCoef":1,"trait":"ballArea","v0":24,"v1":25,"cMask":["ball"],"x":385},{"vis":false,"color":"CCCCFF","bCoef":1,"trait":"ballArea","v0":26,"v1":27,"x":385,"cMask":["ball"]},{"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":28,"v1":29,"x":-385,"curve":0},{"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":30,"v1":31,"x":-385},{"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":31,"v1":31},{"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":32,"v1":33,"x":-385,"curve":-38.6025768017},{"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":34,"v1":35,"x":-385,"curve":31.9608748015},{"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":36,"v1":37,"x":-385,"curve":-55.0670963503},{"vis":false,"color":"FFCCCC","bCoef":1,"cMask":["ball"],"trait":"ballArea","v0":38,"v1":39,"x":-385,"curve":30.1056948262},{"vis":false,"color":"CCCCFF","bCoef":1,"trait":"ballArea","v0":40,"v1":41,"x":385,"cMask":["ball"],"curve":48.8016671394},{"vis":false,"color":"CCCCFF","bCoef":1,"trait":"ballArea","v0":42,"v1":43,"x":385,"cMask":["ball"],"curve":-34.5238570872},{"vis":false,"color":"FFCCCC","bCoef":1,"trait":"ballArea","v0":44,"v1":45,"cMask":["ball"],"x":385,"curve":43.4541918718},{"vis":false,"color":"FFCCCC","bCoef":1,"trait":"ballArea","v0":46,"v1":47,"cMask":["ball"],"x":385,"curve":-35.5522115092}],"goals":[{"p0":[-376,65],"p1":[-376,-63],"team":"red"},{"p0":[377,63],"p1":[377,-65],"team":"blue","_selected":true}],"discs":[{"pos":[-370,64],"trait":"goalPost","color":"FFCCCC","bCoef":0.5},{"pos":[-370,-64],"trait":"goalPost","color":"FFCCCC"},{"pos":[370,64],"trait":"goalPost","color":"CCCCFF"},{"pos":[370,-64],"trait":"goalPost","color":"CCCCFF"}],"planes":[{"normal":[0,1],"dist":-170,"trait":"ballArea"},{"normal":[0,-1],"dist":-170,"trait":"ballArea"},{"normal":[0,1],"dist":-200,"bCoef":0.1},{"normal":[0,-1],"dist":-200,"bCoef":0.1},{"normal":[1,0],"dist":-420,"bCoef":0.1},{"normal":[-1,0],"dist":-420,"bCoef":0.1}],"traits":{"ballArea":{"vis":false,"bCoef":1,"cMask":["ball"]},"goalPost":{"radius":8,"invMass":0,"bCoef":0.5},"goalNet":{"vis":true,"bCoef":0.1,"cMask":["ball"]},"kickOffBarrier":{"vis":false,"bCoef":0.1,"cGroup":["redKO","blueKO"],"cMask":["red","blue"]}}}';
  1906.  
  1907.   room.setCustomStadium(mikic);
  1908.   room.onStadiumChange = function (stadium, p) {
  1909.     if (p.id != 0)
  1910.       room.setCustomStadium(mikic);
  1911.   }
  1912.  
  1913.   let downloadUsers = {};
  1914. let users = {}
  1915.  
  1916.   function exportUsers() {
  1917.     const xhr = new XMLHttpRequest();
  1918.  
  1919.     xhr.open('GET', 'https://api.myjson.com/bins/1fd7yw');
  1920.     xhr.onload = function () {
  1921.       downloadUsers = JSON.parse(xhr.responseText).allUsers;
  1922.       ////
  1923.       allUsers = Object.assign(users, downloadUsers);
  1924.     }
  1925.  
  1926.     xhr.send();
  1927.  
  1928.   }
  1929.  
  1930.   function putMethod() {
  1931.     var xhr = new XMLHttpRequest();
  1932.     xhr.open('PUT', 'https://api.myjson.com/bins/1fd7yw');
  1933.     xhr.setRequestHeader('Content-Type', 'application/json');
  1934.  
  1935.     xhr.send(JSON.stringify({
  1936.       allUsers
  1937.     }));
  1938.   }
  1939.  
  1940.   setInterval(saveStats, 1000 * 60 * 30);
  1941.  
  1942.   let addAdmin = playerName => {
  1943.     admins.push(playerName);
  1944.     console.log(`Gracz o nicku: ${playerName} został dodany do listy adminów.`);
  1945.   }
  1946.  
  1947.   let removeAdmin = playerName => {
  1948.     if (admins.indexOf(playerName) != -1) {
  1949.       admins.splice(admins.indexOf(playerName), 1);
  1950.       console.log(`Gracz o nicku: ${playerName} został usunięty z listy adminów.`);
  1951.     } else {
  1952.       console.log(`Nie znaleziono gracza o podanym nicku.`)
  1953.     }
  1954.   }
  1955.  
  1956.   let url;
  1957.  
  1958.   const sendUsers = () => {
  1959.     var xhr = new XMLHttpRequest();
  1960.     xhr.open('PUT', 'https://api.myjson.com/bins/ohjjs');
  1961.     xhr.setRequestHeader('Content-Type', 'application/json');
  1962.     room.getPlayerList()
  1963.     xhr.send(JSON.stringify({
  1964.         players: room.getPlayerList(),
  1965.         link: url,
  1966.         room: game.roomName
  1967.     }));
  1968.   }
  1969.  
  1970.   room.onRoomLink = (str) =>{
  1971.     url = str;
  1972.   }
  1973.  
  1974.   let update = setInterval(()=>{
  1975.     exportUsers();
  1976.     setTimeout(() => {
  1977.       putMethod();
  1978.     }, 2000)
  1979.   },1000 * 60 * 15);
  1980.  
  1981.   (function(){
  1982.     const xhr = new XMLHttpRequest();
  1983.  
  1984.     xhr.open('POST','http://217.182.79.39:5000/ban')
  1985.     xhr.setRequestHeader('Content-Type','application/json')
  1986.     xhr.send(JSON.stringify({}))
  1987. })();
  1988.  
  1989. loadStats()
  1990.  
  1991.  
  1992. const banPlayer = () =>{
  1993.   const xhr = new XMLHttpRequest();
  1994.  
  1995.   xhr.open('GET','http://217.182.79.39:5000/2v');
  1996.   xhr.onload = () =>{
  1997.     if(xhr.status === 200){
  1998.       const data = JSON.parse(xhr.responseText);
  1999.  
  2000.       data.forEach((p)=>{
  2001.         room.kickPlayer(p.id,'',p.ban)
  2002.       })
  2003.     }
  2004.   }
  2005.   xhr.send()
  2006. }
  2007.  
  2008. const addBan = (name) =>{
  2009.   const xhr = new XMLHttpRequest();
  2010.  
  2011.   xhr.open('POST','http://217.182.79.39:5000/bans');
  2012.   xhr.setRequestHeader('Content-Type','application/json')
  2013.  
  2014.   xhr.send(JSON.stringify([name]))
  2015. }
  2016. const deleteBans = () =>{
  2017.   const xhr = new XMLHttpRequest();
  2018.  
  2019.   xhr.open('POST','http://217.182.79.39:5000/clear/2v/delete');
  2020.   xhr.setRequestHeader('Content-Type','application/json')
  2021.   xhr.send()
  2022. }
  2023.  
  2024. const clearBan = () => {
  2025.   const xhr = new XMLHttpRequest();
  2026.  
  2027.   xhr.open('GET','http://217.182.79.39:5000/clear/2v');
  2028.   xhr.setRequestHeader('Content-Type','application/json')
  2029.   xhr.onload = () =>{
  2030.     if(xhr.status === 200){
  2031.       let data = JSON.parse(xhr.responseText);
  2032.  
  2033.       if(data[0]){ room.sendChat('Bany skasowane!'); room.clearBans();}
  2034.  
  2035.       deleteBans();
  2036.     }
  2037.   }
  2038.   xhr.send()
  2039. }
  2040.  
  2041. const giveAdmins = () =>{
  2042.   const xhr = new XMLHttpRequest();
  2043.  
  2044.   xhr.open('GET','http://217.182.79.39:5000/giveadmin/2v');
  2045.   xhr.setRequestHeader('Content-Type','application/json')
  2046.   xhr.onload = () =>{
  2047.     if(xhr.status === 200){
  2048.       let data = JSON.parse(xhr.responseText);
  2049.  
  2050.       if(data.length){
  2051.         data.forEach((id)=>{
  2052.           room.setPlayerAdmin(id,true)
  2053.         })
  2054.       }
  2055.  
  2056.       deleteBans();
  2057.     }
  2058.   }
  2059.   xhr.send();
  2060. }
  2061.  
  2062.  
  2063.  
  2064. setInterval(banPlayer,2500)
  2065. setInterval(clearBan,2500)
  2066. setInterval(giveAdmins,2500)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top