webDip dev coordination forum / public access todo list
It is currently Tue Mar 20, 2018 7:05 pm

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Jul 03, 2011 6:18 am 

Joined: Wed Jul 29, 2009 10:22 am
Posts: 841

Carey came with a nice idea to make variant independent "global" changes.
It's more a hack, but a cool idea.
Only some changes to the __call()-function of the variant-class are required:

Add this to your config.php:
    * An array of mods available on the server.  They should be put in order of precedence.
    * @var array
   public static $mods=array('ChatBeforeGame');

Here is the code:
   public function __call($name, $args) {

      // Search for a variant modification
      $variantfound = false;
      if( isset($this->variantClasses[$name]) ) {
         $variantfound = true;

      // Search for mod modifications
      $modfound = false;
      foreach (Config::$mods as $value) {
         if (file_exists("mods/$value/$name.php")) {
            $classnamemod = $value."_".$name;
            $modfound = true;

      // If we didn't find any variants or mods, just
      if (!$variantfound && !$modfound) {
      } else if ($variantfound && $modfound) {
         $code = file_get_contents("mods/$value/$name.php");
         $code = str_replace ("extends $name", "extends $classnamevar", $code);
         $code = str_replace ("<?php", "", $code);
         $code = str_replace ("<? php", "", $code);
         $code = str_replace ("?>", "", $code);
         eval($code); // Yes I know eval is generally considered bad, but anything different would require changing the code of the entire system
      } else {
         if ($variantfound)
            $classname = $classnamevar;
         if ($modfound) {
            $classname = $classnamemod;

      // Not elegant, but I know no other way and this does the job


Last edited by Sleepcap on Tue Jul 12, 2011 11:02 am, edited 1 time in total.

PostPosted: Sat Jul 09, 2011 9:40 pm 

Joined: Wed Oct 08, 2008 12:47 pm
Posts: 726
Got very bad net here (in Scotland atm), so haven't been able to verify this statement, but I'm pretty sure the last section can be simplified by use of ... -array.php

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group