2013年6月8日 星期六

【Java教學】開啟伺服器偵測販賣價錢是否正確(防買賣洗錢)

最近發現好像滿多人喜歡販賣所有道具

另外用了個資料表shop_sell_price之類的

但是卻因為價錢沒設定好

被玩家買了便宜 賣商店又高於買的價錢 達到洗錢的效果

[s:168] 牋

對於這個小問題我寫了個小方法偵測

物件:ShopTable

搜尋loadShopAllSell

int price = rs.getInt(\"sell_price\");以下if(price >= 1) {以上貼上下面的程式碼


        //修正販賣價錢錯誤問題
        if (price >= 1) {
          Connection conI     = null;
          PreparedStatement pstmI = null;
          ResultSet rsI       = null;
          try {
            conI   = L1DatabaseFactory.getInstance().getConnection();
            pstmI   = conI.prepareStatement(\"SELECT * FROM shop WHERE item_id='\"+ itemId+\"'\");
            rsI   = pstmI.executeQuery();
            while (rsI.next()) {
              if (rsI.getInt(\"selling_price\") >= 1 && price > rsI.getInt(\"selling_price\")) {
                System.out.println(\"NpcId=\"+rsI.getInt(\"npc_id\")+\", ItemID=\"+itemId+\", PriceError!!!\");
                price = -1;
              }
            }
            rsI.close();
          } catch (SQLException e) {
            _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
          } finally {
            SQLUtil.close(rsI, pstmI, conI);
          }
        }          

沒有留言:

張貼留言