/** * @author João Reis * Caso o serviço Tmux seja desligado e/ou a sessão estiver desligada passar para false e/ou true para a base de dados aos respetivos servidores * @param $IdUtilizador */ function updateRunningServers($IdUtilizador) { global $conn; $Servidores = array(); $Servidores = getServidoresByIdUtilizador($IdUtilizador); $ServersOn = array(); $ServersOn = getRunningServers(); foreach ($Servidores as $Servidor) { // Atualizar base de dados consuante sessoes do Tmux estiverem ativas ou nao $server = new Servidor($Servidor['Id'], $conn); $server->getInfo(); #$server->getFullStatus(); #$serverUpdate = new Servidor($ServersOn[$]); if ($server->getStatus() == true) { $Ligado = false; if (count($ServersOn)) { foreach ($ServersOn as $ServerOn) { if ($ServerOn == $server->getId()) { $Ligado = true; break; // Dar Break ao foreach ServersOn e continuar o Foreach Servidores. o Servidor continua online } } } // Se nao estiver ligado passar para desligado na base de dados if (!$Ligado) { $server->setStatus(0); $server->atualizaInfo(); } } else { $Ligado = false; if (count($ServersOn)) { foreach ($ServersOn as $ServerOn) { if ($ServerOn == $server->getId()) { // Se o servidor esta aqui significa que esta online mas esta offline na base de dados. Passar servidor para online na base de dados $Ligado = true; break; } } } // Se estiver Ligado entao passar para ligado na base de dados if ($Ligado) { $server->setStatus(1); $server->atualizaInfo(); } } } }
$Uti = array("Nome" => utf8_encode($User->getNome()), "Apelido" => utf8_encode($User->getApelido()), "Email" => utf8_encode($User->getEmail()), "Id" => $User->getId(), "IdTema" => $User->getIdTema(), "NomeTema" => $User->getNomeTema(), "IsAdmin" => $User->isAdmin(), "OldUser" => $OldUser, "OldId" => $OldUserC->getId(), "OldNome" => utf8_encode($OldUserC->getNome()), "OldApelido" => utf8_encode($OldUserC->getApelido()), "OldEmail" => utf8_encode($OldUserC->getEmail())); } else { $Uti = array("Nome" => utf8_encode($User->getNome()), "Apelido" => utf8_encode($User->getApelido()), "Email" => utf8_encode($User->getEmail()), "Id" => $User->getId(), "IdTema" => $User->getIdTema(), "NomeTema" => $User->getNomeTema(), "IsAdmin" => $User->isAdmin(), "OldUser" => $OldUser); } $smarty->debugging = false; $smarty->caching = false; $smarty->cache_lifetime = 10; $smarty->assign("NomeTema", utf8_encode($User->getPastaTema()), true); $smarty->assign("PastaTema", utf8_encode($User->getPastaTema()), true); $smarty->assign("Titulo", "Cyber-Panel", true); $smarty->assign("Zona", utf8_encode($linguagens[$User->getLinguagem()]['zona_servidor'] . " :: " . $Servidor->getNomeServidor()), true); $smarty->assign("Utilizador", $Uti); $smarty->assign("Infos", array("NumServidores" => count(getServidoresByIdUtilizador($User->getId())), "NumServidoresOnline" => count(getServidoresByIdUtilizadorAndStatus($User->getId(), 1)), "NumServidoresOffline" => count(getServidoresByIdUtilizadorAndStatus($User->getId(), 0)), "NumSlotsOcupados" => $slotsOcupados)); $smarty->assign("TiposServidores", getAllTiposServidores()); $smarty->assign("Servidores", getServidoresByIdUtilizador($User->getId())); $smarty->assign("Servidor", array("Id" => $Servidor->getId(), "IdUtilizador" => $Servidor->getIdUtilizador(), "TipoServidor" => $Servidor->getTipoServidor(), "NomeTipoServidor" => $Servidor->getNomeTipoServidor(), "NomeServidor" => $Servidor->getNomeServidor(), "Ip" => $Servidor->getIp(), "Porta" => $Servidor->getPorta(), "PortaQuery" => $Servidor->getPortaQuery(), "Mapa" => $Servidor->getMapaAtual(), "MapaDb" => $Servidor->getMapaInicial(), "Motd" => $Servidor->getMotd(), "MaxSlots" => $Servidor->getMaxSlots(), "MaxSlotsDb" => $Servidor->getMaxSlotsDb(), "Slots" => $Servidor->getSlots(), "Jogadores" => $Servidor->getJogadores(), "Instalado" => $Servidor->isInstalado(), "OnlineMode" => $Servidor->getOnlineMode(), "FTP_User" => $Servidor->getFTPUser(), "FTP_Password" => $Servidor->getFTPPassword(), "Status" => $Servidor->getStatus())); $smarty->assign("Lang", $linguagens[$User->getLinguagem()]); $smarty->display($User->getPastaTema() . '/servidor.tpl'); #$smarty->display('Metromega/index.tpl'); ?> <script type="text/javascript"> function Redirect (url) { var ua = navigator.userAgent.toLowerCase(), isIE = ua.indexOf('msie') !== -1, version = parseInt(ua.substr(4, 2), 10); // Internet Explorer 8 and lower if (isIE && version < 9) { var link = document.createElement('a'); link.href = url; document.body.appendChild(link);
#$smarty->display('Metromega/index.tpl'); ?> <script type="text/javascript"> setInterval(function(){ <?php $Servidores = array(); $Servidores = getServidorByTipoServidorAndIdUtilizador($Tipo, $User->getId()); foreach ($Servidores as $Servidor) { $server = new Servidor($Servidor['Id'], $conn); ?> // Pedido Ajax para atualizar status do servidor como os Slots usados, Slots maximos, e mapa atual. // Pedido Ajax para atualizar status do servidor como os Slots usados, Slots maximos, e mapa atual. $.get("includes/api.php", {Id:"<?php echo $server->getId(); ?> ", AJAX: "Info"}, function(Result){ if(Result.Status) { $("#Slots<?php echo $server->getId(); ?> ").text(Result.Slots); // console.log("Updated "+Result.Id+"!"); if(Result.Online == 0) { $("#Status"+Result.Id).html("<font color='red'>Offline</font>"); }