정적 분석 결과 반영. 베팅 코드는 새로 작성

This commit is contained in:
2018-04-08 20:18:18 +09:00
parent ba4ff29e4a
commit b78fe22633
5 changed files with 66 additions and 31 deletions
+3 -3
View File
@@ -97,9 +97,9 @@ if($me['level'] == 0) {
if($myNation['level'] > 0) { if($myNation['level'] > 0) {
// 첩보도시도 목록에 추가 // 첩보도시도 목록에 추가
$where = 'city=0'; $where = 'city=0';
$cities = explode("|", $myNation['spy']); $cities = array_map('intval',explode("|", $myNation['spy']));
for($i=0; $i < count($cities); $i++) { foreach($cities as $citySpy) {
$city = intdiv($cities[$i], 10); $city = intdiv($citySpy, 10);
$where .= " or city='{$city}'"; $where .= " or city='{$city}'";
} }
+3
View File
@@ -83,6 +83,9 @@ switch ($type) {
$cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), ""); $cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), "");
$citycount = MYDB_num_rows($cityresult); $citycount = MYDB_num_rows($cityresult);
$region = 0;
$level = 0;
for ($j=0; $j < $citycount; $j++) { for ($j=0; $j < $citycount; $j++) {
$city = MYDB_fetch_array($cityresult); $city = MYDB_fetch_array($cityresult);
if ($city['city'] == $nation['capital']) { if ($city['city'] == $nation['capital']) {
+2
View File
@@ -50,6 +50,8 @@ $query = "select city,name,pop,pop2 from city where nation='{$nation['nation']}'
$cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$citycount = MYDB_num_rows($cityresult); $citycount = MYDB_num_rows($cityresult);
$totalpop = 0;
$maxpop = 0;
for($j=0; $j < $citycount; $j++) { for($j=0; $j < $citycount; $j++) {
$city = MYDB_fetch_array($cityresult); $city = MYDB_fetch_array($cityresult);
if($city['city'] == $nation['capital']) { $cityname[$j] = "<font color=cyan>[{$city['name']}]</font>"; } if($city['city'] == $nation['capital']) { $cityname[$j] = "<font color=cyan>[{$city['name']}]</font>"; }
+20
View File
@@ -3,6 +3,26 @@ namespace sammo;
include "lib.php"; include "lib.php";
include "func.php"; include "func.php";
$v = new Validator($_POST + $_GET);
$v->rule('integer', [
'amount',
'cost',
'topv',
'value',
'term',
'stuff',
'sel'
]);
$amount = Util::getReq('amount', 'int');
$cost = Util::getReq('cost', 'int');
$topv = Util::getReq('topv', 'int');
$value = Util::getReq('value', 'int');
$term = Util::getReq('term', 'int');
$stuff = Util::getReq('stuff', 'int');
$sel = Util::getReq('sel', 'int');
//로그인 검사 //로그인 검사
$session = Session::requireGameLogin()->setReadOnly(); $session = Session::requireGameLogin()->setReadOnly();
$userID = Session::getUserID(); $userID = Session::getUserID();
+38 -28
View File
@@ -4,48 +4,58 @@ namespace sammo;
include "lib.php"; include "lib.php";
include "func.php"; include "func.php";
// $btn0~15, $gold0~15 // $btn0~15, $gold0~15
$betTarget = -1;
$betGold = -1;
for($i=0;$i<16;$i++){
$textBtn = "btn{$i}";
$textGold = "gold{$i}";
$btn = Util::getReq($textBtn);
$gold = Util::getReq($textGold, 'int');
if($btn === "베팅!" && $gold){
$betTarget = $i;
$betGold = $gold;
break;
}
}
if($betTarget < 0 || $betGold < 10 || $betGold > 1000){
header('Location: b_betting.php');
exit();
}
//로그인 검사 //로그인 검사
$session = Session::requireGameLogin()->setReadOnly(); $session = Session::requireGameLogin()->setReadOnly();
$userID = Session::getUserID(); $userID = Session::getUserID();
$db = DB::db(); $db = DB::db();
$connect=$db->get();
increaseRefresh("베팅", 1); increaseRefresh("베팅", 1);
$query = "select tournament,phase,tnmt_type,develcost from game limit 1"; $tournament = $db->queryFirstField('SELECT tournament FROM game LIMIT 1');
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); if($tournament != 6) {
$admin = MYDB_fetch_array($result); header('Location: b_betting.php');
if($admin['tournament'] != 6) {
//echo "<script>location.replace('b_betting.php');</script>";
echo 'b_betting.php';//TODO:debug all and replace
exit(); exit();
} }
$query = "select gold,bet0,bet1,bet2,bet3,bet4,bet5,bet6,bet7,bet8,bet9,bet10,bet11,bet12,bet13,bet14,bet15,bet0+bet1+bet2+bet3+bet4+bet5+bet6+bet7+bet8+bet9+bet10+bet11+bet12+bet13+bet14+bet15 as bet from general where owner='{$userID}'"; $bets = $db->queryFirstList('SELECT bet0,bet1,bet2,bet3,bet4,bet5,bet6,bet7,bet8,bet9,bet10,bet11,bet12,bet13,bet14,bet15,gold FROM general WHERE `owner`=%i', $userID);
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $myGold = array_pop($bets);
$me = MYDB_fetch_array($result); $totalBet = array_sum($bets);
for($i=0; $i < 16; $i++) { //NOTE: 위 코드에서 $betTarget은 0~15의 정수임이 보장된다.
if(${"btn{$i}"} == "베팅!") { $oldBet = $bets[$betTarget];
$gold = Util::toInt(${"gold{$i}"}); if($betGold + 500 <= $myGold && $betGold + $oldBet <= 1000 && $betGold + $totalBet <= 1000) {
$mebet = $me["bet{$i}"]; $db->update('general', [
if($gold >= 10 && $gold <= 1000) { 'gold'=>$db->sqleval('gold - %i', $betGold),
if($gold + 500 <= $me['gold'] && $gold + $mebet <= 1000 && $gold + $me['bet'] <= 1000) { "bet{$betTarget}"=>$db->sqleval("bet{$betTarget} + %i", $betGold),
$query = "update general set gold=gold-'$gold',bet{$i}=bet{$i}+'$gold',betgold=betgold+'$gold' where owner='{$userID}'"; 'betgold'=>$db->sqleval('betgold + %i', $betGold)
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); ], 'owner = %i', $userID);
$query = "update game set bet{$i}=bet{$i}+'$gold'"; $db->update('game', [
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); "bet{$betTarget}"=>$db->sqleval("bet{$betTarget} + %i", $betGold)
} ], true);
}
}
} }
?> header('location: b_betting.php');
<!--<script>location.replace('b_betting.php');</script>//TODO:debug all and replace-->
b_betting.php