Server plugin: Automatic server messages

Sammy

Master of Whispers
Donator
Posts
278
Likes
167
Like on the US open server, I've seen rcon (server) display automatic messages such as send the website link, etc.

How could I do that with my own server? What does it require? Thanks in advance :).
 

Viserys

ex team lead
Movie Battles II Team Retired
Posts
798
Likes
873
You can run a php script at a certain interval (via cron jobs for example, on linux)

here's the php script (example from BG server):

Code:
<?php
require('q3query.php');

// Server3
$q3 = new q3query('164.132.54.88', 29072);
$q3->set_rconpassword('blabla');
$q3->rcon('svsay ^7Type ^3/showmotd ^7in the console to see the server rules.');
sleep(3);
$q3->rcon('svsay ^7This server has an RTV service. Type ^3!rtv ^7if you want to change maps.');
sleep(3);
$q3->rcon('svsay ^7Type ^3!maplist ^7to see a list of available maps, and ^3!nominate ^7to add one to the vote.');


?>
 

Sammy

Master of Whispers
Donator
Posts
278
Likes
167
You can run a php script at a certain interval (via cron jobs for example, on linux)

here's the php script (example from BG server):

Code:
<?php
require('q3query.php');

// Server3
$q3 = new q3query('164.132.54.88', 29072);
$q3->set_rconpassword('blabla');
$q3->rcon('svsay ^7Type ^3/showmotd ^7in the console to see the server rules.');
sleep(3);
$q3->rcon('svsay ^7This server has an RTV service. Type ^3!rtv ^7if you want to change maps.');
sleep(3);
$q3->rcon('svsay ^7Type ^3!maplist ^7to see a list of available maps, and ^3!nominate ^7to add one to the vote.');


?>
Alright, and what about in relation to q3query? What do I do to get that?
 

Viserys

ex team lead
Movie Battles II Team Retired
Posts
798
Likes
873
you need to save this .php file in the same directory as your automessage.php

Code:
<?php

/*
PHP Quake 3 Library
Copyright (C) 2006-2007 Gerald Kaszuba

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

class q3query {

    private $rconpassword;
    private $fp;
    private $cmd;
    private $lastcmd;

    public function __construct($address, $port) {
        $this->cmd = str_repeat(chr(255), 4);
        $this->fp = fsockopen("udp://$address", $port, $errno, $errstr, 30);
        if (!$this->fp)
            die("$errstr ($errno)<br />\n");
    }

    public function set_rconpassword($p) {
        $this->rconpassword = $p;
    }

    public function rcon($s) {
        sleep(1);
        $this->send('rcon '.$this->rconpassword.' '.$s);
    }
   
    //Returns a parsed array of the rcon status for this server
    public function status(&$cur_map = 0){
        $this->send('rcon '.$this->rconpassword.' status');
        $response = $this->get_response();
        preg_match_all('/^\s+(\S{1,2}?)\s+(\S{1,4})\s+(\S{1,3})\s+(.*)\^7\s+(\S+)\s+(\S+):(\S+)\s+(\S+)\s+(\S+)$/m', $response, $aStatus);
        if ( !is_int($cur_map) ){
            preg_match('/^map:\s+(.*)$/m', $response, $aMap);
            $cur_map = $aMap[1];
        }
        return $aStatus;
    }
   
    //Returns an array of all the maps available on this server
    public function maplist(){
        $this->send('rcon dir maps bsp');
        $response = $this->get_response();
        $parts = split("---------------\n", $response);
        $maplist = split("\n", $parts[1]);
        return $maplist;
    }

    public function get_response($timeout=5) {
        $s = '';
        $bang = time() + $timeout;
        while (!strlen($s) and time() < $bang) {
            $s = $this->recv();
        }
        if (substr($s, 0, 4) != $this->cmd) {
        }
        return substr($s, 4);
    }

    private function send($string) {
        fwrite($this->fp, $this->cmd . $string . "\n");
    }

    private function recv() {
        return fread($this->fp, 9999);
    }
}

?>
 
Posts
18
Likes
17
I'm sorry to revive an old thread, but I can't work out how to implement these scripts in to my server.
Are they referenced some how in the server.cfg file?
Thanks.
 

Viserys

ex team lead
Movie Battles II Team Retired
Posts
798
Likes
873
nothing to do with cfgs. you need to run php
 
Top