Mine sisusse
Otsi siit
  • Rohkem valikuid...
Otsi tulemusi mis sisaldab...
Otsi tulemusi...
Jälgi teemat sisse logides  

Muud skriptid.

Soovitatud postitused

Slottide ehk mängijate arvude kontrollimine cPGS süsteemis

cPGS süsteemis oli kunagi võimalik server.cfg faili abil Counter-Strike serverite slottide arvu suurendada.

See süsteem võrdles lubatud slottide arvu cron tööga ning muutis serveri slotiarvu õigeks kui osutus valeks ning stoppis ja startis Counter-Strike serveri.

 

 

Toimis ka San Andreas - Multiplayer ja teistel mänguserveriltel. Süsteem piltlikult toimis nii, et masterkasutajaga loodi FTP kasutaja kliendi serveri konfiguratsioonile ligipääsuks ning automaatselt kontrollis cron kaudu. Kui FTP konto oli kasutaja poolt kustutatud, loodi automaatselt uus kasutaja.

 

 

cron käsk

php -q -f /home/fcee/slot/check.php

 

 

check.php ehk fail millele cron tuli jooksma seadistada.


/*


-- DB:


CREATE TABLE IF NOT EXISTS `ftp` (
 `id` int(11) NOT NULL,
 `username` varchar(50) NOT NULL,
 `password` varchar(50) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


--
-- Dumping data for table `ftp`
--




-- --------------------------------------------------------


--
-- Table structure for table `servers`
--


CREATE TABLE IF NOT EXISTS `servers` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `server` varchar(255) NOT NULL,
 `username` varchar(255) NOT NULL,
 `ip` varchar(20) NOT NULL,
 `slots` int(11) NOT NULL,
 `cfg` varchar(255) NOT NULL,
 `stop` varchar(255) NOT NULL,
 `start` varchar(255) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


--
-- Dumping data for table `servers`
--


INSERT INTO `servers` (`id`, `server`, `username`, `ip`, `slots`, `cfg`, `stop`, `start`) VALUES
(1, 'smsscripts.net', 'scripts', '127.0.0.1', 2, '/.gameservers/cstrike_0/cstrike/server.cfg', 'http://www.cf.ee:2082/frontend/x3/gameserv/Ctl.html?game=cstrike&n=0&ctl=stop', 'http://www.cf.ee:2082/frontend/x3/gameserv/Ctl.html?ctl=start&n=0&game=cstrike');


*/
$checkPlayers = true;
$checkBinds = true;


$dBserver = '127.0.0.1';
$dBusername = '';
$dBpassword = '';
$dBdatabase = '';
$adminEmail = '';


$password = ''; // master password
$ftpUsername = 'ftps';


mysql_connect($dBserver, $dBusername, $dBpassword) or die();
mysql_select_db($dBdatabase);


$query = "SELECT s.*, f.username AS ftp_username, f.password AS ftp_password FROM servers s LEFT JOIN ftp f ON s.id = f.id";
$result = mysql_query($query);


function update($server, $fileContents) {
   $ftpCon = ftp_connect($server['server']);

   ftp_login($ftpCon, $server['ftp_username'], $server['ftp_password']);
   ftp_pasv($ftpCon, true);
   $tempFile = tmpfile();
   fputs($tempFile, $fileContents);
   fseek($tempFile, 0);
   ftp_fput($ftpCon, $server['cfg'], $tempFile, FTP_BINARY);
   ftp_close($ftpCon);
}


function curl($url, $username) {
   global $password;


   $header = array('Authorization: Basic ' . base64_encode($username . ':' . $password));
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
   $result = curl_exec($ch);
   curl_close ($ch);
   return $result;
}


function generateRandomPassword() {
   $chars = str_split('abcdefghijkmnopqrstuvwxyz023456789');

   $max = count($chars) - 1;
   $pass = '';


   for ($i = 0; $i         $pass .= $chars[rand(0, $max)];
   }


   return $pass;
}


function createFtpAccount(&$server) {
   global $ftpUsername;
   $ftpPassword = generateRandomPassword();
   // delete ftp accoutn
   curl('http://www.cf.ee:2082/json-api/cpanel?cpanel_jsonapi_version=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=delftp&user=ftps', $server['username']);
   // create new account
   curl('http://cf.ee:2082/json-api/cpanel?cpanel_jsonapi_version=2&cpanel_jsonapi_module=Ftp&'
       . "cpanel_jsonapi_func=addftp&user=$ftpUsername&pass=$ftpPassword&homedir=%2F&quota=0",
       $server['username']);

   // get domain 
   $result = curl('http://www.cf.ee:2082/frontend/x3/index.html', $server['username']);
   preg_match('/Peamine Domeen' . 
              '.*?(.*?)/ms', $result, $matches);
   $domain = $matches[1]; 
   $newUsername = $ftpUsername . '@' . $domain;

   mysql_query("REPLACE INTO ftp (id, username, password) VALUES ({$server['id']}, '$newUsername', '$ftpPassword')");
   //ftp://ftps@smsscripts.com:tere@smsscripts.net/.gameservers/cstrike_0/cstrike/server.cfg
   $server['ftp_username'] = $newUsername;
   $server['ftp_password'] = $ftpPassword;
}


function getContents($server) {
   //$url = 'ftp://' . $server['ftp_username'] . ':' . $server['ftp_password'] . '@' . $server['server'] . $server['cfg'];
   //$contents = file_get_contents($url);
   //echo $contents;

   $ftpCon = ftp_connect($server['server']);

   ftp_login($ftpCon, $server['ftp_username'], $server['ftp_password']);
   //ftp_pasv($ftpCon, true);
   $tempFile = tmpfile();
   fseek($tempFile, 0);
   ftp_fget($ftpCon, $tempFile, $server['cfg'], FTP_BINARY);
   //echo filesize($filename);
   fseek($tempFile, 0);
   $contents = '';
   while (($line = fgets($tempFile)) !== false) {
       $contents .= $line;
   }
   //$contents = fget($tempFile);
   echo $contents;

   return $contents;
}




while($server = mysql_fetch_array($result)) {
   if (empty($server['ftp_username'])) {
       createFtpAccount($server);
   }


   $contents = getContents($server);
   if ($contents === false) {
       createFtpAccount($server);
       $contents = getContents($server);
   }
   $changed = '';
   echo $contents;


   // check players
   if ($checkPlayers
       && preg_match('/maxplayers (["\']?)(\d+)\1/', $contents, $matches) 
       && $matches[2] != $server['slots']
   ) {
       $contents = str_replace($matches[0], "maxplayers {$server['slots']}", $contents);
       update($server, $contents);
       $changed .= "Slots changed from {$matches[2]} to {$server['slots']} @  {$server['ip']} " . 
           " (user: {$server['username']})\n";

   }

   // check bind
   if ($checkBinds
       && preg_match('/bind (["\']?)(\d+\.\d+\.\d+\.\d+)\1/', $contents, $matches) 
       && $matches[2] != $server['ip']
   ) {
       update($server, str_replace($matches[0], "bind {$server['ip']}", $contents));
       $changed .= "Bind changed from {$matches[2]} to {$server['ip']} @  {$server['ip']} " . 
           " (user: {$server['username']})\n";
   }

   if (empty($changed)) {
       continue;
   }


   // stop server
   curl($server['stop'], $server['username'], $password);
   curl($server['start'], $server['username'], $password);



   // send admin email
   mail($adminEmail, 'Server conf changed', $changed);
}

 

 

Näidis SQL fail

-- phpMyAdmin SQL Dump
-- version 3.3.9.2
-- http://www.phpmyadmin.net
--
-- Masin: localhost
-- Tegemisaeg: 13.04.2011 kell 15:33:49
-- Serveri versioon: 5.0.92
-- PHP versioon: 5.2.9


SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";




/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;


--
-- Andmebaas: `fcee_slotschk`
--


-- --------------------------------------------------------


--
-- Struktuur tabelile `ftp`
--


CREATE TABLE IF NOT EXISTS `ftp` (
 `id` int(11) NOT NULL,
 `username` varchar(50) NOT NULL,
 `password` varchar(50) NOT NULL,
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


--
-- Tabeli andmete salvestamine `ftp`
--


INSERT INTO `ftp` (`id`, `username`, `password`) VALUES
(1, 'ftps@csserver001x.com', 'gukac4to'),
(2, 'ftps@cs001zzz.com', 'j4vmd5y0');


-- --------------------------------------------------------


--
-- Struktuur tabelile `servers`
--


CREATE TABLE IF NOT EXISTS `servers` (
 `id` int(11) NOT NULL auto_increment,
 `server` varchar(255) NOT NULL,
 `username` varchar(255) NOT NULL,
 `ip` varchar(20) NOT NULL,
 `slots` int(11) NOT NULL,
 `cfg` varchar(255) NOT NULL,
 `stop` varchar(255) NOT NULL,
 `start` varchar(255) NOT NULL,
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


--
-- Tabeli andmete salvestamine `servers`
--


INSERT INTO `servers` (`id`, `server`, `username`, `ip`, `slots`, `cfg`, `stop`, `start`) VALUES
(1, 'cf.ee', 'cs001x', '80.79.113.4', 24, '/.gameservers/cstrike_0/cstrike/server.cfg', 'http://www.cf.ee:2082/frontend/x3/gameserv/Ctl.html?game=cstrike&n=0&ctl=stop', 'http://www.cf.ee:2082/frontend/x3/gameserv/Ctl.html?ctl=start&n=0&game=cstrike'),
(2, 'cf.ee', 'cs001zz', '80.79.113.10', 19, '/.gameservers/cstrike_0/cstrike/server.cfg', 'http://www.cf.ee:2082/frontend/x3/gameserv/Ctl.html?game=cstrike&n=0&ctl=stop', 'http://www.cf.ee:2082/frontend/x3/gameserv/Ctl.html?ctl=start&n=0&game=cstrike');


Jaga seda postitust


Postituse link
Share on other sites

Kommentaari lisamiseks loo konto või logi sisse

Kommenteerimiseks peate olema liige

Loo konto

Liituge meie kommuuni uue kontoga. See on lihtne!

Loo uus konto

Logi sisse

On juba konto? Logi sisse siit.

Logi sisse nüüd
Jälgi teemat sisse logides  

×
×
  • Loo uus...

Oluline informatsioon

Selle veebisaidi paremaks muutmiseks oleme teie seadmesse paigutanud küpsised . Võite kohandada oma küpsiste seadeid , vastasel juhul eeldame, et te olete küpsiste kasutamisega nõus kui jätkate veebisaidil sirvimist.. Palun lugege läbi Kasutustingimused ja Privaatsuspoliitika.