dongpan1416 2013-10-14 01:47
浏览 27

如何编辑我现有的php函数并添加另一个检查? [关闭]

I'd like to add another option for premium accounts. At the moment you can class change your character every 2 days but I want to add another check to allow every 12 hours for premium users. They are determined from another table in PREMIUM there is their strAccountID If they are not premium there will be no rows in that table for their account.

That's my current PHP function which works for all users and allows them to do it every 2 days.

private function doProcessClassChangeFormD()
{
    $db = $this->database[GDB];
    $character = $this->site->SanitizeName($_POST['character']);
    $num_rows = $db->doQuery('SELECT bNation FROM ACCOUNT_CHAR WHERE strAccountID = ? AND ? IN(strCharID1, strCharID2, strCharID3)', $_SESSION['strAccountID'], $character);
    if ($num_rows == -1)
    {
        $db->GetError(__file__, __line__);
        $this->m_ccError = Template::GetLangVar('DB_ERROR');
        return false;
    }
    else if ($num_rows == 0)
    {
        $this->m_ccError = Template::GetLangVar('CC_INVALID_ACCOUNT');
        return false;
    }

    $row = $db->doRead();
    $nation = $row['bNation'];

    $num_rows = $db->doQuery('SELECT Class, Race, Strong, Sta, Dex, Intel, Cha, Points, TransferTime FROM USERDATA WHERE strUserId = ? AND (TransferTime < DATEADD(DAY,-2,GETDATE()) OR TransferTime IS NULL) and zone<>199 and authority<>255', $character);
    if ($num_rows == -1)
    {
        $db->GetError(__file__, __line__);
        $this->m_ccError = Template::GetLangVar('DB_ERROR');
        return false;
    }
    else if ($num_rows == 0)
    {
        $this->m_ccError = Template::GetLangVar('CC_RECENT_TRANSFER');
        return false;
    }

    $row = $db->doRead();

    $oldRace = $row['Race'];
    $oldClass = $row['Class'];
    $newRace = intval($_POST['race']);
    $newClass = intval($_POST['class']);

    $pCT = new ClassTransfer($nation, $oldClass, $oldRace, $newClass, $newRace);
    if (!($res = $pCT->canChangeClass()))
    {   
        $this->m_ccError = $pCT->GetError(__file__, __line__);
        return false;
    }

    $newClass = $res[0];
    $newRace = $res[1];

    $free = $row['Points'] + $row['Strong'] + $row['Sta'] + $row['Dex'] + $row['Intel'] + $row['Cha'];
    $newStats = $pCT->getStarterStats($newClass, $newRace);

    for ($i = 0; $i < 5; $i++)
        $free -= $newStats[$i];

    if ($free > 255)
    {
        $_SESSION['bClassTransfer'] = true;
        $_SESSION['strUserId'] = $character;
        $_SESSION['bNewRace'] = $newRace;
        $_SESSION['bNewClass'] = $newClass;
        $_SESSION['bStrong'] = $newStats[KO_STR];
        $_SESSION['bStamina'] = $newStats[KO_STA];
        $_SESSION['bDexterity'] = $newStats[KO_DEX];
        $_SESSION['bIntelligence'] = $newStats[KO_INT];
        $_SESSION['bCharisma'] = $newStats[KO_CHA];
        $_SESSION['bAvailable'] = $free;

        $this->m_bSelectPoints = true;
        return false;
    }

    $newStats[5] = $free;
    return $this->doExecuteClassChangeD($character, $newClass, $newRace, $newStats);
}

http://pastebin.com/VK4Bi7FJ

I've tried several ways but no success. How I can achieve this?

  • 写回答

2条回答 默认 最新

  • dszn2485 2013-10-14 01:57
    关注

    Easiest way to go about it would be to do a query of the premium table:

    SELECT the strAccountID from PREMIUM where strAccountID equals the current logged in user (stored in a session/cookie somewhere?)

    From there just do a simple if statement. If the above select statement returns a row and the time has been greater than 12 hours, then yes let them change character.

    Do the above around this bit here:

        $num_rows = $db->doQuery('SELECT Class, Race, Strong, Sta, Dex, Intel, Cha, Points,  TransferTime FROM USERDATA WHERE strUserId = ? AND (TransferTime < DATEADD(DAY,-2,GETDATE()) OR TransferTime IS NULL) and zone<>199 and authority<>255', $character);
    

    Then all you would need to do is, if the person is premium, change the above statement to only 12 hours and not 2 days. If they aren't premium then leave it at 2 days.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?