📄 mapleclient.java
字号:
if(subnetInfo.contains("net.sf.odinms.net.login.subnetcount")) {
int subnetCount = Integer.parseInt(subnetInfo.getProperty("net.sf.odinms.net.login.subnetcount"));
for(int i = 0; i < subnetCount; i++) {
String[] connectionInfo = subnetInfo.getProperty("net.sf.odinms.net.login.subnet." + i).split(":");
long subnet = IPAddressTool.dottedQuadToLong(connectionInfo[0]);
long channelIP = IPAddressTool.dottedQuadToLong(connectionInfo[1]);
int channelNumber = Integer.parseInt(connectionInfo[2]);
if(((ipAddress & subnet) == (channelIP & subnet)) && (channel == channelNumber)) {
return connectionInfo[1];
}
}
}
return "0.0.0.0";
}
private void unban() {
int i;
try {
Connection con = DatabaseConnection.getConnection();
loadMacsIfNescessary();
StringBuilder sql = new StringBuilder("DELETE FROM macbans WHERE mac IN (");
for (i = 0; i < macs.size(); i++) {
sql.append("?");
if (i != macs.size() - 1)
sql.append(", ");
}
sql.append(")");
PreparedStatement ps = con.prepareStatement(sql.toString());
i = 0;
for (String mac : macs) {
i++;
ps.setString(i, mac);
}
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("DELETE FROM ipbans WHERE ip LIKE CONCAT(?, '%')");
ps.setString(1, getSession().getRemoteAddress().toString().split(":")[0]);
ps.executeUpdate();
ps.close();
ps = con.prepareStatement("UPDATE accounts SET banned = 0 WHERE id = ?");
ps.setInt(1, accId);
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
log.error("Error while unbanning", e);
}
}
public void updateMacs(String macData) {
for (String mac : macData.split(", ")) {
macs.add(mac);
}
StringBuilder newMacData = new StringBuilder();
Iterator<String> iter = macs.iterator();
while (iter.hasNext()) {
String cur = iter.next();
newMacData.append(cur);
if (iter.hasNext())
newMacData.append(", ");
}
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?");
ps.setString(1, newMacData.toString());
ps.setInt(2, accId);
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
log.error("Error saving MACs", e);
}
}
public void setAccID(int id) {
this.accId = id;
}
public int getAccID() {
return this.accId;
}
public void updateLoginState(int newstate) { // TODO hide?
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con
.prepareStatement("UPDATE accounts SET loggedin = ?, lastlogin = CURRENT_TIMESTAMP() WHERE id = ?");
ps.setInt(1, newstate);
ps.setInt(2, getAccID());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
log.error("ERROR", e);
}
if (newstate == MapleClient.LOGIN_NOTLOGGEDIN) {
loggedIn = false;
serverTransition = false;
} else {
serverTransition = (newstate == MapleClient.LOGIN_SERVER_TRANSITION);
loggedIn = !serverTransition;
}
}
public int getLoginState() { // TODO hide?
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps;
ps = con.prepareStatement("SELECT loggedin, lastlogin, birthday FROM accounts WHERE id = ?");
ps.setInt(1, getAccID());
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
ps.close();
throw new DatabaseException("Everything sucks");
}
birthday = Calendar.getInstance();
long blubb = rs.getLong("birthday");
if (blubb > 0) {
birthday.setTime(rs.getDate("birthday"));
}
int state = rs.getInt("loggedin");
if (state == MapleClient.LOGIN_SERVER_TRANSITION) {
Timestamp ts = rs.getTimestamp("lastlogin");
long t = ts.getTime();
long now = System.currentTimeMillis();
if (t + 30000 < now) { // connecting to chanserver timeout
state = MapleClient.LOGIN_NOTLOGGEDIN;
updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
}
}
rs.close();
ps.close();
if (state == MapleClient.LOGIN_LOGGEDIN) {
loggedIn = true;
} else {
loggedIn = false;
}
return state;
} catch (SQLException e) {
loggedIn = false;
log.error("ERROR", e);
throw new DatabaseException("Everything sucks");
}
}
public boolean checkBirthDate(Calendar date) {
if (date.get(Calendar.YEAR) == birthday.get(Calendar.YEAR) &&
date.get(Calendar.MONTH) == birthday.get(Calendar.MONTH) &&
date.get(Calendar.DAY_OF_MONTH) == birthday.get(Calendar.DAY_OF_MONTH)) {
return true;
}
return false;
}
public void disconnect() {
// pingTask.cancel(true);
MapleCharacter chr = this.getPlayer();
if (chr != null && isLoggedIn()) {
// log.warn("[dc] Player {} disconnected from map {}", new Object[]
// {chr.getName(), chr.getMapId()});
if (chr.getTrade() != null) {
MapleTrade.cancelTrade(chr);
}
chr.cancelAllBuffs();
if (chr.getEventInstance() != null) {
chr.getEventInstance().playerDisconnected(chr);
}
chr.cancelMagicDoor();
chr.saveToDB(true);
chr.getCheatTracker().dispose();
chr.getMap().removePlayer(chr);
try {
WorldChannelInterface wci = getChannelServer().getWorldInterface();
if (chr.getParty() != null) {
MaplePartyCharacter chrp = new MaplePartyCharacter(chr);
chrp.setOnline(false);
wci.updateParty(chr.getParty().getId(), PartyOperation.LOG_ONOFF, chrp);
}
wci.loggedOff(chr.getName(), chr.getId(), channel, chr.getBuddylist().getBuddyIds());
} catch (RemoteException e) {
getChannelServer().reconnectWorld();
} catch (Exception e) {
log.error(getLogMessage(this, "ERROR"), e);
} finally {
if (getChannelServer() != null) {
getChannelServer().removePlayer(chr);
} else {
log.error(getLogMessage(this, "No channelserver associated to char {}", chr.getName()));
}
}
}
if (!this.serverTransition && isLoggedIn()) {
this.updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
}
NPCScriptManager npcsm = NPCScriptManager.getInstance();
if (npcsm != null) {
npcsm.dispose(this);
}
}
public void dropDebugMessage(MessageCallback mc) {
StringBuilder builder = new StringBuilder();
builder.append("Connected: ");
builder.append(getSession().isConnected());
builder.append(" Closing: ");
builder.append(getSession().isClosing());
builder.append(" ClientKeySet: ");
builder.append(getSession().getAttribute(MapleClient.CLIENT_KEY) != null);
builder.append(" loggedin: ");
builder.append(isLoggedIn());
builder.append(" has char: ");
builder.append(getPlayer() != null);
mc.dropMessage(builder.toString());
}
/**
* Undefined when not logged to a channel
*
* @return the channel the client is connected to
*/
public int getChannel() {
return channel;
}
/**
* Convinence method to get the ChannelServer object this client is logged
* on to.
*
* @return The ChannelServer instance of the client.
*/
public ChannelServer getChannelServer() {
return ChannelServer.getInstance(getChannel());
}
public boolean deleteCharacter(int cid) {
Connection con = DatabaseConnection.getConnection();
try {
PreparedStatement ps = con.prepareStatement("SELECT id FROM characters WHERE id = ? AND accountid = ?");
ps.setInt(1, cid);
ps.setInt(2, accId);
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
rs.close();
ps.close();
return false;
}
rs.close();
ps.close();
// ok this is actually our character, delete it
ps = con.prepareStatement("DELETE FROM characters WHERE id = ?");
ps.setInt(1, cid);
ps.executeUpdate();
ps.close();
return true;
} catch (SQLException e) {
log.error("ERROR", e);
}
return false;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public void setChannel(int channel) {
this.channel = channel;
}
public int getWorld() {
return world;
}
public void setWorld(int world) {
this.world = world;
}
public void pongReceived() {
lastPong = System.currentTimeMillis();
}
public void sendPing() {
final long then = System.currentTimeMillis();
getSession().write(MaplePacketCreator.getPing());
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
try {
if (lastPong - then < 0) {
if (getSession().isConnected()) {
log.info(getLogMessage(MapleClient.this, "Autodc"));
getSession().close();
}
}
} catch (NullPointerException e) {
// client already gone
}
}
}, 15000); // note: idletime gets added to this too
}
public static String getLogMessage(MapleClient cfor, String message) {
return getLogMessage(cfor, message, new Object[0]);
}
public static String getLogMessage(MapleCharacter cfor, String message) {
return getLogMessage(cfor == null ? null : cfor.getClient(), message);
}
public static String getLogMessage(MapleCharacter cfor, String message, Object... parms) {
return getLogMessage(cfor == null ? null : cfor.getClient(), message, parms);
}
public static String getLogMessage(MapleClient cfor, String message, Object... parms) {
StringBuilder builder = new StringBuilder();
if (cfor != null) {
if (cfor.getPlayer() != null) {
builder.append("<");
builder.append(MapleCharacterUtil.makeMapleReadable(cfor.getPlayer().getName()));
builder.append(" (cid: ");
builder.append(cfor.getPlayer().getId());
builder.append(")> ");
}
if (cfor.getAccountName() != null) {
builder.append("(Account: ");
builder.append(MapleCharacterUtil.makeMapleReadable(cfor.getAccountName()));
builder.append(") ");
}
}
builder.append(message);
for (Object parm : parms) {
int start = builder.indexOf("{}");
builder.replace(start, start + 2, parm.toString());
}
return builder.toString();
}
public Set<String> getMacs() {
return Collections.unmodifiableSet(macs);
}
public boolean isGm() {
return gm;
}
public void setScriptEngine(String name, ScriptEngine e) {
engines.put(name, e);
}
public ScriptEngine getScriptEngine(String name) {
return engines.get(name);
}
public void removeScriptEngine(String name) {
engines.remove(name);
}
public ScheduledFuture<?> getIdleTask() {
return idleTask;
}
public void setIdleTask(ScheduledFuture<?> idleTask) {
this.idleTask = idleTask;
}
private static class CharNameAndId {
public String name;
public int id;
public CharNameAndId(String name, int id) {
super();
this.name = name;
this.id = id;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -