⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 castletable.java

📁 网络游戏天堂1的java源代码。。。。。
💻 JAVA
字号:
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package l1j.server.server.datatables;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.L1DatabaseFactory;
import l1j.server.server.templates.L1Castle;
import l1j.server.server.utils.SQLUtil;

// Referenced classes of package l1j.server.server:
// IdFactory

public class CastleTable {

	private static l1j.eric.EricLogger _log =  l1j.eric.EricLogger.getLogger2(CastleTable.class.getName());

	private static CastleTable _instance;

	private final Map<Integer, L1Castle> _castles = new ConcurrentHashMap<Integer, L1Castle>();

	public static CastleTable getInstance() {
		if (_instance == null) {
			_instance = new CastleTable();
		}
		return _instance;
	}

	private CastleTable() {
		load();
	}

	private Calendar timestampToCalendar(Timestamp ts) {
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(ts.getTime());
		return cal;
	}

	private String tooLong(String s){
		if(s.length()>10){
			return s.substring(0, 10);
		}
		return s;
	}
	
	private void load() {
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			/*
			//借用
			String html = "-c.html";
			con = L1DatabaseFactory.getInstance().getConnection();
			//etctim
			pstm = con.prepareStatement("SELECT * FROM etcitem ORDER BY item_type ASC");
			rs = pstm.executeQuery();
			String path = "gmHTML/etcitem/";
			File file;
			String tempItemName="";
			FileOutputStream fos = null;
			FileOutputStream fetcitem = new FileOutputStream("gmHTML/gmetcitem"+html);
			String t="<body>物品清單<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			while(rs.next()){
				if(!tempItemName.equals(rs.getString("item_type"))){
					String s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
					if(!tempItemName.equals("")){
						fos.write(s.getBytes());
					}
					tempItemName=rs.getString("item_type");
					file=new File(path+"gm"+tooLong(tempItemName)+html);
					fos=new FileOutputStream(file);
					s= "<body><br><font fg=FFFFCC>"+tempItemName+"</font><br><br>\n";
					fos.write(s.getBytes());
					t="<a link=\""+"gm"+tooLong(tempItemName)+"\"><font fg=FFFFCC> "+tempItemName+" </font></a><br>\n";
					fetcitem.write(t.getBytes());
				}
				String q="<a action=\"gmcommand item "+rs.getInt("item_id")+
					" 1 0 1\"> "+rs.getString("name")+"("+rs.getInt("item_id")+") </a><br>\n";
				fos.write(q.getBytes());
			}
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();
			
			//***************armor
			String str = "aromr";
			path = "gmHTML/"+str+"/";
			pstm = con.prepareStatement("SELECT * FROM armor ORDER BY type ASC");
			rs = pstm.executeQuery();
			tempItemName="";
			fos = null;
			fetcitem = new FileOutputStream("gmHTML/gm"+str+html);
			t="<body>防具清單<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			while(rs.next()){
				if(!tempItemName.equals(rs.getString("type"))){
					String s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
					if(!tempItemName.equals("")){
						fos.write(s.getBytes());
					}
					tempItemName=rs.getString("type");
					file=new File(path+"gm"+tooLong(tempItemName)+html);
					fos=new FileOutputStream(file);
					s= "<body><br><font fg=FFFFCC>"+tempItemName+"</font><br><br>\n";
					fos.write(s.getBytes());
					t="<a link=\""+"gm"+tooLong(tempItemName)+"\"><font fg=FFFFCC> "+tempItemName+" </font></a><br>\n";
					fetcitem.write(t.getBytes());
				}
				String q="<a action=\"gmcommand item "+rs.getInt("item_id")+
					" 1 1 1\"> "+rs.getString("name")+"("+rs.getInt("item_id")+") </a><br>\n";
				fos.write(q.getBytes());
			}
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();
			
			//***************weapon
			str = "weapon";
			path = "gmHTML/"+str+"/";
			pstm = con.prepareStatement("SELECT * FROM weapon ORDER BY type ASC");
			rs = pstm.executeQuery();
			tempItemName="";
			fos = null;
			fetcitem = new FileOutputStream("gmHTML/gm"+str+html);
			t="<body>武器清單<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			while(rs.next()){
				if(!tempItemName.equals(rs.getString("type"))){
					String s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
					if(!tempItemName.equals("")){
						fos.write(s.getBytes());
					}
					tempItemName=rs.getString("type");
					file=new File(path+"gm"+tooLong(tempItemName)+html);
					fos=new FileOutputStream(file);
					s= "<body><br><font fg=FFFFCC>"+tempItemName+"</font><br><br>\n";
					fos.write(s.getBytes());
					t="<a link=\""+"gm"+tooLong(tempItemName)+"\"><font fg=FFFFCC> "+tempItemName+" </font></a><br>\n";
					fetcitem.write(t.getBytes());
				}
				String q="<a action=\"gmcommand item "+rs.getInt("item_id")+
					" 1 1 1\"> "+rs.getString("name")+"("+rs.getInt("item_id")+") </a><br>\n";
				fos.write(q.getBytes());
			}
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();	
			
			//***************npc
			str = "npc";
			path = "gmHTML/"+str+"/";
			pstm = con.prepareStatement("SELECT * FROM npc where impl!='L1Monster' ORDER BY impl ASC");
			rs = pstm.executeQuery();
			tempItemName="1";
			fos = null;
			fetcitem = new FileOutputStream("gmHTML/gm"+str+html);
			t="<body>增加NPC清單<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			while(rs.next()){
				if(!tempItemName.equals(rs.getString("impl"))){
					String s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
					if(!tempItemName.equals("1")){
						fos.write(s.getBytes());
					}
					tempItemName=rs.getString("impl");
					file=new File(path+"gm"+tooLong(tempItemName)+html);
					fos=new FileOutputStream(file);
					s= "<body><br><font fg=FFFFCC>"+tempItemName+"</font><br><br>\n";
					fos.write(s.getBytes());
					t="<a link=\""+"gm"+tooLong(tempItemName)+"\"><font fg=FFFFCC> "+tempItemName+" </font></a><br>\n";
					fetcitem.write(t.getBytes());
				}
				String q="<a action=\"gmcommand insert npc "+rs.getInt("npcid")+
					"\"> "+rs.getString("name")+"("+rs.getString("impl")+") </a><br>\n";
				fos.write(q.getBytes());
			}
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();		
			
			
			//***************insert mob
			str = "mob";
			path = "gmHTML/"+str+"/";
			pstm = con.prepareStatement("SELECT * FROM npc where impl='L1Monster' ORDER BY impl ASC");
			rs = pstm.executeQuery();
			tempItemName="";
			fos = null;
			fetcitem = new FileOutputStream("gmHTML/gm"+str+html);
			t="<body>增加怪物清單(匯入資料庫)<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			while(rs.next()){
				if(!tempItemName.equals(rs.getString("impl"))){
					String s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
					if(!tempItemName.equals("")){
						fos.write(s.getBytes());
					}
					tempItemName=rs.getString("impl");
					file=new File(path+"gm"+tooLong(tempItemName)+html);
					
					fos=new FileOutputStream(file);
					s= "<body><br><font fg=FFFFCC>"+tempItemName+"</font><br><br>\n";
					fos.write(s.getBytes());
					t="<a link=\""+"gm"+tooLong(tempItemName)+"\"><font fg=FFFFCC> "+tempItemName+" </font></a><br>\n";
					fetcitem.write(t.getBytes());
				}
				String q="<a action=\"gmcommand insert mob "+rs.getInt("npcid")+
					"\"> "+rs.getString("name")+"("+rs.getInt("npcid")+") </a><br>\n";
				fos.write(q.getBytes());
			}
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();	
			
			//***************spawn mob
			str = "spawn";
			path = "gmHTML/"+str+"/";
			pstm = con.prepareStatement("SELECT * FROM npc where impl='L1Monster' ORDER BY impl ASC");
			rs = pstm.executeQuery();
			tempItemName="";
			fos = null;
			fetcitem = new FileOutputStream("gmHTML/gm"+str+html);
			t="<body>召喚怪物清單<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			while(rs.next()){
				if(!tempItemName.equals(rs.getString("impl"))){
					String s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
					if(!tempItemName.equals("")){
						fos.write(s.getBytes());
					}
					tempItemName=rs.getString("impl");
					file=new File(path+"gmspawnMob"+html);
					
					fos=new FileOutputStream(file);
					s= "<body><br><font fg=FFFFCC>"+tempItemName+"</font><br><br>\n";
					fos.write(s.getBytes());
					t="<a link=\""+"gmspawnMob"+"\"><font fg=FFFFCC> "+tempItemName+" </font></a><br>\n";
					fetcitem.write(t.getBytes());
				}
				String q="<a action=\"gmcommand spawn "+rs.getInt("npcid")+
					"\"> "+rs.getString("name")+"("+rs.getInt("npcid")+") </a><br>\n";
				fos.write(q.getBytes());
			}
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();
			
			//***************summon mob
			str = "summon";
			path = "gmHTML/"+str+"/";
			pstm = con.prepareStatement("SELECT * FROM npc where impl='L1Monster' ORDER BY impl ASC");
			rs = pstm.executeQuery();
			tempItemName="";
			fos = null;
			fetcitem = new FileOutputStream("gmHTML/gm"+str+html);
			t="<body>召喚寵物清單<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			while(rs.next()){
				if(!tempItemName.equals(rs.getString("impl"))){
					String s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
					if(!tempItemName.equals("")){
						fos.write(s.getBytes());
					}
					tempItemName=rs.getString("impl");
					file=new File(path+"gmsummonMob"+html);
					fos=new FileOutputStream(file);
					s= "<body><br><font fg=FFFFCC>"+tempItemName+"</font><br><br>\n";
					fos.write(s.getBytes());
					t="<a link=\""+"gmsummonMob"+"\"><font fg=FFFFCC> "+tempItemName+" </font></a><br>\n";
					fetcitem.write(t.getBytes());
				}
				String q="<a action=\"gmcommand summon "+rs.getInt("npcid")+
					"\"> "+rs.getString("name")+"("+rs.getInt("npcid")+") </a><br>\n";
				fos.write(q.getBytes());
			}
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();
			
			//***************teleport
			str = "teleport";
			path = "gmHTML/"+str+"/";
			pstm = con.prepareStatement("SELECT * FROM etcitem where item_type='scroll' and locx!=0");
			rs = pstm.executeQuery();
			tempItemName="";
			fos = null;
			fetcitem = new FileOutputStream("gmHTML/gm"+str+html);
			t="<body>傳送清單<br><font fg=996600>==============================</font><br><br>\n";
			fetcitem.write(t.getBytes());
			file=new File(path+"gmteleport2"+html);
			fos=new FileOutputStream(file);
			t="<a link=\""+"gmteleport2\"><font fg=FFFFCC> 傳送清單 </font></a><br>\n";
			fetcitem.write(t.getBytes());
			String s;
			s= "<body><br><font fg=FFFFCC>teleport</font><br><br>\n";
			fos.write(s.getBytes());
			while(rs.next()){

				String q="<a action=\"gmcommand move "+rs.getInt("locx")+" "+rs.getInt("locy")+" "+rs.getInt("mapid")+
					"\"> "+rs.getString("name")+" </a><br>\n";
				fos.write(q.getBytes());
			}
			s = "<br><br><img src=\"#331\" link=\"gmadmin\"><br></body>\n";
			fos.write(s.getBytes());
			t="<br><br><img src=\"#331\" link=\"gmadmin\"></body>\n";
			fetcitem.write(t.getBytes());
			fetcitem.flush();	
			
			
			//~借用
			
			*/
			
			
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con.prepareStatement("SELECT * FROM castle");

			rs = pstm.executeQuery();

			while (rs.next()) {
				L1Castle castle = new L1Castle(rs.getInt(1), rs.getString(2));
				castle.setWarTime(timestampToCalendar((Timestamp) rs
						.getObject(3)));
				castle.setTaxRate(rs.getInt(4));
				castle.setPublicMoney(rs.getInt(5));

				_castles.put(castle.getId(), castle);
			}
		} catch (SQLException e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
		}catch(Exception e){
			e.printStackTrace();
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	public L1Castle[] getCastleTableList() {
		return _castles.values().toArray(new L1Castle[_castles.size()]);
	}

	public L1Castle getCastleTable(int id) {
		return _castles.get(id);
	}

	public void updateCastle(L1Castle castle) {
		Connection con = null;
		PreparedStatement pstm = null;
		try {
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con
					.prepareStatement("UPDATE castle SET name=?, war_time=?, tax_rate=?, public_money=? WHERE castle_id=?");
			pstm.setString(1, castle.getName());
//TODO�@�

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -