Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
BuyCSItemHandler.java
Package: src.rar [view]
Upload User: gwt600
Upload Date: 2021-06-03
Package Size: 704k
Code Size: 5k
Category:
Games
Development Platform:
Java
- /*
- This file is part of the OdinMS Maple Story Server
- Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
- Matthias Butz <matze@odinms.de>
- Jan Christian Meyer <vimes@odinms.de>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License version 3
- as published by the Free Software Foundation. You may not use, modify
- or distribute this program under any other version of the
- GNU Affero General Public License.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package net.sf.odinms.net.channel.handler;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import net.sf.odinms.client.MapleCharacter;
- import net.sf.odinms.client.MapleClient;
- import net.sf.odinms.client.MaplePet;
- import net.sf.odinms.client.MapleRing;
- import net.sf.odinms.database.DatabaseConnection;
- import net.sf.odinms.net.AbstractMaplePacketHandler;
- import net.sf.odinms.server.AutobanManager;
- import net.sf.odinms.server.CashItemFactory;
- import net.sf.odinms.server.CashItemInfo;
- import net.sf.odinms.server.MapleInventoryManipulator;
- import net.sf.odinms.tools.MaplePacketCreator;
- import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
- /**
- *
- * @author Acrylic (Terry Han)
- */
- public class BuyCSItemHandler extends AbstractMaplePacketHandler {
- @Override
- public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
- System.out.println(slea.toString());
- int action = slea.readByte();
- if (action == 3) {
- slea.skip(1);
- int useNX = slea.readInt();
- int snCS = slea.readInt();
- CashItemInfo item = CashItemFactory.getItem(snCS);
- if (c.getPlayer().getCSPoints(useNX) >= item.getPrice()) {
- c.getPlayer().modifyCSPoints(useNX, -item.getPrice());
- } else {
- c.getSession().write(MaplePacketCreator.enableActions());
- AutobanManager.getInstance().autoban(c, "Trying to purchase from the CS when they have no NX");
- return;
- }
- if(item.getId() >= 5390000 && item.getId() <= 5390002){
- c.getPlayer().dropMessage(1, "You may not purchase this item");
- return;
- }
- if (item.getId() >= 5000000 && item.getId() <= 5000100) {
- int petId = MaplePet.createPet(item.getId());
- if (petId == -1) {
- return;
- }
- MapleInventoryManipulator.addById(c, item.getId(), (short) 1, null, petId);
- } else {
- MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount());
- }
- c.getSession().write(MaplePacketCreator.showBoughtCSItem(item.getId()));
- c.getSession().write(MaplePacketCreator.showNXMapleTokens(c.getPlayer()));
- c.getSession().write(MaplePacketCreator.enableCSUse0());
- c.getSession().write(MaplePacketCreator.enableCSUse1());
- c.getSession().write(MaplePacketCreator.enableCSUse2());
- c.getSession().write(MaplePacketCreator.enableActions());
- } else if (action == 5) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("DELETE FROM wishlist WHERE charid = ?");
- ps.setInt(1, c.getPlayer().getId());
- ps.executeUpdate();
- ps.close();
- int i = 10;
- while (i > 0) {
- int sn = slea.readInt();
- if (sn != 0) {
- ps = con.prepareStatement("INSERT INTO wishlist(charid, sn) VALUES(?, ?) ");
- ps.setInt(1, c.getPlayer().getId());
- ps.setInt(2, sn);
- ps.executeUpdate();
- ps.close();
- }
- i--;
- }
- } catch (SQLException se) {
- }
- c.getSession().write(MaplePacketCreator.sendWishList(c.getPlayer().getId(), true));
- } else if (action == 30) {
- int snCS = slea.readInt();
- CashItemInfo item = CashItemFactory.getItem(snCS);
- if (c.getPlayer().getMeso() >= item.getPrice()) {
- c.getPlayer().gainMeso(-item.getPrice(), false);
- MapleInventoryManipulator.addById(c, item.getId(), (short) item.getCount());
- // MapleInventory etcInventory = c.getPlayer().getInventory(MapleInventoryType.ETC);
- // byte slot = etcInventory.findById(item.getId()).getPosition();
- // c.getSession().write(MaplePacketCreator.showBoughtCSQuestItem(slot, item.getId()));
- } else {
- AutobanManager.getInstance().autoban(c, "Trying to purchase from the CS with an insufficient amount");
- return;
- }
- }
- }
- }