コード例 #1
0
 /**
  * Waits for the expiration of the lock.
  */
 protected function checkLock()
 {
     do {
         try {
             echo 'l';
             LockUtil::checkLock(self::LOCK_NAME);
             return;
         } catch (SystemException $e) {
             usleep(50000);
         }
     } while ($this->startTime + $this->lifeTime * 2 - 20 > microtime());
     // lock couldnt be removed; so delete it and exit (prepare for the next attempt)
     LockUtil::removeLock(self::LOCK_NAME);
     throw new SystemException('locking error; removed lock for next attempt');
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: executeServer.php プロジェクト: sonicmaster/RPG
    $game_config[$row['config_name']] = $row['config_value'];
}
if (!defined('WOTAPI_SERVER_RUNTIME')) {
    define('WOTAPI_SERVER_RUNTIME', 5);
}
define('END_TIME', TIME_NOW + 5 + WOTAPI_SERVER_RUNTIME * 60);
if (!defined('SERVER_ID')) {
    define('SERVER_ID', 8);
}
// check lock
require_once LW_DIR . 'lib/util/LockUtil.class.php';
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';
コード例 #4
0
ファイル: common.php プロジェクト: sonicmaster/RPG
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with WOT Game.  If not, see <http://www.gnu.org/licenses/>.
*/
// global locking
if (!defined('LW_DIR')) {
    define('LW_DIR', $ugamela_root_path . 'game/');
}
require_once LW_DIR . 'lib/util/LockUtil.class.php';
$userID = isset($_COOKIE['wcf_userID']) ? intval($_COOKIE['wcf_userID']) : 0;
for ($i = 0; $userID > 0; $i++) {
    try {
        LockUtil::checkLock('global_' . $userID);
    } catch (SystemException $e) {
        if ($i >= 3) {
            throw $e;
            exit;
        }
        sleep(1);
        continue;
    }
    break;
}
// global defines
define('VERSION', '1.3');
define('DEFAULT_LANG', 'de');
define('DEFAULT_SKINPATH', "Eigener Skinpfad");
if (!defined('INSIDE')) {
コード例 #5
0
ファイル: FleetQueue.class.php プロジェクト: sonicmaster/RPG
 /**
  * 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);
 }