Beispiel #1
0
 private function getInstance()
 {
     if ($this->instance == null) {
         $this->instance = DbFactory::getInstance();
     }
     return $this->instance;
 }
Beispiel #2
0
 public function prepareData()
 {
     try {
         $this->_oTable->setTableName('cUser');
         $data = $this->_oTable->getObject(array('userId' => $this->_args['userId']));
         if (count($data) == 0) {
             $this->_retValue = EC_RECORD_NOT_EXIST;
             $this->_retMsg = "userId:" . $this->_args['userId'];
             interface_log(ERROR, $this->_retValue, $this->_retMsg);
             return false;
         }
         //设置用户数据
         $this->_userInfo = $data[0];
         //获取游戏数据
         $this->_oTable->setTableName('cFight');
         $this->_args['userId'] = DbFactory::getInstance('MYZL')->escape($this->_args['userId']);
         $data = $this->_oTable->getObject(array("_where" => " (user1='" . $this->_args['userId'] . "' OR user2='" . $this->_args['userId'] . "')"));
         if (empty($data)) {
             //查不到游戏数据的情况
             $this->_retValue = EC_RECORD_NOT_EXIST;
             $this->_retMsg = " userId:" . $this->_args['userId'];
             interface_log(ERROR, $this->_retValue, $this->_retMsg);
             return false;
         } else {
             if (count($data) > 1) {
                 //有多个进行中的游戏的情况
                 $this->_retValue = EC_MULTIPLE_FIGHT;
                 $this->_retMsg = "userId:" . $this->_args['userId'];
                 interface_log(ERROR, $this->_retValue, $this->_retMsg);
                 return false;
             } else {
                 //开始游戏的操作者不是当前用户的情况
                 if ($data[0]['first'] != $this->_args['userId']) {
                     $this->_retValue = EC_ERROR_START_USR;
                     $this->_retMsg = " userId:" . $this->_args['userId'];
                     interface_log(ERROR, $this->_retValue, $this->_retMsg);
                     return false;
                 }
                 //操作步骤不匹配的情况
                 if ($data[0]['operation'] != START && $data[0]['operation'] != FIRST_END) {
                     $this->_retValue = EC_STEP_ERROR;
                     $this->_retMsg = " userId:" . $this->_args['userId'] . "  step:" . $data[0]['operation'];
                     interface_log(ERROR, $this->_retValue, $this->_retMsg);
                     return false;
                 }
             }
         }
         //设置游戏数据和游戏id
         $this->_fightInfo = $data[0];
         $this->_fightId = $data[0]['fightId'];
     } catch (Exception $e) {
         $errorNum = $this->_oTable->getErrorNum();
         $this->_retMsg = $this->_oTable->getErrorInfo() . $e->getMessage();
         $this->_retValue = genRetCode($errorNum);
         interface_log(ERROR, $this->_retValue, $this->_retMsg);
         return false;
     }
     return true;
 }
Beispiel #3
0
 public function process()
 {
     try {
         DbFactory::getInstance('MYZL')->autoCommit();
         //先获取游戏数据中的msgForOther,如果otherId是当前用户,把msgForOther添加到用户提示文本_responseText中
         $msgForOther = $this->_fightInfo['msgForOther'];
         $otherId = $this->_fightInfo['otherId'];
         if ($otherId == $this->_fromUserName) {
             $this->_responseText .= $msgForOther;
             $this->_fightInfo['msgForOther'] = "";
         }
         //设置msgForOhter和otherId
         $this->_fightInfo['otherId'] = $this->_fromUserName == $this->_fightInfo['user1'] ? $this->_fightInfo['user2'] : $this->_fightInfo['user1'];
         if ($this->_fightInfo['msgForOther'] == "") {
             $this->_fightInfo['msgForOther'] = "对方已加注" . $this->_operand . "金币";
         } else {
             $this->_fightInfo['msgForOther'] .= ", 对方已加注" . $this->_operand . "金币";
         }
         //用户金币不足的情况
         if ($this->_userInfo['money'] < $this->_args['money']) {
             $this->_retValue = EC_NOT_ENOUGH_MONEY;
             interface_log(ERROR, $this->_retValue);
             return false;
         }
         //用户减金币,游戏加金币
         $this->_oTable->setTableName('cUser');
         $newMoney = $this->_userInfo['money'] - $this->_args['money'];
         $this->_oTable->updateObject(array('money' => $newMoney), array('userId' => $this->_args['userId']));
         $this->_fightInfo['money'] += $this->_args['money'];
         //设置下一个动作的操作码和操作人
         $ret = $this->setNextOpAndUser();
         if ($ret['code']) {
             $this->_retValue = EC_STEP_ERROR;
             $this->_retMsg = "fightId:" . $this->_fightId . " step:" . $this->_fightInfo['historyOp'];
             interface_log(ERROR, $this->_retValue, $this->_retMsg);
             return false;
         }
         //设置历史操作记录
         if ($this->_fightInfo['historyOp'] == '') {
             $newHistoyOp = "CHIP_IN," . $this->_args['userId'];
         } else {
             $newHistoyOp = $this->_fightInfo['historyOp'] . "|CHIP_IN," . $this->_args['userId'];
         }
         $this->_fightInfo['historyOp'] = $newHistoyOp;
         //更新下注金额的下限
         if ($this->_args['money'] > $this->_fightInfo['minMoney']) {
             $this->_fightInfo['minMoney'] = $this->_args['money'];
         }
         //更新游戏数据
         $this->_oTable->setTableName('cFight');
         $this->_oTable->updateObject($this->_fightInfo, array('fightId' => $this->_fightId));
         DbFactory::getInstance('MYZL')->tryCommit();
         //设置用户提示文本
         if ($this->_responseText) {
             $this->_responseText .= ', ' . sprintf(MYZL_HINT_CHIPIN_SUC, $this->_operand, $GLOBALS['constants']['stepName'][$this->_fightInfo['operation']]);
         } else {
             $this->_responseText = sprintf(MYZL_HINT_CHIPIN_SUC, $this->_operand, $GLOBALS['constants']['stepName'][$this->_fightInfo['operation']]);
         }
     } catch (DB_Exception $e) {
         DbFactory::getInstance('MYZL')->rollback();
         $errorNum = $this->_oTable->getErrorNum();
         $this->_retMsg = $this->_oTable->getErrorInfo() . $e->getMessage();
         $this->_retValue = genRetCode($errorNum);
         interface_log(ERROR, $this->_retValue, $this->_retMsg);
         return false;
     }
     return true;
 }
Beispiel #4
0
    $oTable = new SingleTableOperation('cWaitingUser', 'MYZL');
    while (1) {
        $data = $oTable->getObject(array('_sortExpress' => 'addTimeStamp'));
        matcher_log(DEBUG, 0, json_encode($data));
        if (count($data) < 2) {
            sleep(2);
            continue;
        } else {
            $length = count($data);
            for ($i = 0; $i + 1 < $length; $i = $i + 2) {
                $userId1 = $data[$i]['userId'];
                if ($i >= $length) {
                    continue;
                }
                $userId2 = $data[$i + 1]['userId'];
                DbFactory::getInstance('MYZL')->autoCommit();
                //minus bullets
                DbFactory::getInstance('MYZL')->update("update cUser set bulletNum=bulletNum-1 where userId IN('" . $userId1 . "', '" . $userId2 . "')");
                //删除
                $oTable->delObject(array('userId' => array($userId1, $userId2)));
                //添加
                $oTable->addObject(array('_tableName' => 'cFight', 'user1' => $userId1, 'user2' => $userId2, 'first' => $userId1, 'current' => $userId1, 'operation' => START, 'maxMoney' => $maxMoney, 'minMoney' => $minMoney, 'operator' => 0));
                matcher_log(DEBUG, 0, "add {$userId1} and {$userId2} to fight");
                DbFactory::getInstance('MYZL')->tryCommit();
            }
        }
    }
} catch (DB_Exception $e) {
    DbFactory::getInstance()->rollback();
    matcher_log(ERROR, 0, $oTable->getErrorInfo() . $e->getMessage());
}
Beispiel #5
0
 /**
  * 基本类,提供增删改查
  * @author benzhan
  * @param string $tableName 表名
  * @param string/object $dbKey $dbKey,默认为'DB'
  */
 function __construct($tableName = '', $dbKey = 'DB')
 {
     $this->_tableName = strtolower($tableName);
     $this->_db = DbFactory::getInstance($dbKey);
 }
Beispiel #6
0
 private function divideMoney()
 {
     $this->_oTable->setTableName('cUser');
     if ($this->_result['out']) {
         if ($this->_result['dead']) {
             //有一方中枪,把金币给另外一方
             $userId = $this->_args['userId'] == $this->_fightInfo['user1'] ? $this->_fightInfo['user2'] : $this->_fightInfo['user1'];
             DbFactory::getInstance('MYZL')->update("update cUser set money=money + " . $this->_fightInfo['money'] . " where userId='" . $userId . "'");
             $this->_responseText .= "对方获得【" . $this->_fightInfo['money'] . "金币】";
             $this->_fightInfo['msgForOther'] .= "你获得【" . $this->_fightInfo['money'] . "金币】";
         } else {
             //平局,平分金币
             DbFactory::getInstance('MYZL')->update("update cUser set money=money + " . $this->_fightInfo['money'] / 2 . " where userId IN ('" . $this->_fightInfo['user1'] . "','" . $this->_fightInfo['user2'] . "')");
             $this->_responseText .= "你获得【" . $this->_fightInfo['moeny'] / 2 . "金币】 ,对方获得【" . $this->_fightInfo['moeny'] / 2 . "金币】";
             $this->_fightInfo['msgForOther'] .= "你获得【" . $this->_fightInfo['moeny'] / 2 . "金币】 ,对方获得【" . $this->_fightInfo['moeny'] / 2 . "金币】";
         }
     }
 }
Beispiel #7
0
 public function process()
 {
     try {
         DbFactory::getInstance('MYZL')->autoCommit();
         //获取msgForOther并设置用户提示文本
         $msgForOther = $this->_fightInfo['msgForOther'];
         $otherId = $this->_fightInfo['otherId'];
         if ($otherId == $this->_fromUserName) {
             $this->_responseText .= $msgForOther;
             $this->_fightInfo['msgForOther'] = "";
         }
         //设置用户提示文本
         $this->_fightInfo['otherId'] = $this->_fromUserName == $this->_fightInfo['user1'] ? $this->_fightInfo['user2'] : $this->_fightInfo['user1'];
         if ($this->_fightInfo['msgForOther'] == "") {
             $this->_fightInfo['msgForOther'] = "对方已经使用道具";
         } else {
             $this->_fightInfo['msgForOther'] .= ", 对方已经使用道具";
         }
         //获取道具变量,使用这种方式是为了兼容后续可能出现的一次使用多个道具的情况
         $magic = $this->_args['magic'];
         if ($magic != '') {
             $xsft = 0;
             $hdcx = 0;
             $chxs = 0;
             $sszm = 0;
             if ($magic == XSFT) {
                 $xsft = 1;
             } else {
                 if ($magic == HDCX) {
                     $hdcx = 1;
                 } else {
                     if ($magic == CHXS) {
                         $chxs = 1;
                     } else {
                         if ($magic == SSZM) {
                             $sszm = 1;
                         } else {
                             $this->_retValue = EC_ERROR_MAGIC;
                             $this->_retMsg = "fightId:" . $this->_fightId . " userId:" . $this->_args['userId'] . " magic:" . $magic;
                             interface_log(ERROR, $this->_retValue, $this->_retMsg);
                             return false;
                         }
                     }
                 }
             }
             if ($this->_fightInfo['current'] == $this->_args['userId']) {
                 if ($hdcx) {
                     //如果当前轮次开枪的操作者是当前玩家,则当前玩家不能使用壶底抽薪的技能
                     $this->_retValue = EC_ERROR_MAGIC;
                     $this->_retMsg = "fightId:" . $this->_fightId . " userId:" . $this->_args['userId'] . " magic:" . HDCX;
                     interface_log(ERROR, $this->_retValue, $this->_retMsg);
                     return false;
                 }
             } else {
                 if ($xsft || $chxs || $sszm) {
                     //如果当前轮次开枪的操作者不是当前玩家,则当前玩家只能使用壶底抽薪的技能,其他的技能不可用
                     $this->_retValue = EC_ERROR_MAGIC;
                     $this->_retMsg = "fightId:" . $this->_fightId . " userId:" . $this->_args['userId'] . " magic:" . ($xsft ? XSFT : "") . ($chxs ? CHXS : "") . ($sszm ? SSZM : "");
                     interface_log(ERROR, $this->_retValue, $this->_retMsg);
                     return false;
                 }
             }
             if ($this->_args['magic']) {
                 //更新用户道具数
                 if ($this->_userInfo['xsft'] - $xsft < 0 || $this->_userInfo['hdcx'] - $hdcx < 0 || $this->_userInfo['chxs'] - $chxs < 0 || $this->_userInfo['sszm'] - $sszm < 0) {
                     $this->_retValue = EC_NOT_ENOUGH_MAGIC;
                     $this->_retMsg = "fightId:" . $this->_fightId . " userId:" . $this->_args['userId'] . " magic:" . ($xsft ? XSFT : " ") . ($chxs ? CHXS : " ") . ($sszm ? SSZM : " ") . ($hdcx ? HDCX : " ");
                     interface_log(ERROR, $this->_retValue, $this->_retMsg);
                     return false;
                 }
                 $this->_oTable->setTableName('cUser');
                 $this->_oTable->updateObject(array('xsft' => $this->_userInfo['xsft'] - $xsft, 'hdcx' => $this->_userInfo['hdcx'] - $hdcx, 'chxs' => $this->_userInfo['chxs'] - $chxs, 'sszm' => $this->_userInfo['sszm'] - $sszm), array('userId' => $this->_args['userId']));
             }
         }
         //设置下一步动作和操作码和操作人
         $ret = $this->setNextOpAndUser();
         if ($ret['code']) {
             $this->_retValue = EC_STEP_ERROR;
             $this->_retMsg = "fightId:" . $this->_fightId . " step:" . $this->_fightInfo['historyOp'];
             interface_log(ERROR, $this->_retValue, $this->_retMsg);
             return false;
         }
         //更新游戏数据中的magic1,magic2和magicUsed1和magicUsed2
         if ($this->_args['magic']) {
             $this->setMagic();
         }
         //更新历史操作记录
         if ($this->_fightInfo['historyOp'] == '') {
             $newHistoyOp = PUT_MAGIC . ',' . $this->_args['userId'];
         } else {
             $newHistoyOp = $this->_fightInfo['historyOp'] . "|" . PUT_MAGIC . ',' . $this->_args['userId'];
         }
         $this->_fightInfo['historyOp'] = $newHistoyOp;
         //更新游戏记录
         unset($this->_fightInfo['fightId']);
         $this->_oTable->setTableName('cFight');
         $this->_oTable->updateObject($this->_fightInfo, array('fightId' => $this->_fightId));
         DbFactory::getInstance('MYZL')->tryCommit();
         //设置用户提示文本
         if ($this->_responseText) {
             if ($this->_args['magic']) {
                 $this->_responseText .= ', ' . sprintf(MYZL_HINT_PUTMAGIC_SUC, $GLOBALS['constants']['magicName'][$this->_operand], $GLOBALS['constants']['stepName'][$this->_fightInfo['operation']]);
             } else {
                 $this->_responseText .= ', ' . sprintf(MYZL_HINT_PUTMAGIC_SUC_NO, $GLOBALS['constants']['stepName'][$this->_fightInfo['operation']]);
             }
         } else {
             if ($this->_args['magic']) {
                 $this->_responseText = sprintf(MYZL_HINT_PUTMAGIC_SUC, $GLOBALS['constants']['magicName'][$this->_operand], $GLOBALS['constants']['stepName'][$this->_fightInfo['operation']]);
             } else {
                 $this->_responseText = sprintf(MYZL_HINT_PUTMAGIC_SUC_NO, $GLOBALS['constants']['stepName'][$this->_fightInfo['operation']]);
             }
         }
     } catch (DB_Exception $e) {
         DbFactory::getInstance('MYZL')->rollback();
         $errorNum = $this->_oTable->getErrorNum();
         $this->_retMsg = $this->_oTable->getErrorInfo() . $e->getMessage();
         $this->_retValue = genRetCode($errorNum);
         interface_log(ERROR, $this->_retValue, $this->_retMsg);
         return false;
     }
     return true;
 }
Beispiel #8
0
 public function process()
 {
     try {
         $this->_oTable->setTableName('cUser');
         $data = $this->_oTable->getObject(array('userId' => $this->_args['userId']));
         if (count($data) == 0) {
             $this->_retValue = EC_USER_NOT_EXIST;
             $this->_retMsg = "userId:" . $this->_args['userId'];
             interface_log(ERROR, $this->_retValue, $this->_retMsg);
             return false;
         }
         $this->_args['userId'] = DbFactory::getInstance('MYZL')->escape($this->_args['userId']);
         //分别获取cFight和cFightUncheck中的记录
         $this->_oTable->setTableName('cFight');
         $data = $this->_oTable->getObject(array("_where" => " (user1='" . $this->_args['userId'] . "' OR user2='" . $this->_args['userId'] . "')"));
         $this->_oTable->setTableName('cFightUncheck');
         $data1 = $this->_oTable->getObject(array("_where" => "operation='SECOND_END' AND (user1='" . $this->_args['userId'] . "' OR user2='" . $this->_args['userId'] . "')"));
         if (empty($data) && !empty($data1)) {
             //有一方尚未查看游戏结果的情况
             $data = $data1;
             //delete fight info in uncheck table
             $fightId = $data[0]['fightId'];
             if ($data[0]['current'] != $this->_args['userId']) {
                 //当前用户非最后一下开枪的用户,清理游戏数据
                 $this->_oTable->setTableName('cFightEnd');
                 $this->_oTable->addObject($data[0]);
                 $this->_oTable->setTableName('cFightUncheck');
                 $this->_oTable->delObject(array('fightId' => $fightId));
             }
         }
         if (empty($data) && empty($data1)) {
             $this->_retValue = EC_FIGHT_NOT_EXIST;
             $this->_retMsg = "fightId:" . $this->_args['fightId'] . " userId:" . $this->_args['userId'];
             interface_log(ERROR, $this->_retValue, $this->_retMsg);
             return false;
         } else {
             if (count($data) > 1) {
                 $this->_retValue = EC_MULTIPLE_FIGHT;
                 $this->_retMsg = "userId:" . $this->_args['userId'];
                 interface_log(ERROR, $this->_retValue, $this->_retMsg);
                 return false;
             } else {
                 $this->_fightInfo = $data[0];
                 $msgForOther = $this->_fightInfo['msgForOther'];
                 $otherId = $this->_fightInfo['otherId'];
                 if ($otherId == $this->_args['userId']) {
                     //设置用户提示文本,并把msgForOther更新为空,以免给用户重复的提示
                     $this->_responseText .= $msgForOther;
                     $this->_oTable->setTableName('cFight');
                     $this->_oTable->updateObject(array('msgForOther' => ""), array("fightId" => $this->_fightInfo['fightId']));
                 }
                 interface_log(DEBUG, 0, "reponseText:" . $this->_responseText);
                 $this->_data = $this->_fightInfo;
                 return true;
             }
         }
         $this->_data = array();
     } catch (DB_Exception $e) {
         $errorNum = $this->_oTable->getErrorNum();
         $this->_retMsg = $this->_oTable->getErrorInfo() . $e->getMessage();
         $this->_retValue = genRetCode($errorNum);
         interface_log(ERROR, $this->_retValue, $this->_retMsg);
         return false;
     }
     return true;
 }