Ejemplo n.º 1
0
Archivo: 1095.php Proyecto: rwruss/ib3
<?php

include './slotFunctions.php';
include './unitClass.php';
$unitFile = fopen($gamePath . '/unitDat.dat', 'rb');
$slotFile = fopen($gamePath . '/gameSlots.slt', 'rb');
// Gathering options for a resource point
// Get data about this resource point
$thisPoint = loadUnit($postVals[1], $unitFile, 400);
// Check for nearby units that can work at this locaiton
$thisPlayer = loadPlayer($pGameID, $unitFile, 400);
$unitList = new itemSlot($thisPlayer->get('unitSlot'), $slotFile, 40);
echo '<script>useDeskTop.newPane("somePane");
thisDiv = useDeskTop.getPane("somePane");';
for ($i = 1; $i <= sizeof($unitList->slotData); $i++) {
    $checkUnit = loadUnit($unitList->slotData[$i], $unitFile, 400);
    if ($checkUnit->get('uType') == 8) {
        $xDist = $checkUnit->get('xLoc') - $thisPoint->get('xLoc');
        $yDist = $checkUnit->get('yLoc') - $thisPoint->get('yLoc');
        if ($xDist * $xDist + $yDist * $yDist <= 400) {
            $actionPoints = $checkUnit->actionPoints();
            // unit is close enough to gather -> show the unit as an option
            echo 'unitList.newUnit({unitType:"warband", unitID:' . $unitList->slotData[$i] . ', unitName:"unit name", actionPoints:' . $actionPoints . ', strength:75, tNum:' . $checkUnit->get('uType') . '});
			var orderBox = actionBox(thisDiv, "1122,' . $postVals[1] . ',' . $unitList->slotData[$i] . '", ' . $actionPoints . ');
			unitList.renderSum(' . $unitList->slotData[$i] . ', orderBox.unitSpace);';
        }
    }
}
echo '</script>';
fclose($unitFile);
fclose($slotFile);
Ejemplo n.º 2
0
Archivo: 1115.php Proyecto: rwruss/ib3
<?php

/*
This script gives a menu for transfering control of a unit to another player
*/
include './unitClass.php';
include './slotFunctions.php';
$unitFile = fopen($gamePath . '/unitDat.dat', 'rb');
$slotFile = fopen($gamePath . '/gameSlots.slt', 'rb');
// Confirm that you are the owner of the unit
$thisUnit = loadUnit($postVals[1], $unitFile, 400);
if ($thisUnit->get('owner') != $gGameID) {
    exit('error 1-5111');
}
// Get a list of players to transfer the unit to (run the chain of player's lords)
$thisPlayer = loadPlayer($pGameID, $unitFile, 400);
$lordID = $thisPlayer->get('lordID');
while ($lordID > 0) {
    echo 'Assign to player #' . $lordID;
    $nextLord = loadPlayer($lordID, $unitFile, 400);
    $lordID = $nextLord('lordID');
}
fclose($unitFile);
fclose($slotFile);
Ejemplo n.º 3
0
function sendMessage($target, $subject, $msgContent, $replyTo, $msgType, $unitFile, $unitSlotFile)
{
    global $gamePath, $pGameID;
    $msgSlotFile = fopen($gamePath . '/msgSlots.slt', 'r+b');
    $trgObject = loadUnit($target, $unitFile, 400);
    //$trgObject = new unit($target, $unitFile, 400);
    //fseek($unitFile, $target*$defaultBlockSize);
    //$trgDat = unpack('i*', fread($unitFile, 400));
    print_r($trgObject->unitDat);
    //Determine who all to send it to based on target type
    $toList = [];
    switch ($trgObject->unitDat[4]) {
        case 1:
            // a town object
            echo 'Send to all members of a town';
            $townDat = new itemSlot($trgObject->unitDat[19], $unitSlotFile, 40);
            print_r($townDat->slotData);
            for ($i = 1; $i < sizeof($townDat->slotData); $i += 2) {
                if ($townDat->slotData[$i] < -1) {
                    $toList[] = $townDat->slotData[$i + 1];
                }
            }
            break;
        case 10:
            // a tribe object
            echo 'This is a tribe... send to ' . $trgObject->unitDat[6];
            $toList[] = $trgObject->unitDat[6];
            break;
        case 13:
            // a player object
            echo 'Send to player ' . $target;
            $toList[] = $target;
    }
    $sendList = array_unique($toList);
    if (sizeof($sendList) > 0) {
        for ($i = 0; $i < sizeof($sendList); $i++) {
            echo 'Record message for player ' . $sendList[$i];
            $trgPlayer = loadPlayer($sendList[$i], $unitFile, 400);
            if ($trgPlayer->unitDat[25] == 0) {
                if (flock($msgSlotFile, LOCK_EX)) {
                    fseek($msgSlotFile, 0, SEEK_END);
                    $use_slot = max(1, ftell($msgSlotFile) / 40);
                    fseek($msgSlotFile, $use_slot * 40 + 39);
                    fwrite($msgSlotFile, pack("C", 0));
                    fflush($msgSlotFile);
                    flock($msgSlotFile, LOCK_UN);
                    // release the lock
                    $trgPlayer->unitDat[25] = $use_slot;
                }
                echo 'Createa  new message slot at ' . $trgPlayer->unitDat[25];
            }
            $msgSlot = new blockSlot($trgPlayer->unitDat[25], $msgSlotFile, 40);
            // Set unread flag
            $trgPlayer->unitDat[5] = 1;
            $trgPlayer->saveAll($unitFile);
            // Record message contents in message file and message index
            $messageContentFile = fopen($gamePath . '/messages.dat', 'r+b');
            // if message is a reply, get pvs info.
            if ($replyTo > 0) {
                fseek($messageContentFile, $replyTo);
                $pvsDat = explode('<-!->', fread($messageContentFile, 100));
                $subject = substr($pvsDat[0], 16);
            }
            if (flock($messageContentFile, LOCK_EX)) {
                fseek($messageContentFile, 0, SEEK_END);
                $msgSpot = ftell($messageContentFile);
                //fwrite($subject);
                $blockLength = strlen($subject) + strlen($msgContent) + 5 + 4 + 4 + 4 + 4 + 4;
                // total length is subject length + message length + separator length + total length integer + time integer + sender ID + message ID in reply to + message type
                echo 'Message length is ' . $blockLength . ' (' . strlen($subject) . ') + (' . strlen($msgContent) . ') + 9 written at spot ' . $msgSpot . '<br>
        Subject: ' . $subject . '<br>
        Content: ' . $msgContent . '<br>';
                fwrite($messageContentFile, pack('i*', $blockLength, time(), $pGameID, $replyTo, $msgType) . $subject . '<-!->' . $msgContent);
                $msgSlot->addItem($msgSlotFile, pack('i*', $msgSpot, 1, 1), $msgSlot->findLoc(0, 3));
                // message start loc, message file num, read/unread
            }
        }
    }
    fclose($msgSlotFile);
}
Ejemplo n.º 4
0
Archivo: 3001.php Proyecto: rwruss/ib3
        }
        break;
    case 10:
        // a tribe object
        echo 'This is a tribe... send to ' . $trgObject->unitDat[6];
        $toList[] = $trgObject->unitDat[6];
        break;
    case 13:
        // a player object
        $toList[] = $msg[0];
}
$sendList = array_unique($toList);
if (sizeof($sendList) > 0) {
    for ($i = 0; $i < sizeof($sendList); $i++) {
        echo 'Record message for player ' . $sendList[$i];
        $trgPlayer = loadPlayer($sendList[$i], $unitFile, 400);
        if ($trgPlayer->unitDat[25] == 0) {
            if (flock($slotFile, LOCK_EX)) {
                fseek($slotFile, 0, SEEK_END);
                $use_slot = max(1, ftell($slotFile) / 40);
                fseek($slotFile, $use_slot * 40 + 39);
                fwrite($slotFile, pack("C", 0));
                fflush($slotFile);
                flock($slotFile, LOCK_UN);
                // release the lock
                $trgPlayer->unitDat[25] = $use_slot;
            }
            echo 'Createa  new message slot at ' . $trgPlayer->unitDat[25];
        }
        $msgSlot = new blockSlot($trgPlayer->unitDat[25], $slotFile, 40);
        // Set unread flag
Ejemplo n.º 5
0
Archivo: 1112.php Proyecto: rwruss/ib3
<?php

/* This script processes disbanding an army*/
include './slotFunctions.php';
include './unitClass.php';
$unitFile = fopen($gamePath . '/unitDat.dat', 'rb');
$slotFile = fopen($gamePath . '/gameSlots.slt', 'rb');
// Load army data
$trgArmy = loadUnit($postVals[1], $unitFile, 400);
// Confirm that the player can disband the army
if ($trgArmy->get('controller') != $pGameID) {
    exit('error 1-2111');
}
// Load list of units in army
$armyList = new itemSlot($trgArmy->get('unitListSlot'), $slotFile, 400);
// Set the units to not be in any army
for ($i = 1; $i <= sizeof($armyList->slotData); $i++) {
    if ($armyList->slotData[$i] > 0) {
        $trgUnit = loadUnit($armyList->slotData[$i], $unitFile, 400);
        $trgUnit->save('armyID', 0);
    }
}
// Remove the army from the list of player's units
$playerObj = loadPlayer($pGameID, $unitFile, 400);
$unitList = new itemSlot($playerObj->get('unitSlot'), $slotFile, 400);
$unitList->deleteByValue($postVals[1], $slotFile);
fclose($unitFile);
fclose($slotFile);
Ejemplo n.º 6
0
<?php

require 'api/local/config.inc.php';
require 'api/common.inc.php';
require 'api/mysql.inc.php';
connectMysql('dyn');
$user_id = 0;
session_start();
$player = loadPlayer();
$player_id = $player['id'];
$player_nick = $player['nick'];
// On remplace le session_id par celui donné en POST s'il existe, ce qui permet à un joueur de rejoindre une autre partie.
// TODO : il faut donner la possibilité à quelqu'un de pouvoir créer une nouvelle partie même s'il est déjà associé à une partie (par exemple si le player_host se barre avant de créer)
if (isset($_POST['session_id'])) {
    $_SESSION['session_id'] = intval($_POST['session_id']);
}
//if (isset($_GET['session_id'])) $_SESSION['session_id'] = intval($_GET['session_id']); // Idem en GET, pour le debug
// Chargement des infos de la session (si elles existent)
$player_host = 0;
if (isset($_SESSION['session_id'])) {
    $session_id = $_SESSION['session_id'];
    $res = $DB->query("SELECT * FROM sessions WHERE status < 2 AND id = " . $session_id);
    // On ignore les sessions qui ont déjà démarré
    if ($rs = $res->fetch()) {
        $player_host = $rs['player_host'];
    } else {
        unset($_SESSION['session_id']);
    }
}
// Si la session n'existe pas (ou plus) on la créée
if (!isset($_SESSION['session_id'])) {
Ejemplo n.º 7
0
require 'local/config.inc.php';
require 'common.inc.php';
require 'mysql.inc.php';
session_readonly();
$session_id = 0;
if (isset($_SESSION['session_id'])) {
    $session_id = $_SESSION['session_id'];
}
connectMysql('dyn');
cleanSessions();
$res = $DB->query("SELECT * FROM sessions WHERE public = 1 AND status = 0 AND id > " . $session_id);
// On ignore les sessions qui ont déjà démarré, et celles que l'utilisateur a déjà vu
if ($rs = $res->fetch()) {
    $session_id = $rs['id'];
    session_start();
    loadPlayer();
    $_SESSION['session_id'] = $session_id;
    session_write_close();
    $DB->query("UPDATE players SET session_id = " . $session_id . " WHERE id = " . $_SESSION['player_id']);
} else {
    if ($session_id > 0) {
        session_start();
        unset($_SESSION['session_id']);
        $session_id = 0;
        session_write_close();
        if (isset($_SESSION['player_id'])) {
            $DB->query("UPDATE players SET session_id = 0 WHERE id = " . $_SESSION['player_id']);
        }
    }
}
echo json_encode(array('found' => $session_id != 0 ? 1 : 0));
Ejemplo n.º 8
0
Archivo: 1132.php Proyecto: rwruss/ib3
// Verify that the player can end the war
fseek($warFile, $postVals[1] * $defaultBlockSize);
$warDat = unpack('i*', fread($warFile, $warBlockSize));
if ($warDat[5] != $pGameID && $warDat[6] != $pGameID) {
    exit('erorr 1312-1');
}
$sideSwitch = 1;
$playerSide = 1;
$oppside = 2;
if ($warDat[6] == $pGameID) {
    // player is the defender
    $sideSwitch = -1;
    $playerSide = 2;
    $oppside = 1;
}
$requiredScore = [0, 0, 0, 0];
// Verify that the warscore is high enough to enforce the demand
if ($warDat[8] < $requiredScore[$warDat[1]]) {
    exit('You cannot enforce these conditions');
}
$aPlayer = loadPlayer($warDat[5], $unitFile, 400);
$dPlayer = loadPlayer($warDat[6], $unitFile, 400);
// update the diplomacy for both players to put in a truce
$aDipSlot = new blockSlot($aPlayer->get('dipSlot'), $slotFile, 40);
$dDipSlot = new blockSlot($dPlayer->get('dipSlot'), $slotFile, 40);
$aDipSlot->addItem($slotFile, pack('i*', $warDat[6], 3, time(), 3 * 24 * 3600));
$dDipSlot->addItem($slotFile, pack('i*', $warDat[5], 3, time(), 3 * 24 * 3600));
// Make the demanded changes on the defender
fclose($warFile);
fclose($unitFile);
fclose($slotFile);
Ejemplo n.º 9
0
Archivo: 1111.php Proyecto: rwruss/ib3
<?php

/*
This script will process transfering units from one player to another
*/
include './unitClass.php';
include './slotFunctions.php';
$unitFile = fopen($gamePath . '/unitDat.dat', 'rb');
$slotFile = fopen($gamePath . '/gameSlots.slt', 'rb');
// Load player Dat
$thisPlayer = loadPlayer($pGameId, $unitFile, 400);
// Load list of units that the player controls
$unitList = new itemSlot($thisPlayer->get('unitSlot'), $slotFile, 40);
// Load target player Dat
$trgPlayer = loadPlayer($postVals[1], $unitFile, 400);
// Load target unit slotFile
$trgSlot = new itemSlot($trgPlayer->get('unitSlot'), $slotFile, 40);
$pvSize = sizeof($postVals);
for ($i = 2; $i < $pvSize; $i++) {
    $trgUnit = loadUnit($postVals[$i], $unitFile, 400);
    // confirm that unit is controlled by player
    if ($trgUnit->get('controller') == $pGameId) {
        // Change the unit's controller
        $trgUnit->save('controller', $postVals[1]);
        // Add to the unit slot for the new controller
        $trgSlot - addItem($postVal[$i], $slotFile);
    }
}
fclose($slotFile);
fclose($unitFiel);