Example #1
0
function leaveRun()
{
    // Access the globals.
    global $DB;
    global $TIMEMARK;
    global $MySelf;
    $runid = $_GET[id];
    $userid = $MySelf->getID();
    // Are we actually still in this run?
    if (userInRun($userid, $runid) == "none") {
        makeNotice("You can not leave a run you are currently not a part of.", "warning", "Not you run.", "index.php?action=show&id={$runid}", "[cancel]");
    }
    // Is $runid truly an integer?
    numericCheck($runid);
    // Oh yeah?
    if (runIsLocked($runid)) {
        confirm("Do you really want to leave mining operation #{$runid} ?<br><br>Careful: This operation has been locked by " . runSupervisor($runid, true) . ". You can not rejoin the operation unless its unlocked again.");
    } else {
        confirm("Do you really want to leave mining operation #{$runid} ?");
    }
    // Did the run start yet? If not, delete the request.
    $runStart = $DB->getCol("SELECT starttime FROM runs WHERE id='{$runid}' LIMIT 1");
    if ($TIMEMARK < $runStart[0]) {
        // Event not started yet. Delete.
        $DB->query("DELETE FROM joinups WHERE run='{$runid}' AND userid='{$userid}'");
    } else {
        // Event started, just mark inactive.
        $DB->query("update joinups set parted = '{$TIMEMARK}' where run = '{$runid}' and userid = '{$userid}' and parted IS NULL");
    }
    makeNotice("You have left the run.", "notice", "You left the Op.", "index.php?action=show&id={$runid}", "[OK]");
}
Example #2
0
function toggleLock()
{
    global $MySelf;
    // Check the ID for validity.
    if (!numericCheckBool($_GET[id], 0)) {
        makeNotice("That run ID is invalid.", "error", "Invalid RUN");
    } else {
        $ID = $_GET[id];
    }
    // Only the owner of the run can do this.
    if (runSupervisor($ID) != $MySelf->getUsername()) {
        makeNotice("Only the supervisor of a run can lock and unlock his/her run.", "warning", "Unable to comply", "index.php?action=show&id={$_GET['id']}", "[Cancel]");
    }
    // Determine what the user wants.
    switch ($_GET[state]) {
        // User wants to lock.
        case "lock":
            confirm("You are about to lock Mining Operation #{$ID}. No one will be able to join up until you choose to unlock it. Is that what you want?");
            $bool = "1";
            break;
            // User wants to unlock.
        // User wants to unlock.
        case "unlock":
            confirm("You are about to unlock Mining Operation #{$ID}. Everyone will be able to join up again until you choose to relock it. Is that what you want?");
            $bool = "0";
            break;
            // User wants to screw around.
        // User wants to screw around.
        default:
            makeNotice("I dont know what you want off me. I only know lock and unlock. Sorry.", "warning", "Ehh?");
    }
    // Update the database!
    global $DB;
    $DB->query("UPDATE runs SET isLocked='{$bool}' WHERE id='{$ID}' LIMIT 1");
    // Success?
    if ($DB->affectedRows != 1) {
        header("Location: index.php?action=show&id={$ID}");
    } else {
        makeNotice("Unable to set the new locked status in the database. Be sure to run the correct sql schema!", "warning", "Cannot write to database.");
    }
}
Example #3
0
function joinRun()
{
    // Access the globals.
    global $DB;
    global $TIMEMARK;
    global $MySelf;
    $runid = (int) $_GET[id];
    $userid = $MySelf->GetID();
    // Are we allowed to join runs?
    if (!$MySelf->canJoinRun()) {
        makeNotice("You are not allowed to join mining operations. Please ask your CEO to unblock your account.", "error", "Forbidden");
    }
    // Is $runid truly an integer?
    numericCheck($runid);
    // Is the run still open?
    if (!miningRunOpen($runid)) {
        makeNotice("This mining operation has been closed!", "warning", "Can not join", "index.php?action=show&id={$runid}");
    }
    // Are we banned from the run?
    $State = $DB->getCol("SELECT status FROM joinups WHERE run='{$runid}' and userid='" . $MySelf->getID() . "'ORDER BY id DESC LIMIT 1");
    $State = $State[0];
    switch ($State) {
        case "2":
            // We have been kicked.
            $kicked = true;
            break;
        case "3":
            // We have been banned!
            if (runSupervisor($runid) == $MySelf->getUsername() || $MySelf->isOfficial()) {
                $banned = "You have been banned from this operation but your rank overrides this block.";
            } else {
                makeNotice("You have been banned from this operation. You can not rejoin it.", "warning", "You are banned.", "index.php?action=list", "[cancel]");
            }
            break;
    }
    // Is the run locked?
    if (runIsLocked($runid)) {
        makeNotice("You can not join this run as this run has been locked by " . runSupervisor($runid) . ".", "notice", "Mining operation locked", "index.php?action=show&id={$runid}", "[Cancel]");
    }
    // Join with shiptype.
    if (!$_GET['confirmed-ship']) {
        $table = new table(1, true);
        $table->addHeader(">> Join an Operation");
        // If we have been kicked, inform the user.
        if ($kicked) {
            $table->addRow("#880000");
            $table->addCol("Warning: You have been recently kicked. Please check if you are allowed to rejoin to avoid a ban.");
        }
        // If we are banned by an official, inform the user.
        if ($banned) {
            $table->addRow("#880000");
            $table->addCol($banned);
        }
        $table->addRow();
        $table->addCol($form . "Join the Operation in " . ucfirst(getLocationOfRun($runid)) . ".");
        $table->addRow();
        $table->addCol("You have requested to join mining operation #{$runid}. Please choose the shipclass " . "you are going to join up with.");
        $table->addRow();
        $table->addCol("Shiptype: " . $hiddenstuff . joinAs(), array("align" => "center"));
        $table->addRow("#444455");
        $table->addCol("<input type=\"submit\" name=\"submit\" value=\"Join mining operation\">" . $form_end, array("align" => "center"));
        $page = "<h2>Join an Operation.</h2>";
        $page .= "<form action=\"index.php\" method=\"GET\">";
        $page .= "<input type=\"hidden\" name=\"id\" value=\"{$runid}\">";
        $page .= "<input type=\"hidden\" name=\"confirmed-ship\" value=\"true\">";
        $page .= "<input type=\"hidden\" name=\"confirmed\" value=\"true\">";
        $page .= "<input type=\"hidden\" name=\"multiple\" value=\"true\">";
        $page .= "<input type=\"hidden\" name=\"action\" value=\"joinrun\">";
        $page .= $table->flush();
        $page .= "</form>";
        return $page;
    }
    // Sanitize the Shiptype.
    global $SHIPTYPES;
    $ShiptypesCount = count($SHIPTYPES);
    if (!numericCheck($_GET[shiptype], 0, $ShiptypesCount)) {
        makeNotice("The shiptype you tried to join up with is invalid, please go back, and try again.", "warning", "Shiptype invalid!", "index.php?action=show&id={$_GET['id']}");
    } else {
        $shiptype = $_GET[shiptype];
    }
    // Warn the user if he is already in another run.
    $joinedothers = $DB->query("select run from joinups where userid='{$userid}' and parted IS NULL order by run");
    // And check for that just now.
    if ($joinedothers->numRows() > 0) {
        confirm("You joined another mining operation already!<br>Are you sure you want to join multiple runs at the same time?");
    }
    // Get the correct time to join (in case event hasnt started yet)
    $startOfRun = $DB->getCol("SELECT starttime FROM runs WHERE id='{$runid}' LIMIT 1");
    if ($startOfRun[0] > $TIMEMARK) {
        $time = $startOfRun[0];
    } else {
        $time = $TIMEMARK;
    }
    // Dont allow him to join the same mining run twice.
    if (userInRun($MySelf->getID(), "{$runid}") == "none") {
        // Mark user as joined.
        $DB->query("insert into joinups (userid, run, joined, shiptype) values (?,?,?,?)", array("{$userid}", "{$runid}", "{$time}", "{$shiptype}"));
        // Forward user to his joined run.
        makeNotice("You have joined the Mining Operation.", "notice", "Joining confirmed", "index.php?action=show&id={$id}");
    } else {
        // Hes already in that run.
        makeNotice("You are already in that mining run!", "notice", "Joinup not confirmed", "index.php?action=show&id={$id}");
    }
}
Example #4
0
function kick()
{
    // Set some vars.
    $joinID = $_GET[joinid];
    $state = $_GET[state];
    numericCheck($joinID, 0);
    numericCheck($state, 0, 3);
    global $DB;
    global $MySelf;
    global $TIMEMARK;
    // Get the RunID.
    $runID = $DB->getCol("SELECT run, joined FROM joinups WHERE id='{$joinID}' LIMIT 1");
    $runID = $runID[0];
    // Are we allowed to kick/ Ban?
    if (runSupervisor($runID) != $MySelf->getUsername() && !$MySelf->isOfficial()) {
        makeNotice("You are not allowed to kick/ban/remove people from a run. Only the run supervisor or a corporation official is allowed to do that.", "warning", "Not allowed");
    }
    // get the userid (to be kicked)
    $kicked = $DB->getCol("SELECT userid FROM joinups WHERE id='{$joinID}' LIMIT 1");
    $kicked = $kicked[0];
    // We cant kick ourselves.
    if ($kicked == $MySelf->getID()) {
        makeNotice("You can not remove, kick or ban yourself. Get someone else to do the job for you.", "notice", "Can not comply");
    }
    // get confirmations.
    switch ($state) {
        case "1":
            confirm("Are you sure you want to remove " . ucfirst(idToUsername($kicked)) . "?<br>" . "By removing the user he or she retains all shares of his ISK and is honorably discharged from this operation.");
            break;
        case "2":
            confirm("Are you sure you want to kick " . ucfirst(idToUsername($kicked)) . "?<br>" . "By kicking the user he or she loses all shares of his ISK and is dishonorably discharged from this operation.");
            break;
        case "3":
            confirm("Are you sure you want to ban " . ucfirst(idToUsername($kicked)) . "?<br>" . "By banning the user he or she loses all shares of his ISK and is dishonorably discharged from this operation and additionally the user can never rejoin his operation.");
            break;
    }
    /* 
     * Logic bomb work-around
     * If a user joins an op before it starts, and the leaves during the operation
     * he will receive huge bonuses while all the others will get negative amounts.
     * So we have to...
     * 
     * 1. Check if the op has started yet (current time < operation start)
     *  If "no" then we are not affected by the logic bomb.
     *  
     *  If "yes" then we need to set the kicktime AND the jointime to the current time.
     *  Why? If we just set the kicktime to the jointime then the "kicked at" time will
     *  always show the time of the op launch, never the real kick time. Also, the
     *  duration is always zero seconds, so the user will never receive any share from
     *  this run.
     */
    if ($TIMEMARK < $kicked[joined]) {
        $partedTime = $kicked[joined];
    } else {
        $partedTime = $TIMEMARK;
    }
    // Now lets handle kicks, bans and removals.
    $DB->query("update joinups set remover = '" . $MySelf->getID() . "' where run = '{$runID}' and userid = '{$kicked}' and parted IS NULL");
    $DB->query("update joinups set status = '{$state}' where run = '{$runID}' and userid = '{$kicked}' and parted IS NULL");
    $DB->query("update joinups set parted = '{$partedTime}' where run = '{$runID}' and userid = '{$kicked}' and parted IS NULL");
    // Thats it, for now.
    header("Location: index.php?action=show&id={$runID}");
}
Example #5
0
                $lock .= " [<a href=\"index.php?action=lockrun&id={$row['id']}&state=lock\">Lock Run</a>] ";
            }
        }
        // IS in the run, give option to leave.
        $add .= " [<a href=\"index.php?action=partrun&id={$ID}\">Leave Op</a>] [<a href=\"index.php?action=cans\">Manage Cans</a>]";
        //$add .= " [Leave Op Disabled] [<a href=\"index.php?action=cans\">Manage Cans</a>]";
        // Make the charity button.
        $charityFlag = $DB->getCol("SELECT charity FROM joinups WHERE run='{$ID}' AND userid='" . $MySelf->getID() . "' AND parted IS NULL LIMIT 1");
        if ($charityFlag[0]) {
            $charity = " [<a href=\"index.php?action=toggleCharity&id={$ID}\">Unset Charity Flag</a>]";
        } else {
            $charity = " [<a href=\"index.php?action=toggleCharity&id={$ID}\">Set Charity Flag</a>]";
        }
    }
    // Give option to end this op.
    if ($MySelf->getID() == $row['supervisor'] || $MySelf->canCloseRun() && ($MySelf->isOfficial() || runSupervisor($row['id']) == $MySelf->getUsername())) {
        $add2 = " [<a href=\"index.php?action=endrun&id={$ID}\">Close Op</a>]";
    }
    // Refresh button.
    $refresh_button = " [<a href=\"index.php?action=show&id={$row['id']}\">Reload page</a>]";
    $general_info->addCol($join . $addHaul . $add2 . $lock . $add . $charity . $refresh_button);
} else {
    // Mining run ended.
    // Row: Ended
    $general_info->addRow();
    $general_info->addCol("Ended on:", $common_mode);
    $general_info->addCol(date("d.m.y H:i", $row['endtime']));
    $ranForSecs = $row['endtime'] - $row['starttime'];
    // Duration
    $general_info->addRow();
    $general_info->addCol("Duration:", $common_mode);
Example #6
0
function endrun()
{
    global $DB;
    global $TIMEMARK;
    global $MySelf;
    // Is $_GET[id] truly a number?
    numericCheck($_GET[id]);
    // Are we allowed to close runs?
    $supervisor = $DB->getCol("SELECT supervisor FROM runs WHERE id='" . $_GET[id] . "' LIMIT 1");
    if (!$MySelf->canCloseRun() && $MySelf->getID() != $supervisor[0]) {
        makeNotice("You are not allowed to close runs!", "error", "forbidden");
    }
    // We sure about this?
    confirm("Are you sure you want to close mining operation {$_GET['id']}? " . "This will remove any active pilots that are still on this" . " run, and close this run for good.");
    // Run already closed?
    if (!miningRunOpen($_GET[id])) {
        makeNotice("This mining operation has already been closed!", "warning", "Operation closed already", "index.php?action=show&id={$_GET['id']}");
    }
    // Moved to the end of the payout to allow correct calculations
    // Update the database.
    //$DB->query("update runs set endtime = '$TIMEMARK' where id = '$_GET[id]' and endtime is NULL");
    // now "eject" all members.
    //$DB->query("update joinups set parted = '$TIMEMARK' where parted is NULL and run = '$_GET[id]'");
    // Calculate Payout, IF this is an official run.
    $ID = $_GET[id];
    $OfficialRun = $DB->getCol("SELECT isOfficial FROM runs WHERE id='{$ID}'");
    // calculate the total value of this op.
    $ISK = getTotalWorth($ID, true);
    if ($OfficialRun[0] && getTotalWorth($ID) != 0) {
        // Select all people, except banned ones.
        $joinedPeople = $DB->query("SELECT DISTINCT userid FROM joinups WHERE run ='{$ID}' AND status < 2");
        // Also, create the charity array.
        $charityDB = $DB->query("SELECT userid, charity FROM joinups WHERE run ='{$ID}' AND status < 2");
        while ($c = $charityDB->fetchRow()) {
            $charityArray[$c[userid]] = $c[charity];
        }
        // get the payout array. Fun guaranteed.
        while ($peep = $joinedPeople->fetchRow()) {
            $payoutArray[$peep[userid]] = calcPayoutPercent($ID, $peep[userid]);
        }
        // Calulate the percent-modifier.
        $percentModifier = 100 / array_sum($payoutArray);
        // Apply the modifier to the percentage.
        $names = array_keys($payoutArray);
        // Add the credit.
        $supervisor = usernameToID(runSupervisor($_GET[id]));
        foreach ($names as $name) {
            $percent = $payoutArray[$name] * $percentModifier;
            $payout = $ISK / 100 * $percent;
            // You cannot loose isk from a mission.
            if ($payout != 0 && !$charityArray[$name]) {
                addCredit($name, $supervisor, $payout, $_GET[id]);
                $finalPercent[$name] = $payout;
            }
        }
        // Moved to the end of the payout to allow correct calculations
        // Update the database.
        $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL");
        // now "eject" all members.
        $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'");
        // wrap things up.
        makeEmailReceipt($ID, $finalPercent);
        makeNotice("The mining operation has ended. All still active pilots have been removed from the run and each pilot has been credited his share of the net income.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]");
    }
    // Moved to the end of the payout to allow correct calculations
    // Update the database.
    $DB->query("update runs set endtime = '{$TIMEMARK}' where id = '{$ID}' and endtime is NULL");
    // now "eject" all members.
    $DB->query("update joinups set parted = '{$TIMEMARK}' where parted is NULL and run = '{$ID}'");
    // wrap things up.
    makeNotice("The mining operation has ended. All still active pilots have been removed from the run.", "notice", "Mining Operation closed", "index.php?action=list", "[OK]");
}
Example #7
0
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 *  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 *  OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
// Row: Joinups.
// Are we the supervisor of this run and/or an official?
if (runSupervisor($ID) == $MySelf->getID() || $MySelf->isOfficial()) {
    // We are.
    $join_info = new table(9, true);
    $icankick = true;
} else {
    // We are not.
    $join_info = new table(6, true);
}
$join_info->addHeader(">> Active Pilots");
if ($joinlog->numRows() > 0) {
    // Someone or more joined.
    $join_info->addRow("#060622");
    $join_info->addCol("Pilot", array("bold" => true));
    $join_info->addCol("Joined", array("bold" => true));
    $join_info->addCol("Active Time", array("bold" => true));
    $join_info->addCol("State", array("bold" => true));