forum.webdiplomacy.net

webDip dev coordination forum / public access todo list
It is currently Thu Aug 24, 2017 6:53 am

All times are UTC




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

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

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:
Code:
   /**
    * 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:
Code:
   public function __call($name, $args) {

      // Search for a variant modification
      $variantfound = false;
      if( isset($this->variantClasses[$name]) ) {
         $classnamevar=$this->variantClasses[$name].'Variant_'.$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;
            break;
         }
      }

      // If we didn't find any variants or mods, just
      if (!$variantfound && !$modfound) {
         $classname=$name;
      } 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
         $classname=$classnamemod;
      } else {
         if ($variantfound)
            $classname = $classnamevar;
         if ($modfound) {
            require_once("mods/$value/$name.php");
            $classname = $classnamemod;
         }
      }

      // Not elegant, but I know no other way and this does the job
      switch(count($args))
...


Oliver


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

Top
 Profile  
 
PostPosted: Sat Jul 09, 2011 9:40 pm 
Offline

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 http://php.net/manual/en/function.call- ... -array.php


Top
 Profile  
 
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:  
cron
Powered by phpBB® Forum Software © phpBB Group