/**
  * Switches between two modes: the impact and the return 'mode'.
  * 
  * @param	array	event data
  */
 public function execute($data)
 {
     // TODO: remove this passage?
     // lock management
     echo "l";
     do {
         try {
             LockUtil::checkLock($this->ownerID);
             LockUtil::checkLock($this->ofiaraID);
             // everything checked
             break;
         } catch (SystemException $e) {
             echo 'waiting 0.5s because of a lock ...';
             usleep(500000);
         }
     } while (true);
     echo "m";
     LockUtil::setLock($this->ownerID, 10);
     if ($this->ofiaraID) {
         LockUtil::setLock($this->ofiaraID, 10);
     }
     // execute
     $this->initArrays();
     $this->eventData = $data;
     // return
     if ($data['state'] == 1) {
         if (count($this->fleet)) {
             $this->executeReturn();
             $this->sendReturnMessage();
         }
     } else {
         if ($data['state'] == 0) {
             $this->executeImpact();
             $this->sendImpactOwnerMessage();
             $this->sendImpactOfiaraMessage();
         } else {
             $this->executeUnknownEvent();
         }
     }
     // TODO: integrate this in wcf event listener?
     FleetOvent::update($this);
     // lock management
     LockUtil::removeLock($this->ownerID);
     LockUtil::removeLock($this->ofiaraID);
     return;
 }
 /**
  * Sets a new lock.
  */
 protected function setLock()
 {
     $lockTime = 2 * $this->lifeTime + $this->startTime - microtime(true) - 10;
     LockUtil::setLock(self::LOCK_NAME, $lockTime);
 }
예제 #3
0
do {
    $locked = false;
    // check
    try {
        LockUtil::checkLock('wotapipserver');
    } catch (SystemException $e) {
        echo 'l';
        $locked = true;
        // wait 0.05s
        usleep(50000);
        // remove if waiting 15s already
        if (time() - TIME_NOW > 15) {
            LockUtil::removeLock('wotapipserver');
            echo 'removed lock';
        }
    }
} while ($locked);
LockUtil::setLock('wotapipserver', END_TIME + 5);
// load
require_once LW_DIR . 'lib/system/io/socket/WOTAPIServer.class.php';
require_once LW_DIR . 'lib/system/io/socket/WOTAPIServerClient.class.php';
require_once WCF_DIR . 'lib/system/io/socket/SocketDaemon.class.php';
if (!defined('WOTAPI_PORT')) {
    define('WOTAPI_PORT', 57154);
}
if (!defined('CRYPTER_KEY')) {
    define('CRYPTER_KEY', base64_decode('SAG ICH NICHT'));
}
// fire
$server = SocketDaemon::createServer('WOTAPIServer', 'WOTAPIServerClient', 0, WOTAPI_PORT);
SocketDaemon::process();
예제 #4
0
 /**
  * Inserts the fleet
  */
 public function fire()
 {
     LockUtil::checkLock(WCF::getUser()->userID);
     LockUtil::setLock(WCF::getUser()->userID, 10);
     EventHandler::fireAction($this, 'shouldFire');
     $this->fleetEditor = FleetEditor::create($this->startPlanetID, $this->endPlanetID, $this->ships, $this->galaxy, $this->system, $this->planet, $this->metal, $this->crystal, $this->deuterium, $this->getDuration(), $this->missionID);
     $planet = Planet::getInstance($this->startPlanetID);
     $planet->getEditor()->changeResources(-$this->metal, -$this->crystal, -($this->deuterium + $this->getConsumption()));
     $ships = array();
     foreach ($this->ships as $specID => $shipCount) {
         $ships[$specID] = -$shipCount;
     }
     $planet->getEditor()->changeLevel($ships);
     // TODO: integrate in wcf eventlistener didFire@FleetQueue
     if ($this->missionID == 11) {
         $formation = new NavalFormation($this->formationID);
         $formation->getEditor()->addFleet($this->fleetEditor->fleetID);
     }
     if ($this->missionID == 12) {
         $standByTime = intval(@$_REQUEST['standByTime']);
         $wakeUpTime = $this->fleetEditor->impactTime + $standByTime;
         $newReturnTime = $this->fleetEditor->returnTime + $standByTime;
         $this->fleetEditor->changeTime(array('return' => $newReturnTime));
         $wakeUpEvent = WOTEventEditor::create(1, $this->fleetEditor->fleetID, array('state' => 2), $wakeUpTime);
         $this->fleetEditor->update(array('wakeUpEventID' => $wakeUpEvent->eventID, 'wakeUpTime' => $wakeUpTime));
     }
     if (WCF::getUser()->userID == 1) {
         FleetOvent::create($this->fleetEditor, false, true);
     }
     EventHandler::fireAction($this, 'didFire');
     $this->deleteFleetQueue();
     LockUtil::removeLock(WCF::getUser()->userID);
 }