PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/System/Core/Configuration.php

https://bitbucket.org/viswanath608/outragebot
PHP | 129 lines | 86 code | 26 blank | 17 comment | 14 complexity | 1f30df42b87aaa3341f075447f1a64e5 MD5 | raw file
  1. <?php
  2. /**
  3. * OUTRAGEbot - PHP 5.3 based IRC bot
  4. *
  5. * Author: David Weston <westie@typefish.co.uk>
  6. *
  7. * Version: 2.0.0-Alpha
  8. * Git commit: 95304f4359b55dae9234c2c1156593d3c5fdb40d
  9. * Committed at: Thu Dec 1 23:01:51 GMT 2011
  10. *
  11. * Licence: http://www.typefish.co.uk/licences/
  12. */
  13. class CoreConfiguration
  14. {
  15. /**
  16. * Loads a configuration file from a specific location.
  17. */
  18. static function ParseLocation($sLocation)
  19. {
  20. $sConfigName = substr(basename($sLocation), 0, -4);
  21. if($sConfigName[0] == "~")
  22. {
  23. return false;
  24. }
  25. $aConfiguration = parse_ini_file($sLocation, true);
  26. if(!is_array($aConfiguration) || count($aConfiguration) <= 1)
  27. {
  28. println(" * Sorry, looks like the network {$sConfigName} failed to load!");
  29. return false;
  30. }
  31. $pConfig = new stdClass();
  32. $bSlave = false;
  33. foreach($aConfiguration as $sConfigKey => $aConfigObject)
  34. {
  35. if($sConfigKey[0] == "~")
  36. {
  37. $sConfigKey = substr($sConfigKey, 1);
  38. $pConfig->$sConfigKey = (object) $aConfigObject;
  39. continue;
  40. }
  41. $aConfigObject = array_merge(array("nickname" => $sConfigKey), $aConfigObject, array("slave" => $bSlave));
  42. $pConfig->Bots[$sConfigKey] = (object) $aConfigObject;
  43. $bSlave = true;
  44. }
  45. $sInstance = $sConfigName.' (#'.uniqid().')';
  46. self::verifyConfiguration($pConfig, $sInstance);
  47. Core::addInstance($sInstance, new CoreMaster($pConfig));
  48. }
  49. /**
  50. * Ensures that the required variables are indeed in memory.
  51. */
  52. static function verifyConfiguration($pConfig, $sInstance)
  53. {
  54. $pConfig->Server = new stdClass();
  55. $pNetwork = $pConfig->Network;
  56. if(empty($pNetwork->delimiter))
  57. {
  58. $pNetwork->delimiter = "!";
  59. }
  60. if(empty($pNetwork->rotation))
  61. {
  62. $pNetwork->rotation = SEND_DEF;
  63. }
  64. if(empty($pNetwork->quitmsg))
  65. {
  66. $pNetwork->quitmsg = "OUTRAGEbot is going to bed :(";
  67. }
  68. if(empty($pNetwork->version))
  69. {
  70. $pNetwork->version = "OUTRAGEbot ".BOT_VERSION." (rel. ".BOT_RELDATE."); David Weston; http://outrage.typefish.co.uk";
  71. }
  72. if(empty($pNetwork->perform))
  73. {
  74. $pNetwork->perform = array();
  75. }
  76. $pNetwork->ownerArray = array();
  77. $pNetwork->scriptArray = array();
  78. $pNetwork->channelArray = array();
  79. if(!empty($pNetwork->owners))
  80. {
  81. foreach(explode(',', $pNetwork->owners) as $sOwnerAddress)
  82. {
  83. $pNetwork->ownerArray[] = trim($sOwnerAddress);
  84. }
  85. }
  86. if(!empty($pNetwork->channels))
  87. {
  88. foreach(explode(',', $pNetwork->channels) as $sChannelName)
  89. {
  90. $pNetwork->channelArray[] = trim($sChannelName);
  91. }
  92. }
  93. if(!empty($pNetwork->scripts))
  94. {
  95. foreach(explode(',', $pNetwork->scripts) as $sScriptName)
  96. {
  97. $pNetwork->scriptArray[] = trim($sScriptName);
  98. }
  99. }
  100. $pConfig->sInstance = $sInstance;
  101. return $pConfig;
  102. }
  103. }