forked from MagicBane/Server
Initial Repository Push
This commit is contained in:
@@ -0,0 +1,381 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client;
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.util.ByteUtils;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyAgreement;
|
||||
import javax.crypto.ShortBufferException;
|
||||
import javax.crypto.interfaces.DHPublicKey;
|
||||
import javax.crypto.spec.DHParameterSpec;
|
||||
import javax.crypto.spec.DHPublicKeySpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.BufferOverflowException;
|
||||
import java.nio.BufferUnderflowException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.*;
|
||||
|
||||
public class ClientAuthenticator {
|
||||
|
||||
private final AbstractConnection origin;
|
||||
|
||||
private ByteBuffer buffer = ByteBuffer.allocate(100);
|
||||
private byte[] secretKeyBytes = new byte[16];
|
||||
private SecretKeySpec BFKey;
|
||||
|
||||
private Cipher cipher;
|
||||
private byte[] iVecEnc = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
private byte[] iVecDec = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
private int iVecEncOffset = 0;
|
||||
private int iVecDecOffset = 0;
|
||||
private int totalRead = 0;
|
||||
private KeyFactory keyFactory;
|
||||
private DHParameterSpec dhParamSpec;
|
||||
private KeyPairGenerator keyPairGen;
|
||||
private KeyAgreement keyAgree;
|
||||
private boolean initialized = false;
|
||||
private boolean keyInit = false;
|
||||
private byte[] secretKey;
|
||||
private byte[] serverPublicKey;
|
||||
|
||||
public ClientAuthenticator(AbstractConnection origin) {
|
||||
super();
|
||||
this.origin = origin;
|
||||
try {
|
||||
// init the resuable Crypto Stuff.
|
||||
this.keyFactory = KeyFactory.getInstance("DH");
|
||||
this.dhParamSpec = new DHParameterSpec(ClientAuthenticator.P, ClientAuthenticator.G);
|
||||
|
||||
this.keyPairGen = KeyPairGenerator.getInstance("DH");
|
||||
this.keyPairGen.initialize(this.dhParamSpec);
|
||||
this.keyAgree = KeyAgreement.getInstance("DH");
|
||||
|
||||
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
|
||||
Logger.error("NoSuchAlgorithmException " + e.getMessage());
|
||||
this.keyInit = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.keyInit = true;
|
||||
}
|
||||
|
||||
private void calcKeys(AbstractConnection origin, byte[] clientPublicKeyBytes) {
|
||||
|
||||
try {
|
||||
// get the forwarded client public key, in byte[] form.
|
||||
|
||||
// Convert client public key to a BigInteger
|
||||
BigInteger clientPublicKeyBI = new BigInteger(1, clientPublicKeyBytes);
|
||||
|
||||
// convert the client's Public Key to a DHPublicKey object
|
||||
DHPublicKeySpec dhKeySpec = new DHPublicKeySpec(clientPublicKeyBI, ClientAuthenticator.P, ClientAuthenticator.G);
|
||||
DHPublicKey clientPublicKey = (DHPublicKey) this.keyFactory.generatePublic(dhKeySpec);
|
||||
|
||||
// Now calculate the server's PublicKey
|
||||
byte[] serverPublicKeyBytes = new byte[96];
|
||||
boolean invalid = true;
|
||||
|
||||
int tryCnt = 1;
|
||||
while (invalid) {
|
||||
KeyPair keyPair = keyPairGen.generateKeyPair();
|
||||
this.keyAgree = KeyAgreement.getInstance("DH");
|
||||
this.keyAgree.init(keyPair.getPrivate());
|
||||
DHPublicKey serverPublicKey = (DHPublicKey) keyPair.getPublic();
|
||||
|
||||
String hex = serverPublicKey.getY().toString(16);
|
||||
|
||||
if (hex.length() == 192) {
|
||||
invalid = false;
|
||||
serverPublicKeyBytes = ByteUtils.stringHexToByteArray(hex);
|
||||
}
|
||||
if (tryCnt >= 5)
|
||||
// Give java 4 tries to get a Public key of valid length.
|
||||
throw new Exception("Not able to generate a valid length public key");
|
||||
++tryCnt;
|
||||
}
|
||||
|
||||
// Calculate shared DH Secret Key
|
||||
keyAgree.doPhase(clientPublicKey, true);
|
||||
this.secretKey = keyAgree.generateSecret();
|
||||
this.serverPublicKey = serverPublicKeyBytes;
|
||||
|
||||
// Now we have the server's publicKey and the common secretKey
|
||||
} catch (Exception e) {
|
||||
origin.disconnect();
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized int initialize(AbstractConnection origin) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
int read = -1;
|
||||
|
||||
// Read the data from connections socket channel
|
||||
try {
|
||||
read = origin.getSocketChannel().read(this.buffer);
|
||||
} catch (IOException e) {
|
||||
if (e.getLocalizedMessage() != null && !e.getLocalizedMessage().equals(MBServerStatics.EXISTING_CONNECTION_CLOSED) && !e.getLocalizedMessage().equals(MBServerStatics.RESET_BY_PEER))
|
||||
Logger.error(e);
|
||||
origin.disconnect();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (read == -1) {
|
||||
Logger.info("EOF on Socket Channel, Disconnecting " + origin.getLocalAddressAndPortAsString());
|
||||
origin.disconnect();
|
||||
return read;
|
||||
}
|
||||
|
||||
this.totalRead += read;
|
||||
|
||||
if (this.totalRead > 100)
|
||||
Logger.error( "Possible Spam warning: "
|
||||
+ origin.getSocketChannel().socket().toString());
|
||||
|
||||
// Not all arrived yet, so wait for more
|
||||
if (this.totalRead < 100)
|
||||
return read;
|
||||
|
||||
this.buffer.flip();
|
||||
this.buffer.getInt(); // get the length first & throw away value.
|
||||
|
||||
byte[] PeerPubKeyEnc = new byte[96];
|
||||
this.buffer.get(PeerPubKeyEnc);
|
||||
|
||||
this.calcKeys(origin, PeerPubKeyEnc);
|
||||
|
||||
try {
|
||||
byte[] sharedSecret = this.secretKey;
|
||||
byte[] PubKeyEnc = this.serverPublicKey;
|
||||
|
||||
// Cut DH SecretKey down to 16 bytes
|
||||
System.arraycopy(sharedSecret, 0, secretKeyBytes, 0, 16);
|
||||
|
||||
// Calculate Blowfish Secret Key and make ciphers streams.
|
||||
this.BFKey = new SecretKeySpec(this.secretKeyBytes, "Blowfish");
|
||||
|
||||
// Initialize cipher and Ivecs.
|
||||
// Ivecs must be run through the cipher once
|
||||
// to prep the cipher for cfb mode.
|
||||
this.cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
|
||||
this.cipher.init(Cipher.ENCRYPT_MODE, this.BFKey);
|
||||
this.cipher.update(this.iVecEnc, 0, 8, this.iVecEnc, 0);
|
||||
this.cipher.update(this.iVecDec, 0, 8, this.iVecDec, 0);
|
||||
|
||||
// Send public key to peer
|
||||
byte[] pubKeyLen = {0x00, 0x00, 0x00, 0x60}; // hex for 96
|
||||
ByteBuffer bb = ByteBuffer.wrap(pubKeyLen);
|
||||
bb.position(bb.limit());
|
||||
origin.sendBB(bb);
|
||||
bb = ByteBuffer.wrap(PubKeyEnc);
|
||||
bb.position(bb.limit());
|
||||
origin.sendBB(bb);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
origin.disconnect();
|
||||
return read;
|
||||
}
|
||||
/*
|
||||
* //Send Secret Key to Login Server if (PortalServer.ServerType ==
|
||||
* "Login") { byte[] keyinfo = new byte[20]; keyinfo[0] = 0x11;
|
||||
* keyinfo[1] = 0x11; keyinfo[2] = 0x11; keyinfo[3] = 0x11; for (int i =
|
||||
* 0; i < 16; i++) keyinfo[i + 4] = ShortSharedSecret[i];
|
||||
* PortalPair.HandleOutput(keyinfo, 20); }
|
||||
*/
|
||||
this.initialized = true;
|
||||
|
||||
// long endTime = System.currentTimeMillis();
|
||||
//
|
||||
// long time = endTime - startTime;
|
||||
// // Logger.debug("", "Authenticator took " + time + " ms to initialize.");
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
public synchronized void encrypt(final ByteBuffer dataIn, final ByteBuffer dataOut) {
|
||||
try {
|
||||
// Assume that if position != 0 that we need to flip.
|
||||
if (dataIn.position() != 0)
|
||||
dataIn.flip();
|
||||
|
||||
int count = dataIn.limit();
|
||||
|
||||
//Line up the iVecEncOffset.. fall through is intentional
|
||||
if (iVecEncOffset != 0)
|
||||
if ((this.iVecEncOffset + dataIn.limit()) < 8) {
|
||||
//This handles cases where the net msg + offset won't reach 8 bytes total
|
||||
//prevents BufferUnderflowException in small net messages. -
|
||||
int newEncOffset = this.iVecEncOffset + dataIn.limit();
|
||||
for (int i = this.iVecEncOffset; i < newEncOffset; i++) {
|
||||
this.iVecEnc[i] = (byte) (dataIn.get() ^ this.iVecEnc[i]);
|
||||
dataOut.put(this.iVecEnc[i]);
|
||||
}
|
||||
this.iVecEncOffset = newEncOffset;
|
||||
return;
|
||||
} else
|
||||
switch (iVecEncOffset) {
|
||||
case 1:
|
||||
this.iVecEnc[1] = (byte) (dataIn.get() ^ this.iVecEnc[1]);
|
||||
dataOut.put(this.iVecEnc[1]);
|
||||
case 2:
|
||||
this.iVecEnc[2] = (byte) (dataIn.get() ^ this.iVecEnc[2]);
|
||||
dataOut.put(this.iVecEnc[2]);
|
||||
case 3:
|
||||
this.iVecEnc[3] = (byte) (dataIn.get() ^ this.iVecEnc[3]);
|
||||
dataOut.put(this.iVecEnc[3]);
|
||||
case 4:
|
||||
this.iVecEnc[4] = (byte) (dataIn.get() ^ this.iVecEnc[4]);
|
||||
dataOut.put(this.iVecEnc[4]);
|
||||
case 5:
|
||||
this.iVecEnc[5] = (byte) (dataIn.get() ^ this.iVecEnc[5]);
|
||||
dataOut.put(this.iVecEnc[5]);
|
||||
case 6:
|
||||
this.iVecEnc[6] = (byte) (dataIn.get() ^ this.iVecEnc[6]);
|
||||
dataOut.put(this.iVecEnc[6]);
|
||||
case 7:
|
||||
this.iVecEnc[7] = (byte) (dataIn.get() ^ this.iVecEnc[7]);
|
||||
dataOut.put(this.iVecEnc[7]);
|
||||
count -= (8 - iVecEncOffset);
|
||||
this.iVecEncOffset = 0;
|
||||
this.cipher.update(this.iVecEnc, 0, 8, this.iVecEnc, 0);
|
||||
}
|
||||
|
||||
//Main loop - unrolled x8
|
||||
int loopCount = (count) >> 3;
|
||||
for (int i = 0; i < loopCount; i++) {
|
||||
|
||||
this.iVecEnc[0] = (byte) (dataIn.get() ^ this.iVecEnc[0]);
|
||||
this.iVecEnc[1] = (byte) (dataIn.get() ^ this.iVecEnc[1]);
|
||||
this.iVecEnc[2] = (byte) (dataIn.get() ^ this.iVecEnc[2]);
|
||||
this.iVecEnc[3] = (byte) (dataIn.get() ^ this.iVecEnc[3]);
|
||||
this.iVecEnc[4] = (byte) (dataIn.get() ^ this.iVecEnc[4]);
|
||||
this.iVecEnc[5] = (byte) (dataIn.get() ^ this.iVecEnc[5]);
|
||||
this.iVecEnc[6] = (byte) (dataIn.get() ^ this.iVecEnc[6]);
|
||||
this.iVecEnc[7] = (byte) (dataIn.get() ^ this.iVecEnc[7]);
|
||||
|
||||
dataOut.put(this.iVecEnc[0]);
|
||||
dataOut.put(this.iVecEnc[1]);
|
||||
dataOut.put(this.iVecEnc[2]);
|
||||
dataOut.put(this.iVecEnc[3]);
|
||||
dataOut.put(this.iVecEnc[4]);
|
||||
dataOut.put(this.iVecEnc[5]);
|
||||
dataOut.put(this.iVecEnc[6]);
|
||||
dataOut.put(this.iVecEnc[7]);
|
||||
this.cipher.update(this.iVecEnc, 0, 8, this.iVecEnc, 0);
|
||||
}
|
||||
|
||||
//Resync the iVecEncOffset to handle the remainder..
|
||||
this.iVecEncOffset = count % 8;
|
||||
for (int i = 0; i < iVecEncOffset; i++) {
|
||||
this.iVecEnc[i] = (byte) (dataIn.get() ^ this.iVecEnc[i]);
|
||||
dataOut.put(this.iVecEnc[i]);
|
||||
}
|
||||
} catch (BufferUnderflowException e) {
|
||||
if (dataIn != null && dataOut != null)
|
||||
Logger.warn("Encrypt Error: (in)" + dataIn.toString() + " :: (out)" + dataOut.toString());
|
||||
Logger.error("ClientAuth.encrypt() -> Underflow" + e);
|
||||
} catch (BufferOverflowException e) {
|
||||
if (dataIn != null && dataOut != null)
|
||||
Logger.warn("Encrypt Error: (in)" + dataIn.toString() + " :: (out)" + dataOut.toString());
|
||||
Logger.error("ClientAuth.encrypt() -> Overflow" + e);
|
||||
} catch (Exception e) {
|
||||
Logger.error("ClientAuth.encrypt()" + e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void decrypt(ByteBuffer dataIn, ByteBuffer dataOut) {
|
||||
try { // get lock
|
||||
synchronized (dataIn) { // TODO is this lock needed?
|
||||
|
||||
// Assume that if position != 0 that we need to flip.
|
||||
if (dataIn.position() != 0)
|
||||
dataIn.flip();
|
||||
|
||||
byte encryptedByte;
|
||||
byte decryptedByte;
|
||||
|
||||
for (int i = 0; i < dataIn.limit(); ++i) {
|
||||
|
||||
// Get byte out of ByteBuffer
|
||||
encryptedByte = dataIn.get();
|
||||
|
||||
// XOR it against the iVEC
|
||||
decryptedByte = (byte) (encryptedByte ^ this.iVecDec[this.iVecDecOffset]);
|
||||
|
||||
// put the decrypted byte into the outgoing ByteBuffer
|
||||
dataOut.put(decryptedByte);
|
||||
|
||||
// store the encrypted byte back into the iVEC
|
||||
this.iVecDec[this.iVecDecOffset] = encryptedByte;
|
||||
|
||||
// Increment ivecOffset
|
||||
this.iVecDecOffset++;
|
||||
|
||||
// Check to see if iVecOffset is at MAX. If so, reset
|
||||
if (this.iVecDecOffset > 7) {
|
||||
try {
|
||||
this.cipher.update(this.iVecDec, 0, 8,
|
||||
this.iVecDec, 0);
|
||||
} catch (ShortBufferException e) {
|
||||
// suck up this error
|
||||
Logger.error(e);
|
||||
}
|
||||
this.iVecDecOffset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error("ClientAuth.decrypt()" + e);
|
||||
}
|
||||
}
|
||||
|
||||
private void initiateKey(byte[] clientPublicKeyBytes) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the secretKeyBytes
|
||||
*/
|
||||
public byte[] getSecretKeyBytes() {
|
||||
return secretKeyBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the initialized
|
||||
*/
|
||||
public boolean initialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
private static final byte P_Bytes[] = {(byte) 0xFB, (byte) 0x46, (byte) 0x56, (byte) 0xB4, (byte) 0xBE, (byte) 0x81, (byte) 0xA4,
|
||||
(byte) 0x2C, (byte) 0x37, (byte) 0xC4, (byte) 0xA2, (byte) 0x61, (byte) 0x4A, (byte) 0xAC, (byte) 0x65, (byte) 0x90,
|
||||
(byte) 0x31, (byte) 0xB6, (byte) 0x83, (byte) 0x26, (byte) 0x63, (byte) 0x94, (byte) 0x08, (byte) 0x95, (byte) 0x56,
|
||||
(byte) 0x8D, (byte) 0x5E, (byte) 0xBF, (byte) 0x94, (byte) 0x10, (byte) 0x5A, (byte) 0x37, (byte) 0xB6, (byte) 0x82,
|
||||
(byte) 0x1A, (byte) 0x75, (byte) 0x2B, (byte) 0xF1, (byte) 0x94, (byte) 0xB7, (byte) 0x7E, (byte) 0x56, (byte) 0xC6,
|
||||
(byte) 0xD1, (byte) 0xF5, (byte) 0x18, (byte) 0xE1, (byte) 0xA5, (byte) 0x13, (byte) 0x9E, (byte) 0xC1, (byte) 0x85,
|
||||
(byte) 0x98, (byte) 0xB7, (byte) 0x32, (byte) 0xDB, (byte) 0x38, (byte) 0x09, (byte) 0x1A, (byte) 0xF8, (byte) 0x5C,
|
||||
(byte) 0xDA, (byte) 0x4F, (byte) 0x9F, (byte) 0x67, (byte) 0x93, (byte) 0x72, (byte) 0x8F, (byte) 0x75, (byte) 0x4F,
|
||||
(byte) 0x0B, (byte) 0xBD, (byte) 0x69, (byte) 0x61, (byte) 0x97, (byte) 0x1F, (byte) 0xEE, (byte) 0xFB, (byte) 0x5B,
|
||||
(byte) 0xB0, (byte) 0x85, (byte) 0xC4, (byte) 0x27, (byte) 0x7E, (byte) 0x41, (byte) 0x42, (byte) 0xC2, (byte) 0xF1,
|
||||
(byte) 0xDA, (byte) 0x64, (byte) 0x8F, (byte) 0x4E, (byte) 0x28, (byte) 0xFD, (byte) 0x2A, (byte) 0x63};
|
||||
|
||||
private static final BigInteger P = new BigInteger(1, P_Bytes);
|
||||
private static final BigInteger G = BigInteger.valueOf(5);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
package engine.net.client;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.DisconnectJob;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.AbstractNetMsg;
|
||||
import engine.net.Network;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.login.LoginErrorMsg;
|
||||
import engine.objects.Account;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.session.SessionID;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.NotYetConnectedException;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class ClientConnection extends AbstractConnection {
|
||||
|
||||
// Enumeration of a message's origin for logging purposes
|
||||
private enum MessageSource {
|
||||
|
||||
SOURCE_CLIENT,
|
||||
SOURCE_SERVER
|
||||
}
|
||||
|
||||
private byte cryptoInitTries = 0;
|
||||
protected SessionID sessionID = null;
|
||||
private final ClientAuthenticator crypto;
|
||||
private final String clientIpAddress;
|
||||
public String machineID;
|
||||
public long guildtreespam = 0;
|
||||
public long ordernpcspam = 0;
|
||||
public ReentrantLock trainLock = new ReentrantLock();
|
||||
public ReentrantLock sellLock = new ReentrantLock();
|
||||
public ReentrantLock buyLock = new ReentrantLock();
|
||||
|
||||
public boolean desyncDebug = false;
|
||||
|
||||
public byte[] lastByteBuffer;
|
||||
|
||||
public ClientConnection(ClientConnectionManager connMan,
|
||||
SocketChannel sockChan) {
|
||||
super(connMan, sockChan, true);
|
||||
this.crypto = new ClientAuthenticator(this);
|
||||
|
||||
this.clientIpAddress = sockChan.socket().getRemoteSocketAddress()
|
||||
.toString().replace("/", "").split(":")[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _sendMsg(AbstractNetMsg msg) {
|
||||
try {
|
||||
msg.setOrigin(this);
|
||||
ByteBuffer bb = msg.serialize();
|
||||
|
||||
// Application protocol logging toggled via
|
||||
// DevCmd: netdebug on|off
|
||||
|
||||
if (MBServerStatics.DEBUG_PROTOCOL)
|
||||
applicationProtocolLogger(msg, MessageSource.SOURCE_SERVER);
|
||||
|
||||
boolean retval = this.sendBB(bb);
|
||||
Network.byteBufferPool.putBuffer(bb);//return here.
|
||||
|
||||
return retval;
|
||||
|
||||
} catch (Exception e) { // Catch-all
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sending a NetMsg to the client involves NOT including a dataLen parameter
|
||||
* and also involves encrypting the data.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected boolean _sendBB(ByteBuffer bb) {
|
||||
boolean useCrypto = this.crypto.initialized();
|
||||
boolean retVal;
|
||||
|
||||
// Logger.debug("useCrypto: " + useCrypto + ". bb.cap(): " +
|
||||
// bb.capacity());
|
||||
if (useCrypto == false)
|
||||
retVal = super._sendBB(bb);
|
||||
else {
|
||||
if (bb == null)
|
||||
Logger.error("Incoming bb is null");
|
||||
ByteBuffer encrypted = Network.byteBufferPool.getBufferToFit(bb.capacity());
|
||||
if (encrypted == null)
|
||||
Logger.error("Encrypted bb is null");
|
||||
this.crypto.encrypt(bb, encrypted);
|
||||
retVal = super._sendBB(encrypted);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receiving data from a client involves the initial Crypto Key Exchange,
|
||||
* waiting for a complete NetMsg to arrive using an accumulation factory and
|
||||
* decrypting the data.
|
||||
*/
|
||||
//FIXME the int return value on this means nothing! Clean it up!
|
||||
@Override
|
||||
protected int read() {
|
||||
|
||||
if (readLock.tryLock())
|
||||
try {
|
||||
|
||||
// First and foremost, check to see if we the Crypto is initted yet
|
||||
if (!this.crypto.initialized())
|
||||
this.crypto.initialize(this);
|
||||
|
||||
if (!this.crypto.initialized()) {
|
||||
++this.cryptoInitTries;
|
||||
if (this.cryptoInitTries >= MBServerStatics.MAX_CRYPTO_INIT_TRIES) {
|
||||
Logger.info("Failed to initialize after "
|
||||
+ MBServerStatics.MAX_CRYPTO_INIT_TRIES
|
||||
+ " tries. Disconnecting.");
|
||||
this.disconnect();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// check to see if SessionID == null;
|
||||
if (this.sessionID == null)
|
||||
this.sessionID = new SessionID(this.crypto.getSecretKeyBytes());
|
||||
|
||||
// Get ByteBuffers out of pool.
|
||||
ByteBuffer bb = Network.byteBufferPool.getBuffer(16);
|
||||
ByteBuffer decrypted = Network.byteBufferPool.getBuffer(16);
|
||||
// ByteBuffer bb = ByteBuffer.allocate(1024 * 4);
|
||||
|
||||
int totalBytesRead = 0;
|
||||
int lastRead = 0;
|
||||
do {
|
||||
try {
|
||||
bb.clear();
|
||||
decrypted.clear();
|
||||
lastRead = this.sockChan.read(bb);
|
||||
// On EOF on the SocketChannel, disconnect.
|
||||
if (lastRead <= -1) {
|
||||
this.disconnect();
|
||||
break;
|
||||
}
|
||||
|
||||
if (lastRead == 0)
|
||||
continue;
|
||||
|
||||
// ByteBuffer decrypted = ByteBuffer.allocate(lastRead);
|
||||
this.crypto.decrypt(bb, decrypted);
|
||||
this.factory.addData(decrypted);
|
||||
|
||||
|
||||
this.checkInternalFactory();
|
||||
|
||||
totalBytesRead += lastRead;
|
||||
|
||||
|
||||
} catch (NotYetConnectedException e) {
|
||||
Logger.error(e.getLocalizedMessage());
|
||||
totalBytesRead = -1; // Set error retVal
|
||||
break;
|
||||
|
||||
} catch (ClosedChannelException e) {
|
||||
// TODO Should a closed channel be logged or just cleaned up?
|
||||
// this.logEXCEPTION(e);
|
||||
this.disconnect();
|
||||
totalBytesRead = -1; // Set error retVal
|
||||
break;
|
||||
|
||||
} catch (IOException e) {
|
||||
if ( e.getLocalizedMessage() != null && (!e.getLocalizedMessage().equals(MBServerStatics.EXISTING_CONNECTION_CLOSED) && !e.getLocalizedMessage().equals(MBServerStatics.RESET_BY_PEER))){
|
||||
Logger.info("Error Reading message opcode " + this.lastOpcode);
|
||||
Logger.error(e);
|
||||
}
|
||||
this.disconnect();
|
||||
totalBytesRead = -1; // Set error retVal
|
||||
break;
|
||||
|
||||
} catch (Exception e){
|
||||
Logger.info("Error Reading message opcode " + this.lastOpcode);
|
||||
Logger.error(e);
|
||||
totalBytesRead = -1; // Set error retVal
|
||||
this.disconnect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (lastRead > 0);
|
||||
|
||||
Network.byteBufferPool.putBuffer(bb);
|
||||
Network.byteBufferPool.putBuffer(decrypted);
|
||||
|
||||
return totalBytesRead;
|
||||
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
else {
|
||||
Logger.debug("Another thread already has a read lock! Skipping.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
super.disconnect();
|
||||
try {
|
||||
|
||||
if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER))
|
||||
ConfigManager.worldServer.removeClient(this);
|
||||
else
|
||||
ConfigManager.loginServer.removeClient(this);
|
||||
|
||||
// TODO There has to be a more direct way to do this...
|
||||
SessionManager.remSession(
|
||||
SessionManager.getSession(sessionID));
|
||||
} catch (NullPointerException e) {
|
||||
Logger
|
||||
.error(
|
||||
"Tried to remove improperly initialized session. Skipping." +
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
public void forceDisconnect() {
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
/*
|
||||
* Getters n setters
|
||||
*/
|
||||
|
||||
public SessionID getSessionID() {
|
||||
return sessionID;
|
||||
}
|
||||
|
||||
public byte[] getSecretKeyBytes() {
|
||||
return this.crypto.getSecretKeyBytes();
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience getters for SessionManager
|
||||
*/
|
||||
public Account getAccount() {
|
||||
return SessionManager.getAccount(this);
|
||||
}
|
||||
|
||||
public PlayerCharacter getPlayerCharacter() {
|
||||
return SessionManager.getPlayerCharacter(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleClientMsg(ClientNetMsg msg) {
|
||||
|
||||
Protocol protocolMsg = msg.getProtocolMsg();
|
||||
|
||||
switch (protocolMsg) {
|
||||
case KEEPALIVESERVERCLIENT:
|
||||
this.setLastKeepAliveTime();
|
||||
break;
|
||||
// case ClientOpcodes.OpenVault:
|
||||
// case ClientOpcodes.Random:
|
||||
// case ClientOpcodes.DoorTryOpen:
|
||||
// case ClientOpcodes.SetSelectedObect:
|
||||
// case ClientOpcodes.MoveObjectToContainer:
|
||||
// case ClientOpcodes.ToggleSitStand:
|
||||
// case ClientOpcodes.SocialChannel:
|
||||
// case ClientOpcodes.OpenFriendsCondemnList:
|
||||
case SELLOBJECT:
|
||||
this.setLastMsgTime();
|
||||
break;
|
||||
case MOVETOPOINT:
|
||||
case ARCCOMBATMODEATTACKING:
|
||||
this.setLastMsgTime();
|
||||
break;
|
||||
default:
|
||||
this.setLastMsgTime();
|
||||
break;
|
||||
}
|
||||
|
||||
// Application protocol logging toggled via
|
||||
// DevCmd: netdebug on|off
|
||||
|
||||
if (MBServerStatics.DEBUG_PROTOCOL)
|
||||
applicationProtocolLogger(msg, MessageSource.SOURCE_CLIENT);
|
||||
|
||||
return ConfigManager.handler.handleClientMsg(msg); // *** Refactor : Null check then call
|
||||
}
|
||||
// Method logs detailed information about application
|
||||
// protocol traffic. Toggled at runtime via the
|
||||
// DevCmd netdebug on|off
|
||||
|
||||
private void applicationProtocolLogger(AbstractNetMsg msg, MessageSource origin) {
|
||||
|
||||
String outString = "";
|
||||
PlayerCharacter tempPlayer = null;
|
||||
|
||||
// Log the protocolMsg
|
||||
if (origin == MessageSource.SOURCE_CLIENT)
|
||||
outString = " Incoming protocolMsg: ";
|
||||
else
|
||||
outString = " Outgoing protocolMsg: ";
|
||||
|
||||
Logger.info(outString
|
||||
+ Integer.toHexString(msg.getProtocolMsg().opcode)
|
||||
+ '/' + msg.getProtocolMsg());
|
||||
|
||||
// Dump message contents using reflection
|
||||
tempPlayer = this.getPlayerCharacter();
|
||||
outString = "";
|
||||
outString += (tempPlayer == null) ? "PlayerUnknown" : tempPlayer.getFirstName() + ' '
|
||||
+ msg.toString();
|
||||
Logger.info(outString);
|
||||
}
|
||||
|
||||
public void kickToLogin(int errCode, String message) {
|
||||
|
||||
LoginErrorMsg lom = new LoginErrorMsg(errCode, message);
|
||||
|
||||
if (!sendMsg(lom))
|
||||
Logger.error("Failed to send message"); // TODO Do we just accept this failure to send Msg?
|
||||
|
||||
DisconnectJob dj = new DisconnectJob(this);
|
||||
JobScheduler.getInstance().scheduleJob(dj, 250);
|
||||
|
||||
}
|
||||
|
||||
public final String getClientIpAddress() {
|
||||
return this.clientIpAddress;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client;
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.AbstractConnectionManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
public class ClientConnectionManager extends AbstractConnectionManager {
|
||||
|
||||
public ClientConnectionManager(String threadName, InetAddress hostAddress, int port)
|
||||
throws IOException {
|
||||
super(threadName, hostAddress, port);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractConnection getNewIncomingConnection(SocketChannel sockChan) {
|
||||
return new ClientConnection(this, sockChan);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractConnection getNewOutgoingConnection(SocketChannel sockChan) {
|
||||
return new ClientConnection(this, sockChan);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,338 @@
|
||||
package engine.net.client;
|
||||
|
||||
/* This class defines Magicbane's application network protocol.
|
||||
--> Name / Opcode / Message / Handler
|
||||
*/
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.client.handlers.*;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.net.client.msg.chat.*;
|
||||
import engine.net.client.msg.commands.ClientAdminCommandMsg;
|
||||
import engine.net.client.msg.group.*;
|
||||
import engine.net.client.msg.guild.*;
|
||||
import engine.net.client.msg.login.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
|
||||
public enum Protocol {
|
||||
|
||||
|
||||
NONE(0x0, null, null),
|
||||
ABANDONASSET(0xFDDBB233, AbandonAssetMsg.class, AbandonAssetMsgHandler.class), // AbandonAsset
|
||||
ACTIVATECHARTER(0x296C0B22, UseCharterMsg.class, null),// Use Guild Charter
|
||||
ACTIVATENPC(0xC9AAE81E, ActivateNPCMessage.class, ActivateNPCMsgHandler.class),
|
||||
ACTIVATEPLEDGE(0x5A694DC0, SwearInMsg.class, SwearInHandler.class), // Swear In
|
||||
ADDFRIEND(0xCFA1C787,AddFriendMessage.class,null),
|
||||
ALLIANCECHANGE(0x0E7D0B57, AllianceChangeMsg.class, AllianceChangeMsgHandler.class), // Remove From Allies/Enemies List
|
||||
ALLYENEMYLIST(0xAEA443FD, AllyEnemyListMsg.class, AllyEnemyListMsgHandler.class),
|
||||
ARCCOMBATMODEATTACKING(0xD8B10579, SetCombatModeMsg.class, null), // Attack From Outside Combat Mode
|
||||
ARCHOTZONECHANGE(0xDCFF196F, null, null), //change hotzone
|
||||
ARCIGNORELISTUPDATE(0x4B1B17C2, IgnoreListMsg.class, null), //req/show ignore list
|
||||
ARCLOGINNOTIFY(0x010FED87, ArcLoginNotifyMsg.class, ArcLoginNotifyMsgHandler.class), //Client Confirms entering world
|
||||
ARCMINECHANGEPRODUCTION(0x1EAA993F, ArcMineChangeProductionMsg.class, null),
|
||||
ARCMINETOWERCRESTUPDATE(0x34164D0D, null, null),
|
||||
ARCMINEWINDOWAVAILABLETIME(0x6C909DE7, ArcMineWindowAvailableTimeMsg.class, null),
|
||||
ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, null),
|
||||
ARCOWNEDMINESLIST(0x59184455, ArcOwnedMinesListMsg.class, null),
|
||||
ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, null), // Pet Attack
|
||||
ARCPETCMD(0x4E80E001, PetCmdMsg.class, null), // Stop ArcPetAttack, Toggle Assist, Toggle Rest
|
||||
ARCPOWERPROJECTILE(0xA2312D3B, null, null),
|
||||
ARCPROMPTRECALL(0xE3196B6E, PromptRecallMsg.class, null), //Recall Prompt
|
||||
ARCREQUESTTRADEBUSY(0xD4BAB4DF, InvalidTradeRequestMsg.class, null), // Attempt trade with someone who is already trading
|
||||
ARCSERVERSTATUS(0x87BA4462, null, null), //Update Server Status
|
||||
ARCSIEGESPIRE(0x36A49BC6, ArcSiegeSpireMsg.class, ArcSiegeSpireMsgHandler.class), // Activate/Deactivate Spires
|
||||
ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request
|
||||
ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window
|
||||
ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow
|
||||
ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, null), //Refine
|
||||
ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, null), //Refiner screen
|
||||
ARCVIEWASSETTRANSACTIONS(0xBFA476E4, ArcViewAssetTransactionsMsg.class, ArcViewAssetTransactionsMsgHandler.class),
|
||||
ASSETSUPPORT(0xc481f89D, AssetSupportMsg.class, AssetSupportMsgHandler.class),
|
||||
BANISHMEMBER(0x31AA3368, BanishUnbanishMsg.class, BanishUnbanishHandler.class), // Banish/Unbanish
|
||||
BANKINVENTORY(0x32F3F503, ShowBankInventoryMsg.class, null), // ShowCombatInfo Bank Inventory
|
||||
BREAKFEALTY(0x479A4C19, BreakFealtyMsg.class, BreakFealtyHandler.class),
|
||||
BUYFROMNPC(0xA2B8DFA5, BuyFromNPCMsg.class, null), // Buy Item From NPC
|
||||
CANCELGUILDCREATION(0x385EA922, GuildCreationCloseMsg.class, GuildCreationCloseHandler.class), //Close the window
|
||||
CHANGEALTITUDE(0x624F08BA, ChangeAltitudeMsg.class, ChangeAltitudeHandler.class), //Change Altitude
|
||||
CHANGEGUILDLEADER(0xE40BC95D, ChangeGuildLeaderMsg.class, ChangeGuildLeaderHandler.class),
|
||||
CHANNELMUTE(0xC1BDC53A, ChatFilterMsg.class, ChannelMuteMsgHandler.class), //Chat Channels that are turned on
|
||||
CHARSELECTSCREEN(0x682C935D, null, null), // Character Selection Screen
|
||||
CHATCITY(0x9D402901, ChatCityMsg.class, null), // Chat Channel: /City
|
||||
CHATCSR(0x14EBA1C3, ChatCSRMsg.class, null), //Chat Channel: CSR
|
||||
CHATGROUP(0xA895B634, ChatGroupMsg.class, null), // Chat Channel: /group
|
||||
CHATGUILD(0xA9D92ED4, ChatGuildMsg.class, null), // Chat Channel: /guild
|
||||
CHATIC(0x00A75F35, ChatICMsg.class, null), // Chat Channel: /IC
|
||||
CHATINFO(0x9D4B61EB, ChatInfoMsg.class, null), // Chat Channel: /Info
|
||||
CHATPVP(0x14EBA570, ChatPvPMsg.class, null), // Chat Channel: PVP
|
||||
CHATSAY(0x14EA0393, ChatSayMsg.class, null), // Chat Channel: /say
|
||||
CHATSHOUT(0xA8D5B560, ChatShoutMsg.class, null), // Chat Channel: /shout
|
||||
CHATTELL(0x9D4AC896, ChatTellMsg.class, null), // Chat Channel: /tell
|
||||
CHECKUNIQUEGUILD(0x689097D7, GuildCreationOptionsMsg.class, GuildCreationOptionsHandler.class), // Set Guild Name/Motto in Use Guild Charter
|
||||
CITYASSET(0x7cae1678, CityAssetMsg.class, null),
|
||||
CITYCHOICE(0x406610BB, CityChoiceMsg.class, CityChoiceMsgHandler.class),
|
||||
CITYDATA(0xB8A947D4, WorldObjectMsg.class, null), //Realm Data - Optional(?)
|
||||
CITYZONE(0x254947F2, CityZoneMsg.class, null), //For Creating City Object Clientside(Terraform)/Rename City.
|
||||
CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset
|
||||
CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class),
|
||||
CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, null), //Admin Command
|
||||
CLIENTUPDATEVAULT( 0x66EDBECD, UpdateVaultMsg.class, null),
|
||||
COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, null), //Toggle Combat mode
|
||||
CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null),
|
||||
COSTTOOPENBANK(0x135BE5E8, AckBankWindowOpenedMsg.class, null), // ACK Bank Window Opened
|
||||
CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, null), // Commit New Character,
|
||||
CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation
|
||||
CUSTOMERPETITION(0x7F9D7D6D, PetitionReceivedMsg.class, null),
|
||||
DELETEOBJECT(0x57F069D8, DeleteItemMsg.class, null), //Delete Item from Inventory
|
||||
DESTROYBUILDING(0x3CB6FAD3, DestroyBuildingMsg.class, DestroyBuildingHandler.class), // Destroy Building
|
||||
DISBANDGUILD(0x77AABD64, DisbandGuildMsg.class, DisbandGuildHandler.class), //Disband Guild
|
||||
DISMISSGUILD(0x8D2D3D61, DismissGuildMsg.class, DismissGuildHandler.class),
|
||||
DOORTRYOPEN(0xA83DD8C8, DoorTryOpenMsg.class, DoorTryOpenMsgHandler.class), // Open/Close Door
|
||||
ENTERWORLD(0xB9783F85, RequestEnterWorldMsg.class, RequestEnterWorldHandler.class), // Request Enter World
|
||||
EQUIP(0x3CB1AF8C, TransferItemFromInventoryToEquipMsg.class, null), // Transfer Item from Inventory to Equip
|
||||
EXPERIENCE(0xC57802A7, GrantExperienceMsg.class, null), //TODO rename once identified
|
||||
FORGETOBJECTS(0xE307A0E1, UnloadObjectsMsg.class, null), // Unload Objects
|
||||
FRIENDACCEPT(0xCA297870,AcceptFriendMsg.class,FriendAcceptHandler.class),
|
||||
FRIENDDECLINE(0xF08FC279,DeclineFriendMsg.class,FriendDeclineHandler.class),
|
||||
FURNITURE(0xCE7FA503, FurnitureMsg.class, FurnitureHandler.class),
|
||||
GAMESERVERIPRESPONSE(0x6C95CF87, GameServerIPResponseMsg.class, null), // Game Server IP Response
|
||||
GLOBALCHANNELMESSAGE(0x2bf03fd2, null, null),
|
||||
GOLDTOVAULT(0x3ABAEE49, TransferGoldFromInventoryToVaultMsg.class, null), // Transfer Gold from Inventory to Vault
|
||||
GROUPDISBAND(0xE2B85AA4, DisbandGroupMsg.class, DisbandGroupHandler.class), //Disband Group
|
||||
GROUPFOLLOW(0xC61B0476, FormationFollowMsg.class, FormationFollowHandler.class), //Toggle Follow, set Formation
|
||||
GROUPLEADERAPPOINT(0xEF778DD3, AppointGroupLeaderMsg.class, AppointGroupLeaderHandler.class), //Appoint new group leader
|
||||
GROUPREMOVE(0x6E50277C, RemoveFromGroupMsg.class, RemoveFromGroupHandler.class), //Remove from Group
|
||||
GROUPTREASURE(0x01041C66, ToggleGroupSplitMsg.class, ToggleGroupSplitHandler.class), // Toggle Group Split
|
||||
GUILDMEMBERONLINE(0x7B79EB3A, GuildEnterWorldMsg.class, null), // Send Enter World Message to Guild
|
||||
GUILDRANKCHANGE(0x0DEFB21F, ChangeRankMsg.class, ChangeRankHandler.class), // Change Rank
|
||||
GUILDTREESTATUS(0x4B95FB85, GuildTreeStatusMsg.class, null),
|
||||
HIRELINGSERVICE(0xD3D93322,HirelingServiceMsg.class,HirelingServiceMsgHandler.class),
|
||||
IGNORE(0xBD8881EE, IgnoreMsg.class, null), //client sent /ignore command
|
||||
INITIATETRADEHUDS(0x667D29D8, OpenTradeWindowMsg.class, null), // Open Trade Window
|
||||
INVITEGROUP(0x004A2012, GroupInviteMsg.class, GroupInviteHandler.class), // Send/Receive/Deny Group Invite
|
||||
INVITEGUILDFEALTY(0x0274D612, InviteToSubMsg.class, InviteToSubHandler.class), // Invite Guild to Swear
|
||||
INVITETOGUILD(0x6819062A, InviteToGuildMsg.class, InviteToGuildHandler.class), // Invite player to guild, refuse guild invite
|
||||
ITEMHEALTHUPDATE(0xB635F55E, ItemHealthUpdateMsg.class, null), //Update Durability of item
|
||||
ITEMPRODUCTION(0x3CCE8E30, ItemProductionMsg.class, ItemProductionMsgHandler.class),
|
||||
ITEMTOVAULT(0x3ABE4927, TransferItemFromInventoryToVaultMsg.class, null), // Transfer Item to Vault
|
||||
JOINFORPROVINCE(0x1FB369CD, AcceptSubInviteMsg.class, AcceptSubInviteHandler.class), //Response to invite to swear?
|
||||
JOINFORSWORN(0xF6A4170F, null, null),
|
||||
JOINGROUP(0x7EC5E636, GroupInviteResponseMsg.class, GroupInviteResponseHandler.class), // Accept Group Invite
|
||||
JOINGUILD(0xF0C5F2FF, AcceptInviteToGuildMsg.class, AcceptInviteToGuildHandler.class), // Accept guild invite
|
||||
KEEPALIVESERVERCLIENT(0x49EE129C, KeepAliveServerClientMsg.class, KeepAliveServerClientHandler.class), // Keep Alive
|
||||
LEADERBOARD(0x6F0C1386, LeaderboardMessage.class, null),
|
||||
LEADERCHANNELMESSAGE(0x17b306f9, ChatGlobalMsg.class, null),
|
||||
LEAVEGROUP(0xD8037303, LeaveGroupMsg.class, LeaveGroupHandler.class), //Leave Group
|
||||
LEAVEGUILD(0x1801EA32, LeaveGuildMsg.class, LeaveGuildHandler.class), // Leave Guild
|
||||
LEAVEREQUEST(0xC79D775C, LeaveWorldMsg.class, null), //Client Request Leave World
|
||||
LEAVEWORLD(0xB801EAEC, null, null), //Response to client for Request Leave World
|
||||
LOADCHARACTER(0x5756BC53, null, null), // Load Player/NPC/Mob, other then self
|
||||
LOADSTRUCTURE(0xB8A3A654, LoadStructureMsg.class, null), //Load Buildings and World Detail Objects
|
||||
LOCKUNLOCKDOOR(0x8D0E8C44, LockUnlockDoorMsg.class, LockUnlockDoorMsgHandler.class), // Lock/Unlock Door
|
||||
LOGIN(0x3D51E445, ClientLoginInfoMsg.class, null), // Login Information
|
||||
LOGINFAILED(0x47B867F6, null, null), // Login Error
|
||||
LOGINTOGAMESERVER(0x77910FDF, LoginToGameServerMsg.class, LoginToGameServerMsgHandler.class), // Login to Game Server
|
||||
MANAGECITYASSETS(0xCFF01225, ManageCityAssetsMsg.class, ManageCityAssetMsgHandler.class), // Manage city assets
|
||||
MANAGENPC(0x43A273FA, null, null), // Open Hireling Management Page
|
||||
MERCHANT(0x3E645EF4, MerchantMsg.class, MerchantMsgHandler.class), // Open Teleport List, Teleport, Open Shrine, Request Boon, open/manage warehouse window
|
||||
MINIONTRAINING(0xD355F528, MinionTrainingMessage.class, MinionTrainingMsgHandler.class),
|
||||
MODIFYGUILDSTATE(0x38936FEA, ToggleLfgRecruitingMsg.class, null), //Toggle LFGroup/LFGuild/Recruiting
|
||||
MOTD(0xEC841E8D, MOTDMsg.class, MOTDEditHandler.class), //Send/Rec Guild/Nation/IC MOTD Message
|
||||
MOVECORRECTION(0x47FAD1E3, null, null), //Force move to point?
|
||||
MOVEOBJECTTOCONTAINER(0xD1639F7C, LootMsg.class, null), //Send/Recv MoveObjectToContainer Msg
|
||||
MOVETOPOINT(0x49EF7241, MoveToPointMsg.class, MoveToPointHandler.class), // Move to point
|
||||
NAMEVERIFY(0x1B3BF0B1, null, null), // Invalid Name in Character Creation
|
||||
NEWWORLD(0x982E4A77, WorldDataMsg.class, null), // World Data
|
||||
OBJECTACTION(0x06855A36, ObjectActionMsg.class, ObjectActionMsgHandler.class), //Use item
|
||||
OKCOSTTOOPENBANK(0x6F97A502, null, null),
|
||||
OPENFRIENDSCONDEMNLIST(0x49E5FE4F, OpenFriendsCondemnListMsg.class, OpenFriendsCondemnListMsgHandler.class), // Friends/Con demn/Kill/Death/Heraldry List
|
||||
OPENVAULT(0xBE048E50, OpenVaultMsg.class, null), // Open Vault Window
|
||||
ORDERNPC(0x61C707B1, OrderNPCMsg.class, OrderNPCMsgHandler.class),
|
||||
PASSIVEMESSAGETRIGGER(0x2FF9E2E4, null, null), //PassiveMessageTriggerMsg
|
||||
PET(0x624F3D8C, PetMsg.class, null), //Summon Pet?
|
||||
PLACEASSET(0x940962DF, PlaceAssetMsg.class, PlaceAssetMsgHandler.class),
|
||||
PLAYERDATA(0xB206D352, SendOwnPlayerMsg.class, null), //Enter World, Own Player Data
|
||||
PLAYERFRIENDS(0xDDEF9E7D, FriendRequestMsg.class, FriendRequestHandler.class),
|
||||
POWER(0x3C97A459, PerformActionMsg.class, null), // REQ / CMD Perform Action
|
||||
POWERACTION(0xA0B27EEB, ApplyEffectMsg.class, null), // Apply Effect, add to effects icons
|
||||
POWERACTIONDD(0xD43052F8, ModifyHealthMsg.class, null), //Modify Health/Mana/Stamina using power
|
||||
POWERACTIONDDDIE(0xC27D446B, null, null), //Modify Health/Mana/Stamina using power and kill target
|
||||
POWERTARGNAME(0x5A807CCE, SendSummonsRequestMsg.class, null), // Send Summons Request
|
||||
RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, null), // Modify Stat
|
||||
RANDOM(0xAC5D0135, RandomMsg.class, null), //RequestSend random roll
|
||||
READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World
|
||||
REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?)
|
||||
RECOMMENDNATION(0x6D4579E9, RecommendNationMsg.class, RecommendNationMsgHandler.class), // Recommend as Ally/Enemy, error
|
||||
RECYCLEPOWER(0x24033B67, RecyclePowerMsg.class, null), //Unlock power for reUse
|
||||
REMOVECHAR(0x5D3F9739, DeleteCharacterMsg.class, null), // Delete Character
|
||||
REMOVEFRIEND(0xE0D5DB42,RemoveFriendMessage.class,RemoveFriendHandler.class),
|
||||
REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class),
|
||||
REPAIROBJECT(0x782219CE, RepairMsg.class, null), //Repair Window Req/Ack, RepairObject item Req/Ack
|
||||
REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, null), // MoveObjectToContainer Window Request
|
||||
REQUESTGUILDLIST(0x85DCC6D7, ReqGuildListMsg.class, RequestGuildListHandler.class),
|
||||
REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, null), // Attack
|
||||
REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History
|
||||
REQUESTTOOPENBANK(0xF26E453F, null, null), // RequestToOpenBankMsg
|
||||
REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, null), // Trade Request
|
||||
REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade
|
||||
REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request
|
||||
RESETAFTERDEATH(0xFDCBB98F,RespawnMsg.class, null), //Respawn Request/Response
|
||||
ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null),
|
||||
SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode
|
||||
SCALEOBJECT(0xE2B392D9, null, null), // Adjust scale of object
|
||||
SELECTCHAR(0x7E6A9338, GameServerIPRequestMsg.class, null), // Game Server IP Request
|
||||
SELECTCITY(0x7E6BE630, null, null),
|
||||
SELECTSERVER(0x440D28B7, ServerInfoMsg.class, null), // Server Info Request/Response
|
||||
SELLOBJECT(0x57111C67, SellToNPCMsg.class, null), //Sell to NPC
|
||||
SENDCITYENTRY(0xBC3B5E72, null, null), //Send Teleport/Repledge List
|
||||
SENDGUILDENTRY(0x6D5EF164, null, null),
|
||||
SENDMEMBERENTRY(0x6949C720, GuildListMsg.class, GuildListHandler.class), // ShowCombatInfo guild members list, I think
|
||||
SETITEMFLAG(0xE8C1B53B, null, null),
|
||||
SETMOTD(0xFD21FC7C, MOTDCommitMsg.class, MOTDCommitHandler.class), //Commit Guild/Nation/IC MOTD Message
|
||||
SETOBJVAL(0x08A50FD1, null, null),
|
||||
SETRUNE(0x888E7C64, ApplyRuneMsg.class, null), //Apply Promotion, Stat Rune (maybe disc also)
|
||||
SETSELECTEDOBECT(0x64E10938, TargetObjectMsg.class, null), // Target an object
|
||||
SHOPINFO(0x267DAB90, SellToNPCWindowMsg.class, null), //open Sell to NPC Window
|
||||
SHOPLIST(0x682DAB4D, BuyFromNPCWindowMsg.class, null), // Open Buy From NPC Window
|
||||
SHOWCOMBATINFO(0x9BF1E5EA, ShowMsg.class, null), // Request/Response /show
|
||||
SHOWVAULTINVENTORY(0xD1FB4842, null, null), // Show Vault Inventory
|
||||
SOCIALCHANNEL(0x2BF58FA6, SocialMsg.class, null), // Socials
|
||||
STANDARDALERT(0xFA0A24BB, ErrorPopupMsg.class, null), //Popup messages
|
||||
STUCK(0x3D04AF3A, StuckCommandMsg.class, null), // /Stuck Command
|
||||
SWEARINGUILD(0x389B66B1, SwearInGuildMsg.class, SwearInGuildHandler.class),
|
||||
SYNC(0x49ec109f, null, null), //Client/Server loc sync
|
||||
SYSTEMBROADCASTCHANNEL(0x2FAD89D1, ChatSystemMsg.class, null), // Chat Channel: System Message
|
||||
SYSTEMCHANNEL(0x29BB4D66, ChatSystemChannelMsg.class, null), // Chat System Channel
|
||||
TARGETEDACTION(0xB79BA48F, TargetedActionMsg.class, null), //Message sent for attacks
|
||||
TAXCITY(0xCD41EAA6, TaxCityMsg.class, TaxCityMsgHandler.class),
|
||||
TAXRESOURCES(0x4AD458AF, TaxResourcesMsg.class, TaxResourcesMsgHandler.class),
|
||||
TELEPORT(0x23E726EA, TeleportToPointMsg.class, null), // Teleport to point
|
||||
TERRITORYCHANGE(0x6B388C8C,TerritoryChangeMessage.class, null), //Hey rich, look what I found? :)
|
||||
TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, null), //Toggle Sit/Stand
|
||||
TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window
|
||||
TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, null), // Add an Item to the Trade Window
|
||||
TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // Cancel trade/ACK trade complete
|
||||
TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, null), // Commit to trade
|
||||
TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item
|
||||
TRADEUNCONFIRM(0xEBE280E0, UncommitToTradeMsg.class, null), // Uncommit to trade
|
||||
TRAINERLIST(0x41FABA62, TrainerInfoMsg.class, null), //Req/Send Trainer Info/Pricing
|
||||
TRAINSKILL(0xB0BF68CD, TrainMsg.class, null), //Train skills/powers
|
||||
TRANSFERASSET(0x3EA1C4C9, TransferAssetMsg.class, TransferAssetMsgHandler.class), // Transfer Building
|
||||
TRANSFERGOLDFROMVAULTTOINVENTORY(0x011D0123, TransferGoldFromVaultToInventoryMsg.class, null), // Transfer Gold from Vault to Inventory
|
||||
TRANSFERGOLDTOFROMBUILDING(0x1B1AC8C7, TransferGoldToFromBuildingMsg.class, TransferGoldToFromBuildingMsgHandler.class), // Transfer Gold to/From Building, Transfer Error
|
||||
TRANSFERITEMFROMBANK(0x9D04977B, TransferItemFromBankToInventoryMsg.class, null), // Transfer Item from Bank to Inventory
|
||||
TRANSFERITEMFROMVAULTTOINVENTORY(0x0119A64D, TransferItemFromVaultToInventoryMsg.class, null), // Transfer Item from Vault to Inventory
|
||||
TRANSFERITEMTOBANK(0xD48C46FA, TransferItemFromInventoryToBankMsg.class, null), // Transfer Item from Inventory to Bank
|
||||
UNEQUIP(0xC6BFB907, TransferItemFromEquipToInventoryMsg.class, null), // Transfer Item from Equip to Inventory
|
||||
UNKNOWN(0x238C9259, UnknownMsg.class,null),
|
||||
UPDATECHARORMOB(0xB6D78961, null, null),
|
||||
UPDATECLIENTALLIANCES(0xF3FEB5D4, null, GuildUnknownHandler.class), //AlliancesMsg
|
||||
UPDATECLIENTINVENTORIES(0xE66F533D, UpdateInventoryMsg.class, null), //Update player inventory
|
||||
UPDATEEFFECTS(0xD4675293, null, null), //Update all effects for an item
|
||||
UPDATEFRIENDSTATUS(0x654E2255, UpdateFriendStatusMessage.class, UpdateFriendStatusHandler.class),
|
||||
UPDATEGOLDVALUE(0x6915A3FB, null, null), // Update gold in inventory and/or bank
|
||||
UPDATEGROUP(0x004E6BCE, GroupUpdateMsg.class, GroupUpdateHandler.class), // Update Group Info
|
||||
UPDATEGUILD(0x001D4DF6, GuildInfoMsg.class, GuildInfoHandler.class), // REQ / CMD Promote/Demote Screen
|
||||
UPDATEOBJECT(0x1A724739, null, null),
|
||||
UPDATESTATE(0x001A45FB, UpdateStateMsg.class, null), // REQ / CMD Toggle Run/Walk Sit/Stand :: UpdateStateMessage
|
||||
UPDATETRADEWINDOW(0x406EBDE6, UpdateTradeWindowMsg.class, null), // Trade Complete
|
||||
UPGRADEASSET(0x2B85A865, UpgradeAssetMessage.class, UpgradeAssetMsgHandler.class),
|
||||
VENDORDIALOG(0x98ACD594, VendorDialogMsg.class, null), // Send/Recv Vendor Dialog
|
||||
VERSIONINFO(0x4B7EE463, VersionInfoMsg.class, null), // Version Information
|
||||
VIEWRESOURCES(0xCEFD0346, ViewResourcesMessage.class, null),
|
||||
VISUALUPDATE(0x33402fd2, null, null),
|
||||
WEIGHTINVENTORY(0xF1B6A85C, LootWindowResponseMsg.class, null), // MoveObjectToContainer Window Response
|
||||
WHOREQUEST(0xF431CCE9, WhoRequestMsg.class, null), // Request /who
|
||||
WHORESPONSE(0xD7C36568, WhoResponseMsg.class, null), // Response /who
|
||||
REQUESTBALLLIST(0xE366FF64,RequestBallListMessage.class,RequestBallListHandler.class),
|
||||
SENDBALLENTRY(0xAC2B5EDC,SendBallEntryMessage.class,SendBallEntryHandler.class),
|
||||
UNKNOWN1(-263523523, Unknown1Msg.class,null),
|
||||
DROPGOLD(1461654160,DropGoldMsg.class,null);
|
||||
|
||||
public int opcode;
|
||||
private Class message;
|
||||
private Class handlerClass;
|
||||
public Constructor constructor;
|
||||
public AbstractClientMsgHandler handler;
|
||||
|
||||
Protocol(int opcode, Class message, Class handlerClass) {
|
||||
this.opcode = opcode;
|
||||
this.message = message;
|
||||
this.handlerClass = handlerClass;
|
||||
|
||||
// Create reference to message class constructor.
|
||||
|
||||
if (this.message != null) {
|
||||
Class[] params = {AbstractConnection.class, ByteBufferReader.class};
|
||||
|
||||
try {
|
||||
this.constructor = this.message.getConstructor(params);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Create instance of message handler for incoming protocol messages
|
||||
|
||||
if (this.handlerClass != null) {
|
||||
try {
|
||||
handler = (AbstractClientMsgHandler) handlerClass.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static HashMap<Integer, Protocol> _protocolMsgByOpcode = new HashMap<>();
|
||||
|
||||
public static Protocol getByOpcode(int opcode) {
|
||||
|
||||
Protocol protocol = _protocolMsgByOpcode.get(opcode);
|
||||
|
||||
if (protocol != null)
|
||||
return protocol;
|
||||
|
||||
return Protocol.NONE;
|
||||
}
|
||||
|
||||
public static void initProtocolLookup() {
|
||||
|
||||
for (Protocol protocol : Protocol.values()) {
|
||||
|
||||
if (_protocolMsgByOpcode.containsKey(protocol.opcode)){
|
||||
Logger.error("Duplicate opcodes for " + protocol.name() + " and " + _protocolMsgByOpcode.get(protocol.opcode).name());
|
||||
}
|
||||
_protocolMsgByOpcode.put(protocol.opcode, protocol);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int FindNextValidOpcode(ByteBufferReader reader){
|
||||
int startPos = reader.position();
|
||||
int bytesLeft = reader.remaining();
|
||||
|
||||
if (bytesLeft < 4)
|
||||
return startPos;
|
||||
int nextPos = startPos;
|
||||
for (int i = 1; i< bytesLeft; i++ ){
|
||||
reader.position(nextPos);
|
||||
if (reader.remaining() < 4)
|
||||
return reader.position();
|
||||
int newOpcode = reader.getInt();
|
||||
|
||||
Protocol foundProtocol = Protocol.getByOpcode(newOpcode);
|
||||
if (foundProtocol.equals(Protocol.NONE)){
|
||||
nextPos += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
//found opcode. return position - 4 to rewind back to start of opcode, so we can handle it.
|
||||
return reader.position() - 4;
|
||||
}
|
||||
|
||||
return startPos;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.Enum.GuildState;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.*;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.AbandonAssetMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which processes
|
||||
* client requests to abandon a building.
|
||||
*/
|
||||
public class AbandonAssetMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
// Instance variables
|
||||
|
||||
public AbandonAssetMsgHandler() {
|
||||
super(AbandonAssetMsg.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
PlayerCharacter player;
|
||||
Building building;
|
||||
AbandonAssetMsg msg;
|
||||
|
||||
// Member variable assignment
|
||||
msg = (AbandonAssetMsg) baseMsg;
|
||||
|
||||
player = origin.getPlayerCharacter();
|
||||
building = BuildingManager.getBuildingFromCache(msg.getUUID());
|
||||
|
||||
// Oops! *** Refactor: Log error
|
||||
if ((player == null) || (building == null))
|
||||
return true;
|
||||
|
||||
// Early exit if object is not owned by the player
|
||||
if (building.getOwnerUUID() != player.getObjectUUID())
|
||||
return true;
|
||||
|
||||
// Cannot abandon a building without a blueprint.
|
||||
// Players do not own rocks or shrubbery.
|
||||
if (building.getBlueprintUUID() == 0)
|
||||
return true;
|
||||
|
||||
// Players cannot abandon shrines
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon shrine!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.MINE)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot abandon mine!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Blueprint.isMeshWallPiece(building.getBlueprintUUID())) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon fortress asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BARRACK)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon fortress asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BULWARK)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon siege asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.SIEGETENT)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon siege asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.BANESTONE)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to abandon banestone!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Trees require special handling beyond an individual building
|
||||
if ((building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL))
|
||||
AbandonAllCityObjects(player, building);
|
||||
else
|
||||
AbandonSingleAsset(player, building);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void AbandonSingleAsset(PlayerCharacter sourcePlayer,
|
||||
Building targetBuilding) {
|
||||
|
||||
// Transfer the building asset ownership and refresh all clients
|
||||
|
||||
DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(targetBuilding.getObjectUUID());
|
||||
targetBuilding.getFriends().clear();
|
||||
|
||||
// Clear protection status but only if a seige building
|
||||
|
||||
if (targetBuilding.getBlueprint().getBuildingGroup().equals(BuildingGroup.BULWARK) ||
|
||||
targetBuilding.getBlueprint().getBuildingGroup().equals(BuildingGroup.SIEGETENT))
|
||||
targetBuilding.setProtectionState(Enum.ProtectionState.NONE);
|
||||
|
||||
DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(targetBuilding.getObjectUUID());
|
||||
targetBuilding.getCondemned().clear();
|
||||
targetBuilding.setOwner(null);
|
||||
targetBuilding.refreshGuild();
|
||||
|
||||
}
|
||||
|
||||
private void AbandonAllCityObjects(PlayerCharacter sourcePlayer,
|
||||
Building targetBuilding) {
|
||||
Guild sourceGuild;
|
||||
Zone cityZone;
|
||||
|
||||
sourceGuild = sourcePlayer.getGuild();
|
||||
|
||||
if (sourceGuild == null)
|
||||
return;
|
||||
|
||||
if (sourceGuild.getSubGuildList().size() > 0) {
|
||||
ChatManager.chatCityError(sourcePlayer, "You Cannot abandon a nation city.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cityZone = ZoneManager.findSmallestZone(targetBuilding.getLoc());
|
||||
|
||||
// Can't abandon a tree not within a player city zone
|
||||
if (cityZone.isPlayerCity() == false)
|
||||
return;
|
||||
|
||||
if (targetBuilding.getCity() == null)
|
||||
return;
|
||||
|
||||
if (targetBuilding.getCity().getBane() != null){
|
||||
ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Can't abandon Tree while a bane exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetBuilding.getCity().hasBeenTransfered == true) {
|
||||
ChatManager.chatCityError(sourcePlayer, "City can only be abandoned once per rebooting.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Guild no longer owns his tree.
|
||||
if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), 0)) {
|
||||
Logger.error("Failed to update Owned City to Database");
|
||||
return;
|
||||
}
|
||||
|
||||
sourceGuild.setCityUUID(0);
|
||||
sourceGuild.setGuildState(GuildState.Errant);
|
||||
sourceGuild.setNation(null);
|
||||
|
||||
// Transfer the city assets
|
||||
TransferCityAssets(sourcePlayer, targetBuilding);
|
||||
|
||||
GuildManager.updateAllGuildTags(sourceGuild);
|
||||
GuildManager.updateAllGuildBinds(sourceGuild, null);
|
||||
|
||||
}
|
||||
|
||||
private void TransferCityAssets(PlayerCharacter sourcePlayer,
|
||||
Building cityTOL) {
|
||||
|
||||
Zone cityZone;
|
||||
|
||||
// Build list of buildings within this parent zone
|
||||
cityZone = ZoneManager.findSmallestZone(cityTOL.getLoc());
|
||||
|
||||
for (Building cityBuilding : cityZone.zoneBuildingSet) {
|
||||
|
||||
Blueprint cityBlueprint;
|
||||
cityBlueprint = cityBuilding.getBlueprint();
|
||||
|
||||
// Buildings without blueprints cannot be abandoned
|
||||
if (cityBlueprint == null)
|
||||
continue;
|
||||
|
||||
// Transfer ownership of valid city assets
|
||||
if ((cityBlueprint.getBuildingGroup() == BuildingGroup.TOL)
|
||||
|| (cityBlueprint.getBuildingGroup() == BuildingGroup.SPIRE)
|
||||
|| (cityBlueprint.getBuildingGroup() == BuildingGroup.BARRACK)
|
||||
|| (cityBlueprint.isWallPiece())
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE))
|
||||
AbandonSingleAsset(sourcePlayer, cityBuilding);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
|
||||
/* @Summary: This is the abstract class from which all message handlers
|
||||
* for mainline application protocol derive. Namely those
|
||||
* routed and executed via ClientMessageHandler.
|
||||
*/
|
||||
|
||||
public abstract class AbstractClientMsgHandler {
|
||||
private final Class<? extends ClientNetMsg> handler;
|
||||
|
||||
public AbstractClientMsgHandler(Class<? extends ClientNetMsg> handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public boolean handleNetMsg(ClientNetMsg msg) {
|
||||
|
||||
boolean executionSucceded;
|
||||
|
||||
try {
|
||||
executionSucceded = _handleNetMsg(msg, (ClientConnection) msg.getOrigin());
|
||||
} catch (MsgSendException e) {
|
||||
e.printStackTrace();
|
||||
executionSucceded = false;
|
||||
}
|
||||
|
||||
return executionSucceded;
|
||||
}
|
||||
|
||||
protected abstract boolean _handleNetMsg(ClientNetMsg msg, ClientConnection origin) throws MsgSendException;}
|
||||
@@ -0,0 +1,122 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.AcceptInviteToGuildMsg;
|
||||
import engine.net.client.msg.guild.GuildInfoMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildHistory;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
public class AcceptInviteToGuildHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public AcceptInviteToGuildHandler() {
|
||||
super(AcceptInviteToGuildMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player;
|
||||
AcceptInviteToGuildMsg msg;
|
||||
Guild guild;
|
||||
|
||||
msg = (AcceptInviteToGuildMsg) baseMsg;
|
||||
|
||||
// get PlayerCharacter of person accepting invite
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
guild = (Guild) DbManager.getObject(GameObjectType.Guild, msg.getGuildUUID());
|
||||
|
||||
|
||||
if (guild == null)
|
||||
return true;
|
||||
|
||||
if (guild.getGuildType() == null){
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
// verify they accepted for the correct guild
|
||||
|
||||
if (player.getLastGuildToInvite() != msg.getGuildUUID())
|
||||
return true;
|
||||
|
||||
if ( (player.getGuild() != null) &&
|
||||
(player.getGuild().isErrant() == false)) {
|
||||
ChatManager.chatGuildError(player,
|
||||
"You already belongs to a guild!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// verify they are acceptable level for guild
|
||||
|
||||
if (player.getLevel() < guild.getRepledgeMin() || player.getLevel() > guild.getRepledgeMax())
|
||||
return true;
|
||||
|
||||
// Add player to guild
|
||||
player.setGuild(guild);
|
||||
|
||||
// Cleanup guild stuff
|
||||
player.resetGuildStatuses();
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player, guild, 2));
|
||||
|
||||
player.incVer();
|
||||
|
||||
//Add to guild History
|
||||
|
||||
if (player.getGuild() != null){
|
||||
if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(player.getGuildUUID(), player, DateTime.now(), GuildHistoryType.JOIN)){
|
||||
GuildHistory guildHistory = new GuildHistory(player.getGuildUUID(),player.getGuild().getName(),DateTime.now(), GuildHistoryType.JOIN) ;
|
||||
player.getGuildHistory().add(guildHistory);
|
||||
}
|
||||
}
|
||||
|
||||
// Send guild join message
|
||||
|
||||
ChatManager.chatGuildInfo(player, player.getFirstName() + " has joined the guild");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.GuildState;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.AcceptSubInviteMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AcceptSubInviteHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public AcceptSubInviteHandler() {
|
||||
super(AcceptSubInviteMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
AcceptSubInviteMsg msg = (AcceptSubInviteMsg) baseMsg;
|
||||
PlayerCharacter sourcePlayer;
|
||||
Guild sourceGuild;
|
||||
Guild targetGuild;
|
||||
Dispatch dispatch;
|
||||
|
||||
// get PlayerCharacter of person sending sub invite
|
||||
|
||||
sourcePlayer = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return true;
|
||||
|
||||
sourceGuild = sourcePlayer.getGuild();
|
||||
targetGuild = (Guild) DbManager.getObject(GameObjectType.Guild, msg.guildUUID());
|
||||
|
||||
//must be source guild to sub to
|
||||
|
||||
if (targetGuild == null) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
|
||||
return true;
|
||||
}
|
||||
if (sourceGuild == null) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sourceGuild.equals(targetGuild))
|
||||
return true;
|
||||
|
||||
if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(sourcePlayer, "Only a guild leader can accept fealty!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//source guild is limited to 7 subs
|
||||
//TODO this should be based on TOL rank
|
||||
|
||||
if (!targetGuild.canSubAGuild(sourceGuild)) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 45); // Failure to swear guild
|
||||
return true;
|
||||
}
|
||||
|
||||
//all tests passed, let's Handle code
|
||||
//Update Target Guild State.
|
||||
|
||||
sourceGuild.upgradeGuildState(false);
|
||||
|
||||
//Add sub so GuildMaster can Swear in.
|
||||
|
||||
ArrayList<Guild> subs = targetGuild.getSubGuildList();
|
||||
subs.add(sourceGuild);
|
||||
|
||||
targetGuild.setGuildState(GuildState.Nation);
|
||||
|
||||
|
||||
//Let's send the message back.
|
||||
|
||||
msg.setUnknown02(1);
|
||||
msg.setResponse("Your guild is now a " + sourceGuild.getGuildState().name() + '.');
|
||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
ChatManager.chatSystemInfo(sourcePlayer, "Your guild is now a " + sourceGuild.getGuildState().name() + '.');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.ItemType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.*;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ActivateNPCMessage;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ManageCityAssetsMsg;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which keeps
|
||||
* client's tcp connection open.
|
||||
*/
|
||||
public class ActivateNPCMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ActivateNPCMsgHandler() {
|
||||
super(ActivateNPCMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
ActivateNPCMessage msg;
|
||||
PlayerCharacter player;
|
||||
Building building;
|
||||
Contract contract;
|
||||
CharacterItemManager itemMan;
|
||||
Zone zone;
|
||||
|
||||
msg = (ActivateNPCMessage) baseMsg;
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
building = BuildingManager.getBuildingFromCache(msg.buildingUUID());
|
||||
|
||||
if (player == null || building == null)
|
||||
return false;
|
||||
|
||||
ArrayList<Item> ItemLists = new ArrayList<>();
|
||||
|
||||
// Filter hirelings by slot type
|
||||
|
||||
for (Item hirelings : player.getInventory()) {
|
||||
if (hirelings.getItemBase().getType().equals(ItemType.CONTRACT)) {
|
||||
contract = DbManager.ContractQueries.GET_CONTRACT(hirelings.getItemBase().getUUID());
|
||||
if (contract == null)
|
||||
continue;
|
||||
if (contract.canSlotinBuilding(building))
|
||||
ItemLists.add(hirelings);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.getUnknown01() == 1) {
|
||||
//Request npc list to slot
|
||||
ActivateNPCMessage anm = new ActivateNPCMessage();
|
||||
anm.setSize(ItemLists.size());
|
||||
anm.setItemList(ItemLists);
|
||||
Dispatch dispatch = Dispatch.borrow(player, anm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
if (msg.getUnknown01() == 0) {
|
||||
|
||||
//Slot npc
|
||||
|
||||
if (building.getBlueprintUUID() == 0) {
|
||||
ChatManager.chatSystemError(player, "Unable to load Blueprint for Building Mesh " + building.getMeshUUID());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (building.getBlueprint().getMaxSlots() == building.getHirelings().size())
|
||||
return false;
|
||||
|
||||
Vector3fImmutable NpcLoc = new Vector3fImmutable(building.getLoc());
|
||||
|
||||
Item contractItem = Item.getFromCache(msg.getUnknown04());
|
||||
|
||||
if (contractItem == null)
|
||||
return false;
|
||||
|
||||
if (!player.getCharItemManager().doesCharOwnThisItem(contractItem.getObjectUUID())) {
|
||||
Logger.error(player.getName() + "has attempted to place Hireling : " + contractItem.getName() + "without a valid contract!");
|
||||
return false;
|
||||
}
|
||||
|
||||
itemMan = player.getCharItemManager();
|
||||
|
||||
zone = ZoneManager.findSmallestZone(NpcLoc);
|
||||
|
||||
if (zone == null)
|
||||
return false;
|
||||
|
||||
contract = DbManager.ContractQueries.GET_CONTRACT(contractItem.getItemBase().getUUID());
|
||||
|
||||
if (contract == null)
|
||||
return false;
|
||||
|
||||
// Check if contract can be slotted in this building
|
||||
|
||||
if (contract.canSlotinBuilding(building) == false)
|
||||
return false;
|
||||
|
||||
if (!BuildingManager.addHireling(building, player, NpcLoc, zone, contract, contractItem))
|
||||
return false;
|
||||
|
||||
itemMan.delete(contractItem);
|
||||
itemMan.updateInventory();
|
||||
|
||||
ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, building);
|
||||
|
||||
mca1.actionType = 3;
|
||||
|
||||
mca1.setTargetType(building.getObjectType().ordinal());
|
||||
mca1.setTargetID(building.getObjectUUID());
|
||||
mca1.setTargetType3(building.getObjectType().ordinal());
|
||||
mca1.setTargetID3(building.getObjectUUID());
|
||||
mca1.setAssetName1(building.getName());
|
||||
mca1.setUnknown54(1);
|
||||
Dispatch dispatch = Dispatch.borrow(player, mca1);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.AllianceType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.AllianceChangeMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* protecting and unprotecting city assets
|
||||
*/
|
||||
public class AllianceChangeMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public AllianceChangeMsgHandler() {
|
||||
super(AllianceChangeMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
AllianceChangeMsg msg;
|
||||
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (AllianceChangeMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
Guild toGuild = null;
|
||||
toGuild = Guild.getGuild(msg.getSourceGuildID());
|
||||
if (toGuild.isErrant())
|
||||
return true;
|
||||
|
||||
if (player.getGuild().isErrant())
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
switch (msg.getMsgType()){
|
||||
case AllianceChangeMsg.MAKE_ALLY:
|
||||
case 1: //allyfromRecommended
|
||||
player.getGuild().addGuildToAlliance(msg, AllianceType.Ally, toGuild, player);
|
||||
break;
|
||||
case AllianceChangeMsg.MAKE_ENEMY:
|
||||
case 2: //enemy recommend
|
||||
player.getGuild().addGuildToAlliance(msg, AllianceType.Enemy, toGuild, player);
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
player.getGuild().removeGuildFromAllAlliances(toGuild);
|
||||
break;
|
||||
|
||||
}
|
||||
msg.setMsgType(AllianceChangeMsg.INFO_SUCCESS);
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void MakeEnemy(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
if (fromGuild == null)
|
||||
return;
|
||||
|
||||
if (toGuild == null)
|
||||
return;
|
||||
|
||||
if (!Guild.sameGuild(origin.getPlayerCharacter().getGuild(), fromGuild)){
|
||||
msg.setMsgType(AllianceChangeMsg.ERROR_NOT_SAME_GUILD);
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GuildStatusController.isInnerCouncil(origin.getPlayerCharacter().getGuildStatus()) && !GuildStatusController.isGuildLeader(origin.getPlayerCharacter().getGuildStatus())){
|
||||
msg.setMsgType(AllianceChangeMsg.ERROR_NOT_AUTHORIZED);
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void makeAlly(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
if (fromGuild == null)
|
||||
return;
|
||||
|
||||
if (toGuild == null)
|
||||
return;
|
||||
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void removeFromAlliance(Guild fromGuild, Guild toGuild, AllianceChangeMsg msg, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
if (fromGuild == null)
|
||||
return;
|
||||
|
||||
if (toGuild == null)
|
||||
return;
|
||||
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.AllyEnemyListMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* protecting and unprotecting city assets
|
||||
*/
|
||||
public class AllyEnemyListMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public AllyEnemyListMsgHandler() {
|
||||
super(AllyEnemyListMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
AllyEnemyListMsg msg;
|
||||
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (AllyEnemyListMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
AllyEnemyListMsgHandler.showAllyEnemyList(player.getGuild(), Guild.getGuild(msg.getGuildID()), msg, origin);
|
||||
|
||||
|
||||
|
||||
|
||||
// dispatch = Dispatch.borrow(player, baseMsg);
|
||||
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void showAllyEnemyList(Guild fromGuild, Guild toGuild, AllyEnemyListMsg msg, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
if (fromGuild == null)
|
||||
return;
|
||||
|
||||
if (toGuild == null)
|
||||
return;
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
// UpdateClientAlliancesMsg ucam = new UpdateClientAlliancesMsg();
|
||||
//
|
||||
// dispatch = Dispatch.borrow(origin.getPlayerCharacter(), ucam);
|
||||
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.AppointGroupLeaderMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class AppointGroupLeaderHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public AppointGroupLeaderHandler() {
|
||||
super(AppointGroupLeaderMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
AppointGroupLeaderMsg msg = (AppointGroupLeaderMsg) baseMsg;
|
||||
|
||||
PlayerCharacter source = SessionManager.getPlayerCharacter(origin);
|
||||
if (source == null) {
|
||||
return false;
|
||||
}
|
||||
Group group = GroupManager.getGroup(source);
|
||||
if (group == null) {
|
||||
return false;
|
||||
}
|
||||
if (group.getGroupLead() != source) {
|
||||
return false;
|
||||
}
|
||||
PlayerCharacter target = SessionManager.getPlayerCharacterByID(msg.getTargetID());
|
||||
if (target == null) {
|
||||
return false;
|
||||
}
|
||||
if (target == source) { // Can't appoint self leader
|
||||
AppointGroupLeaderMsg reply = new AppointGroupLeaderMsg();
|
||||
reply.setResponse(1);
|
||||
Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), reply);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Change Group Leader
|
||||
if (!group.setGroupLead(target.getObjectUUID())) {
|
||||
return false; // failed to update group leader
|
||||
}
|
||||
// Refresh everyones group list
|
||||
GroupUpdateMsg gim = new GroupUpdateMsg();
|
||||
gim.setGroup(group);
|
||||
gim.setPlayer(target);
|
||||
gim.setMessageType(2);
|
||||
gim.addPlayer(source);
|
||||
|
||||
group.sendUpdate(gim);
|
||||
|
||||
// Disable Formation
|
||||
target.setFollow(false);
|
||||
gim = new GroupUpdateMsg();
|
||||
gim.setGroup(group);
|
||||
gim.setPlayer(target);
|
||||
gim.setMessageType(8);
|
||||
group.sendUpdate(gim);
|
||||
|
||||
String text = target.getFirstName() + " is the new group leader.";
|
||||
ChatManager.chatGroupInfo(source, text);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.*;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ArcLoginNotifyMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.HotzoneChangeMsg;
|
||||
import engine.net.client.msg.PetMsg;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.session.Session;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ArcLoginNotifyMsgHandler() {
|
||||
super(ArcLoginNotifyMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null) {
|
||||
Logger.error(ConfigManager.MB_WORLD_NAME.getValue()+ ".EnterWorld", "Unable to find player for session");
|
||||
origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player not found.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// cancel logout Timer if exists
|
||||
if (player.getTimers().containsKey("Logout")) {
|
||||
|
||||
JobScheduler.getInstance().cancelScheduledJob(player.getTimers().get("Logout"));
|
||||
player.getTimers().remove("Logout");
|
||||
}
|
||||
player.setTimeStamp("logout", 0);
|
||||
|
||||
// refresh group window if still in group for both this player
|
||||
// and everyone else in the group
|
||||
|
||||
if (GroupManager.getGroup(player) != null) {
|
||||
GroupManager.RefreshMyGroupList(player, origin);
|
||||
GroupManager.RefreshOthersGroupList(player);
|
||||
}
|
||||
|
||||
player.setEnteredWorld(true);
|
||||
// Set player active
|
||||
player.resetRegenUpdateTime();
|
||||
player.setActive(true);
|
||||
|
||||
//player.sendAllEffects(player.getClientConnection());
|
||||
// Send Enter world message to guild
|
||||
|
||||
ChatManager.GuildEnterWorldMsg(player, origin);
|
||||
|
||||
// Send Guild, Nation and IC MOTD
|
||||
GuildManager.enterWorldMOTD(player);
|
||||
ChatManager.sendSystemMessage(player, ConfigManager.MB_WORLD_GREETING.getValue());
|
||||
|
||||
// Set player mask for QT
|
||||
if (player.getRace() != null && player.getRace().getToken() == -524731385)
|
||||
player.setObjectTypeMask(MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD);
|
||||
else
|
||||
player.setObjectTypeMask(MBServerStatics.MASK_PLAYER);
|
||||
|
||||
// If player not already in world, then set them to bind loc and add
|
||||
// to world
|
||||
|
||||
if (player.newChar)
|
||||
player.newChar = false; // TODO Fix safe mode
|
||||
|
||||
// PowersManager.applyPower(player, player, new
|
||||
// Vector3f(0f, 0f, 0f), -1661758934, 50, false);
|
||||
|
||||
// Add player to the QT for tracking
|
||||
|
||||
player.setLoc(player.getLoc());
|
||||
|
||||
//send online status to friends.
|
||||
PlayerFriends.SendFriendsStatus(player, true);
|
||||
|
||||
// Handle too many simultaneous logins from the same forum account by disconnecting the other account(s)
|
||||
|
||||
Account thisAccount = SessionManager.getAccount(player);
|
||||
int maxAccounts = MBServerStatics.MAX_ACTIVE_GAME_ACCOUNTS_PER_DISCORD_ACCOUNT;
|
||||
|
||||
if (maxAccounts > 0) {
|
||||
|
||||
int count = 1;
|
||||
for (Account othAccount : SessionManager.getAllActiveAccounts()) {
|
||||
|
||||
if (othAccount.equals(thisAccount))
|
||||
continue;
|
||||
|
||||
if (thisAccount.discordAccount.equals(othAccount.discordAccount) == false)
|
||||
continue;
|
||||
|
||||
count++;
|
||||
|
||||
if (count > maxAccounts) {
|
||||
Session otherSession = SessionManager.getSession(othAccount);
|
||||
if (otherSession != null) {
|
||||
ClientConnection otherConn = otherSession.getConn();
|
||||
if (otherConn != null) {
|
||||
ChatManager.chatSystemInfo(player, "Only 4 accounts may be used simultaneously. Account '" + othAccount.getUname() + "' has been disconnected.");
|
||||
otherConn.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.setTimeStamp("logout", 0);
|
||||
|
||||
if (player.getPet() != null) {
|
||||
PetMsg pm = new PetMsg(5, player.getPet());
|
||||
Dispatch dispatch = Dispatch.borrow(player, pm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
//Send current hotzone
|
||||
Zone hotzone = ZoneManager.getHotZone();
|
||||
|
||||
if (hotzone != null) {
|
||||
HotzoneChangeMsg hcm = new HotzoneChangeMsg(hotzone.getObjectType().ordinal(), hotzone.getObjectUUID());
|
||||
Dispatch dispatch = Dispatch.borrow(player, hcm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
if (player.getGuild() != null && !player.getGuild().isErrant()) {
|
||||
Guild.UpdateClientAlliancesForPlayer(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ArcSiegeSpireMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which requests that
|
||||
* siege spires be toggled on or off.
|
||||
*/
|
||||
|
||||
public class ArcSiegeSpireMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ArcSiegeSpireMsgHandler() {
|
||||
super(ArcSiegeSpireMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player;
|
||||
Building spire;
|
||||
ArcSiegeSpireMsg msg;
|
||||
|
||||
msg = (ArcSiegeSpireMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
spire = (Building) DbManager.getObject(GameObjectType.Building, msg.getBuildingUUID());
|
||||
|
||||
if (spire == null)
|
||||
return true;
|
||||
|
||||
if (spire.getCity() == null)
|
||||
return true;
|
||||
|
||||
spire.getCity().transactionLock.writeLock().lock();
|
||||
|
||||
try{
|
||||
|
||||
|
||||
//can't activate a spire that's not rank 1.
|
||||
|
||||
if (spire.getRank() < 1)
|
||||
return true;
|
||||
|
||||
// can't activate a spire without a city
|
||||
|
||||
if (spire.getCity() == null)
|
||||
return true;
|
||||
|
||||
// Must have management authority for the spire
|
||||
|
||||
if ((player.getGuild().equals(spire.getGuild()) == false)
|
||||
|| (GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) )
|
||||
return true;
|
||||
|
||||
// Handle case where spire is sabotaged
|
||||
|
||||
if (spire.getTimeStamp("DISABLED") > System.currentTimeMillis()) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle case where spire's toggle delay hasn't yet passed
|
||||
|
||||
if (spire.getTimeStamp("TOGGLEDELAY") > System.currentTimeMillis()) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 174); //This siege spire cannot be toggled yet.
|
||||
return true;
|
||||
}
|
||||
|
||||
// This protocol message is a toggle. If it's currently active then disable
|
||||
// the spire.
|
||||
|
||||
if (spire.isSpireIsActive()) {
|
||||
spire.disableSpire(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Must be enough gold on the spire to turn it on
|
||||
|
||||
if (!spire.hasFunds(5000)){
|
||||
ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox
|
||||
return true;
|
||||
}
|
||||
|
||||
if (spire.getStrongboxValue() < 5000) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox
|
||||
return true;
|
||||
}
|
||||
|
||||
spire.transferGold(-5000,false);
|
||||
spire.enableSpire();
|
||||
|
||||
// Spire is now enabled. Reset the toggle delay
|
||||
|
||||
spire.setTimeStamp("TOGGLEDELAY", System.currentTimeMillis() + (long) 10 * 60 * 1000);
|
||||
}catch(Exception e){
|
||||
Logger.error(e);
|
||||
}finally{
|
||||
spire.getCity().transactionLock.writeLock().unlock();
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ArcViewAssetTransactionsMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Warehouse;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which transfers
|
||||
* gold between a building's strongbox and a player character.
|
||||
*/
|
||||
|
||||
public class ArcViewAssetTransactionsMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ArcViewAssetTransactionsMsgHandler() {
|
||||
super(ArcViewAssetTransactionsMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player;
|
||||
ArcViewAssetTransactionsMsg msg;
|
||||
ArcViewAssetTransactionsMsg newMsg;
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
Dispatch dispatch;
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
msg = (ArcViewAssetTransactionsMsg) baseMsg;
|
||||
|
||||
Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(msg.getWarehouseID());
|
||||
|
||||
if (warehouse == null)
|
||||
return true;
|
||||
|
||||
newMsg = new ArcViewAssetTransactionsMsg(warehouse,msg);
|
||||
newMsg.configure();
|
||||
|
||||
dispatch = Dispatch.borrow(player, newMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.SupportMsgType;
|
||||
import engine.Enum.TaxType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* protecting and unprotecting city assets
|
||||
*/
|
||||
public class AssetSupportMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public AssetSupportMsgHandler() {
|
||||
super(AssetSupportMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
NPC vendor;
|
||||
Building targetBuilding;
|
||||
Dispatch dispatch;
|
||||
|
||||
AssetSupportMsg msg;
|
||||
CityAssetMsg outMsg;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (AssetSupportMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
vendor = NPC.getFromCache(msg.getNpcID());
|
||||
|
||||
if (msg.getMessageType() !=6 && msg.getMessageType() != 7){
|
||||
if (vendor == null)
|
||||
return true;
|
||||
|
||||
vendor.getBuilding();
|
||||
|
||||
if (vendor.getBuilding() == null)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
SupportMsgType supportType = SupportMsgType.typeLookup.get(msg.getMessageType());
|
||||
|
||||
if (supportType == null) {
|
||||
supportType = Enum.SupportMsgType.NONE;
|
||||
Logger.error("No enumeration for support type" + msg.getMessageType());
|
||||
}
|
||||
switch (supportType) {
|
||||
|
||||
case PROTECT:
|
||||
targetBuilding = BuildingManager.getBuildingFromCache(msg.getProtectedBuildingID());
|
||||
protectAsset(msg,targetBuilding, vendor, origin);
|
||||
break;
|
||||
case UNPROTECT:
|
||||
targetBuilding = BuildingManager.getBuildingFromCache(msg.getProtectedBuildingID());
|
||||
unprotectAsset(targetBuilding, vendor, origin);
|
||||
break;
|
||||
case VIEWUNPROTECTED:
|
||||
outMsg = new CityAssetMsg();
|
||||
outMsg.setBuildingID(msg.getBuildingID());
|
||||
outMsg.configure();
|
||||
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
case REMOVETAX:
|
||||
targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (targetBuilding == null)
|
||||
return true;
|
||||
|
||||
targetBuilding.removeTaxes();
|
||||
unprotectAsset(targetBuilding, null, origin);
|
||||
|
||||
ManageCityAssetsMsg mca = new ManageCityAssetsMsg(origin.getPlayerCharacter(),targetBuilding);
|
||||
|
||||
// Action TYPE
|
||||
mca.actionType = 3;
|
||||
mca.setTargetType(targetBuilding.getObjectType().ordinal());
|
||||
mca.setTargetID(targetBuilding.getObjectUUID());
|
||||
mca.setTargetType3(targetBuilding.getObjectType().ordinal());
|
||||
mca.setTargetID3(targetBuilding.getObjectUUID());
|
||||
mca.setAssetName1(targetBuilding.getName());
|
||||
mca.setUnknown54(1);
|
||||
dispatch = Dispatch.borrow(player, mca);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
|
||||
case ACCEPTTAX: //AcceptTax
|
||||
|
||||
targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (targetBuilding == null)
|
||||
return true;
|
||||
|
||||
targetBuilding.acceptTaxes();
|
||||
|
||||
mca = new ManageCityAssetsMsg(origin.getPlayerCharacter(),targetBuilding);
|
||||
|
||||
// Action TYPE
|
||||
mca.actionType = 3;
|
||||
mca.setTargetType(targetBuilding.getObjectType().ordinal());
|
||||
mca.setTargetID(targetBuilding.getObjectUUID());
|
||||
mca.setTargetType3(targetBuilding.getObjectType().ordinal());
|
||||
mca.setTargetID3(targetBuilding.getObjectUUID());
|
||||
mca.setAssetName1(targetBuilding.getName());
|
||||
mca.setUnknown54(1);
|
||||
|
||||
dispatch = Dispatch.borrow(player, mca);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
dispatch = Dispatch.borrow(player, baseMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void protectAsset(AssetSupportMsg msg, Building targetBuilding, NPC vendor, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
Zone serverZone;
|
||||
City serverCity;
|
||||
ManageNPCMsg outMsg;
|
||||
int protectionSlots;
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
if (targetBuilding == null)
|
||||
return;
|
||||
|
||||
serverZone = vendor.getParentZone();
|
||||
|
||||
if (serverZone == null)
|
||||
return;
|
||||
|
||||
serverCity = City.GetCityFromCache(serverZone.getPlayerCityUUID());
|
||||
|
||||
if (serverCity == null)
|
||||
return;
|
||||
|
||||
if (!serverCity.isLocationOnCityZone(targetBuilding.getLoc())){
|
||||
ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Structura must be on city zone for to protect.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((serverCity.getTOL() == null)|| (serverCity.getTOL().getRank() < 1))
|
||||
return;
|
||||
|
||||
if (serverCity.protectionEnforced == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster can not protect structura during bane!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (serverCity.getRuneMaster() == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster is needed for to protect structura!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Enforce runemaster protection limits
|
||||
|
||||
protectionSlots = (2 * serverCity.getRuneMaster().getRank()) + 6;
|
||||
|
||||
if (serverCity.getRuneMaster().getProtectedBuildings().size() >=
|
||||
protectionSlots) {
|
||||
ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Runemaster can only protect " + protectionSlots + " structura!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.getWeeklyTax() != 0){
|
||||
if (!serverCity.getTOL().addProtectionTax(targetBuilding, origin.getPlayerCharacter(), TaxType.WEEKLY, msg.getWeeklyTax(), msg.getEnforceKOS() == 1 ? true: false)){
|
||||
ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Failed to add taxes to building.");
|
||||
return;
|
||||
}
|
||||
targetBuilding.setProtectionState(Enum.ProtectionState.PENDING);
|
||||
}else if (msg.getProfitTax() != 0){
|
||||
if (!serverCity.getTOL().addProtectionTax(targetBuilding, origin.getPlayerCharacter(), TaxType.PROFIT, msg.getProfitTax(), msg.getEnforceKOS() == 1 ? true: false)){
|
||||
ErrorPopupMsg.sendErrorMsg(origin.getPlayerCharacter(), "Failed to add taxes to building.");
|
||||
return;
|
||||
}
|
||||
targetBuilding.setProtectionState(Enum.ProtectionState.PENDING);
|
||||
}else
|
||||
targetBuilding.setProtectionState(Enum.ProtectionState.CONTRACT);
|
||||
|
||||
|
||||
|
||||
outMsg = new ManageNPCMsg(vendor);
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
private static void unprotectAsset(Building targetBuilding, NPC vendor, ClientConnection origin) {
|
||||
|
||||
if (targetBuilding == null)
|
||||
return;
|
||||
|
||||
// Early exit if UUID < the last database derived building UUID.
|
||||
|
||||
if (targetBuilding.getProtectionState() == Enum.ProtectionState.NPC) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetBuilding.getProtectionState() == engine.Enum.ProtectionState.NONE)
|
||||
return;
|
||||
|
||||
if (GuildStatusController.isInnerCouncil(origin.getPlayerCharacter().getGuildStatus()) == false)
|
||||
return;
|
||||
|
||||
targetBuilding.removeTaxes();
|
||||
|
||||
targetBuilding.setProtectionState(engine.Enum.ProtectionState.NONE);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.BanishUnbanishMsg;
|
||||
import engine.net.client.msg.guild.GuildListMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildHistory;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
public class BanishUnbanishHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public BanishUnbanishHandler() {
|
||||
super(BanishUnbanishMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
BanishUnbanishMsg msg = (BanishUnbanishMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
int target = msg.getTarget();
|
||||
PlayerCharacter source = origin.getPlayerCharacter();
|
||||
|
||||
if(source == null || source.getGuild().isErrant() || source.getGuild().getObjectUUID() == 0)
|
||||
return true;
|
||||
|
||||
if (GuildStatusController.isGuildLeader(source.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false)
|
||||
return true;
|
||||
|
||||
if (source.getObjectUUID() == target) {
|
||||
ErrorPopupMsg.sendErrorPopup(source, 103); // You may not banish this char
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
Guild guild = source.getGuild();
|
||||
PlayerCharacter realizedTarget = PlayerCharacter.getFromCache(target);
|
||||
|
||||
if(realizedTarget != null) {
|
||||
// Guild leader can't leave guild. must pass GL or disband
|
||||
if ( GuildStatusController.isGuildLeader(realizedTarget.getGuildStatus()) == false) {
|
||||
//ICs cannot banish other ICs
|
||||
if (!(GuildStatusController.isInnerCouncil(realizedTarget.getGuildStatus()) && GuildStatusController.isGuildLeader(source.getGuildStatus()) == false)) {
|
||||
success = true;
|
||||
if (msg.getMsgType() == 1){
|
||||
if (!DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getObjectUUID(), realizedTarget.getObjectUUID())){
|
||||
ChatManager.chatGuildError(source, "Failed To unbanish " + realizedTarget.getName());
|
||||
return true;
|
||||
}
|
||||
guild.getBanishList().remove(realizedTarget);
|
||||
}
|
||||
|
||||
|
||||
else{
|
||||
|
||||
if (!DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getObjectUUID(), realizedTarget.getObjectUUID())){
|
||||
ChatManager.chatGuildError(source, "Failed To Banish " + realizedTarget.getName());
|
||||
return true;
|
||||
}
|
||||
guild.removePlayer(realizedTarget, GuildHistoryType.BANISHED);
|
||||
guild.getBanishList().add(realizedTarget); //TODO we might encapsulate this a bit better; also not sure that a list of PC objects is really ideal
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (guild.getGuildLeaderUUID() != target) {
|
||||
PlayerCharacter toBanish = PlayerCharacter.getPlayerCharacter(target);
|
||||
if (toBanish == null)
|
||||
return true;
|
||||
//already added previously.
|
||||
if (SessionManager.getPlayerCharacterByID(toBanish.getObjectUUID()) != null)
|
||||
return true;
|
||||
|
||||
if(DbManager.GuildQueries.BANISH_FROM_GUILD_OFFLINE(target, GuildStatusController.isGuildLeader(source.getGuildStatus())) != 0) {
|
||||
|
||||
success = true;
|
||||
|
||||
//Set guild history
|
||||
|
||||
if (DbManager.GuildQueries.ADD_TO_GUILDHISTORY(guild.getObjectUUID(), toBanish, DateTime.now(), GuildHistoryType.BANISHED)){
|
||||
GuildHistory guildHistory = new GuildHistory(toBanish.getGuildUUID(),toBanish.getGuild().getName(),DateTime.now(), GuildHistoryType.BANISHED) ;
|
||||
toBanish.getGuildHistory().add(guildHistory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(success) {
|
||||
//TODO re enable this once we get unbanish working!!!!
|
||||
//DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getobjectUUID(), target);
|
||||
|
||||
// Send left guild message to rest of guild
|
||||
String targetName = PlayerCharacter.getFirstName(target);
|
||||
ChatManager.chatGuildInfo(guild,
|
||||
targetName + " has been banished from " + guild.getName() + '.');
|
||||
GuildListMsg guildListMsg = new GuildListMsg(guild);
|
||||
dispatch = Dispatch.borrow(source, guildListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
} else {
|
||||
ErrorPopupMsg.sendErrorPopup(source, 103); // You may not banish this char
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.BreakFealtyMsg;
|
||||
import engine.net.client.msg.guild.SendGuildEntryMsg;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.session.Session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BreakFealtyHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public BreakFealtyHandler() {
|
||||
super(BreakFealtyMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
BreakFealtyMsg bfm;
|
||||
PlayerCharacter player;
|
||||
Guild toBreak;
|
||||
Guild guild;
|
||||
Dispatch dispatch;
|
||||
|
||||
bfm = (BreakFealtyMsg) baseMsg;
|
||||
|
||||
// get PlayerCharacter of person accepting invite
|
||||
|
||||
player = SessionManager.getPlayerCharacter(
|
||||
origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
toBreak = (Guild) DbManager.getObject(GameObjectType.Guild, bfm.getGuildUUID());
|
||||
|
||||
if (toBreak == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
guild = player.getGuild();
|
||||
|
||||
if (guild == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (toBreak.isNPCGuild()){
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(),MBServerStatics.worldUUID)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (guild.getGuildState()) {
|
||||
case Sworn:
|
||||
guild.setNation(null);
|
||||
GuildManager.updateAllGuildTags(guild);
|
||||
GuildManager.updateAllGuildBinds(guild, null);
|
||||
break;
|
||||
case Province:
|
||||
guild.setNation(guild);
|
||||
GuildManager.updateAllGuildTags(guild);
|
||||
GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity());
|
||||
break;
|
||||
}
|
||||
|
||||
guild.downgradeGuildState();
|
||||
|
||||
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
//Update Map.
|
||||
|
||||
final Session s = SessionManager.getSession(player);
|
||||
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
|
||||
|
||||
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : guildMembers) {
|
||||
ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!');
|
||||
}
|
||||
|
||||
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : breakFealtyMembers) {
|
||||
ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!');
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!toBreak.getSubGuildList().contains(guild)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Failure to break fealty!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Only guild leader can break fealty!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Bane.getBaneByAttackerGuild(guild) != null)
|
||||
{
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You may break fealty with active bane!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!DbManager.GuildQueries.UPDATE_PARENT(guild.getObjectUUID(),MBServerStatics.worldUUID)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (guild.getGuildState()) {
|
||||
case Sworn:
|
||||
guild.setNation(null);
|
||||
GuildManager.updateAllGuildTags(guild);
|
||||
GuildManager.updateAllGuildBinds(guild, null);
|
||||
break;
|
||||
case Province:
|
||||
guild.setNation(guild);
|
||||
GuildManager.updateAllGuildTags(guild);
|
||||
GuildManager.updateAllGuildBinds(guild, guild.getOwnedCity());
|
||||
break;
|
||||
}
|
||||
|
||||
guild.downgradeGuildState();
|
||||
toBreak.getSubGuildList().remove(guild);
|
||||
|
||||
if (toBreak.getSubGuildList().isEmpty())
|
||||
toBreak.downgradeGuildState();
|
||||
|
||||
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
//Update Map.
|
||||
|
||||
final Session s = SessionManager.getSession(player);
|
||||
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
|
||||
|
||||
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(guild.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : guildMembers) {
|
||||
ChatManager.chatGuildInfo(member, guild.getName() + " has broke fealty from " + toBreak.getName() + '!');
|
||||
}
|
||||
|
||||
ArrayList<PlayerCharacter> breakFealtyMembers = SessionManager.getActivePCsInGuildID(toBreak.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : breakFealtyMembers) {
|
||||
ChatManager.chatGuildInfo(member, guild.getName() + " has broken fealty from " + toBreak.getName() + '!');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ChangeAltitudeMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Regions;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public class ChangeAltitudeHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ChangeAltitudeHandler() {
|
||||
super(ChangeAltitudeMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
ChangeAltitudeMsg msg = (ChangeAltitudeMsg) baseMsg;
|
||||
|
||||
PlayerCharacter pc = origin.getPlayerCharacter();
|
||||
if (pc == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AbstractCharacter.CanFly(pc))
|
||||
return false;
|
||||
|
||||
if (pc.isSwimming())
|
||||
return false;
|
||||
if (pc.getRegion() != null && !pc.getRegion().isOutside())
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Find out if we already have an altitude timer running and if so
|
||||
// do not process more alt change requests
|
||||
|
||||
if (pc.getTakeOffTime() != 0)
|
||||
return false;
|
||||
|
||||
|
||||
// remove all movement timers and jobs
|
||||
//TODO: test if they can fly
|
||||
|
||||
float targetAlt;
|
||||
float amount = msg.getAmountToMove();
|
||||
if (amount != 10 && amount != 60)
|
||||
return false;
|
||||
if (pc.getAltitude() == 60 && msg.up())
|
||||
return true;
|
||||
if (pc.getAltitude() == 0 && !msg.up())
|
||||
return true;
|
||||
|
||||
pc.update();
|
||||
pc.stopMovement(pc.getLoc());
|
||||
msg.setStartAlt(pc.getAltitude());
|
||||
if (msg.up()) {
|
||||
|
||||
pc.landingRegion = null;
|
||||
if (pc.getAltitude() == 0){
|
||||
Regions upRegion = pc.getRegion();
|
||||
if (upRegion != null){
|
||||
float startAlt = 0;
|
||||
Building regionBuilding = Regions.GetBuildingForRegion(upRegion);
|
||||
if (upRegion != null)
|
||||
startAlt = upRegion.lerpY(pc) - regionBuilding.getLoc().y;
|
||||
float rounded = startAlt *.10f;
|
||||
|
||||
rounded = ((int)rounded) * 10;
|
||||
|
||||
if (rounded < 0)
|
||||
rounded = 0;
|
||||
|
||||
|
||||
msg.setStartAlt(startAlt);
|
||||
targetAlt = rounded + amount;
|
||||
|
||||
if (targetAlt > 60)
|
||||
targetAlt = 60;
|
||||
|
||||
pc.setAltitude(startAlt);
|
||||
pc.setDesiredAltitude(targetAlt);
|
||||
}else{
|
||||
msg.setStartAlt(pc.getAltitude());
|
||||
targetAlt = pc.getAltitude() + amount;
|
||||
if (targetAlt > 60)
|
||||
targetAlt = 60;
|
||||
}
|
||||
}else{
|
||||
msg.setStartAlt(pc.getAltitude());
|
||||
|
||||
targetAlt = pc.getAltitude() + amount;
|
||||
if (targetAlt > 60)
|
||||
targetAlt = 60;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
msg.setStartAlt(pc.getAltitude());
|
||||
targetAlt = pc.getAltitude() - amount;
|
||||
if (targetAlt < 0)
|
||||
targetAlt = 0;
|
||||
}
|
||||
msg.setTargetAlt(targetAlt);
|
||||
if (pc.getAltitude() < 1 && targetAlt > pc.getAltitude()) {
|
||||
// char is on the ground and is about to start flight
|
||||
if (pc.getStamina() < 10) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (MBServerStatics.MOVEMENT_SYNC_DEBUG) {
|
||||
Logger.info ("Changing Altitude, moving=" + pc.isMoving() +
|
||||
" Current Loc " + pc.getLoc().getX() + ' ' + pc.getLoc().getZ() +
|
||||
" End Loc " + pc.getEndLoc().getX() + ' ' + pc.getEndLoc().getZ());
|
||||
}
|
||||
|
||||
if (msg.up()){
|
||||
pc.update();
|
||||
pc.setDesiredAltitude(targetAlt);
|
||||
pc.setTakeOffTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
else{
|
||||
Regions region = PlayerCharacter.InsideBuildingRegionGoingDown(pc);
|
||||
|
||||
|
||||
|
||||
if (region != null){
|
||||
float landingAltitude = 0;
|
||||
Building building = Regions.GetBuildingForRegion(region);
|
||||
if (building != null)
|
||||
landingAltitude = region.lerpY(pc) - building.getLoc().y;
|
||||
|
||||
if (landingAltitude >= targetAlt){
|
||||
pc.landingRegion = region;
|
||||
pc.landingAltitude = landingAltitude;
|
||||
pc.setDesiredAltitude(landingAltitude);
|
||||
}else{
|
||||
pc.landingRegion = null;
|
||||
pc.setDesiredAltitude(targetAlt);
|
||||
}
|
||||
|
||||
|
||||
}else
|
||||
pc.setDesiredAltitude(targetAlt);
|
||||
|
||||
pc.update();
|
||||
|
||||
|
||||
pc.setTakeOffTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add timer for height change cooldown, this also tells getLoc we are not moving
|
||||
//MovementManager.addChangeAltitudeTimer(pc, msg.getStartAlt(), msg.getTargetAlt(), (int)((MBServerStatics.HEIGHT_CHANGE_TIMER_MS * amount) + 100 ) );
|
||||
|
||||
// Add flight timer job to check stam and ground you when you run out
|
||||
//MovementManager.addFlightTimer(pc, msg, MBServerStatics.FLY_FREQUENCY_MS);
|
||||
//Send change altitude to all in range
|
||||
DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ChangeGuildLeaderMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.GuildInfoMsg;
|
||||
import engine.net.client.msg.guild.GuildListMsg;
|
||||
import engine.objects.City;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class ChangeGuildLeaderHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ChangeGuildLeaderHandler() {
|
||||
super(ChangeGuildLeaderMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
ChangeGuildLeaderMsg msg;
|
||||
PlayerCharacter sourcePlayer;
|
||||
PlayerCharacter targetPlayer;
|
||||
City city;
|
||||
|
||||
msg = (ChangeGuildLeaderMsg) baseMsg;
|
||||
sourcePlayer = origin.getPlayerCharacter();
|
||||
if (sourcePlayer == null)
|
||||
return true;
|
||||
if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()) == false)
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
Guild glGuild = sourcePlayer.getGuild();
|
||||
|
||||
if (glGuild == null)
|
||||
return true;
|
||||
|
||||
if (!glGuild.isGuildLeader(sourcePlayer.getObjectUUID()))
|
||||
return true;
|
||||
targetPlayer = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getTargetID());
|
||||
|
||||
|
||||
if (targetPlayer == null)
|
||||
return true;
|
||||
|
||||
if (GuildStatusController.isGuildLeader(targetPlayer.getGuildStatus()))
|
||||
return true;
|
||||
|
||||
if (!Guild.sameGuild(sourcePlayer.getGuild(),targetPlayer.getGuild()))
|
||||
return false;
|
||||
|
||||
|
||||
//updateSource will generate a new promote/demote screen for sourcePlayer
|
||||
//updateTarget will sync guild info for the target and all players in range
|
||||
|
||||
|
||||
|
||||
|
||||
String targetName = null;
|
||||
boolean isMale = true;
|
||||
boolean updateTarget;
|
||||
|
||||
Enum.GuildType t = Enum.GuildType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter());
|
||||
|
||||
|
||||
if (!DbManager.GuildQueries.SET_GUILD_LEADER(targetPlayer.getObjectUUID(), glGuild.getObjectUUID())){
|
||||
ChatManager.chatGuildError(sourcePlayer, "Failed to change guild leader!");
|
||||
return false;
|
||||
}
|
||||
|
||||
glGuild.setGuildLeader(targetPlayer);
|
||||
|
||||
|
||||
|
||||
if (glGuild.getOwnedCity() != null){
|
||||
city = glGuild.getOwnedCity();
|
||||
if (!city.transferGuildLeader(targetPlayer)){
|
||||
ChatManager.chatGuildError(sourcePlayer, "Failed to Transfer City Objects. Contact CCR!");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
targetPlayer.setGuildLeader(true);
|
||||
targetPlayer.setInnerCouncil(true);
|
||||
targetPlayer.setFullMember(true);
|
||||
targetPlayer.incVer();
|
||||
targetName = targetPlayer.getFirstName();
|
||||
updateTarget = true;
|
||||
|
||||
|
||||
ChatManager.chatGuildInfo(sourcePlayer.getGuild(),
|
||||
targetName + " has been promoted to "
|
||||
+ "guild leader!");
|
||||
|
||||
//These values record a change, not the new value...
|
||||
|
||||
|
||||
|
||||
//updateOldGuildLeader
|
||||
sourcePlayer.setInnerCouncil(true);
|
||||
sourcePlayer.setFullMember(true);
|
||||
sourcePlayer.setGuildLeader(false);
|
||||
sourcePlayer.incVer();
|
||||
|
||||
GuildInfoMsg guildInfoMsg = new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 2);
|
||||
Dispatch dispatch = Dispatch.borrow(sourcePlayer, guildInfoMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
GuildListMsg guildListMsg = new GuildListMsg(sourcePlayer.getGuild());
|
||||
|
||||
dispatch = Dispatch.borrow(sourcePlayer, guildListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
|
||||
if (targetPlayer != null) {
|
||||
if (updateTarget)
|
||||
DispatchMessage.sendToAllInRange(targetPlayer, new GuildInfoMsg(targetPlayer, targetPlayer.getGuild(), 2));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.ChangeRankMsg;
|
||||
import engine.net.client.msg.guild.GuildInfoMsg;
|
||||
import engine.net.client.msg.guild.GuildListMsg;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class ChangeRankHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ChangeRankHandler() {
|
||||
super(ChangeRankMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
ChangeRankMsg msg;
|
||||
PlayerCharacter sourcePlayer;
|
||||
PlayerCharacter targetPlayer;
|
||||
|
||||
msg = (ChangeRankMsg) baseMsg;
|
||||
sourcePlayer = origin.getPlayerCharacter();
|
||||
|
||||
targetPlayer = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getPlayerUUID());
|
||||
|
||||
if (msg.getPlayerUUID() == 0)
|
||||
targetPlayer = sourcePlayer;
|
||||
|
||||
//updateSource will generate a new promote/demote screen for sourcePlayer
|
||||
//updateTarget will sync guild info for the target and all players in range
|
||||
|
||||
boolean updateSource = false, updateTarget = false;
|
||||
|
||||
if (sourcePlayer == null ||GuildStatusController.isInnerCouncil(sourcePlayer.getGuildStatus()) == false)
|
||||
return true;
|
||||
|
||||
if (targetPlayer != null && (targetPlayer.getGuild().equals(sourcePlayer.getGuild()) == false))
|
||||
return true;
|
||||
|
||||
String targetName = null;
|
||||
boolean isMale;
|
||||
|
||||
if (msg.getPreviousRank() != msg.getNewRank()) {
|
||||
Enum.GuildType t = Enum.GuildType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter());
|
||||
|
||||
if (targetPlayer != null) {
|
||||
targetPlayer.setGuildTitle(msg.getNewRank());
|
||||
|
||||
targetName = targetPlayer.getFirstName();
|
||||
isMale = targetPlayer.getRace().getRaceType().getCharacterSex().equals(Enum.CharacterSex.MALE);
|
||||
} else {
|
||||
DbManager.GuildQueries.UPDATE_GUILD_RANK_OFFLINE(msg.getPlayerUUID(), msg.getNewRank(), sourcePlayer.getGuild().getObjectUUID());
|
||||
|
||||
targetName = PlayerCharacter.getFirstName(msg.getPlayerUUID());
|
||||
isMale = true;
|
||||
}
|
||||
|
||||
ChatManager.chatGuildInfo(sourcePlayer.getGuild(),
|
||||
targetName + " has been "
|
||||
+ ((msg.getNewRank() > msg.getPreviousRank()) ? "pro" : "de") + "moted to "
|
||||
+ t.getRankForGender(msg.getNewRank(), isMale) + '!');
|
||||
updateSource = true;
|
||||
}
|
||||
|
||||
//These values record a change, not the new value...
|
||||
boolean icUpdate = false, recruitUpdate = false, taxUpdate = false;
|
||||
|
||||
//Handle the offline case..
|
||||
if (targetPlayer == null) {
|
||||
int updateMask = DbManager.GuildQueries.UPDATE_GUILD_STATUS_OFFLINE(msg.getPlayerUUID(),
|
||||
msg.getIc() > 0,
|
||||
msg.getRec() > 0,
|
||||
msg.getTax() > 0,
|
||||
sourcePlayer.getGuild().getObjectUUID());
|
||||
|
||||
//These values come from the updateIsStatusOffline function
|
||||
icUpdate = (updateMask & 4) > 0;
|
||||
recruitUpdate = (updateMask & 2) > 0;
|
||||
taxUpdate = (updateMask & 1) > 0;
|
||||
|
||||
if (targetName == null && updateMask > 0)
|
||||
targetName = PlayerCharacter.getFirstName(msg.getPlayerUUID());
|
||||
} else {
|
||||
icUpdate = (GuildStatusController.isInnerCouncil(targetPlayer.getGuildStatus()) != (msg.getIc() > 0)) && GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus());
|
||||
recruitUpdate = (GuildStatusController.isRecruiter(targetPlayer.getGuildStatus()) != (msg.getRec() > 0)) && GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus());
|
||||
taxUpdate = (GuildStatusController.isTaxCollector(targetPlayer.getGuildStatus()) != (msg.getTax() > 0)) && GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus());
|
||||
|
||||
//This logic branch only executes if targetPlayer has passed a null check...
|
||||
if (icUpdate){
|
||||
targetPlayer.setInnerCouncil(msg.getIc() > 0);
|
||||
targetPlayer.setFullMember(true);
|
||||
targetPlayer.incVer();
|
||||
}
|
||||
|
||||
if (recruitUpdate)
|
||||
targetPlayer.setRecruiter(msg.getRec() > 0);
|
||||
|
||||
if (taxUpdate)
|
||||
targetPlayer.setTaxCollector(msg.getTax() > 0);
|
||||
|
||||
if (targetName == null)
|
||||
targetName = targetPlayer.getFirstName();
|
||||
}
|
||||
|
||||
if (icUpdate) {
|
||||
ChatManager.chatGuildInfo(sourcePlayer.getGuild(),
|
||||
(msg.getIc() > 0)
|
||||
? targetName + " has been appointed to the inner council."
|
||||
: targetName + " is no longer a member of the inner council.");
|
||||
|
||||
updateSource = true;
|
||||
updateTarget = true;
|
||||
}
|
||||
|
||||
if (recruitUpdate) {
|
||||
updateSource = true;
|
||||
updateTarget = true;
|
||||
}
|
||||
|
||||
if (taxUpdate) {
|
||||
updateSource = true;
|
||||
updateTarget = true;
|
||||
}
|
||||
|
||||
if (targetPlayer != null) {
|
||||
targetPlayer.incVer();
|
||||
if (updateTarget)
|
||||
DispatchMessage.sendToAllInRange(targetPlayer, new GuildInfoMsg(targetPlayer, targetPlayer.getGuild(), 2));
|
||||
}
|
||||
|
||||
if (updateSource) {
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 2));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
dispatch = Dispatch.borrow(sourcePlayer, new GuildListMsg(sourcePlayer.getGuild()));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.Enum.GuildState;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ChatFilterMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which processes
|
||||
* client requests to abandon a building.
|
||||
*/
|
||||
public class ChannelMuteMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
// Instance variables
|
||||
|
||||
public ChannelMuteMsgHandler() {
|
||||
super(ChatFilterMsg.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void AbandonSingleAsset(PlayerCharacter sourcePlayer,
|
||||
Building targetBuilding) {
|
||||
|
||||
// Transfer the building asset ownership and refresh all clients
|
||||
|
||||
DbManager.BuildingQueries.CLEAR_FRIENDS_LIST(targetBuilding.getObjectUUID());
|
||||
targetBuilding.getFriends().clear();
|
||||
|
||||
DbManager.BuildingQueries.CLEAR_CONDEMNED_LIST(targetBuilding.getObjectUUID());
|
||||
targetBuilding.getCondemned().clear();
|
||||
targetBuilding.setOwner(null);
|
||||
targetBuilding.refreshGuild();
|
||||
}
|
||||
|
||||
private void AbandonAllCityObjects(PlayerCharacter sourcePlayer,
|
||||
Building targetBuilding) {
|
||||
Guild sourceGuild;
|
||||
Zone cityZone;
|
||||
|
||||
sourceGuild = sourcePlayer.getGuild();
|
||||
|
||||
if (sourceGuild == null)
|
||||
return;
|
||||
|
||||
if (sourceGuild.getSubGuildList().size() > 0) {
|
||||
ChatManager.chatCityError(sourcePlayer, "You Cannot abandon a nation city.");
|
||||
return;
|
||||
}
|
||||
|
||||
cityZone = ZoneManager.findSmallestZone(targetBuilding.getLoc());
|
||||
|
||||
// Can't abandon a tree not within a player city zone
|
||||
if (cityZone.isPlayerCity() == false)
|
||||
return;
|
||||
|
||||
if (targetBuilding.getCity().hasBeenTransfered == true) {
|
||||
ChatManager.chatCityError(sourcePlayer, "City can only be abandoned once per rebooting.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Guild no longer owns his tree.
|
||||
if (!DbManager.GuildQueries.SET_GUILD_OWNED_CITY(sourceGuild.getObjectUUID(), 0)) {
|
||||
Logger.error( "Failed to update Owned City to Database");
|
||||
return;
|
||||
}
|
||||
|
||||
sourceGuild.setCityUUID(0);
|
||||
sourceGuild.setGuildState(GuildState.Errant);
|
||||
sourceGuild.setNation(null);
|
||||
|
||||
// Transfer the city assets
|
||||
TransferCityAssets(sourcePlayer, targetBuilding);
|
||||
|
||||
GuildManager.updateAllGuildTags(sourceGuild);
|
||||
GuildManager.updateAllGuildBinds(sourceGuild, null);
|
||||
|
||||
}
|
||||
|
||||
private void TransferCityAssets(PlayerCharacter sourcePlayer,
|
||||
Building cityTOL) {
|
||||
|
||||
Zone cityZone;
|
||||
|
||||
// Build list of buildings within this parent zone
|
||||
cityZone = ZoneManager.findSmallestZone(cityTOL.getLoc());
|
||||
|
||||
for (Building cityBuilding : cityZone.zoneBuildingSet) {
|
||||
|
||||
Blueprint cityBlueprint;
|
||||
cityBlueprint = cityBuilding.getBlueprint();
|
||||
|
||||
// Buildings without blueprints cannot be abandoned
|
||||
if (cityBlueprint == null)
|
||||
continue;
|
||||
|
||||
// Transfer ownership of valid city assets
|
||||
if ((cityBlueprint.getBuildingGroup() == BuildingGroup.TOL)
|
||||
|| (cityBlueprint.getBuildingGroup() == BuildingGroup.SPIRE)
|
||||
|| (cityBlueprint.getBuildingGroup() == BuildingGroup.BARRACK)
|
||||
|| (cityBlueprint.isWallPiece())
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE))
|
||||
AbandonSingleAsset(sourcePlayer, cityBuilding);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.CityChoiceMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.TeleportRepledgeListMsg;
|
||||
import engine.objects.City;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which keeps
|
||||
* client's tcp connection open.
|
||||
*/
|
||||
|
||||
public class CityChoiceMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public CityChoiceMsgHandler() {
|
||||
super(CityChoiceMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
Dispatch dispatch;
|
||||
|
||||
CityChoiceMsg msg = (CityChoiceMsg) baseMsg;
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
switch (msg.getMsgType()) {
|
||||
case 5:
|
||||
TeleportRepledgeListMsg trlm = new TeleportRepledgeListMsg(player, false);
|
||||
trlm.configure();
|
||||
dispatch = Dispatch.borrow(player, trlm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case 3:
|
||||
City city = City.getCity(msg.getCityID());
|
||||
|
||||
if (city == null)
|
||||
return true;
|
||||
|
||||
Guild cityGuild = city.getGuild();
|
||||
|
||||
if (cityGuild == null)
|
||||
return true;
|
||||
|
||||
if (player.getLevel() < cityGuild.getRepledgeMin() || player.getLevel() > cityGuild.getRepledgeMax())
|
||||
return true;
|
||||
|
||||
//if repledge, reguild the player but set his building now.
|
||||
|
||||
GuildManager.joinGuild(player, cityGuild, city.getObjectUUID(), Enum.GuildHistoryType.JOIN);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.db.archive.CityRecord;
|
||||
import engine.db.archive.DataWarehouse;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClaimAssetMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.objects.Blueprint;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import static engine.math.FastMath.sqr;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which keeps
|
||||
* client's tcp connection open.
|
||||
*/
|
||||
public class ClaimAssetMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
// Instance variables
|
||||
|
||||
private final ReentrantReadWriteLock claimLock = new ReentrantReadWriteLock();
|
||||
|
||||
public ClaimAssetMsgHandler() {
|
||||
super(ClaimAssetMsg.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
this.claimLock.writeLock().lock();
|
||||
|
||||
try{
|
||||
PlayerCharacter sourcePlayer;
|
||||
Building targetBuilding;
|
||||
Blueprint blueprint;
|
||||
ClaimAssetMsg msg;
|
||||
int targetUUID;
|
||||
|
||||
msg = (ClaimAssetMsg) baseMsg;
|
||||
targetUUID = msg.getUUID();
|
||||
|
||||
sourcePlayer = origin.getPlayerCharacter();
|
||||
targetBuilding = BuildingManager.getBuildingFromCache(targetUUID);
|
||||
|
||||
// Oops! *** Refactor: Log error
|
||||
|
||||
if ((sourcePlayer == null) ||
|
||||
(targetBuilding == null))
|
||||
return true;
|
||||
|
||||
// Player must be reasonably close to building in order to claim
|
||||
|
||||
if (sourcePlayer.getLoc().distanceSquared2D(targetBuilding.getLoc()) > sqr(100))
|
||||
return true;
|
||||
|
||||
// Early exit if object to be claimed is not errant
|
||||
|
||||
if (targetBuilding.getOwnerUUID() != 0)
|
||||
return true;
|
||||
|
||||
|
||||
// Early exit if UUID < the last database derived building UUID.
|
||||
|
||||
if (targetBuilding.getProtectionState() == Enum.ProtectionState.NPC) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Early exit if claiming player does not
|
||||
// have a guild.
|
||||
|
||||
// Errant players cannot claim
|
||||
|
||||
if (sourcePlayer.getGuild().isErrant())
|
||||
return true;
|
||||
|
||||
// Can't claim an object without a blueprint
|
||||
|
||||
if (targetBuilding.getBlueprintUUID() == 0)
|
||||
return true;
|
||||
|
||||
blueprint = targetBuilding.getBlueprint();
|
||||
|
||||
//cant claim mine this way.
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.MINE)
|
||||
return true;
|
||||
|
||||
// Players cannot claim shrines
|
||||
|
||||
if ((targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.SHRINE))
|
||||
return true;
|
||||
|
||||
// Can't claim a tree if your guild already owns one
|
||||
// *** Refactor : Send error to player here
|
||||
|
||||
if ((sourcePlayer.getGuild().isNation()) &&
|
||||
(blueprint.getBuildingGroup() == BuildingGroup.TOL))
|
||||
return true;
|
||||
|
||||
// Process the transfer of the building(s)
|
||||
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.TOL) {
|
||||
targetBuilding.getCity().claim(sourcePlayer);
|
||||
|
||||
// Push transfer of city to data warehouse
|
||||
CityRecord cityRecord = CityRecord.borrow(targetBuilding.getCity(), Enum.RecordEventType.TRANSFER);
|
||||
DataWarehouse.pushToWarehouse(cityRecord);
|
||||
|
||||
} else
|
||||
targetBuilding.claim(sourcePlayer);
|
||||
|
||||
} catch(Exception e){
|
||||
Logger.error("ClaimAssetMsgHandler", e.getMessage());
|
||||
}finally{
|
||||
this.claimLock.writeLock().unlock();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which keeps
|
||||
* client's tcp connection open.
|
||||
*/
|
||||
public class ClaimGuildTreeMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
// Instance variables
|
||||
|
||||
private final ReentrantReadWriteLock claimLock = new ReentrantReadWriteLock();
|
||||
private static final int RENAME_TREE = 2;
|
||||
private static final int BIND_TREE = 3;
|
||||
private static final int OPEN_CITY = 4;
|
||||
private static final int CLOSE_CITY = 5;
|
||||
|
||||
public ClaimGuildTreeMsgHandler() {
|
||||
super(ClaimGuildTreeMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
this.claimLock.writeLock().lock();
|
||||
|
||||
try{
|
||||
PlayerCharacter sourcePlayer;
|
||||
Building building;
|
||||
Blueprint blueprint;
|
||||
Zone playerZone= null;
|
||||
City playerCity= null;
|
||||
ClaimGuildTreeMsg msg;
|
||||
int targetUUID;
|
||||
Dispatch dispatch;
|
||||
|
||||
msg = (ClaimGuildTreeMsg) baseMsg;
|
||||
targetUUID = msg.getTargetID();
|
||||
|
||||
sourcePlayer = origin.getPlayerCharacter();
|
||||
building = BuildingManager.getBuildingFromCache(targetUUID);
|
||||
|
||||
if (building != null)
|
||||
playerZone = building.getParentZone();
|
||||
|
||||
if (playerZone != null)
|
||||
playerCity = City.getCity(playerZone.getPlayerCityUUID());
|
||||
|
||||
// Oops! *** Refactor: Log error
|
||||
switch (msg.getMessageType()){
|
||||
case RENAME_TREE:
|
||||
if ((sourcePlayer == null) ||
|
||||
(building == null) || playerZone == null ||playerCity == null)
|
||||
return true;
|
||||
|
||||
// Early exit if object to be claimed is not errant
|
||||
|
||||
if (building.getOwnerUUID() == 0)
|
||||
return true;
|
||||
|
||||
// Errant players cannot rename
|
||||
|
||||
if (sourcePlayer.getGuild().isErrant())
|
||||
return true;
|
||||
|
||||
// Can't rename an object without a blueprint
|
||||
|
||||
if (building.getBlueprintUUID() == 0)
|
||||
return true;
|
||||
|
||||
blueprint = building.getBlueprint();
|
||||
|
||||
//can only rename tree this way.
|
||||
if (blueprint.getBuildingGroup() != BuildingGroup.TOL)
|
||||
return true;
|
||||
|
||||
//dont rename if guild is null
|
||||
if (building.getGuild().isErrant())
|
||||
return true;
|
||||
|
||||
if (!ManageCityAssetMsgHandler.playerCanManageNotFriends(sourcePlayer, building))
|
||||
return true;
|
||||
|
||||
|
||||
if (!playerCity.renameCity(msg.getTreeName())){
|
||||
ChatManager.chatSystemError(sourcePlayer, "Failed to rename city!");
|
||||
return true;
|
||||
}
|
||||
|
||||
GuildTreeStatusMsg gtsm = new GuildTreeStatusMsg(building,sourcePlayer);
|
||||
gtsm.configure();
|
||||
dispatch = Dispatch.borrow(sourcePlayer, gtsm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
CityZoneMsg czm = new CityZoneMsg(2,playerZone.getLoc().x, playerZone.getLoc().y, playerZone.getLoc().z, playerCity.getCityName(),playerZone, Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents);
|
||||
DispatchMessage.dispatchMsgToAll(czm);
|
||||
|
||||
break;
|
||||
case BIND_TREE:
|
||||
|
||||
Guild pcGuild = sourcePlayer.getGuild();
|
||||
|
||||
//test tree is valid for binding, same guild or same nation
|
||||
if (!Guild.sameNation(pcGuild, building.getGuild())) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (building.getGuild().isErrant())
|
||||
return true;
|
||||
|
||||
|
||||
//get bind city
|
||||
Zone zone =building.getParentZone();
|
||||
|
||||
if (zone == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (playerCity == null && building.getGuild() != null)
|
||||
playerCity = building.getGuild().getOwnedCity();
|
||||
|
||||
if (playerCity == null)
|
||||
return true;
|
||||
|
||||
|
||||
sourcePlayer.setBindBuildingID(building.getObjectUUID());
|
||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case OPEN_CITY:
|
||||
case CLOSE_CITY:
|
||||
if ((sourcePlayer == null) ||
|
||||
(building == null) || playerZone == null ||playerCity == null)
|
||||
return true;
|
||||
|
||||
if (!ManageCityAssetMsgHandler.playerCanManageNotFriends(sourcePlayer, building))
|
||||
return true;
|
||||
|
||||
boolean open = (msg.getMessageType() == OPEN_CITY);
|
||||
|
||||
if (!playerCity.openCity(open)){
|
||||
ErrorPopupMsg.sendErrorMsg(sourcePlayer, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} catch(Exception e){
|
||||
Logger.error( e.getMessage());
|
||||
}finally{
|
||||
try{
|
||||
this.claimLock.writeLock().unlock();
|
||||
}catch(Exception e){
|
||||
Logger.info("failClaimsync");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.DestroyBuildingMsg;
|
||||
import engine.objects.Blueprint;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message where the
|
||||
* client is requesting a building be destroyed.
|
||||
*/
|
||||
|
||||
public class DestroyBuildingHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public DestroyBuildingHandler() {
|
||||
super(DestroyBuildingMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter pc = origin.getPlayerCharacter();
|
||||
|
||||
DestroyBuildingMsg msg;
|
||||
msg = (DestroyBuildingMsg) baseMsg;
|
||||
|
||||
int buildingUUID = msg.getUUID();
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(buildingUUID);
|
||||
;
|
||||
if (pc == null || building == null)
|
||||
return true;
|
||||
|
||||
Blueprint blueprint;
|
||||
|
||||
blueprint = building.getBlueprint();
|
||||
|
||||
// Can't destroy buildings without a blueprint.
|
||||
|
||||
if (blueprint == null)
|
||||
return true;
|
||||
|
||||
// Cannot destroy Oblivion database derived buildings.
|
||||
|
||||
if (building.getProtectionState() == Enum.ProtectionState.NPC) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(building, pc))
|
||||
return true;
|
||||
|
||||
// Can't destroy a tree of life
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.TOL)
|
||||
return true;
|
||||
|
||||
// Can't destroy a shrine
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.SHRINE)
|
||||
return true;
|
||||
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.MINE)
|
||||
return true;
|
||||
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.RUNEGATE)
|
||||
return true;
|
||||
|
||||
// Turn off spire if destoying
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.SPIRE)
|
||||
building.disableSpire(true);
|
||||
|
||||
if (blueprint.getBuildingGroup() == BuildingGroup.WAREHOUSE) {
|
||||
|
||||
City city = building.getCity();
|
||||
|
||||
if (city != null)
|
||||
city.setWarehouseBuildingID(0);
|
||||
}
|
||||
|
||||
building.setRank(-1);
|
||||
WorldGrid.RemoveWorldObject(building);
|
||||
WorldGrid.removeObject(building);
|
||||
building.getParentZone().zoneBuildingSet.remove(building);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.DisbandGroupMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class DisbandGroupHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public DisbandGroupHandler() {
|
||||
super(DisbandGroupMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter source = SessionManager.getPlayerCharacter(origin);
|
||||
if (source == null) {
|
||||
return false;
|
||||
}
|
||||
Group group = GroupManager.getGroup(source);
|
||||
if (group == null) {
|
||||
return false;
|
||||
}
|
||||
if (group.getGroupLead() != source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clear all group member lists
|
||||
GroupUpdateMsg gim = new GroupUpdateMsg();
|
||||
gim.setGroup(group);
|
||||
gim.setMessageType(4);
|
||||
|
||||
// send the disbanded popup to everyone in group
|
||||
group.sendUpdate(gim);
|
||||
|
||||
// cleanup group
|
||||
GroupManager.deleteGroup(group);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.db.archive.DataWarehouse;
|
||||
import engine.db.archive.GuildRecord;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.DisbandGuildMsg;
|
||||
import engine.net.client.msg.guild.LeaveGuildMsg;
|
||||
import engine.objects.Bane;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class DisbandGuildHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public DisbandGuildHandler() {
|
||||
super(DisbandGuildMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player;
|
||||
Guild guild;
|
||||
Dispatch dispatch;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
//don't allow non guild leaders to disband guild.
|
||||
|
||||
if (player == null || GuildStatusController.isGuildLeader(player.getGuildStatus()) == false)
|
||||
return true;
|
||||
|
||||
guild = player.getGuild();
|
||||
|
||||
if (guild == null || guild.isErrant())
|
||||
return true;
|
||||
|
||||
// Don't allow disbanding if a city is owned
|
||||
// *** Refactor: We should allow this by abandoning the tree first.
|
||||
|
||||
if (guild.getOwnedCity() != null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a soverign guild!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Bane guildBane = Bane.getBaneByAttackerGuild(guild);
|
||||
|
||||
if (guildBane != null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a guild with an active bane!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (guild.getSubGuildList().size() > 0) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You cannot disband a nation!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send message to guild (before kicking everyone out of it)
|
||||
|
||||
ChatManager.chatGuildInfo(guild, guild.getName() + " has been disbanded!");
|
||||
|
||||
// Log event to data warehous
|
||||
|
||||
GuildRecord guildRecord = GuildRecord.borrow(guild, Enum.RecordEventType.DISBAND);
|
||||
DataWarehouse.pushToWarehouse(guildRecord);
|
||||
|
||||
// Remove us as a subguild of our nation
|
||||
|
||||
if (guild.getNation() != null && Guild.sameGuild(guild, guild.getNation()) == false && guild.getNation().isErrant() == false)
|
||||
guild.getNation().removeSubGuild(guild);
|
||||
|
||||
// Update all online guild players
|
||||
|
||||
for (PlayerCharacter pcs : Guild.GuildRoster(guild)) {
|
||||
|
||||
guild.removePlayer(pcs,GuildHistoryType.DISBAND);
|
||||
}
|
||||
|
||||
//Save Guild data
|
||||
|
||||
player.setGuildLeader(false);
|
||||
player.setInnerCouncil(false);
|
||||
guild.setGuildLeaderUUID(0);
|
||||
guild.setNation(null);
|
||||
|
||||
DbManager.GuildQueries.DELETE_GUILD(guild);
|
||||
|
||||
DbManager.removeFromCache(guild);
|
||||
WorldGrid.removeObject(guild, player);
|
||||
|
||||
// Send message back to client
|
||||
|
||||
LeaveGuildMsg leaveGuildMsg = new LeaveGuildMsg();
|
||||
leaveGuildMsg.setMessage("You guild has been disbanded!");
|
||||
dispatch = Dispatch.borrow(player, leaveGuildMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.DismissGuildMsg;
|
||||
import engine.net.client.msg.guild.SendGuildEntryMsg;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.session.Session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DismissGuildHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public DismissGuildHandler() {
|
||||
super(DismissGuildMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
DismissGuildMsg dismissMsg;
|
||||
PlayerCharacter player;
|
||||
Guild toDismiss;
|
||||
Guild nation;
|
||||
Dispatch dispatch;
|
||||
|
||||
dismissMsg = (DismissGuildMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
toDismiss = (Guild) DbManager.getObject(GameObjectType.Guild, dismissMsg.getGuildID());
|
||||
|
||||
if (toDismiss == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
nation = player.getGuild();
|
||||
|
||||
if (nation == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Nothing to disband, your guild is not a nation!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!nation.getSubGuildList().contains(toDismiss)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You do not have authority to dismiss this guild!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Only a guild leader can dismiss a subguild!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Restriction on active bane desubbing
|
||||
|
||||
if (Bane.getBaneByAttackerGuild(toDismiss) != null)
|
||||
{
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You may not dismiss subguild with active bane!");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (toDismiss.getGuildState()) {
|
||||
case Sworn:
|
||||
|
||||
if (!DbManager.GuildQueries.UPDATE_PARENT(toDismiss.getObjectUUID(), MBServerStatics.worldUUID)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
nation.getSubGuildList().remove(toDismiss);
|
||||
toDismiss.downgradeGuildState();
|
||||
toDismiss.setNation(null);
|
||||
GuildManager.updateAllGuildBinds(toDismiss, null);
|
||||
|
||||
break;
|
||||
case Province:
|
||||
if (!DbManager.GuildQueries.UPDATE_PARENT(toDismiss.getObjectUUID(),MBServerStatics.worldUUID)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
nation.getSubGuildList().remove(toDismiss);
|
||||
toDismiss.downgradeGuildState();
|
||||
toDismiss.setNation(toDismiss);
|
||||
|
||||
break;
|
||||
case Petitioner:
|
||||
nation.getSubGuildList().remove(toDismiss);
|
||||
toDismiss.downgradeGuildState();
|
||||
break;
|
||||
case Protectorate:
|
||||
nation.getSubGuildList().remove(toDismiss);
|
||||
toDismiss.downgradeGuildState();
|
||||
break;
|
||||
}
|
||||
|
||||
GuildManager.updateAllGuildTags(toDismiss);
|
||||
|
||||
if (nation.getSubGuildList().isEmpty())
|
||||
nation.downgradeGuildState();
|
||||
|
||||
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
final Session s = SessionManager.getSession(player);
|
||||
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
|
||||
|
||||
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : guildMembers) {
|
||||
ChatManager.chatGuildInfo(member, toDismiss.getName() + " has been dismissed as a subguild!");
|
||||
}
|
||||
|
||||
ArrayList<PlayerCharacter> dismissedMembers = SessionManager.getActivePCsInGuildID(toDismiss.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : dismissedMembers) {
|
||||
ChatManager.chatGuildInfo(member, nation.getName() + "has dismissed you as a sub!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DoorState;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.DoorTryOpenMsg;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import engine.objects.Blueprint;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handle
|
||||
* open and close door requests to and from the client.
|
||||
*
|
||||
*/
|
||||
public class DoorTryOpenMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public DoorTryOpenMsgHandler() {
|
||||
super(DoorTryOpenMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
DoorTryOpenMsg msg;
|
||||
Building targetBuilding;
|
||||
int doorNumber;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (DoorTryOpenMsg)baseMsg;
|
||||
player = origin.getPlayerCharacter();
|
||||
targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingUUID());
|
||||
|
||||
if (player == null || targetBuilding == null) {
|
||||
Logger.error("Player or Building returned NULL in OpenCloseDoor handling.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Must be within x distance from door to manipulate it
|
||||
|
||||
if (player.getLoc().distanceSquared2D(targetBuilding.getLoc()) > MBServerStatics.OPENCLOSEDOORDISTANCE * MBServerStatics.OPENCLOSEDOORDISTANCE)
|
||||
return true;
|
||||
|
||||
doorNumber = Blueprint.getDoorNumberbyMesh(msg.getDoorID());
|
||||
|
||||
if ((targetBuilding.isDoorLocked(doorNumber) == true) && msg.getToggle() == 0x01) {
|
||||
msg.setUnk1(2);
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
return true; //don't open a locked door
|
||||
}
|
||||
|
||||
if (msg.getToggle() == 0x01) {
|
||||
targetBuilding.setDoorState(doorNumber, DoorState.OPEN);
|
||||
targetBuilding.submitOpenDoorJob(msg.getDoorID());
|
||||
} else {
|
||||
targetBuilding.setDoorState(doorNumber, DoorState.CLOSED);
|
||||
}
|
||||
|
||||
HashSet<AbstractWorldObject> container = WorldGrid.getObjectsInRangePartial(targetBuilding, MBServerStatics.CHARACTER_LOAD_RANGE,
|
||||
MBServerStatics.MASK_PLAYER);
|
||||
|
||||
for (AbstractWorldObject awo : container) {
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter)awo;
|
||||
Dispatch dispatch = Dispatch.borrow(playerCharacter, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.FormationFollowMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class FormationFollowHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public FormationFollowHandler() {
|
||||
super(FormationFollowMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin)
|
||||
throws MsgSendException {
|
||||
FormationFollowMsg msg = (FormationFollowMsg) baseMsg;
|
||||
|
||||
PlayerCharacter source = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
Group group = GroupManager.getGroup(source);
|
||||
|
||||
if (group == null)
|
||||
return false;
|
||||
|
||||
if (msg.isFollow()) {// Toggle follow
|
||||
source.toggleFollow();
|
||||
if (group.getGroupLead() == source) {
|
||||
if (source.getFollow()) {
|
||||
ChatManager.chatGroupInfo(source, "falls into formation");
|
||||
} else {
|
||||
ChatManager.chatGroupInfo(source, "breaks formation");
|
||||
}
|
||||
} else {
|
||||
if (source.getFollow()) {
|
||||
ChatManager.chatGroupInfo(source, source.getFirstName() + " falls into formation");
|
||||
} else {
|
||||
ChatManager.chatGroupInfo(source, source.getFirstName() + " breaks formation");
|
||||
}
|
||||
}
|
||||
GroupUpdateMsg gum = new GroupUpdateMsg();
|
||||
gum.setGroup(group);
|
||||
gum.setPlayer(source);
|
||||
gum.setMessageType(8);
|
||||
|
||||
group.sendUpdate(gum);
|
||||
} else {// Set Formation
|
||||
if (group.getGroupLead() != source) {
|
||||
return false;
|
||||
}
|
||||
group.setFormation(msg.getFormation());
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.AcceptFriendMsg;
|
||||
import engine.net.client.msg.AddFriendMessage;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.PlayerFriends;
|
||||
|
||||
public class FriendAcceptHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public FriendAcceptHandler() {
|
||||
super(AcceptFriendMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
AcceptFriendMsg msg = (AcceptFriendMsg)baseMsg;
|
||||
|
||||
|
||||
HandleAcceptFriend(player,msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//change to Request
|
||||
public static void HandleAcceptFriend(PlayerCharacter player, AcceptFriendMsg msg){
|
||||
PlayerCharacter sourceFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.sourceName);
|
||||
|
||||
if (sourceFriend == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.sourceName);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerFriends.AddToFriends(sourceFriend.getObjectUUID(), player.getObjectUUID());
|
||||
PlayerFriends.AddToFriends(player.getObjectUUID(), sourceFriend.getObjectUUID());
|
||||
|
||||
|
||||
AddFriendMessage outMsg = new AddFriendMessage(player);
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(sourceFriend, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
outMsg = new AddFriendMessage(sourceFriend);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
ChatManager.chatSystemInfo(sourceFriend, player.getFirstName() + " has agreed to be your friend.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.DeclineFriendMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class FriendDeclineHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public FriendDeclineHandler() {
|
||||
super(DeclineFriendMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
DeclineFriendMsg msg = (DeclineFriendMsg)baseMsg;
|
||||
|
||||
|
||||
HandleDeclineFriend(player,msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//change to Request
|
||||
public static void HandleDeclineFriend(PlayerCharacter player, DeclineFriendMsg msg){
|
||||
PlayerCharacter sourceFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.sourceName);
|
||||
|
||||
if (sourceFriend == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.sourceName);
|
||||
return;
|
||||
}
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(sourceFriend, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.FriendRequestMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class FriendRequestHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public FriendRequestHandler() {
|
||||
super(FriendRequestMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
FriendRequestMsg msg = (FriendRequestMsg)baseMsg;
|
||||
|
||||
HandleRequestFriend(player,msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void HandleRequestFriend(PlayerCharacter player, FriendRequestMsg msg){
|
||||
PlayerCharacter targetFriend = SessionManager.getPlayerCharacterByLowerCaseName(msg.friendName);
|
||||
|
||||
if (targetFriend == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Could not find player " + msg.friendName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetFriend.equals(player))
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(targetFriend, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
ChatManager.chatSystemInfo(player, "Your friend request has been sent.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.FurnitureMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class FurnitureHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public FurnitureHandler() {
|
||||
super(FurnitureMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
FurnitureMsg msg = (FurnitureMsg) baseMsg;
|
||||
|
||||
PlayerCharacter pc = origin.getPlayerCharacter();
|
||||
if (pc == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (msg.getType() == 1)
|
||||
msg.setType(2);
|
||||
|
||||
if (msg.getType() == 3)
|
||||
msg.setType(2);
|
||||
Dispatch dispatch = Dispatch.borrow(pc, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.GroupInviteMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class GroupInviteHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GroupInviteHandler() {
|
||||
super(GroupInviteMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
GroupInviteMsg msg = (GroupInviteMsg) baseMsg;
|
||||
PlayerCharacter source = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
Group group = GroupManager.getGroup(source);
|
||||
|
||||
// Group is new, create it.
|
||||
|
||||
if (group == null)
|
||||
group = GroupInviteHandler.createGroup(source, origin);
|
||||
|
||||
if (group == null)
|
||||
return false;
|
||||
|
||||
if (!group.isGroupLead(source)) // person doing invite must be group lead
|
||||
return true;
|
||||
|
||||
PlayerCharacter target = null;
|
||||
|
||||
if (msg.getInvited() == 1) { // Use name for invite
|
||||
target = SessionManager.getPlayerCharacterByLowerCaseName(msg.getName().toLowerCase());
|
||||
} else { // Use ID for invite
|
||||
target = SessionManager.getPlayerCharacterByID(msg.getTargetID());
|
||||
}
|
||||
|
||||
if (target == null)
|
||||
return false;
|
||||
|
||||
// Client must be online
|
||||
|
||||
if (SessionManager.getClientConnection(target) == null)
|
||||
return false;
|
||||
|
||||
if (source == target) // Inviting self, so we're done
|
||||
return false;
|
||||
|
||||
|
||||
//Skip invite if target is ignoring source
|
||||
|
||||
if (target.isIgnoringPlayer(source))
|
||||
return false;
|
||||
|
||||
|
||||
// dont block invites to people already in a group and
|
||||
// dont check for pending invites, the client does it
|
||||
// Send invite message to target
|
||||
|
||||
msg.setSourceType(GameObjectType.PlayerCharacter.ordinal());
|
||||
msg.setSourceID(source.getObjectUUID());
|
||||
msg.setTargetType(0);
|
||||
msg.setTargetID(0);
|
||||
msg.setGroupType(GameObjectType.Group.ordinal());
|
||||
msg.setGroupID(group.getObjectUUID());
|
||||
msg.setInvited(1);
|
||||
msg.setName(source.getFirstName());
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(target, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// this can only be called if you already know you are not in a group
|
||||
// and have issued an invite
|
||||
|
||||
private static Group createGroup(PlayerCharacter pc, ClientConnection origin) {
|
||||
|
||||
if (pc == null)
|
||||
return null;
|
||||
|
||||
Group group = new Group(pc, GroupManager.incrGroupCount());
|
||||
group.addGroupMember(pc);
|
||||
GroupManager.addNewGroup(group);
|
||||
|
||||
pc.setFollow(false);
|
||||
// Send add self to group message
|
||||
GroupUpdateMsg msg = new GroupUpdateMsg();
|
||||
msg.setGroup(group);
|
||||
msg.setPlayer(pc);
|
||||
msg.setMessageType(1);
|
||||
Dispatch dispatch = Dispatch.borrow(pc, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
group.addUpdateGroupJob();
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.GroupInviteResponseMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static engine.net.client.handlers.KeyCloneAudit.KEYCLONEAUDIT;
|
||||
|
||||
public class GroupInviteResponseHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GroupInviteResponseHandler() {
|
||||
super(GroupInviteResponseMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
GroupInviteResponseMsg msg = (GroupInviteResponseMsg) baseMsg;
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return false;
|
||||
|
||||
// if we are already in a group we are leaving it
|
||||
|
||||
Group currGroup = GroupManager.getGroup(player);
|
||||
|
||||
if (currGroup != null) // if we are already in a group we are leaving it
|
||||
GroupManager.LeaveGroup(player);
|
||||
|
||||
// not sure we need to test for invites to wrong grp as only
|
||||
// 1 invite can be on screen at a time
|
||||
//if (invitesPending.get(player) != msg.getGroupID()) // Can't accept
|
||||
// invite to
|
||||
// wrong group
|
||||
// return;
|
||||
|
||||
Group group = GroupManager.getGroup(msg.getGroupID());
|
||||
|
||||
if (group == null)
|
||||
return false;
|
||||
|
||||
if (group.addGroupMember(player) == false)
|
||||
return false;
|
||||
{
|
||||
player.setFollow(true);
|
||||
GroupManager.addPlayerGroupMapping(player, group);
|
||||
Set<PlayerCharacter> members = group.getMembers();
|
||||
GroupUpdateMsg groupUpdateMsg;
|
||||
|
||||
// Send all group members to player added
|
||||
for (PlayerCharacter groupMember : members) {
|
||||
|
||||
groupUpdateMsg = new GroupUpdateMsg();
|
||||
groupUpdateMsg.setGroup(group);
|
||||
groupUpdateMsg.setMessageType(1);
|
||||
|
||||
if (groupMember == null)
|
||||
continue;
|
||||
|
||||
if (groupMember.equals(player))
|
||||
continue;
|
||||
|
||||
groupUpdateMsg.setPlayer(groupMember);
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, groupUpdateMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
|
||||
// send new group member to everyone in group.
|
||||
groupUpdateMsg = new GroupUpdateMsg();
|
||||
groupUpdateMsg.setGroup(group);
|
||||
groupUpdateMsg.setMessageType(1);
|
||||
groupUpdateMsg.setPlayer(player);
|
||||
group.sendUpdate(groupUpdateMsg);
|
||||
|
||||
String text = player.getFirstName() + " has joined the group.";
|
||||
ChatManager.chatGroupInfo(player, text);
|
||||
|
||||
// Run Keyclone Audit
|
||||
|
||||
KEYCLONEAUDIT.audit(player, group);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
|
||||
public class GroupUpdateHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GroupUpdateHandler() {
|
||||
super(GroupUpdateMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
//GroupUpdateMsg msg = (GroupUpdateMsg) baseMsg;
|
||||
// not sure what to do with these as we spend our time sending them
|
||||
// to the whole group ourselves
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.GuildControlMsg;
|
||||
import engine.net.client.msg.guild.GuildListMsg;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class GuildControlHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GuildControlHandler() {
|
||||
super(GuildControlMsg.class);
|
||||
}
|
||||
|
||||
// TODO Don't think this protocolMsg (0x3235E5EA) is actually player history. so
|
||||
// take further look at it.
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
GuildControlMsg msg = (GuildControlMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
// until we know what it's for, just echo it back.
|
||||
msg.setUnknown05((byte) 1);
|
||||
|
||||
//Send a GuildList msg
|
||||
if(msg.getUnknown01() == 1) {
|
||||
|
||||
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
|
||||
//TODO figure out why GL can't be changed and IC can't be banished
|
||||
//Bounce back the rank options
|
||||
msg.setGM((byte) (GuildStatusController.isGuildLeader(player.getGuildStatus()) ? 1 : 0));
|
||||
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
if (GuildStatusController.isInnerCouncil(player.getGuildStatus()) || GuildStatusController.isGuildLeader(player.getGuildStatus())) {
|
||||
dispatch = Dispatch.borrow(player, new GuildListMsg(player.getGuild()));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
} else
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Only guild leader and inner council have such authority!");
|
||||
|
||||
|
||||
} else if(msg.getUnknown01() == 2) {
|
||||
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
//If we don't get a valid PC for whatever reason.. just ignore it.
|
||||
PlayerCharacter pc = PlayerCharacter.getFromCache(msg.getUnknown03());
|
||||
|
||||
if(pc != null) {
|
||||
dispatch = Dispatch.borrow(player,new GuildListMsg(pc));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.GuildCreationCloseMsg;
|
||||
|
||||
public class GuildCreationCloseHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GuildCreationCloseHandler() {
|
||||
super(GuildCreationCloseMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
// GuildCreationCloseMsg msg = (GuildCreationCloseMsg) baseMsg;
|
||||
// origin.sendMsg(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.Enum.ItemType;
|
||||
import engine.Enum.OwnerType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.GuildCreationFinalizeMsg;
|
||||
import engine.net.client.msg.guild.GuildInfoMsg;
|
||||
import engine.objects.*;
|
||||
import engine.util.StringUtils;
|
||||
|
||||
public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GuildCreationFinalizeHandler() {
|
||||
super(GuildCreationFinalizeMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player;
|
||||
GuildCreationFinalizeMsg msg;
|
||||
Enum.GuildType charterType;
|
||||
Guild newGuild;
|
||||
ItemBase itemBase;
|
||||
Item charter;
|
||||
Dispatch dispatch;
|
||||
|
||||
msg = (GuildCreationFinalizeMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
boolean isGuildLeader = GuildStatusController.isGuildLeader(player.getGuildStatus());
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) || player.getGuild() != null && player.getGuild().getGuildLeaderUUID() == player.getObjectUUID()) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.MUST_LEAVE_GUILD);
|
||||
return true;
|
||||
}
|
||||
|
||||
//Validate the Charter
|
||||
|
||||
charter = msg.getCharter();
|
||||
|
||||
if (charter == null || charter.getOwnerType() != OwnerType.PlayerCharacter || charter.getOwnerID() != player.getObjectUUID()) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
itemBase = charter.getItemBase();
|
||||
|
||||
|
||||
// Item must be a valid charterType (type 10 in db)
|
||||
|
||||
if (itemBase == null || (itemBase.getType().equals(ItemType.GUILDCHARTER) == false)) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND);
|
||||
return true;
|
||||
}
|
||||
charterType = Enum.GuildType.getGuildTypeFromCharter(itemBase);
|
||||
|
||||
|
||||
|
||||
if (charterType == null){
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.NO_CHARTER_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Validate Guild Tags
|
||||
|
||||
if (!msg.getGuildTag().isValid()) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.CREST_RESERVED);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Validation passes. Leave current guild and create new one.
|
||||
|
||||
if (player.getGuild() != null && player.getGuild().getObjectUUID() != 0)
|
||||
player.getGuild().removePlayer(player,GuildHistoryType.LEAVE);
|
||||
|
||||
|
||||
|
||||
int leadershipType = ((msg.getICVoteFlag() << 1) | msg.getMemberVoteFlag());
|
||||
|
||||
newGuild = new Guild( msg.getName(),null, charterType.ordinal(),
|
||||
charterType.getLeadershipType(leadershipType), msg.getGuildTag(),
|
||||
StringUtils.truncate(msg.getMotto(), 120));
|
||||
|
||||
newGuild.setGuildLeaderForCreate(player);
|
||||
|
||||
synchronized (this) {
|
||||
if (!DbManager.GuildQueries.IS_NAME_UNIQUE(msg.getName())) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.UNIQUE_NAME);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!DbManager.GuildQueries.IS_CREST_UNIQUE(msg.getGuildTag())) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.UNIQUE_CREST);
|
||||
return true;
|
||||
}
|
||||
|
||||
newGuild = DbManager.GuildQueries.SAVE_TO_DATABASE(newGuild);
|
||||
}
|
||||
|
||||
if (newGuild == null) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, GuildManager.FAILURE_TO_SWEAR_GUILD);
|
||||
return true;
|
||||
}
|
||||
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
GuildManager.joinGuild(player, newGuild, GuildHistoryType.CREATE);
|
||||
|
||||
newGuild.setGuildLeader(player);
|
||||
player.setGuildLeader(true);
|
||||
player.setInnerCouncil(true);
|
||||
player.setFullMember(true);
|
||||
player.setGuildTitle(charterType.getNumberOfRanks() - 1);
|
||||
player.getCharItemManager().delete(charter);
|
||||
player.getCharItemManager().updateInventory();
|
||||
player.incVer();
|
||||
|
||||
DispatchMessage.sendToAllInRange(player, new GuildInfoMsg(player, newGuild, 2));
|
||||
|
||||
ChatManager.chatSystemInfo(player, msg.getName() + " has arrived on Grief server!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.GuildCreationOptionsMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class GuildCreationOptionsHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GuildCreationOptionsHandler() {
|
||||
super(GuildCreationOptionsMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
GuildCreationOptionsMsg msg = (GuildCreationOptionsMsg) baseMsg;
|
||||
PlayerCharacter sourcePlayer = origin.getPlayerCharacter();
|
||||
Dispatch dispatch;
|
||||
|
||||
if(msg.getScreenType() == 1) {
|
||||
msg.setScreenType(3);
|
||||
} else if(msg.getScreenType() == 2) {
|
||||
msg.setScreenType(4);
|
||||
}
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return true;
|
||||
|
||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.GuildInfoMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class GuildInfoHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GuildInfoHandler() {
|
||||
super(GuildInfoMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
GuildInfoMsg msg = (GuildInfoMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
// get source player
|
||||
PlayerCharacter sourcePlayer = SessionManager
|
||||
.getPlayerCharacter(origin);
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return true;
|
||||
|
||||
if(msg.getMsgType() == 1) {
|
||||
dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 4));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
} else if(msg.getMsgType() == 5) {
|
||||
|
||||
if(msg.getObjectType() == GameObjectType.PlayerCharacter.ordinal()) {
|
||||
PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(msg.getObjectID());
|
||||
dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(pc, pc.getGuild(), 5));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
} else {
|
||||
//TODO Change this to a null object when we make a null object.
|
||||
|
||||
dispatch = Dispatch.borrow(sourcePlayer,new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 1));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
}
|
||||
|
||||
// Send PromoteDemoteScreen info message response. 0x001D4DF6
|
||||
|
||||
// Send guild member list? 0x6949C720
|
||||
// GuildList(source, origin);
|
||||
|
||||
// send 0x3235E5EA? See what that is
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.GuildListMsg;
|
||||
|
||||
public class GuildListHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GuildListHandler() {
|
||||
super(GuildListMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
// GuildListMsg msg = (GuildListMsg) baseMsg;
|
||||
|
||||
// GuildListMsg msg = new GuildListMsg(origin);
|
||||
// GuildTableList gtl = new GuildTableList();
|
||||
// gtl.setUUID(pc.getUUID()); gtl.setName(pc.getName());
|
||||
// msg.add(gtl);
|
||||
// origin.sendMsg(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.GuildUnknownMsg;
|
||||
|
||||
public class GuildUnknownHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public GuildUnknownHandler() {
|
||||
super(GuildUnknownMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
// GuildUnknownMsg msg = (GuildUnknownMsg) baseMsg;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.HirelingServiceMsg;
|
||||
import engine.net.client.msg.ManageNPCMsg;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.NPC;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class HirelingServiceMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public HirelingServiceMsgHandler() {
|
||||
super(HirelingServiceMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player;
|
||||
HirelingServiceMsg msg;
|
||||
|
||||
msg = (HirelingServiceMsg) baseMsg;
|
||||
|
||||
// get PlayerCharacter of person accepting invite
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
switch (msg.messageType){
|
||||
case HirelingServiceMsg.SETREPAIRCOST:
|
||||
Building building = BuildingManager.getBuildingFromCache(msg.buildingID);
|
||||
|
||||
if (building == null)
|
||||
return true;
|
||||
|
||||
NPC npc = NPC.getFromCache(msg.npcID);
|
||||
|
||||
if (npc == null)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.playerCanManage(player, building))
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
npc.setRepairCost(msg.repairCost);
|
||||
ManageNPCMsg outMsg = new ManageNPCMsg(npc);
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.InviteToGuildMsg;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class InviteToGuildHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public InviteToGuildHandler() {
|
||||
super(InviteToGuildMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
InviteToGuildMsg msg;
|
||||
PlayerCharacter sourcePlayer;
|
||||
PlayerCharacter targetPlayer;
|
||||
Dispatch dispatch;
|
||||
|
||||
msg = (InviteToGuildMsg) baseMsg;
|
||||
|
||||
// First see if this is a refusal to another guild invite
|
||||
|
||||
if (msg.getResponse() == 4)
|
||||
return true; // Player refused invite
|
||||
|
||||
// get sourcePlayer player
|
||||
|
||||
sourcePlayer = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return true;
|
||||
|
||||
if (msg.getTargetUUID() == 0) {
|
||||
// get targetPlayer player by name
|
||||
targetPlayer = SessionManager.getPlayerCharacterByLowerCaseName(msg.getTargetName());
|
||||
|
||||
if (targetPlayer == null) {
|
||||
ChatManager.chatGuildError(sourcePlayer,
|
||||
"No such player exists!");
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
if (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal()) {
|
||||
|
||||
targetPlayer = SessionManager.getPlayerCharacterByID(msg.getTargetUUID());
|
||||
|
||||
if (targetPlayer == null) {
|
||||
ChatManager.chatGuildError(sourcePlayer,
|
||||
"No such player exists!");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
ChatManager.chatGuildError(sourcePlayer,
|
||||
"You cannot invite that character!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// get sourcePlayer guild. Verify sourcePlayer player is in guild
|
||||
|
||||
if (sourcePlayer.getGuild().getObjectUUID() == 0 || sourcePlayer.getGuild().isErrant()) {
|
||||
ChatManager.chatGuildError(sourcePlayer,
|
||||
"You cannot invite someone for errant!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Enum.GuildType guildType = Enum.GuildType.values()[sourcePlayer.getGuild().getCharter()];
|
||||
|
||||
if (guildType == null){
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, GuildManager.NO_CHARTER_FOUND);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// verify sourcePlayer player is full member so they can invite
|
||||
|
||||
if (GuildStatusController.isFullMember(sourcePlayer.getGuildStatus()) == false) {
|
||||
ChatManager.chatGuildError(sourcePlayer,
|
||||
"You do not have authority to invite!");
|
||||
return true;
|
||||
}
|
||||
|
||||
//block invite is targetPlayer is ignoring sourcePlayer
|
||||
|
||||
if (targetPlayer.isIgnoringPlayer(sourcePlayer))
|
||||
return true;
|
||||
|
||||
if ((targetPlayer.getGuild().isErrant() == false)) {
|
||||
ChatManager.chatGuildError(sourcePlayer,
|
||||
targetPlayer.getFirstName() + " already belongs to a guild!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// verify targetPlayer player is not on banish list
|
||||
|
||||
if (sourcePlayer.getGuild().getBanishList().contains(targetPlayer)) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 135);// Character is considered BANISHED by guild leadership
|
||||
return true;
|
||||
}
|
||||
|
||||
//verify targetPlayer meets level requirements of guild
|
||||
|
||||
if ((targetPlayer.getLevel() < sourcePlayer.getGuild().getRepledgeMin()) || targetPlayer.getLevel() > sourcePlayer.getGuild().getRepledgeMax()) {
|
||||
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 135);// you do not meet the level required for this SWORN guild
|
||||
return true;
|
||||
}
|
||||
|
||||
targetPlayer.setLastGuildToInvite(sourcePlayer.getGuild().getObjectUUID());
|
||||
|
||||
// setup guild invite message to send to targetPlayer
|
||||
|
||||
msg.setSourceType(sourcePlayer.getObjectType().ordinal());
|
||||
msg.setSourceUUID(sourcePlayer.getObjectUUID());
|
||||
msg.setTargetType(targetPlayer.getObjectType().ordinal());
|
||||
|
||||
msg.setTargetUUID(targetPlayer.getObjectUUID());
|
||||
msg.setGuildTag(sourcePlayer.getGuild().getGuildTag());
|
||||
msg.setGuildName(sourcePlayer.getGuild().getName());
|
||||
msg.setGuildType(sourcePlayer.getGuild().getObjectType().ordinal());
|
||||
msg.setGuildUUID(sourcePlayer.getGuild().getObjectUUID());
|
||||
msg.setTargetName("");
|
||||
|
||||
dispatch = Dispatch.borrow(targetPlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.InviteToSubMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class InviteToSubHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public InviteToSubHandler() {
|
||||
super(InviteToSubMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter source;
|
||||
PlayerCharacter target;
|
||||
Guild sourceGuild;
|
||||
Guild targetGuild;
|
||||
InviteToSubMsg msg = (InviteToSubMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
source = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (source == null)
|
||||
return true;
|
||||
|
||||
target = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, msg.getTargetUUID());
|
||||
|
||||
if (target == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(source, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Ignore invites to sub if ignoring player
|
||||
|
||||
if (target.isIgnoringPlayer(source))
|
||||
return true;
|
||||
|
||||
sourceGuild = source.getGuild();
|
||||
targetGuild = target.getGuild();
|
||||
|
||||
//source must be in guild
|
||||
|
||||
if (sourceGuild == null) {
|
||||
sendChat(source, "You must be in a guild to invite to sub.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sourceGuild.isErrant()){
|
||||
sendChat(source, "You must be in a guild to invite to sub.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//source must be GL or IC
|
||||
|
||||
if (GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) {
|
||||
sendChat(source, "Only guild leadership can invite to sub.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sourceGuild.getNation().isErrant())
|
||||
return true;
|
||||
|
||||
//target must be in a guild
|
||||
|
||||
if (targetGuild == null)
|
||||
return true;
|
||||
|
||||
if (sourceGuild.equals(targetGuild))
|
||||
return true;
|
||||
|
||||
//target must be GL or IC
|
||||
|
||||
if (GuildStatusController.isInnerCouncil(target.getGuildStatus()) == false && GuildStatusController.isGuildLeader(target.getGuildStatus()) == false) {
|
||||
sendChat(source, "Target player is not guild leadership.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//Can't already be same nation or errant
|
||||
//source guild is limited to 7 subs
|
||||
//TODO this should be based on TOL rank
|
||||
|
||||
|
||||
if (!sourceGuild.canSubAGuild(targetGuild)) {
|
||||
sendChat(source, "This Guild can't be subbed.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//all tests passed, let's send invite.
|
||||
|
||||
if (target.getClientConnection() != null) {
|
||||
msg.setGuildTag(sourceGuild.getGuildTag());
|
||||
msg.setGuildName(sourceGuild.getName());
|
||||
msg.setGuildUUID(sourceGuild.getObjectUUID());
|
||||
msg.setUnknown02(1);
|
||||
|
||||
dispatch = Dispatch.borrow(target, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
} else {
|
||||
sendChat(source, "Failed to send sub invite to target.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void sendChat(PlayerCharacter source, String msg) {
|
||||
ChatManager.chatGuildError(source, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,521 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.ItemType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.ItemProductionMsg;
|
||||
import engine.net.client.msg.ManageNPCMsg;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/*
|
||||
* @Summary: Processes application protocol message which modifies
|
||||
* hireling inventory through rolling, junking or depositing.
|
||||
*/
|
||||
public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
private static final int ACTION_PRODUCE = 1;
|
||||
private static final int ACTION_JUNK = 2;
|
||||
private static final int ACTION_RECYCLE = 3;
|
||||
private static final int ACTION_COMPLETE = 4;
|
||||
private static final int ACTION_DEPOSIT = 6;
|
||||
private static final int ACTION_SETPRICE = 5;
|
||||
private static final int ACTION_TAKE = 7;
|
||||
private static final int ACTION_CONFIRM_SETPRICE = 9; // Unsure. Sent by client
|
||||
private static final int ACTION_CONFIRM_DEPOSIT = 10; // Unsure. Sent by client
|
||||
private static final int ACTION_CONFIRM_TAKE = 11; // Unsure. Sent by client
|
||||
|
||||
public ItemProductionMsgHandler() {
|
||||
super(ItemProductionMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
NPC vendorNPC;
|
||||
ItemProductionMsg msg;
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (ItemProductionMsg) baseMsg;
|
||||
player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
// Grab reference to vendor we are interacting with
|
||||
|
||||
vendorNPC = (NPC) DbManager.getObject(engine.Enum.GameObjectType.NPC, msg.getNpcUUID());
|
||||
|
||||
// Oops?
|
||||
|
||||
if (vendorNPC == null)
|
||||
return true;
|
||||
|
||||
// Process Request
|
||||
|
||||
switch (msg.getActionType()) {
|
||||
|
||||
case ACTION_PRODUCE:
|
||||
boolean isRandom = false;
|
||||
if (msg.getUnknown03() != 0 && msg.getpToken() == 0 && msg.getsToken() == 0)
|
||||
isRandom = true;
|
||||
//Create Multiple Item Function.. Fill all empty slots
|
||||
if (msg.isMultiple()){
|
||||
int emptySlots = vendorNPC.getRank() - vendorNPC.getRolling().size();
|
||||
if (emptySlots > 0){
|
||||
for (int i = 0;i<emptySlots;i++){
|
||||
vendorNPC.produceItem(player.getObjectUUID(),msg.getTotalProduction(),isRandom,msg.getpToken(),msg.getsToken(),msg.getName(),msg.getItemUUID());
|
||||
}
|
||||
}
|
||||
}else
|
||||
vendorNPC.produceItem(player.getObjectUUID(),msg.getTotalProduction(),isRandom,msg.getpToken(),msg.getsToken(),msg.getName(),msg.getItemUUID());
|
||||
break;
|
||||
case ACTION_JUNK:
|
||||
junkItem(msg.getItemUUID(), vendorNPC, origin);
|
||||
break;
|
||||
case ACTION_RECYCLE:
|
||||
recycleItem(msg.getItemIDtoTypeMap(), vendorNPC, origin);
|
||||
msg.setActionType(7);
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case ACTION_COMPLETE:
|
||||
|
||||
vendorNPC.completeItem(msg.getItemUUID());
|
||||
|
||||
// ManageNPCMsg outMsg = new ManageNPCMsg(vendorNPC);
|
||||
// outMsg.setMessageType(1);
|
||||
//
|
||||
// dispatch = Dispatch.borrow(player, outMsg);
|
||||
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
break;
|
||||
case ACTION_DEPOSIT:
|
||||
depositItem(msg.getItemUUID(), vendorNPC, origin);
|
||||
break;
|
||||
case ACTION_SETPRICE:
|
||||
setItemPrice(msg.getItemType(),msg.getItemUUID(), msg.getItemPrice(), vendorNPC, origin);
|
||||
break;
|
||||
case ACTION_TAKE:
|
||||
takeItem(msg.getItemIDtoTypeMap(), vendorNPC, origin);
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Method sets the price on an item in the vendor inventory
|
||||
|
||||
private static void setItemPrice(int itemType, int itemUUID, int itemPrice, NPC vendor, ClientConnection origin) {
|
||||
|
||||
Item targetItem;
|
||||
ItemProductionMsg outMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (itemType == GameObjectType.Item.ordinal())
|
||||
targetItem = Item.getFromCache(itemUUID);
|
||||
else if (itemType == GameObjectType.MobLoot.ordinal())
|
||||
targetItem = MobLoot.getFromCache(itemUUID);
|
||||
else
|
||||
targetItem = null;
|
||||
|
||||
|
||||
if (targetItem == null)
|
||||
return;
|
||||
|
||||
if (targetItem.getObjectType() == GameObjectType.Item){
|
||||
if (!DbManager.ItemQueries.UPDATE_VALUE(targetItem, itemPrice)) {
|
||||
ChatManager.chatInfoError(origin.getPlayerCharacter(), "Failed to set price! Contact CCR For help.");
|
||||
return;
|
||||
}
|
||||
targetItem.setValue(itemPrice);
|
||||
outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_SETPRICE, true);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}else if (targetItem.getObjectType() == GameObjectType.MobLoot){
|
||||
MobLoot mobLoot = (MobLoot)targetItem;
|
||||
if (!DbManager.NPCQueries.UPDATE_ITEM_PRICE(mobLoot.getObjectUUID(), vendor.getObjectUUID(), itemPrice)) {
|
||||
ChatManager.chatInfoError(origin.getPlayerCharacter(), "Failed to set price! Contact CCR For help.");
|
||||
return;
|
||||
}
|
||||
targetItem.setValue(itemPrice);
|
||||
outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_SETPRICE, true);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
// Set item's price
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Method adds an item from the players inventory to the vendor.
|
||||
|
||||
private static void depositItem(int itemUUID, NPC vendor, ClientConnection origin) {
|
||||
|
||||
Item targetItem;
|
||||
ItemProductionMsg outMsg;
|
||||
CharacterItemManager itemMan;
|
||||
Dispatch dispatch;
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (origin.sellLock.tryLock()) {
|
||||
try {
|
||||
targetItem = Item.getFromCache(itemUUID);
|
||||
|
||||
if (targetItem == null)
|
||||
return;
|
||||
|
||||
if (targetItem.getItemBase().getType() == ItemType.GOLD)
|
||||
return;
|
||||
|
||||
if (!vendor.getCharItemManager().hasRoomInventory(targetItem.getItemBase().getWeight())){
|
||||
|
||||
ErrorPopupMsg.sendErrorPopup(player, 21);
|
||||
return;
|
||||
}
|
||||
|
||||
itemMan = origin.getPlayerCharacter().getCharItemManager();
|
||||
|
||||
if (itemMan == null)
|
||||
return;
|
||||
|
||||
if (vendor.getCharItemManager().getInventoryWeight() > 500) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 21);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!targetItem.validForInventory(origin, player, itemMan)){
|
||||
ErrorPopupMsg.sendErrorPopup(player, 19);
|
||||
return;
|
||||
}
|
||||
|
||||
// Transfer item from player to vendor's inventory
|
||||
|
||||
if (!itemMan.sellToNPC(targetItem, vendor)){
|
||||
ErrorPopupMsg.sendErrorPopup(player, 109);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_DEPOSIT, true);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_CONFIRM_DEPOSIT, true);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
origin.getPlayerCharacter().getCharItemManager().updateInventory();
|
||||
}catch (Exception e){
|
||||
Logger.error(e);
|
||||
}finally {
|
||||
origin.sellLock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Method completes an item that has been previously rolled
|
||||
// adding it to the NPC's inventory
|
||||
|
||||
private static void completeItem(int itemUUID, NPC vendor, ClientConnection origin, ItemProductionMsg msg) {
|
||||
|
||||
Item targetItem;
|
||||
ManageNPCMsg outMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (origin.buyLock.tryLock()) {
|
||||
try {
|
||||
targetItem = Item.getFromCache(itemUUID);
|
||||
|
||||
if (targetItem == null)
|
||||
return;
|
||||
|
||||
|
||||
if (!vendor.getCharItemManager().forgeContains(targetItem, vendor))
|
||||
return;
|
||||
|
||||
boolean worked = DbManager.ItemQueries.UPDATE_FORGE_TO_INVENTORY(targetItem);
|
||||
if (!worked) {
|
||||
Guild guild = vendor.getGuild();
|
||||
if (guild == null)
|
||||
return;
|
||||
//ChatManager.chatGuildInfo(guild, "Failed to complete Item " + targetItem.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
targetItem.containerType = Enum.ItemContainerType.INVENTORY;
|
||||
targetItem.setOwner(vendor);
|
||||
vendor.getCharItemManager().addItemToInventory(targetItem);
|
||||
|
||||
vendor.removeItemFromForge(targetItem);
|
||||
|
||||
outMsg = new ManageNPCMsg(vendor);
|
||||
outMsg.setMessageType(ACTION_PRODUCE);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
} finally {
|
||||
origin.buyLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Method handles recycling of an item
|
||||
|
||||
private static void recycleItem(HashMap<Integer, Integer> itemList, NPC vendor, ClientConnection origin) {
|
||||
|
||||
Item targetItem;
|
||||
ItemProductionMsg outMsg;
|
||||
int totalValue = 0;
|
||||
int currentStrongbox;
|
||||
Dispatch dispatch;
|
||||
|
||||
if (vendor.getBuilding() == null)
|
||||
return;
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
if (itemList == null)
|
||||
return;
|
||||
|
||||
if (origin.sellLock.tryLock()) {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
for (int itemUUID : itemList.keySet()) {
|
||||
int itemValue = 0;
|
||||
|
||||
int type = itemList.get(itemUUID);
|
||||
|
||||
if (type == GameObjectType.Item.ordinal())
|
||||
targetItem = Item.getFromCache(itemUUID);
|
||||
else
|
||||
targetItem = MobLoot.getFromCache(itemUUID);
|
||||
|
||||
if (targetItem == null)
|
||||
continue;
|
||||
|
||||
if (targetItem.getItemBase().getType() == ItemType.GOLD)
|
||||
return;
|
||||
|
||||
if (!vendor.getCharItemManager().doesCharOwnThisItem(targetItem.getObjectUUID()))
|
||||
continue;
|
||||
if (vendor.getCharItemManager().inventoryContains(targetItem) == false)
|
||||
continue;
|
||||
|
||||
itemValue = targetItem.getBaseValue();
|
||||
|
||||
if (vendor.getBuilding().getStrongboxValue() + itemValue > vendor.getBuilding().getMaxGold()) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 201);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (targetItem.getItemBase().getType()) {
|
||||
case CONTRACT:
|
||||
case GUILDCHARTER:
|
||||
case DEED:
|
||||
case REALMCHARTER:
|
||||
case SCROLL:
|
||||
case TEARS:
|
||||
itemValue = 0;
|
||||
continue;
|
||||
}
|
||||
totalValue += itemValue;
|
||||
long start = System.currentTimeMillis();
|
||||
vendor.getCharItemManager().recycle(targetItem);
|
||||
long end = System.currentTimeMillis();
|
||||
long timetook = end - start;
|
||||
|
||||
// ChatManager.chatSystemInfo(player, "Took " + timetook + " ms to finish");
|
||||
|
||||
outMsg = new ItemProductionMsg(vendor.getBuilding(), vendor, targetItem, ACTION_TAKE, true);
|
||||
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
// Refund a portion of the gold
|
||||
|
||||
if (!vendor.getBuilding().transferGold(totalValue,false))
|
||||
return;
|
||||
|
||||
|
||||
|
||||
}catch (Exception e){
|
||||
Logger.error(e);
|
||||
}finally {
|
||||
|
||||
origin.sellLock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Refresh vendor's inventory to client
|
||||
|
||||
}
|
||||
|
||||
// Method junks an item that has been rolled but not completed
|
||||
|
||||
private static void junkItem(int itemUUID, NPC vendor, ClientConnection origin) {
|
||||
|
||||
MobLoot targetItem;
|
||||
ManageNPCMsg outMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
if (origin.sellLock.tryLock()) {
|
||||
try {
|
||||
targetItem = MobLoot.getFromCache(itemUUID);
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
// Can't junk nothing!
|
||||
|
||||
if (targetItem == null)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
if (!vendor.getCharItemManager().forgeContains(targetItem, vendor))
|
||||
return;
|
||||
|
||||
// Cannot junk items without a forge!
|
||||
|
||||
if (vendor.getBuilding() == null)
|
||||
return;
|
||||
|
||||
// Delete the item and cancel any pending rolling timer jobs
|
||||
|
||||
targetItem.recycle(vendor);
|
||||
vendor.removeItemFromForge(targetItem);
|
||||
|
||||
// Refresh vendor's inventory to client
|
||||
|
||||
outMsg = new ManageNPCMsg(vendor);
|
||||
outMsg.setMessageType(1);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
;
|
||||
} finally {
|
||||
origin.sellLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Method removes item from an NPC's inventory and transferes it to a player
|
||||
|
||||
private static void takeItem(HashMap<Integer, Integer> itemList, NPC vendor, ClientConnection origin) {
|
||||
|
||||
Item targetItem;
|
||||
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
for (int itemUUID : itemList.keySet()) {
|
||||
|
||||
int type = itemList.get(itemUUID);
|
||||
if (type == GameObjectType.Item.ordinal()){
|
||||
targetItem = Item.getFromCache(itemUUID);
|
||||
|
||||
}
|
||||
else{
|
||||
targetItem = MobLoot.getFromCache(itemUUID);
|
||||
|
||||
}
|
||||
|
||||
if (targetItem == null)
|
||||
return;
|
||||
|
||||
|
||||
if (targetItem.getItemBase().getType() == ItemType.GOLD)
|
||||
return;
|
||||
if (vendor.getCharItemManager().inventoryContains(targetItem) == false)
|
||||
return;
|
||||
|
||||
if (player.getCharItemManager().hasRoomInventory(targetItem.getItemBase().getWeight()) == false)
|
||||
return;
|
||||
|
||||
player.getCharItemManager().buyFromNPC(targetItem, vendor);
|
||||
|
||||
}
|
||||
|
||||
player.getCharItemManager().updateInventory();
|
||||
|
||||
// Update NPC inventory to client
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Method handles rolling item requests from the client
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.KeepAliveServerClientMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which keeps
|
||||
* client's tcp connection open.
|
||||
*/
|
||||
|
||||
public class KeepAliveServerClientHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public KeepAliveServerClientHandler() {
|
||||
super(KeepAliveServerClientMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter pc = origin.getPlayerCharacter();
|
||||
|
||||
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
KeepAliveServerClientMsg msg;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (KeepAliveServerClientMsg) baseMsg;
|
||||
|
||||
|
||||
// Send ping to client
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(pc, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public enum KeyCloneAudit {
|
||||
KEYCLONEAUDIT;
|
||||
|
||||
void audit(PlayerCharacter player, Group group) {
|
||||
|
||||
int machineCount = 0;
|
||||
String machineID;
|
||||
|
||||
machineID = player.getClientConnection().machineID;
|
||||
|
||||
for (PlayerCharacter member : group.getMembers())
|
||||
if (machineID.equals(member.getClientConnection().machineID))
|
||||
machineCount = machineCount + 1;
|
||||
|
||||
// (int) ConfigManager.WORLDSERVER.config.get("keyclone")
|
||||
if (machineCount > 4) {
|
||||
Logger.error("Keyclone detected from: " + player.getAccount().getUname() +
|
||||
" with machine count of: " + machineCount);
|
||||
DbManager.AccountQueries.SET_TRASH(machineID);
|
||||
}
|
||||
// Refactor to separate file to log keyclones
|
||||
// DbManager.AccountQueries.EMPTY_TRASH(machineID);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.LeaveGroupMsg;
|
||||
|
||||
public class LeaveGroupHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public LeaveGroupHandler() {
|
||||
super(LeaveGroupMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
GroupManager.LeaveGroup(origin);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.LeaveGuildMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class LeaveGuildHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public LeaveGuildHandler() {
|
||||
super(LeaveGuildMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
LeaveGuildMsg msg = (LeaveGuildMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
// get PlayerCharacter of person leaving invite
|
||||
|
||||
PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return true;
|
||||
|
||||
// Guild leader can't leave guild. must pass GL or disband
|
||||
|
||||
if (GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus())) {
|
||||
msg.setMessage("You must switch leadership of your guild before leaving!");
|
||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
// get old Guild
|
||||
Guild oldGuild = sourcePlayer.getGuild();
|
||||
|
||||
if (oldGuild == null || oldGuild.isErrant()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send left guild message to rest of guild
|
||||
ChatManager.chatGuildInfo(oldGuild, sourcePlayer.getFirstName() + " has left the guild.");
|
||||
|
||||
oldGuild.removePlayer(sourcePlayer, GuildHistoryType.LEAVE);
|
||||
|
||||
// Send message back to client
|
||||
msg.setMessage("You have left the guild.");
|
||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.LockUnlockDoorMsg;
|
||||
import engine.objects.Blueprint;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handle
|
||||
* lock and unlock door requests to and from the client.
|
||||
*
|
||||
*/
|
||||
|
||||
public class LockUnlockDoorMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public LockUnlockDoorMsgHandler() {
|
||||
super(LockUnlockDoorMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declarations
|
||||
|
||||
PlayerCharacter player;
|
||||
Building targetBuilding;
|
||||
int doorNum;
|
||||
LockUnlockDoorMsg msg;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (LockUnlockDoorMsg) baseMsg;
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
targetBuilding = BuildingManager.getBuilding((int) msg.getTargetID());
|
||||
|
||||
if (player == null || targetBuilding == null) {
|
||||
Logger.warn("Player or Building returned NULL in LockUnlock msg handling.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player.getLoc().distanceSquared2D(targetBuilding.getLoc()) > MBServerStatics.OPENCLOSEDOORDISTANCE * MBServerStatics.OPENCLOSEDOORDISTANCE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!BuildingManager.playerCanManage(player, targetBuilding)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
doorNum = Blueprint.getDoorNumberbyMesh(msg.getDoorID());
|
||||
|
||||
// Debugging code
|
||||
|
||||
// Logger.debug("DoorLockUnlock", "Door mesh: " + msg.getDoorID() + " Door number: " + doorNum);
|
||||
|
||||
boolean stateChanged;
|
||||
|
||||
if (targetBuilding.isDoorLocked(doorNum)) {
|
||||
stateChanged = targetBuilding.setDoorState(doorNum, engine.Enum.DoorState.UNLOCKED);
|
||||
} else {
|
||||
stateChanged = targetBuilding.setDoorState(doorNum, engine.Enum.DoorState.LOCKED);
|
||||
}
|
||||
|
||||
if (stateChanged == false) {
|
||||
Logger.error("WorldServerMsgHandler.LockUnlockDoor", "Failed to update db for building: " + targetBuilding.getObjectUUID() + ", door: " + msg.getDoorID());
|
||||
}
|
||||
|
||||
if (targetBuilding.isDoorLocked(doorNum)) {
|
||||
msg.setUnk1(1); // Which is this, locked or unlocaked?
|
||||
} else {
|
||||
msg.setUnk1(0);
|
||||
}
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.LoginToGameServerMsg;
|
||||
import engine.net.client.msg.login.LoginErrorMsg;
|
||||
import engine.objects.Account;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.session.CSSession;
|
||||
import engine.session.Session;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which keeps
|
||||
* logs the character nto the game using the CSession key generated
|
||||
* by the Login server.
|
||||
*/
|
||||
|
||||
public class LoginToGameServerMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public LoginToGameServerMsgHandler() {
|
||||
super(LoginToGameServerMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
LoginToGameServerMsg msg = (LoginToGameServerMsg) baseMsg;
|
||||
|
||||
CSSession sessionInfo = CSSession.getCrossServerSession(msg.getSecKey());
|
||||
|
||||
if (sessionInfo == null) {
|
||||
Logger.error("Failed to validate session information from " + origin.getLocalAddressAndPortAsString());
|
||||
origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to validate session data");
|
||||
// TODO Evaluate if we need to delete CSSessions here. We couldn't
|
||||
// find it before, why would this attempt be different?
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Account acc = sessionInfo.getAccount();
|
||||
|
||||
if (acc == null) {
|
||||
String err = "Session returned NULL Account. Conn:" + origin.getLocalAddressAndPortAsString();
|
||||
Logger.error(err);
|
||||
origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, err);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerCharacter pc = sessionInfo.getPlayerCharacter();
|
||||
|
||||
if (pc == null) {
|
||||
String err = "Session returned NULL PlayerCharacter. Conn:" + origin.getLocalAddressAndPortAsString();
|
||||
|
||||
Logger.error(err);
|
||||
origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, err);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If account is suspended, kick
|
||||
|
||||
if (acc.status.equals(Enum.AccountStatus.BANNED)) {
|
||||
origin.kickToLogin(MBServerStatics.LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT, "Account banned.");
|
||||
return true;
|
||||
}
|
||||
|
||||
ClientConnection old = SessionManager.getClientConnection(acc);
|
||||
|
||||
if (old != null)
|
||||
if (old != origin) {
|
||||
Logger.info("Disconnecting other client connection Using Same Account " + old.getRemoteAddressAndPortAsString());
|
||||
old.disconnect();
|
||||
}
|
||||
|
||||
// Set machine ID here from CSS info
|
||||
origin.machineID = sessionInfo.getMachineID();
|
||||
|
||||
// Send response
|
||||
msg.setSecKey("");
|
||||
|
||||
if (!origin.sendMsg(msg)) {
|
||||
Logger.error("Failed to send message");
|
||||
origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send ValidateGameServer to client.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//# Why was this all changed?
|
||||
// CLEAN UP OTHER INSTANCES OF THIS CHARACTER
|
||||
|
||||
Session toKill = SessionManager.getSession(sessionInfo.getPlayerCharacter());
|
||||
|
||||
if (toKill != null) {
|
||||
if (toKill.getConn() != null) {
|
||||
LoginErrorMsg lom = new LoginErrorMsg(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "You may not login the same character twice!");
|
||||
ClientConnection conn = toKill.getConn();
|
||||
if (conn != null && !conn.sendMsg(lom))
|
||||
Logger.error("Failed to send message"); // TODO Do we just accept this failure to send Msg?
|
||||
}
|
||||
SessionManager.remSession(toKill);
|
||||
WorldGrid.RemoveWorldObject(sessionInfo.getPlayerCharacter());
|
||||
}
|
||||
Session s = SessionManager.getNewSession(sessionInfo.getAccount(), origin);
|
||||
SessionManager.setPlayerCharacter(s, sessionInfo.getPlayerCharacter());
|
||||
|
||||
Logger.info("Login from Account: " + sessionInfo.getAccount().getUname() + " Character: " +
|
||||
sessionInfo.getPlayerCharacter().getName() + " machineID: " + sessionInfo.getMachineID());
|
||||
|
||||
DbManager.AccountQueries.SET_ACCOUNT_LOGIN(sessionInfo.getAccount(), sessionInfo.getPlayerCharacter().getName(), origin.getClientIpAddress(), sessionInfo.getMachineID());
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.guild.MOTDCommitMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class MOTDCommitHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public MOTDCommitHandler() {
|
||||
super(MOTDCommitMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
MOTDCommitMsg msg = (MOTDCommitMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
// get source player
|
||||
PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(
|
||||
origin);
|
||||
|
||||
if (sourcePlayer == null)
|
||||
return true;
|
||||
|
||||
int type = msg.getType();
|
||||
|
||||
if (type == 0 || type == 1 || type == 3) {
|
||||
|
||||
if (GuildStatusController.isInnerCouncil(sourcePlayer.getGuildStatus()) == false)
|
||||
return true;
|
||||
|
||||
Guild guild = sourcePlayer.getGuild();
|
||||
|
||||
if (guild == null)
|
||||
return true;
|
||||
|
||||
if (type == 1) { // Guild MOTD
|
||||
guild.setMOTD(msg.getMessage());
|
||||
ChatManager.chatGuildMOTD(sourcePlayer, msg.getMessage(),
|
||||
true);
|
||||
} else if (type == 3) { // IC MOTD
|
||||
guild.setICMOTD(msg.getMessage());
|
||||
ChatManager
|
||||
.chatICMOTD(sourcePlayer, msg.getMessage(), true);
|
||||
} else if (type == 0) { // Nation MOTD
|
||||
Guild nation = guild.getNation();
|
||||
if (nation == null)
|
||||
return true;
|
||||
if (nation.isNation()) { // only
|
||||
// nation's
|
||||
// primary guild can
|
||||
// set nation motd
|
||||
nation.setMOTD(msg.getMessage());
|
||||
ChatManager.chatNationMOTD(sourcePlayer,
|
||||
msg.getMessage(), true);
|
||||
}
|
||||
}
|
||||
dispatch = Dispatch.borrow(sourcePlayer, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.LeaveGuildMsg;
|
||||
import engine.net.client.msg.guild.MOTDMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class MOTDEditHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public MOTDEditHandler() {
|
||||
super(MOTDMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
MOTDMsg msg = (MOTDMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
// get source player
|
||||
PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter(
|
||||
origin);
|
||||
|
||||
if (playerCharacter == null)
|
||||
return true;
|
||||
|
||||
int type = msg.getType();
|
||||
|
||||
msg.setResponse((byte) 1);
|
||||
if (type == 0 || type == 1 || type == 3) {
|
||||
if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You do not have such authority!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Guild guild = playerCharacter.getGuild();
|
||||
|
||||
if (guild == null || guild.getObjectUUID() == 0) {
|
||||
|
||||
LeaveGuildMsg leaveGuildMsg = new LeaveGuildMsg();
|
||||
leaveGuildMsg.setMessage("You do not belong to a guild!");
|
||||
dispatch = Dispatch.borrow(playerCharacter, leaveGuildMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type == 1) // Guild MOTD
|
||||
msg.setMessage(guild.getMOTD());
|
||||
else if (type == 3) // IC MOTD
|
||||
msg.setMessage(guild.getICMOTD());
|
||||
else if (type == 0) { // Nation MOTD
|
||||
Guild nation = guild.getNation();
|
||||
if (nation == null || !nation.isNation()) {
|
||||
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You do not have such authority!");
|
||||
return true;
|
||||
}
|
||||
msg.setMessage(nation.getMOTD());
|
||||
}
|
||||
dispatch = Dispatch.borrow(playerCharacter, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Bounds;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.ManageCityAssetsMsg;
|
||||
import engine.net.client.msg.PlaceAssetMsg;
|
||||
import engine.objects.*;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which opens
|
||||
* and processes the various building asset management windows.
|
||||
*/
|
||||
public class ManageCityAssetMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ManageCityAssetMsgHandler() {
|
||||
super(ManageCityAssetsMsg.class);
|
||||
}
|
||||
|
||||
public static boolean playerCanManageNotFriends(PlayerCharacter player, Building building){
|
||||
|
||||
//Player Can only Control Building if player is in Same Guild as Building and is higher rank than IC.
|
||||
|
||||
if (player == null)
|
||||
return false;
|
||||
|
||||
if (building.getRank() == -1)
|
||||
return false;
|
||||
|
||||
if (BuildingManager.IsOwner(building, player))
|
||||
return true;
|
||||
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false && GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false)
|
||||
return false;
|
||||
|
||||
//Somehow guild leader check fails above? lets check if Player is true Guild GL.
|
||||
if (building.getGuild() != null && building.getGuild().isGuildLeader(player.getObjectUUID()))
|
||||
return true;
|
||||
|
||||
return Guild.sameGuild(building.getGuild(), player.getGuild());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
ManageCityAssetsMsg msg;
|
||||
PlayerCharacter player;
|
||||
ManageCityAssetsMsg outMsg;
|
||||
Building building;
|
||||
|
||||
msg = (ManageCityAssetsMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
building = BuildingManager.getBuildingFromCache(msg.getTargetID());
|
||||
|
||||
if (building == null){
|
||||
if (msg.actionType == 14) {
|
||||
|
||||
Zone zone = ZoneManager.findSmallestZone(player.getLoc());
|
||||
|
||||
if (!zone.isPlayerCity()){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Unable to find city to command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
City city = City.GetCityFromCache(zone.getPlayerCityUUID());
|
||||
|
||||
if (city == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Unable to find city to command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!city.getGuild().equals(player.getGuild())){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You are not in the correct guild to command this city.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!GuildStatusController.isInnerCouncil(player.getGuildStatus()) && !GuildStatusController.isGuildLeader(player.getGuildStatus())){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You must be an Inner Council or Guild leader to access city commands.");
|
||||
return true;
|
||||
}
|
||||
ManageCityAssetsMsg mca = new ManageCityAssetsMsg(player, building);
|
||||
mca.actionType = 15;
|
||||
Dispatch dispatch = Dispatch.borrow(player, mca);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
outMsg = new ManageCityAssetsMsg(player, building);
|
||||
|
||||
if (player.isSafeMode()){
|
||||
outMsg.actionType = 4;
|
||||
outMsg.setTargetType(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID(building.getObjectUUID());
|
||||
outMsg.setAssetName(building.getName());
|
||||
Dispatch dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.actionType == 2 || msg.actionType == 22) {
|
||||
|
||||
if (building.getBlueprint() != null && building.getBlueprint().getBuildingGroup() == engine.Enum.BuildingGroup.BANESTONE) {
|
||||
|
||||
outMsg.actionType = 18;
|
||||
outMsg.setTargetType(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID(building.getObjectUUID());
|
||||
|
||||
} else if (BuildingManager.playerCanManage(player, building)) { //TODO allow Friends list.
|
||||
configWindowState(player, building, outMsg);
|
||||
outMsg.actionType = 3;
|
||||
outMsg.setTargetType(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID(building.getObjectUUID());
|
||||
outMsg.setTargetType3(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID3(building.getObjectUUID());
|
||||
outMsg.setUnknown54(1);
|
||||
|
||||
} else {
|
||||
|
||||
if (building.getBlueprintUUID() != 0)
|
||||
switch (building.getBlueprint().getBuildingGroup()) {
|
||||
case SHRINE:
|
||||
if (building.getRank() == -1) {
|
||||
if (!Bounds.collide(player.getLoc(), building)) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 64);
|
||||
return true;
|
||||
}
|
||||
|
||||
Shrine shrine = Shrine.shrinesByBuildingUUID.get(building.getObjectUUID());
|
||||
|
||||
if (shrine == null)
|
||||
return true;
|
||||
|
||||
if (shrine.getFavors() == 0) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 166); // There is no more favor in this shrine to loot
|
||||
return true;
|
||||
}
|
||||
|
||||
BuildingManager.lootBuilding(player, building);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case WAREHOUSE:
|
||||
//TODO check
|
||||
if (building.getRank() == -1) {
|
||||
if (!Bounds.collide(player.getLoc(), building)) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 64);
|
||||
return true;
|
||||
}
|
||||
|
||||
Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(building.getObjectUUID());
|
||||
|
||||
if (warehouse == null)
|
||||
return true;
|
||||
|
||||
if (warehouse.isEmpty()) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 167); // no more resources.
|
||||
return true;
|
||||
}
|
||||
|
||||
BuildingManager.lootBuilding(player, building);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (building.getRank() == -1)
|
||||
return true;
|
||||
|
||||
AbstractCharacter owner = building.getOwner();
|
||||
|
||||
//no owner, send building info
|
||||
if (owner == null) {
|
||||
msg.actionType = 4;
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
outMsg.actionType = 4;
|
||||
outMsg.setTargetType(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID(building.getObjectUUID());
|
||||
outMsg.setAssetName(building.getName());
|
||||
|
||||
}
|
||||
Dispatch dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.actionType == 13) {
|
||||
outMsg.actionType = 13;
|
||||
Dispatch dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Rename Building.
|
||||
|
||||
if (msg.actionType == 5) {
|
||||
|
||||
//TODO we need to check names before allowing
|
||||
building.setName(msg.getAssetName());
|
||||
configWindowState(player, building, outMsg);
|
||||
|
||||
outMsg.actionType = 3;
|
||||
outMsg.setTargetType(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID(building.getObjectUUID());
|
||||
outMsg.setTargetType3(GameObjectType.Building.ordinal());
|
||||
outMsg.setTargetID3(building.getObjectUUID());
|
||||
outMsg.setAssetName1(building.getName());
|
||||
outMsg.setUnknown54(1);
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
|
||||
//TOL, update city name also
|
||||
//TODO update city and zone in database
|
||||
//TODO update city map data in game server
|
||||
}
|
||||
|
||||
if (msg.actionType == 14) {
|
||||
ManageCityAssetsMsg mca = new ManageCityAssetsMsg(player, building);
|
||||
mca.actionType = 15;
|
||||
Dispatch dispatch = Dispatch.borrow(player, mca);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (msg.actionType == 20) {
|
||||
|
||||
Zone baneZone = building.getParentZone();
|
||||
|
||||
if (baneZone == null)
|
||||
return true;
|
||||
|
||||
City banedCity = City.getCity(baneZone.getPlayerCityUUID());
|
||||
|
||||
if (banedCity == null)
|
||||
return true;
|
||||
|
||||
Bane bane = banedCity.getBane();
|
||||
|
||||
if (bane == null || bane.getLiveDate() != null || player.getGuild() != banedCity.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false)
|
||||
return true;
|
||||
|
||||
int baneHour = msg.getBaneHour();
|
||||
|
||||
if (baneHour < 16 || baneHour > 24) {
|
||||
PlaceAssetMsg.sendPlaceAssetError(origin, 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
DateTime baneLive = new DateTime(bane.getPlacementDate());
|
||||
baneLive = baneHour == 24 ? baneLive.plusDays(3) : baneLive.plusDays(2);
|
||||
baneLive = baneHour == 24 ? baneLive.hourOfDay().setCopy(0) : baneLive.hourOfDay().setCopy(baneHour);
|
||||
baneLive = baneLive.minuteOfHour().setCopy(0);
|
||||
baneLive = baneLive.secondOfMinute().setCopy(1);
|
||||
bane.setLiveDate(baneLive);
|
||||
outMsg.actionType = 18;
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void configWindowState(PlayerCharacter player, Building building, ManageCityAssetsMsg manageCityAssetsMsg) {
|
||||
|
||||
// Tests to turn on upgrade button if a building is not
|
||||
// at it's maximum allowed rank or currently ranking
|
||||
|
||||
|
||||
// Owner is obviously allowed to upgrade his own buildings
|
||||
|
||||
if (building.getOwner().equals(player)) {
|
||||
|
||||
// Players cannot destroy or transfer a TOL.
|
||||
|
||||
if (building.getBlueprint() == null){
|
||||
manageCityAssetsMsg.buttonDestroy = 0;
|
||||
manageCityAssetsMsg.buttonTransfer = 0;
|
||||
manageCityAssetsMsg.buttonAbandon = 0;
|
||||
manageCityAssetsMsg.buttonUpgrade = 0;
|
||||
}
|
||||
else
|
||||
if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL) {
|
||||
manageCityAssetsMsg.buttonDestroy = 0;
|
||||
manageCityAssetsMsg.buttonTransfer = 0;
|
||||
manageCityAssetsMsg.buttonAbandon = 1;
|
||||
manageCityAssetsMsg.buttonUpgrade = 1;
|
||||
}
|
||||
else if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.MINE) {
|
||||
manageCityAssetsMsg.buttonDestroy = 0;
|
||||
manageCityAssetsMsg.buttonTransfer = 0;
|
||||
manageCityAssetsMsg.buttonAbandon = 0;
|
||||
manageCityAssetsMsg.buttonUpgrade = 0; // Cannot upgrade a mine
|
||||
}
|
||||
else{
|
||||
manageCityAssetsMsg.buttonDestroy = 1;
|
||||
manageCityAssetsMsg.buttonTransfer = 1;
|
||||
manageCityAssetsMsg.buttonAbandon = 1;
|
||||
manageCityAssetsMsg.buttonUpgrade = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Inner Council of the same guild can also upgrade
|
||||
|
||||
if ((player.getGuild().equals(building.getGuild())) &&
|
||||
GuildStatusController.isInnerCouncil(player.getGuildStatus()))
|
||||
manageCityAssetsMsg.buttonUpgrade = 1;
|
||||
|
||||
// Disable upgrade button if at max rank.
|
||||
|
||||
if (building.getBlueprint() == null)
|
||||
manageCityAssetsMsg.buttonUpgrade = 0;
|
||||
else
|
||||
if (building.getRank() >= building.getBlueprint().getMaxRank())
|
||||
manageCityAssetsMsg.buttonUpgrade = 0;;
|
||||
|
||||
// If a building is not protected we can exit here
|
||||
|
||||
if (building.assetIsProtected() == false)
|
||||
return;
|
||||
|
||||
// Protection is displayed as "UNDER SIEGE" if
|
||||
// an active bane is invalidating the protection
|
||||
// contracts of the city.
|
||||
|
||||
if ((building.getCity() != null) &&
|
||||
(building.getCity().protectionEnforced == false)) {
|
||||
manageCityAssetsMsg.labelProtected = 0;
|
||||
manageCityAssetsMsg.labelSiege = 1;
|
||||
manageCityAssetsMsg.labelCeaseFire = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Building is currently protected by a TOL
|
||||
|
||||
manageCityAssetsMsg.labelProtected = 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,465 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.InterestManagement.RealmMap;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.*;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.TeleportJob;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.*;
|
||||
import engine.powers.PowersBase;
|
||||
import engine.server.MBServerStatics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes a variety of windows the client can open
|
||||
* such as realm blessings and warehouse deposits.
|
||||
*/
|
||||
|
||||
public class MerchantMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public MerchantMsgHandler() {
|
||||
super(MerchantMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
MerchantMsg msg;
|
||||
PlayerCharacter player;
|
||||
NPC npc;
|
||||
int msgType;
|
||||
Building warehouse;
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
msg = (MerchantMsg) baseMsg;
|
||||
npc = NPC.getNPC(msg.getNPCID());
|
||||
|
||||
// Early exit if something goes awry
|
||||
|
||||
if ((player == null) || (npc == null))
|
||||
return true;
|
||||
|
||||
// Player must be within talking range
|
||||
|
||||
if (player.getLoc().distanceSquared2D(npc.getLoc()) > MBServerStatics.NPC_TALK_RANGE * MBServerStatics.NPC_TALK_RANGE) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 14);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Process application protocol message
|
||||
|
||||
msgType = msg.getType();
|
||||
|
||||
switch (msgType) {
|
||||
case 3:
|
||||
break;
|
||||
case 5:
|
||||
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
requestSwearAsSubGuild(msg, origin, player, npc);
|
||||
break;
|
||||
case 10:
|
||||
teleportRepledgeScreen(msg, origin, player, false, npc);
|
||||
break;
|
||||
case 11:
|
||||
teleportRepledge(msg, origin, player, false, npc);
|
||||
break;
|
||||
case 12:
|
||||
teleportRepledgeScreen(msg, origin, player, true, npc);
|
||||
break;
|
||||
case 13:
|
||||
teleportRepledge(msg, origin, player, true, npc);
|
||||
break;
|
||||
case 14:
|
||||
if (isHermit(npc))
|
||||
requestHermitBlessing(msg, origin, player, npc);
|
||||
else
|
||||
requestBoon(msg, origin, player, npc);
|
||||
break;
|
||||
case 15:
|
||||
LeaderboardMessage lbm = new LeaderboardMessage();
|
||||
dispatch = Dispatch.borrow(player, lbm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case 16:
|
||||
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
warehouse = npc.getBuilding();
|
||||
vrm.setGuild(player.getGuild());
|
||||
vrm.setWarehouseBuilding(warehouse);
|
||||
vrm.configure();
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case 17:
|
||||
Warehouse.warehouseWithdraw(msg, player, npc, origin);
|
||||
break;
|
||||
case 18:
|
||||
Warehouse.warehouseDeposit(msg, player, npc, origin);
|
||||
break;
|
||||
case 19:
|
||||
Warehouse.warehouseLock(msg, player, npc, origin);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void requestSwearAsSubGuild(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) {
|
||||
|
||||
boolean Disabled = true;
|
||||
|
||||
if (Disabled){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Swearing to Safeholds have been temporary disabled."); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGuild().isErrant()){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!"); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGuild().getNation() != null && !player.getGuild().getNation().isErrant()){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You already belong to a nation!"); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGuild().getGuildLeaderUUID() != player.getObjectUUID()){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You must be a Guild Leader to Swear your guild as a Sub Guild!"); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GuildStatusController.isGuildLeader(player.getGuildStatus())){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You must be a Guild Leader to Swear your guild as a Sub Guild!"); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!npc.getGuild().isNPCGuild()){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Runemaster does not belong to a safehold!"); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
if (npc.getGuild().getRepledgeMin() > player.getLevel()){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You are too low of a level to sub to this guild!"); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
if (npc.getGuild().getRepledgeMax() < 75){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Runemaster Guild Cannot Swear in your guild!"); //Cannot sub as errant guild.
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!DbManager.GuildQueries.UPDATE_PARENT(player.getGuild().getObjectUUID(), npc.getGuild().getObjectUUID())) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
GuildManager.updateAllGuildBinds(player.getGuild(), npc.getGuild().getOwnedCity());
|
||||
|
||||
|
||||
|
||||
//update Guild state.
|
||||
player.getGuild().setNation(npc.getGuild());
|
||||
GuildManager.updateAllGuildTags(player.getGuild());
|
||||
|
||||
//update state twice, errant to petitioner, to sworn.
|
||||
player.getGuild().upgradeGuildState(false);//to petitioner
|
||||
player.getGuild().upgradeGuildState(false);//to sworn
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void requestHermitBlessing(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) {
|
||||
|
||||
Guild guild;
|
||||
Realm realm;
|
||||
City city;
|
||||
Building tol;
|
||||
|
||||
// Validate player can obtain blessing
|
||||
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 173); // You must be the leader of a guild to receive a blessing
|
||||
return;
|
||||
}
|
||||
|
||||
guild = player.getGuild();
|
||||
city = guild.getOwnedCity();
|
||||
|
||||
if (city == null) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 179); // Only landed guilds may claim a territory
|
||||
return;
|
||||
}
|
||||
tol = city.getTOL();
|
||||
|
||||
if (tol.getRank() != 7) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 181); // Your tree must be rank 7 before claiming a territory
|
||||
return;
|
||||
}
|
||||
|
||||
realm = RealmMap.getRealmForCity(city);
|
||||
|
||||
if (realm.getCanBeClaimed() == false) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 180); // This territory cannot be ruled by anyone
|
||||
return;
|
||||
}
|
||||
|
||||
if (realm.isRuled() == true) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 178); // This territory is already claimed
|
||||
return;
|
||||
}
|
||||
|
||||
// Everything should be good, apply boon for this hermit
|
||||
|
||||
PowersManager.applyPower(player, player, player.getLoc(), getPowerforHermit(npc).getToken(), 40, false);
|
||||
|
||||
}
|
||||
|
||||
private static void requestBoon(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, NPC npc) {
|
||||
|
||||
Building shrineBuilding;
|
||||
Shrine shrine;
|
||||
|
||||
if (npc.getGuild() != player.getGuild())
|
||||
return;
|
||||
|
||||
shrineBuilding = npc.getBuilding();
|
||||
|
||||
if (shrineBuilding == null)
|
||||
return;
|
||||
|
||||
if (shrineBuilding.getBlueprint() != null && shrineBuilding.getBlueprint().getBuildingGroup() != engine.Enum.BuildingGroup.SHRINE)
|
||||
return;
|
||||
|
||||
if (shrineBuilding.getRank() == -1)
|
||||
return;
|
||||
|
||||
shrine = Shrine.shrinesByBuildingUUID.get(shrineBuilding.getObjectUUID());
|
||||
|
||||
if (shrine == null)
|
||||
return;
|
||||
|
||||
if (shrine.getFavors() == 0) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 172);
|
||||
return;
|
||||
}
|
||||
|
||||
//already haz boon.
|
||||
|
||||
if (player.containsEffect(shrine.getShrineType().getPowerToken())) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 199);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Shrine.canTakeFavor(player, shrine))
|
||||
return;
|
||||
|
||||
if (!shrine.takeFavor(player))
|
||||
return;
|
||||
|
||||
PowersBase shrinePower = PowersManager.getPowerByToken(shrine.getShrineType().getPowerToken());
|
||||
|
||||
if (shrinePower == null) {
|
||||
ChatManager.chatSystemError(player, "FAILED TO APPLY POWER!");
|
||||
return;
|
||||
}
|
||||
|
||||
int rank = shrine.getRank();
|
||||
//R8 trees always get atleast rank 2 boons. rank uses index, where 0 is first place, 1 is second, etc...
|
||||
if (shrineBuilding.getCity() != null && shrineBuilding.getCity().getTOL() != null && shrineBuilding.getCity().getTOL().getRank() == 8)
|
||||
if (rank != 0)
|
||||
rank = 1;
|
||||
int trains = 40 - (rank * 10);
|
||||
if (trains < 0)
|
||||
trains = 0;
|
||||
|
||||
//System.out.println(trains);
|
||||
PowersManager.applyPower(player, player, player.getLoc(), shrinePower.getToken(), trains, false);
|
||||
ChatManager.chatGuildInfo(player.getGuild(), player.getName() + " has recieved a boon costing " + 1 + " point of favor.");
|
||||
shrineBuilding.addEffectBit(1000000 << 2);
|
||||
shrineBuilding.updateEffects();
|
||||
|
||||
//remove the effect so players loading shrines dont see the effect go off.
|
||||
shrineBuilding.removeEffectBit(1000000 << 2);
|
||||
}
|
||||
|
||||
private static void teleportRepledgeScreen(MerchantMsg msg, ClientConnection origin, PlayerCharacter pc, boolean isTeleport, NPC npc) {
|
||||
|
||||
Dispatch dispatch;
|
||||
TeleportRepledgeListMsg trlm;
|
||||
|
||||
//verify npc is runemaster
|
||||
|
||||
Contract contract = npc.getContract();
|
||||
|
||||
if (contract == null || !contract.isRuneMaster())
|
||||
return;
|
||||
|
||||
if (!isTeleport)
|
||||
trlm = new TeleportRepledgeListMsg(pc, false);
|
||||
else
|
||||
trlm = new TeleportRepledgeListMsg(pc, true);
|
||||
|
||||
trlm.configure();
|
||||
|
||||
dispatch = Dispatch.borrow(pc, trlm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
private static void teleportRepledge(MerchantMsg msg, ClientConnection origin, PlayerCharacter player, boolean isTeleport, NPC npc) {
|
||||
|
||||
//verify npc is runemaster
|
||||
|
||||
Contract contract = npc.getContract();
|
||||
Dispatch dispatch;
|
||||
|
||||
if (contract == null || !contract.isRuneMaster())
|
||||
return;
|
||||
|
||||
//get city to teleport/repledge to and verify valid
|
||||
|
||||
ArrayList<City> cities;
|
||||
|
||||
City targetCity = null;
|
||||
|
||||
if (isTeleport)
|
||||
cities = City.getCitiesToTeleportTo(player);
|
||||
else
|
||||
cities = City.getCitiesToRepledgeTo(player);
|
||||
for (City city : cities) {
|
||||
if (city.getObjectUUID() == msg.getCityID()) {
|
||||
targetCity = city;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetCity == null)
|
||||
return;
|
||||
|
||||
//verify level required to teleport or repledge
|
||||
|
||||
Guild toGuild = targetCity.getGuild();
|
||||
|
||||
if (toGuild != null)
|
||||
if (isTeleport) {
|
||||
if (player.getLevel() < toGuild.getTeleportMin() || player.getLevel() > toGuild.getTeleportMax())
|
||||
return;
|
||||
}
|
||||
else if (player.getLevel() < toGuild.getRepledgeMin() || player.getLevel() > toGuild.getRepledgeMax())
|
||||
return;
|
||||
|
||||
boolean joinedGuild = false;
|
||||
|
||||
//if repledge, reguild the player
|
||||
|
||||
if (!isTeleport)
|
||||
joinedGuild = GuildManager.joinGuild(player, targetCity.getGuild(), targetCity.getObjectUUID(), GuildHistoryType.JOIN);
|
||||
|
||||
int time;
|
||||
|
||||
if (!isTeleport) //repledge
|
||||
time = MBServerStatics.REPLEDGE_TIME_IN_SECONDS;
|
||||
else
|
||||
time = MBServerStatics.TELEPORT_TIME_IN_SECONDS;
|
||||
|
||||
//resend message
|
||||
msg.setTeleportTime(time);
|
||||
|
||||
if ((!isTeleport && joinedGuild) || (isTeleport)) {
|
||||
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
//teleport player to city
|
||||
|
||||
Vector3fImmutable teleportLoc;
|
||||
|
||||
if (targetCity.getTOL().getRank() == 8)
|
||||
teleportLoc = targetCity.getTOL().getStuckLocation();
|
||||
else
|
||||
teleportLoc = Vector3fImmutable.getRandomPointOnCircle(targetCity.getTOL().getLoc(), MBServerStatics.TREE_TELEPORT_RADIUS);
|
||||
|
||||
if (time > 0) {
|
||||
//TODO add timer to teleport
|
||||
TeleportJob tj = new TeleportJob(player, npc, teleportLoc, origin, true);
|
||||
JobScheduler.getInstance().scheduleJob(tj, time * 1000);
|
||||
}
|
||||
else if (joinedGuild) {
|
||||
player.teleport(teleportLoc);
|
||||
player.setSafeMode();
|
||||
}
|
||||
}
|
||||
|
||||
private static PowersBase getPowerforHermit(NPC npc) {
|
||||
|
||||
int contractID;
|
||||
PowersBase power;
|
||||
Contract contract;
|
||||
|
||||
contract = npc.getContract();
|
||||
contractID = contract.getContractID();
|
||||
power = null;
|
||||
|
||||
switch (contractID) {
|
||||
case 435579:
|
||||
power = PowersManager.getPowerByIDString("BLS-POWER");
|
||||
break;
|
||||
case 435580:
|
||||
power = PowersManager.getPowerByIDString("BLS-FORTUNE");
|
||||
break;
|
||||
case 435581:
|
||||
power = PowersManager.getPowerByIDString("BLS-WISDOM");
|
||||
break;
|
||||
|
||||
}
|
||||
return power;
|
||||
}
|
||||
|
||||
private static boolean isHermit(NPC npc) {
|
||||
|
||||
int contractID;
|
||||
boolean retValue = false;
|
||||
|
||||
contractID = npc.getContractID();
|
||||
|
||||
switch (contractID) {
|
||||
case 435579:
|
||||
case 435580:
|
||||
case 435581:
|
||||
retValue = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.ai.MobileFSM;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which
|
||||
* processes training of minions in guard barracks
|
||||
*/
|
||||
|
||||
public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public static HashMap<Integer, ArrayList<Integer>> _minionsByCaptain = null;
|
||||
|
||||
public MinionTrainingMsgHandler() {
|
||||
super(MinionTrainingMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
MinionTrainingMessage minionMsg = (MinionTrainingMessage) baseMsg;
|
||||
|
||||
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
if (minionMsg.getNpcType() == Enum.GameObjectType.NPC.ordinal()){
|
||||
|
||||
NPC npc = NPC.getFromCache(minionMsg.getNpcID());
|
||||
|
||||
if (npc == null)
|
||||
return true;
|
||||
|
||||
Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID());
|
||||
|
||||
if (b == null)
|
||||
return true;
|
||||
|
||||
//clear minion
|
||||
|
||||
if (npc.minionLock.writeLock().tryLock()) {
|
||||
try {
|
||||
if (minionMsg.getType() == 2) {
|
||||
|
||||
Mob toRemove = Mob.getFromCache(minionMsg.getUUID());
|
||||
|
||||
if (!npc.getSiegeMinionMap().containsKey(toRemove))
|
||||
return true;
|
||||
|
||||
toRemove.setState(MobileFSM.STATE.Disabled);
|
||||
npc.getSiegeMinionMap().remove(toRemove);
|
||||
|
||||
//toRemove.disableIntelligence();
|
||||
WorldGrid.RemoveWorldObject(toRemove);
|
||||
|
||||
if (toRemove.getParentZone() != null)
|
||||
toRemove.getParentZone().zoneMobSet.remove(toRemove);
|
||||
|
||||
DbManager.removeFromCache(toRemove);
|
||||
PlayerCharacter petOwner = toRemove.getOwner();
|
||||
|
||||
if (petOwner != null) {
|
||||
petOwner.setPet(null);
|
||||
toRemove.setOwner(null);
|
||||
PetMsg petMsg = new PetMsg(5, null);
|
||||
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
// we Found the move to remove, lets break the for loop so it doesnt look for more.
|
||||
|
||||
ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b);
|
||||
mca1.actionType = 3;
|
||||
mca1.setTargetType(b.getObjectType().ordinal());
|
||||
mca1.setTargetID(b.getObjectUUID());
|
||||
|
||||
mca1.setTargetType3(npc.getObjectType().ordinal());
|
||||
mca1.setTargetID3(npc.getObjectUUID());
|
||||
mca1.setAssetName1(b.getName());
|
||||
mca1.setUnknown54(1);
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, mca1);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
ManageNPCMsg mnm = new ManageNPCMsg(npc);
|
||||
dispatch = Dispatch.borrow(player, mnm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
//Add Minion
|
||||
}
|
||||
else {
|
||||
Zone zone = npc.getParentZone();
|
||||
|
||||
if (zone == null)
|
||||
return true;
|
||||
|
||||
int maxSlots = 3;
|
||||
|
||||
if (npc.getContractID() == 842)
|
||||
maxSlots = 1;
|
||||
|
||||
if (npc.getSiegeMinionMap().size() == maxSlots)
|
||||
return true;
|
||||
|
||||
int mobBase;
|
||||
|
||||
switch (minionMsg.getMinion()){
|
||||
case 9:
|
||||
mobBase = 13171;
|
||||
break;
|
||||
case 2:
|
||||
mobBase = 13758;
|
||||
break;
|
||||
case 3:
|
||||
mobBase = 13757;
|
||||
break;
|
||||
case 4:
|
||||
mobBase = 2111;
|
||||
break;
|
||||
case 5:
|
||||
mobBase = 12402;
|
||||
break;
|
||||
case 6:
|
||||
mobBase = 2113;
|
||||
break;
|
||||
default:
|
||||
mobBase = minionMsg.getMinion();
|
||||
}
|
||||
|
||||
if (mobBase == 0)
|
||||
return true;
|
||||
|
||||
Mob toCreate = npc.createSiegeMob(mobBase, npc.getGuild(), zone, b.getLoc(), (short) 1);
|
||||
|
||||
if (toCreate == null)
|
||||
return true;
|
||||
|
||||
// toCreate.despawn();
|
||||
if (toCreate != null) {
|
||||
toCreate.setSpawnTime(60 * 15);
|
||||
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + (60 * 15 * 1000));
|
||||
toCreate.setDeathTime(System.currentTimeMillis());
|
||||
toCreate.setState(MobileFSM.STATE.Respawn);
|
||||
}
|
||||
}
|
||||
|
||||
ManageNPCMsg mnm = new ManageNPCMsg(npc);
|
||||
mnm.setMessageType(1);
|
||||
Dispatch dispatch = Dispatch.borrow(player, mnm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
} finally {
|
||||
npc.minionLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}else if (minionMsg.getNpcType() == Enum.GameObjectType.Mob.ordinal()){
|
||||
|
||||
Mob npc = Mob.getFromCache(minionMsg.getNpcID());
|
||||
|
||||
if (npc == null)
|
||||
return true;
|
||||
|
||||
Building b = BuildingManager.getBuildingFromCache(minionMsg.getBuildingID());
|
||||
|
||||
if (b == null)
|
||||
return true;
|
||||
|
||||
//clear minion
|
||||
|
||||
if (npc.minionLock.writeLock().tryLock()) {
|
||||
try {
|
||||
if (minionMsg.getType() == 2) {
|
||||
|
||||
Mob toRemove = Mob.getFromCache(minionMsg.getUUID());
|
||||
if (!npc.getSiegeMinionMap().containsKey(toRemove))
|
||||
return true;
|
||||
|
||||
if (!DbManager.MobQueries.REMOVE_FROM_GUARDS(npc.getObjectUUID(), toRemove.getMobBaseID(), npc.getSiegeMinionMap().get(toRemove)))
|
||||
return true;
|
||||
|
||||
toRemove.setState(MobileFSM.STATE.Disabled);
|
||||
npc.getSiegeMinionMap().remove(toRemove);
|
||||
|
||||
//toRemove.disableIntelligence();
|
||||
WorldGrid.RemoveWorldObject(toRemove);
|
||||
|
||||
if (toRemove.getParentZone() != null)
|
||||
toRemove.getParentZone().zoneMobSet.remove(toRemove);
|
||||
|
||||
DbManager.removeFromCache(toRemove);
|
||||
PlayerCharacter petOwner = toRemove.getOwner();
|
||||
|
||||
if (petOwner != null) {
|
||||
petOwner.setPet(null);
|
||||
toRemove.setOwner(null);
|
||||
PetMsg petMsg = new PetMsg(5, null);
|
||||
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
// we Found the move to remove, lets break the for loop so it doesnt look for more.
|
||||
|
||||
ManageCityAssetsMsg mca1 = new ManageCityAssetsMsg(player, b);
|
||||
mca1.actionType = 3;
|
||||
mca1.setTargetType(b.getObjectType().ordinal());
|
||||
mca1.setTargetID(b.getObjectUUID());
|
||||
|
||||
mca1.setTargetType3(npc.getObjectType().ordinal());
|
||||
mca1.setTargetID3(npc.getObjectUUID());
|
||||
mca1.setAssetName1(b.getName());
|
||||
mca1.setUnknown54(1);
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, mca1);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);;
|
||||
|
||||
ManageNPCMsg mnm = new ManageNPCMsg(npc);
|
||||
dispatch = Dispatch.borrow(player, mnm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
//Add Minion
|
||||
}
|
||||
else {
|
||||
Zone zone = npc.getParentZone();
|
||||
|
||||
if (zone == null)
|
||||
return true;
|
||||
|
||||
int maxSlots = 5;
|
||||
|
||||
if (npc.getContract().getContractID() == 842)
|
||||
maxSlots = 1;
|
||||
|
||||
switch (npc.getRank()){
|
||||
case 1:
|
||||
case 2:
|
||||
maxSlots = 1;
|
||||
break;
|
||||
case 3:
|
||||
maxSlots = 2;
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
maxSlots = 3;
|
||||
break;
|
||||
case 6:
|
||||
maxSlots = 4;
|
||||
break;
|
||||
case 7:
|
||||
maxSlots = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
if (npc.getSiegeMinionMap().size() == maxSlots)
|
||||
return true;
|
||||
|
||||
int mobBase = npc.getMobBaseID();
|
||||
|
||||
if (mobBase == 0)
|
||||
return true;
|
||||
|
||||
String pirateName = NPC.getPirateName(mobBase);
|
||||
|
||||
if (!DbManager.MobQueries.ADD_TO_GUARDS(npc.getObjectUUID(), mobBase, pirateName, npc.getSiegeMinionMap().size() + 1))
|
||||
return true;
|
||||
|
||||
Mob toCreate = npc.createGuardMob(mobBase, npc.getGuild(), zone, b.getLoc(), npc.getLevel(),pirateName);
|
||||
|
||||
if (toCreate == null)
|
||||
return true;
|
||||
|
||||
// toCreate.despawn();
|
||||
if (toCreate != null) {
|
||||
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
|
||||
toCreate.setDeathTime(System.currentTimeMillis());
|
||||
toCreate.setState(MobileFSM.STATE.Respawn);
|
||||
}
|
||||
}
|
||||
|
||||
ManageNPCMsg mnm = new ManageNPCMsg(npc);
|
||||
mnm.setMessageType(1);
|
||||
Dispatch dispatch = Dispatch.borrow(player, mnm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
}catch (Exception e){
|
||||
Logger.error(e);
|
||||
}finally {
|
||||
|
||||
npc.minionLock.writeLock().unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.MovementManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.MoveToPointMsg;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class MoveToPointHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public MoveToPointHandler() {
|
||||
super(MoveToPointMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
MoveToPointMsg msg = (MoveToPointMsg) baseMsg;
|
||||
|
||||
PlayerCharacter pc = (origin != null) ? (origin.getPlayerCharacter()) : null;
|
||||
if (pc == null)
|
||||
return false;
|
||||
|
||||
MovementManager.movement(msg, pc);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,569 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.Enum.ItemType;
|
||||
import engine.InterestManagement.RealmMap;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.*;
|
||||
import engine.math.Bounds;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.*;
|
||||
import engine.powers.PowersBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which actives
|
||||
* items such as charters and deeds in the character's inventory
|
||||
*/
|
||||
public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
// Reentrant lock for dropping banes
|
||||
|
||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
public ObjectActionMsgHandler() {
|
||||
super(ObjectActionMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
ObjectActionMsg msg;
|
||||
PlayerCharacter player;
|
||||
CharacterItemManager itemMan;
|
||||
ArrayList<Long> comps;
|
||||
Dispatch dispatch;
|
||||
boolean waterbucketBypass = false;
|
||||
|
||||
// Member variable assignment
|
||||
msg = (ObjectActionMsg) baseMsg;
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
itemMan = player.getCharItemManager();
|
||||
|
||||
if (itemMan == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
comps = msg.getTargetCompID();
|
||||
|
||||
if (comps.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
long comp = comps.get(0);
|
||||
|
||||
if (((int) comp) != 0) {
|
||||
Item item = Item.getFromCache((int) comp);
|
||||
|
||||
if (item == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//dupe check
|
||||
if (!item.validForInventory(origin, player, itemMan)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ItemBase ib = item.getItemBase();
|
||||
|
||||
if (ib == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (itemMan.doesCharOwnThisItem(item.getObjectUUID())) {
|
||||
|
||||
if (ib.isConsumable() || ib.getType() == ItemType.FARMABLE) {
|
||||
|
||||
int uuid = ib.getUUID();
|
||||
int type = ib.getType().getValue();
|
||||
|
||||
switch (type) {
|
||||
case 27: //Mithril repair
|
||||
break;
|
||||
case 10: //charters
|
||||
//don't think they're handled here?
|
||||
break;
|
||||
case 19: //buildings
|
||||
//Call add building screen here, ib.getUseID() get's building ID
|
||||
|
||||
//if inside player city, center loc on tol. otherwise center on player.
|
||||
Vector3fImmutable loc = player.getLoc();
|
||||
Zone zone = ZoneManager.findSmallestZone(player.getLoc());
|
||||
|
||||
if (zone != null) {
|
||||
if (zone.isPlayerCity()) {
|
||||
loc = zone.getLoc();
|
||||
}
|
||||
}
|
||||
|
||||
PlaceAssetMsg pam = new PlaceAssetMsg();
|
||||
pam.setActionType(2);
|
||||
pam.setContractID(item.getObjectUUID());
|
||||
pam.setX(loc.getX() + 64); //offset grid from tol
|
||||
pam.setY(loc.getY());
|
||||
pam.setZ(loc.getZ() + 64); //offset grid from tol
|
||||
pam.addPlacementInfo(ib.getUseID());
|
||||
|
||||
dispatch = Dispatch.borrow(player, pam);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
//itemMan.consume(item); //temporary fix for dupe.. TODO Make Item Unusable after This message is sent.
|
||||
break;
|
||||
case 25: //furniture
|
||||
//Call add furniture screen here. ib.getUseID() get's furniture ID
|
||||
break;
|
||||
case 33:
|
||||
long shrineCompID = comps.get(1);
|
||||
Building shrineBuilding = BuildingManager.getBuilding((int)shrineCompID);
|
||||
if (shrineBuilding == null) {
|
||||
return true;
|
||||
}
|
||||
if (shrineBuilding.getBlueprint() != null && shrineBuilding.getBlueprint().getBuildingGroup() != engine.Enum.BuildingGroup.SHRINE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (shrineBuilding.getRank() == -1) {
|
||||
return true;
|
||||
}
|
||||
Shrine shrine = Shrine.shrinesByBuildingUUID.get(shrineBuilding.getObjectUUID());
|
||||
|
||||
if (shrine == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (shrine.addFavor(player, item)) {
|
||||
shrineBuilding.addEffectBit(1000000 << 2);
|
||||
shrineBuilding.updateEffects();
|
||||
shrineBuilding.removeEffectBit(1000000 << 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case 35:
|
||||
int charterType = 0;
|
||||
switch (uuid) {
|
||||
case 910020:
|
||||
charterType = 762228431;
|
||||
break;
|
||||
case 910021:
|
||||
charterType = -15978914;
|
||||
break;
|
||||
case 910022:
|
||||
charterType = -600065291;
|
||||
break;
|
||||
}
|
||||
if (claimRealm(player, charterType) == true) {
|
||||
itemMan.consume(item);
|
||||
}
|
||||
break;
|
||||
case 7: //rod of command
|
||||
long compID = comps.get(1);
|
||||
|
||||
int objectType = AbstractWorldObject.extractTypeID(compID).ordinal();
|
||||
Mob toCommand;
|
||||
if (objectType == engine.Enum.GameObjectType.Mob.ordinal()) {
|
||||
toCommand = Mob.getFromCache((int)compID);
|
||||
} //Only Command Mob Types.
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (toCommand == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!toCommand.isSiege())
|
||||
return true;
|
||||
|
||||
if (player.commandSiegeMinion(toCommand)) {
|
||||
itemMan.consume(item);
|
||||
}
|
||||
break;
|
||||
//ANNIVERSERY GIFT
|
||||
case 31:
|
||||
|
||||
|
||||
if (ib.getUUID() == 971012){
|
||||
int random = ThreadLocalRandom.current().nextInt(ItemBase.AnniverseryGifts.size());
|
||||
int annyID = ItemBase.AnniverseryGifts.get(random);
|
||||
|
||||
ItemBase annyIB = ItemBase.getItemBase(annyID);
|
||||
if (annyIB != null){
|
||||
Item gift = MobLoot.createItemForPlayer(player, annyIB);
|
||||
if (gift != null){
|
||||
itemMan.addItemToInventory(gift);
|
||||
itemMan.consume(item);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
LootTable.CreateGamblerItem(item, player);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case 30: //water bucket
|
||||
case 8: //potions, tears of saedron
|
||||
|
||||
case 5: //runes, petition, warrant, scrolls
|
||||
if (uuid > 3000 && uuid < 3050) { //Discipline Runes
|
||||
if (ApplyRuneMsg.applyRune(uuid, origin, player)) {
|
||||
itemMan.consume(item);
|
||||
}
|
||||
break;
|
||||
} else if (uuid > 249999 && uuid < 250123) { //stat and mastery runes
|
||||
if (ApplyRuneMsg.applyRune(uuid, origin, player)) {
|
||||
itemMan.consume(item);
|
||||
}
|
||||
break;
|
||||
} else if (uuid > 250114 && uuid < 250123) { //mastery runes
|
||||
if (ApplyRuneMsg.applyRune(uuid, origin, player)) {
|
||||
itemMan.consume(item);
|
||||
}
|
||||
break;
|
||||
} else if (uuid > 252122 && uuid < 252128) { //mastery runes
|
||||
if (ApplyRuneMsg.applyRune(uuid, origin, player)) {
|
||||
itemMan.consume(item);
|
||||
}
|
||||
break;
|
||||
} else if (uuid > 680069 && uuid < 680074) //Handle Charter, Deed, Petition, Warrant here
|
||||
{
|
||||
break;
|
||||
} else if (uuid > 910010 && uuid < 910019) {
|
||||
|
||||
int rank = uuid - 910010;
|
||||
|
||||
if (rank < 1 || rank > 8) {
|
||||
ChatManager.chatSystemError(player, "Invalid Rank for bane scroll!");
|
||||
return true;
|
||||
}
|
||||
// Only one banestone at a time
|
||||
lock.writeLock().lock();
|
||||
|
||||
try {
|
||||
if (Bane.summonBanestone(player, origin, rank) == true)
|
||||
itemMan.consume(item);
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
break;
|
||||
} else if (uuid == 910010) { //tears of saedron
|
||||
if (comps.size() > 1) {
|
||||
removeRune(player, origin, comps.get(1).intValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
else if (item.getChargesRemaining() > 0) {
|
||||
ArrayList<Long> tarList = msg.getTargetCompID();
|
||||
AbstractWorldObject target = player;
|
||||
if (tarList.size() > 1) {
|
||||
long tarID = tarList.get(1);
|
||||
if (tarID != 0) {
|
||||
AbstractGameObject tarAgo = AbstractGameObject.getFromTypeAndID(tarID);
|
||||
if (tarAgo != null && tarAgo instanceof AbstractWorldObject) {
|
||||
target = (AbstractWorldObject) tarAgo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bypass for waterbuckets
|
||||
|
||||
// test character targeted
|
||||
|
||||
if (ib.getUUID() == 910005) {
|
||||
|
||||
// test for valid target type
|
||||
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter)
|
||||
waterbucketBypass = true;
|
||||
else {
|
||||
// test distance to structure
|
||||
Building targetBuilding = (Building) target;
|
||||
Bounds testBounds = Bounds.borrow();
|
||||
testBounds.setBounds(player.getLoc(), 25);
|
||||
|
||||
if (Bounds.collide(targetBuilding.getBounds(), testBounds, .1f) == false) {
|
||||
ChatManager.chatSystemError(player, "Not in range of structura for to heal!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Send piss bucket animation
|
||||
|
||||
VisualUpdateMessage vum = new VisualUpdateMessage(player, 16323);
|
||||
vum.configure();
|
||||
DispatchMessage.sendToAllInRange(player, vum);
|
||||
}
|
||||
|
||||
if (waterbucketBypass == false)
|
||||
PowersManager.applyPower(player, target, Vector3fImmutable.ZERO, ib.getUseID(), ib.getUseAmount(), true);
|
||||
|
||||
itemMan.consume(item);
|
||||
} else //just remove the item at this point
|
||||
itemMan.consume(item);
|
||||
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
player.cancelOnSpell();
|
||||
break;
|
||||
default: //shouldn't be here, consume item
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
// itemMan.consume(item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO log item does not belong to player
|
||||
// System.out.println("Item does not belong to player");
|
||||
// Cleanup duped item here
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean claimRealm(PlayerCharacter player, int charterUUID) {
|
||||
|
||||
Guild guild;
|
||||
Realm realm;
|
||||
City city;
|
||||
Building tol;
|
||||
float hPMod;
|
||||
Warehouse warehouse;
|
||||
boolean hasResources = true;
|
||||
int resourceValue;
|
||||
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 176); // Only guild leaders can claim a territory
|
||||
return false;
|
||||
}
|
||||
|
||||
guild = player.getGuild();
|
||||
city = guild.getOwnedCity();
|
||||
|
||||
if (city == null) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 179); // Only landed guilds may claim a territory
|
||||
return false;
|
||||
}
|
||||
|
||||
if (city.isLocationOnCityGrid(player.getLoc()) == false) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 186); // Your tree is not inside a territory!
|
||||
return false;
|
||||
}
|
||||
|
||||
tol = city.getTOL();
|
||||
|
||||
if (tol.getRank() != 7) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 181); // Your tree must be rank 7 before claiming a territory
|
||||
return false;
|
||||
}
|
||||
|
||||
realm = RealmMap.getRealmForCity(city);
|
||||
|
||||
if (realm.getCanBeClaimed() == false) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 180); // This territory cannot be ruled by anyone
|
||||
return false;
|
||||
}
|
||||
|
||||
if (realm.isRuled() == true) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 178); // This territory is already claimed
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Realm.HasAllBlessings(player)) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 185); // You must seek the blessing of the three sages before you can rule
|
||||
return false;
|
||||
}
|
||||
|
||||
// Must have the required resources in warehouse to claim realm
|
||||
|
||||
warehouse = city.getWarehouse();
|
||||
|
||||
if (warehouse == null) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 188); // You must have a warehouse to become a capital
|
||||
return false;
|
||||
}
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.goldIB);
|
||||
|
||||
if (resourceValue < 5000000)
|
||||
hasResources = false;
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.stoneIB);
|
||||
|
||||
if (resourceValue < 8000)
|
||||
hasResources = false;
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.lumberIB);
|
||||
|
||||
if (resourceValue < 8000)
|
||||
hasResources = false;
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.galvorIB);
|
||||
|
||||
if (resourceValue < 15)
|
||||
hasResources = false;
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB);
|
||||
|
||||
if (resourceValue < 15)
|
||||
hasResources = false;
|
||||
|
||||
if (hasResources == false) {
|
||||
ErrorPopupMsg.sendErrorPopup(player, 184); // Insufficient gold or resources to upgrade to capital
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove resources from warehouse before claiming realm
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.goldIB);
|
||||
|
||||
if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) {
|
||||
warehouse.getResources().put(Warehouse.goldIB, resourceValue - 5000000);
|
||||
warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, 5000000);
|
||||
} else {
|
||||
Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID());
|
||||
return false;
|
||||
}
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.stoneIB);
|
||||
|
||||
if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) {
|
||||
warehouse.getResources().put(Warehouse.stoneIB, resourceValue - 8000);
|
||||
warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 8000);
|
||||
} else {
|
||||
Logger.error( "stone update failed for warehouse of UUID:" + warehouse.getObjectUUID());
|
||||
return false;
|
||||
}
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.lumberIB);
|
||||
|
||||
if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) {
|
||||
warehouse.getResources().put(Warehouse.lumberIB, resourceValue - 8000);
|
||||
warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 8000);
|
||||
} else {
|
||||
Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID());
|
||||
return false;
|
||||
}
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.galvorIB);
|
||||
|
||||
if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) {
|
||||
warehouse.getResources().put(Warehouse.galvorIB, resourceValue - 15);
|
||||
warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 15);
|
||||
} else {
|
||||
Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID());
|
||||
return false;
|
||||
}
|
||||
|
||||
resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB);
|
||||
|
||||
if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) {
|
||||
warehouse.getResources().put(Warehouse.wormwoodIB, resourceValue - 15);
|
||||
warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 15);
|
||||
} else {
|
||||
Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID());
|
||||
return false;
|
||||
}
|
||||
|
||||
realm.claimRealmForCity(city, charterUUID);
|
||||
|
||||
tol.setRank(8);
|
||||
WorldGrid.updateObject(tol);
|
||||
|
||||
for (Building building : city.getParent().zoneBuildingSet) {
|
||||
|
||||
if (building.getBlueprintUUID() != 0) {
|
||||
|
||||
// TOL Health set through regular linear equation
|
||||
if (building.getBlueprint().getBuildingGroup() == BuildingGroup.TOL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hPMod = (building.getMaxHitPoints() * Realm.getRealmHealthMod(city));
|
||||
building.setMaxHitPoints(building.getMaxHitPoints() + hPMod);
|
||||
}
|
||||
}
|
||||
|
||||
if (!guild.getNation().equals(guild)) {
|
||||
guild.getNation().setRealmsOwned(guild.getNation().getRealmsOwned() + 1);
|
||||
GuildManager.updateAllGuildTags(guild.getNation());
|
||||
}
|
||||
|
||||
guild.setRealmsOwned(guild.getRealmsOwned() + 1);
|
||||
GuildManager.updateAllGuildTags(guild);
|
||||
|
||||
removeAllBlessings(player);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void removeAllBlessings(PlayerCharacter player) {
|
||||
|
||||
PowersBase[] powers = new PowersBase[3];
|
||||
|
||||
powers[0] = PowersManager.getPowerByIDString("BLS-POWER");
|
||||
powers[1] = PowersManager.getPowerByIDString("BLS-FORTUNE");
|
||||
powers[2] = PowersManager.getPowerByIDString("BLS-WISDOM");
|
||||
|
||||
for (PowersBase power : powers) {
|
||||
PowersManager.removeEffect(player, power.getActions().get(0), true, false);
|
||||
}
|
||||
|
||||
}
|
||||
// Handle activation of tears of seadron: Removes rune from player.
|
||||
|
||||
private static void removeRune(PlayerCharacter pc, ClientConnection origin, int runeID) {
|
||||
|
||||
if (pc == null || origin == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
//remove only if rune is discipline
|
||||
if (runeID < 3001 || runeID > 3048) {
|
||||
return;
|
||||
}
|
||||
|
||||
//see if pc has rune
|
||||
ArrayList<CharacterRune> runes = pc.getRunes();
|
||||
|
||||
if (runes == null)
|
||||
return;
|
||||
|
||||
CharacterRune found = pc.getRune(runeID);
|
||||
|
||||
if (found == null)
|
||||
return;
|
||||
|
||||
//TODO see if player needs to refine skills or powers first
|
||||
//attempt remove rune from player
|
||||
|
||||
if (!CharacterRune.removeRune(pc, runeID))
|
||||
return;
|
||||
|
||||
//update client with removed rune.
|
||||
ApplyRuneMsg arm = new ApplyRuneMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), runeID);
|
||||
Dispatch dispatch = Dispatch.borrow(pc, arm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.OpenFriendsCondemnListMsg;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* client requests for various lists
|
||||
*/
|
||||
|
||||
public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public OpenFriendsCondemnListMsgHandler() {
|
||||
super(OpenFriendsCondemnListMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = SessionManager.getPlayerCharacter(origin);
|
||||
Building sourceBuilding;
|
||||
OpenFriendsCondemnListMsg msg;
|
||||
OpenFriendsCondemnListMsg openFriendsCondemnListMsg;
|
||||
Enum.FriendListType friendListType;
|
||||
Dispatch dispatch;
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
msg = (OpenFriendsCondemnListMsg) baseMsg;
|
||||
openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(msg);
|
||||
friendListType = Enum.FriendListType.getListTypeByID(msg.getMessageType());
|
||||
|
||||
if (friendListType == null){
|
||||
Logger.error("Invalid FriendListType for messageType " + msg.getMessageType());
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (friendListType) {
|
||||
case VIEWHERALDRY: // Heraldry
|
||||
|
||||
Heraldry.ValidateHeraldry(player.getObjectUUID());
|
||||
OpenFriendsCondemnListMsg outMsg = new OpenFriendsCondemnListMsg(msg);
|
||||
outMsg.setOrigin(origin);
|
||||
outMsg.setMessageType(2);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
case ADDHERALDRY:
|
||||
Heraldry.ValidateHeraldry(player.getObjectUUID());
|
||||
if (msg.getPlayerID() <= 0){
|
||||
//ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object.");
|
||||
return true;
|
||||
}
|
||||
AbstractCharacter toAdd = null;
|
||||
if (msg.getPlayerType() == GameObjectType.PlayerCharacter.ordinal())
|
||||
toAdd = PlayerCharacter.getFromCache(msg.getPlayerID());
|
||||
else if (msg.getPlayerType() == GameObjectType.NPC.ordinal())
|
||||
toAdd = NPC.getFromCache(msg.getPlayerID());
|
||||
else if (msg.getPlayerType() == GameObjectType.Mob.ordinal())
|
||||
toAdd = Mob.getFromCache(msg.getPlayerID());
|
||||
else{
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (toAdd == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Invalid Heraldry Object.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Heraldry.AddToHeraldy(player.getObjectUUID(), toAdd);
|
||||
|
||||
|
||||
outMsg = new OpenFriendsCondemnListMsg(msg);
|
||||
outMsg.setOrigin(origin);
|
||||
outMsg.setMessageType(2);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
break;
|
||||
case REMOVEHERALDRY:
|
||||
Heraldry.ValidateHeraldry(player.getObjectUUID());
|
||||
Heraldry.RemoveFromHeraldy(player.getObjectUUID(), msg.getPlayerID());
|
||||
|
||||
|
||||
outMsg = new OpenFriendsCondemnListMsg(msg);
|
||||
outMsg.setOrigin(origin);
|
||||
outMsg.setMessageType(2);
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
break;
|
||||
|
||||
case DEALTHS: // Death List
|
||||
openFriendsCondemnListMsg.updateMsg(8, new ArrayList<>(player.pvpDeaths));
|
||||
dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
case KILLS: // Kill List
|
||||
openFriendsCondemnListMsg.updateMsg(10, new ArrayList<>(player.pvpKills));
|
||||
dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
case VIEWCONDEMN:
|
||||
|
||||
sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (sourceBuilding == null)
|
||||
return true;
|
||||
|
||||
openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(12, sourceBuilding.getCondemned(), sourceBuilding.reverseKOS);
|
||||
openFriendsCondemnListMsg.configure();
|
||||
dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
//msg.updateMsg(12, DbManager.GuildQueries.)
|
||||
break;
|
||||
//REMOVE CONDEMN
|
||||
case REMOVECONDEMN:
|
||||
|
||||
sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (sourceBuilding == null)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player))
|
||||
return true;
|
||||
|
||||
Condemned removeCondemn = sourceBuilding.getCondemned().get(msg.getRemoveFriendID());
|
||||
|
||||
if (removeCondemn == null)
|
||||
return true;
|
||||
|
||||
if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.getParent(), removeCondemn.getPlayerUID(), removeCondemn.getGuildUID(), removeCondemn.getFriendType()))
|
||||
return true;
|
||||
|
||||
sourceBuilding.getCondemned().remove(msg.getRemoveFriendID());
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
case TOGGLEACTIVE:
|
||||
|
||||
sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (sourceBuilding == null)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player))
|
||||
return true;
|
||||
|
||||
Condemned condemn = sourceBuilding.getCondemned().get(msg.getRemoveFriendID());
|
||||
|
||||
if (condemn == null)
|
||||
return true;
|
||||
|
||||
condemn.setActive(msg.isReverseKOS());
|
||||
openFriendsCondemnListMsg.setReverseKOS(condemn.isActive());
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case REVERSEKOS:
|
||||
|
||||
|
||||
sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (sourceBuilding == null)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player))
|
||||
return true;
|
||||
|
||||
if (!sourceBuilding.setReverseKOS(msg.isReverseKOS()))
|
||||
return true;
|
||||
break;
|
||||
|
||||
//ADD GUILD CONDEMN
|
||||
case ADDCONDEMN:
|
||||
|
||||
sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (sourceBuilding == null)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player))
|
||||
return true;
|
||||
|
||||
switch (msg.getInviteType()) {
|
||||
case 2:
|
||||
|
||||
if (msg.getPlayerID() == 0)
|
||||
return true;
|
||||
|
||||
if (msg.getPlayerType() != GameObjectType.PlayerCharacter.ordinal())
|
||||
return true;
|
||||
|
||||
PlayerCharacter playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID());
|
||||
|
||||
if (playerCharacter == null)
|
||||
return true;
|
||||
|
||||
if (Guild.sameNationExcludeErrant(sourceBuilding.getGuild(), playerCharacter.getGuild()))
|
||||
return true;
|
||||
|
||||
if (sourceBuilding.getCondemned().containsKey(playerCharacter.getObjectUUID()))
|
||||
return true;
|
||||
|
||||
if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), playerCharacter.getObjectUUID(), msg.getGuildID(), msg.getInviteType())) {
|
||||
Logger.debug( "Failed to add Condemned: " + playerCharacter.getFirstName() + " to Building With UID " + sourceBuilding.getObjectUUID());
|
||||
return true;
|
||||
}
|
||||
|
||||
sourceBuilding.getCondemned().put(playerCharacter.getObjectUUID(), new Condemned(playerCharacter.getObjectUUID(), sourceBuilding.getObjectUUID(), msg.getGuildID(), msg.getInviteType()));
|
||||
break;
|
||||
case 4:
|
||||
if (msg.getGuildID() == 0)
|
||||
return true;
|
||||
|
||||
if (sourceBuilding.getCondemned().containsKey(msg.getGuildID()))
|
||||
return true;
|
||||
|
||||
Guild condemnedGuild = Guild.getGuild(msg.getGuildID());
|
||||
|
||||
if (condemnedGuild == null)
|
||||
return true;
|
||||
|
||||
if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), condemnedGuild.getObjectUUID(), msg.getInviteType())) {
|
||||
Logger.debug("Failed to add Condemned: " + condemnedGuild.getName() + " to Building With UID " + sourceBuilding.getObjectUUID());
|
||||
return true;
|
||||
}
|
||||
|
||||
sourceBuilding.getCondemned().put(condemnedGuild.getObjectUUID(), new Condemned(msg.getPlayerID(), sourceBuilding.getObjectUUID(), condemnedGuild.getObjectUUID(), msg.getInviteType()));
|
||||
break;
|
||||
case 5:
|
||||
if (msg.getNationID() == 0)
|
||||
return true;
|
||||
|
||||
if (sourceBuilding.getCondemned().containsKey(msg.getNationID()))
|
||||
return true;
|
||||
|
||||
Guild condemnedNation = Guild.getGuild(msg.getNationID());
|
||||
|
||||
if (condemnedNation == null)
|
||||
return true;
|
||||
|
||||
if (!DbManager.BuildingQueries.ADD_TO_CONDEMNLIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), condemnedNation.getObjectUUID(), msg.getInviteType())) {
|
||||
Logger.debug( "Failed to add Condemned: " + condemnedNation.getName() + " to Building With UID " + sourceBuilding.getObjectUUID());
|
||||
return true;
|
||||
}
|
||||
|
||||
sourceBuilding.getCondemned().put(condemnedNation.getObjectUUID(), new Condemned(msg.getPlayerID(), sourceBuilding.getObjectUUID(), condemnedNation.getObjectUUID(), msg.getInviteType()));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(12, sourceBuilding.getCondemned(), sourceBuilding.reverseKOS);
|
||||
openFriendsCondemnListMsg.configure();
|
||||
dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
//ADD FRIEND BUILDING
|
||||
case ADDFRIEND:
|
||||
sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (sourceBuilding == null)
|
||||
return true;
|
||||
|
||||
if (msg.getGuildID() == 0)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player))
|
||||
return true;
|
||||
|
||||
PlayerCharacter playerCharacter = null;
|
||||
|
||||
|
||||
|
||||
Guild guildInvited = Guild.getGuild(msg.getGuildID());
|
||||
|
||||
if (guildInvited == null)
|
||||
return true;
|
||||
|
||||
//Check to see if the invited is already on the friends list.
|
||||
switch (msg.getInviteType()) {
|
||||
case 7:
|
||||
playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID());
|
||||
if (playerCharacter == null)
|
||||
return true;
|
||||
if (sourceBuilding.getFriends().containsKey(playerCharacter.getObjectUUID()))
|
||||
return true;
|
||||
break;
|
||||
case 8:
|
||||
case 9:
|
||||
if (sourceBuilding.getFriends().containsKey(guildInvited.getObjectUUID()))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!DbManager.BuildingQueries.ADD_TO_FRIENDS_LIST(sourceBuilding.getObjectUUID(), msg.getPlayerID(), guildInvited.getObjectUUID(), msg.getInviteType())) {
|
||||
Logger.debug( "Failed to add Friend: " + playerCharacter.getFirstName() + " to Building With UID " + sourceBuilding.getObjectUUID());
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (msg.getInviteType()) {
|
||||
case 7:
|
||||
sourceBuilding.getFriends().put(playerCharacter.getObjectUUID(), new BuildingFriends(playerCharacter.getObjectUUID(), sourceBuilding.getObjectUUID(), playerCharacter.getGuild().getObjectUUID(), 7));
|
||||
break;
|
||||
case 8:
|
||||
sourceBuilding.getFriends().put(guildInvited.getObjectUUID(), new BuildingFriends(msg.getPlayerID(), sourceBuilding.getObjectUUID(), guildInvited.getObjectUUID(), 8));
|
||||
break;
|
||||
case 9:
|
||||
sourceBuilding.getFriends().put(guildInvited.getObjectUUID(), new BuildingFriends(msg.getPlayerID(), sourceBuilding.getObjectUUID(), guildInvited.getObjectUUID(), 9));
|
||||
break;
|
||||
}
|
||||
|
||||
openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, sourceBuilding.getFriends());
|
||||
openFriendsCondemnListMsg.configure();
|
||||
|
||||
dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
//REMOVE from friends list.
|
||||
case REMOVEFRIEND:
|
||||
sourceBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (sourceBuilding == null)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(sourceBuilding, player))
|
||||
return true;
|
||||
|
||||
BuildingFriends friend = sourceBuilding.getFriends().get(msg.getRemoveFriendID());
|
||||
|
||||
if (friend == null)
|
||||
return true;
|
||||
|
||||
if (!DbManager.BuildingQueries.REMOVE_FROM_FRIENDS_LIST(sourceBuilding.getObjectUUID(), friend.getPlayerUID(), friend.getGuildUID(), friend.getFriendType())) {
|
||||
Logger.debug( "Failed to remove Friend: " + msg.getRemoveFriendID() + " from Building With UID " + sourceBuilding.getObjectUUID());
|
||||
return true;
|
||||
}
|
||||
sourceBuilding.getFriends().remove(msg.getRemoveFriendID());
|
||||
|
||||
openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, sourceBuilding.getFriends());
|
||||
openFriendsCondemnListMsg.configure();
|
||||
dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
break;
|
||||
//view Friends
|
||||
case VIEWFRIENDS:
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
if (building == null)
|
||||
return true;
|
||||
|
||||
if (!BuildingManager.PlayerCanControlNotOwner(building, player))
|
||||
return true;
|
||||
|
||||
//this message is sent twice back?????
|
||||
|
||||
openFriendsCondemnListMsg = new OpenFriendsCondemnListMsg(26, building.getFriends());
|
||||
openFriendsCondemnListMsg.configure();
|
||||
|
||||
|
||||
dispatch = Dispatch.borrow(player, openFriendsCondemnListMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,575 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.ProfitType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.math.FastMath;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which keeps
|
||||
* client's tcp connection open.
|
||||
*/
|
||||
public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
// Constants used for incoming message type
|
||||
|
||||
private static final int CLIENT_UPGRADE_REQUEST = 3;
|
||||
private static final int CLIENT_REDEED_REQUEST = 6;
|
||||
private static final int SVR_CLOSE_WINDOW = 4;
|
||||
|
||||
public OrderNPCMsgHandler() {
|
||||
super(OrderNPCMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declarations
|
||||
|
||||
PlayerCharacter player;
|
||||
NPC npc;
|
||||
Mob mob;
|
||||
Building building;
|
||||
OrderNPCMsg orderNPCMsg;
|
||||
ManageCityAssetsMsg outMsg;
|
||||
|
||||
// Member variable assignment
|
||||
orderNPCMsg = (OrderNPCMsg) baseMsg;
|
||||
|
||||
if (origin.ordernpcspam > System.currentTimeMillis())
|
||||
return true;
|
||||
|
||||
origin.ordernpcspam = System.currentTimeMillis() + 500;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
if (orderNPCMsg.getActionType() == 28) {
|
||||
OrderNPCMsgHandler.handleCityCommand(orderNPCMsg, player);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (orderNPCMsg.getObjectType() == GameObjectType.NPC.ordinal()) {
|
||||
|
||||
npc = NPC.getFromCache(orderNPCMsg.getNpcUUID());
|
||||
|
||||
if (npc == null)
|
||||
return true;
|
||||
|
||||
building = BuildingManager.getBuildingFromCache(orderNPCMsg.getBuildingUUID());
|
||||
|
||||
if (building == null)
|
||||
return true;
|
||||
|
||||
if (building.getHirelings().containsKey(npc) == false)
|
||||
return true;
|
||||
|
||||
|
||||
if (player.getCharItemManager().getTradingWith() != null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot barter and trade with same timings.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.lastBuildingAccessed = building.getObjectUUID();
|
||||
|
||||
switch (orderNPCMsg.getActionType()) {
|
||||
|
||||
case 2:
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (ManageCityAssetMsgHandler.playerCanManageNotFriends(player, building) == false)
|
||||
return true;
|
||||
|
||||
if (building.getHirelings().containsKey(npc) == false)
|
||||
return true;
|
||||
|
||||
if (npc.remove() == false) {
|
||||
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg();
|
||||
manageCityAssetsMsg.actionType = SVR_CLOSE_WINDOW;
|
||||
manageCityAssetsMsg.setTargetType(building.getObjectType().ordinal());
|
||||
manageCityAssetsMsg.setTargetID(building.getObjectUUID());
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, manageCityAssetsMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
|
||||
case CLIENT_UPGRADE_REQUEST:
|
||||
|
||||
if (BuildingManager.playerCanManage(player, building) == false)
|
||||
return true;
|
||||
|
||||
processUpgradeNPC(player, npc);
|
||||
|
||||
outMsg = new ManageCityAssetsMsg(player, building);
|
||||
|
||||
// Action TYPE
|
||||
outMsg.actionType = 3;
|
||||
outMsg.setTargetType(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID(building.getObjectUUID());
|
||||
outMsg.setTargetType3(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID3(building.getObjectUUID());
|
||||
outMsg.setAssetName1(building.getName());
|
||||
outMsg.setUnknown54(1);
|
||||
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
break;
|
||||
case CLIENT_REDEED_REQUEST:
|
||||
|
||||
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
|
||||
return true;
|
||||
|
||||
processRedeedNPC(npc, building, origin);
|
||||
return true;
|
||||
//MB TODO HANDLE all profits.
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
|
||||
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
|
||||
return true;
|
||||
|
||||
modifySellProfit(orderNPCMsg, origin);
|
||||
dispatch = Dispatch.borrow(player, orderNPCMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
|
||||
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
|
||||
return true;
|
||||
|
||||
modifyBuyProfit(orderNPCMsg, origin);
|
||||
dispatch = Dispatch.borrow(player, orderNPCMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Validation check Owner or IC or friends
|
||||
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
|
||||
if (BuildingManager.playerCanManage(player, building) == false)
|
||||
return true;
|
||||
|
||||
ManageNPCMsg manageNPCMsg = new ManageNPCMsg(npc);
|
||||
Dispatch dispatch = Dispatch.borrow(player, manageNPCMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
|
||||
} else if (orderNPCMsg.getObjectType() == GameObjectType.Mob.ordinal()) {
|
||||
|
||||
mob = Mob.getFromCacheDBID(orderNPCMsg.getNpcUUID());
|
||||
|
||||
if (mob == null)
|
||||
return true;
|
||||
|
||||
building = BuildingManager.getBuildingFromCache(orderNPCMsg.getBuildingUUID());
|
||||
|
||||
if (building == null)
|
||||
return true;
|
||||
|
||||
if (!building.getHirelings().containsKey(mob))
|
||||
return true;
|
||||
|
||||
if (player.getCharItemManager().getTradingWith() != null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot barter and trade with same timings.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.lastBuildingAccessed = building.getObjectUUID();
|
||||
|
||||
switch (orderNPCMsg.getActionType()) {
|
||||
case 2:
|
||||
|
||||
if (BuildingManager.playerCanManage(player, building) == false)
|
||||
return true;
|
||||
|
||||
if (building.getHirelings().containsKey(mob) == false)
|
||||
return true;
|
||||
|
||||
if (mob.remove(building) == false) {
|
||||
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg();
|
||||
manageCityAssetsMsg.actionType = SVR_CLOSE_WINDOW;
|
||||
manageCityAssetsMsg.setTargetType(building.getObjectType().ordinal());
|
||||
manageCityAssetsMsg.setTargetID(building.getObjectUUID());
|
||||
Dispatch dispatch = Dispatch.borrow(player, manageCityAssetsMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case 3:
|
||||
|
||||
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
|
||||
return true;
|
||||
|
||||
processUpgradeNPC(player, mob);
|
||||
|
||||
outMsg = new ManageCityAssetsMsg(player, building);
|
||||
|
||||
// Action TYPE
|
||||
outMsg.actionType = 3;
|
||||
outMsg.setTargetType(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID(building.getObjectUUID());
|
||||
outMsg.setTargetType3(building.getObjectType().ordinal());
|
||||
outMsg.setTargetID3(building.getObjectUUID());
|
||||
outMsg.setAssetName1(building.getName());
|
||||
outMsg.setUnknown54(1);
|
||||
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
break;
|
||||
case 6:
|
||||
|
||||
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
|
||||
return true;
|
||||
|
||||
processRedeedNPC(mob, building, origin);
|
||||
return true;
|
||||
//MB TODO HANDLE all profits.
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
break;
|
||||
}
|
||||
|
||||
// Validation check Owner or IC
|
||||
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
|
||||
if (BuildingManager.playerCanManage(player, building) == false)
|
||||
return true;
|
||||
|
||||
ManageNPCMsg manageNPCMsg = new ManageNPCMsg(mob);
|
||||
Dispatch dispatch = Dispatch.borrow(player, manageNPCMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void modifyBuyProfit(OrderNPCMsg msg, ClientConnection origin) {
|
||||
NPC npc;
|
||||
PlayerCharacter player;
|
||||
Building building;
|
||||
float percent;
|
||||
|
||||
ProfitType profitType = null;
|
||||
player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
npc = NPC.getFromCache(msg.getNpcUUID());
|
||||
|
||||
if (npc == null)
|
||||
return;
|
||||
|
||||
building = npc.getBuilding();
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
NPCProfits profit = NPC.GetNPCProfits(npc);
|
||||
|
||||
if (profit == null)
|
||||
return;
|
||||
|
||||
switch (msg.getActionType()) {
|
||||
case 10:
|
||||
profitType = ProfitType.BuyNormal;
|
||||
break;
|
||||
case 11:
|
||||
profitType = ProfitType.BuyGuild;
|
||||
break;
|
||||
case 12:
|
||||
profitType = ProfitType.BuyNation;
|
||||
}
|
||||
|
||||
percent = msg.getBuySellPercent();
|
||||
percent = FastMath.clamp(percent, 0.0f, 1.0f);
|
||||
|
||||
NPCProfits.UpdateProfits(npc, profit, profitType, percent);
|
||||
}
|
||||
|
||||
private static void modifySellProfit(OrderNPCMsg orderNPCMsg, ClientConnection origin) {
|
||||
NPC npc;
|
||||
PlayerCharacter player;
|
||||
Building building;
|
||||
float percent;
|
||||
|
||||
ProfitType profitType = null;
|
||||
|
||||
player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
npc = NPC.getFromCache(orderNPCMsg.getNpcUUID());
|
||||
|
||||
if (npc == null)
|
||||
return;
|
||||
|
||||
building = npc.getBuilding();
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
NPCProfits profit = NPC.GetNPCProfits(npc);
|
||||
|
||||
if (profit == null)
|
||||
return;
|
||||
|
||||
switch (orderNPCMsg.getActionType()) {
|
||||
case 7:
|
||||
profitType = ProfitType.SellNormal;
|
||||
break;
|
||||
case 8:
|
||||
profitType = ProfitType.SellGuild;
|
||||
break;
|
||||
case 9:
|
||||
profitType = ProfitType.SellNation;
|
||||
}
|
||||
|
||||
percent = orderNPCMsg.getBuySellPercent();
|
||||
|
||||
percent -= 1f;
|
||||
percent = FastMath.clamp(percent, 0.0f, 3.0f);
|
||||
|
||||
NPCProfits.UpdateProfits(npc, profit, profitType, percent);
|
||||
}
|
||||
|
||||
private static void handleCityCommand(OrderNPCMsg orderNpcMsg, PlayerCharacter player) {
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(orderNpcMsg.getBuildingUUID());
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
if (ManageCityAssetMsgHandler.playerCanManageNotFriends(player, building) == false)
|
||||
return;
|
||||
|
||||
if (orderNpcMsg.getPatrolSize() >= 20)
|
||||
Logger.info(player.getName() + " is attempting to add patrol points amount " + orderNpcMsg.getPatrolSize());
|
||||
|
||||
if (orderNpcMsg.getSentrySize() >= 20)
|
||||
Logger.info(player.getName() + " is attempting to add patrol points amount " + orderNpcMsg.getSentryPoints());
|
||||
|
||||
if (orderNpcMsg.getPatrolPoints() != null) {
|
||||
|
||||
if ( !AddPatrolPoints(building.getObjectUUID(), orderNpcMsg.getPatrolPoints())){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Patrol Points must be placed on city zone.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (AbstractCharacter guard : building.getHirelings().keySet()) {
|
||||
if (guard.getObjectType() == GameObjectType.Mob)
|
||||
((Mob) guard).setPatrolPointIndex(0);
|
||||
}
|
||||
} else if (building.getPatrolPoints() != null)
|
||||
ClearPatrolPoints(building.getObjectUUID());
|
||||
|
||||
if (orderNpcMsg.getSentryPoints() != null) {
|
||||
AddSentryPoints(building.getObjectUUID(), orderNpcMsg.getSentryPoints());
|
||||
} else if (building.getSentryPoints() != null)
|
||||
ClearSentryPoints(building.getObjectUUID());
|
||||
|
||||
// Dispatch dispatch = Dispatch.borrow(pc, msg);
|
||||
// DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
|
||||
private static void processUpgradeNPC(PlayerCharacter player, AbstractCharacter abstractCharacter) {
|
||||
|
||||
Building building;
|
||||
|
||||
switch (abstractCharacter.getObjectType()) {
|
||||
|
||||
case NPC:
|
||||
NPC npc = (NPC) abstractCharacter;
|
||||
building = npc.getBuilding();
|
||||
|
||||
// Cannot upgrade an npc not within a building
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
City buildingCity = building.getCity();
|
||||
|
||||
if (buildingCity == null) {
|
||||
npc.processUpgradeNPC(player);
|
||||
return;
|
||||
}
|
||||
|
||||
buildingCity.transactionLock.writeLock().lock();
|
||||
|
||||
try {
|
||||
npc.processUpgradeNPC(player);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
buildingCity.transactionLock.writeLock().unlock();
|
||||
}
|
||||
break;
|
||||
case Mob:
|
||||
|
||||
Mob mob = (Mob) abstractCharacter;
|
||||
building = mob.getBuilding();
|
||||
|
||||
if (mob.getBuilding() == null)
|
||||
return;
|
||||
|
||||
City mobCity = building.getCity();
|
||||
|
||||
if (mobCity == null) {
|
||||
mob.processUpgradeMob(player);
|
||||
return;
|
||||
}
|
||||
|
||||
mobCity.transactionLock.writeLock().lock();
|
||||
|
||||
try {
|
||||
mob.processUpgradeMob(player);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
mobCity.transactionLock.writeLock().unlock();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void processRedeedNPC(AbstractCharacter abstractCharacter, Building building, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
switch (abstractCharacter.getObjectType()) {
|
||||
case NPC:
|
||||
NPC npc = (NPC) abstractCharacter;
|
||||
|
||||
Building cityBuilding = npc.getBuilding();
|
||||
|
||||
if (cityBuilding == null)
|
||||
return;
|
||||
|
||||
npc.processRedeedNPC(origin);
|
||||
break;
|
||||
case Mob:
|
||||
Mob mob = (Mob) abstractCharacter;
|
||||
mob.processRedeedMob(origin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean AddPatrolPoints(int buildingID, ArrayList<Vector3fImmutable> patrolPoints) {
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(buildingID);
|
||||
|
||||
if (building == null)
|
||||
return false;
|
||||
|
||||
Zone zone = building.getParentZone();
|
||||
|
||||
if (zone == null)
|
||||
return false;
|
||||
|
||||
if (zone.getPlayerCityUUID() == 0)
|
||||
return false;
|
||||
|
||||
City city = building.getCity();
|
||||
|
||||
if (city == null)
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
//clear first.
|
||||
|
||||
for (Vector3fImmutable point : patrolPoints) {
|
||||
|
||||
if (city.isLocationOnCityZone(point) == false){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DbManager.BuildingQueries.CLEAR_PATROL(buildingID);
|
||||
|
||||
for (Vector3fImmutable point : patrolPoints) {
|
||||
|
||||
if (!DbManager.BuildingQueries.ADD_TO_PATROL(buildingID, point))
|
||||
return false;
|
||||
}
|
||||
building.patrolPoints = patrolPoints;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean AddSentryPoints(int buildingID, ArrayList<Vector3fImmutable> sentryPoints) {
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(buildingID);
|
||||
|
||||
if (building == null)
|
||||
return false;
|
||||
|
||||
building.sentryPoints = sentryPoints;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean ClearPatrolPoints(int buildingID) {
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(buildingID);
|
||||
|
||||
if (building == null)
|
||||
return false;
|
||||
|
||||
if (building.patrolPoints == null)
|
||||
return true;
|
||||
|
||||
if (DbManager.BuildingQueries.CLEAR_PATROL(buildingID) == false)
|
||||
return false;
|
||||
|
||||
building.patrolPoints.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean ClearSentryPoints(int buildingID) {
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(buildingID);
|
||||
|
||||
if (building == null)
|
||||
return false;
|
||||
|
||||
if (building.sentryPoints == null)
|
||||
return true;
|
||||
|
||||
building.sentryPoints.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,90 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.AllianceType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.AllianceChangeMsg;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.RecommendNationMsg;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* protecting and unprotecting city assets
|
||||
*/
|
||||
public class RecommendNationMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public RecommendNationMsgHandler() {
|
||||
super(RecommendNationMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
RecommendNationMsg msg;
|
||||
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (RecommendNationMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
RecommendNationMsgHandler.RecommendNation(player.getGuild(), Guild.getGuild(msg.getGuildID()), msg, origin);
|
||||
|
||||
|
||||
|
||||
|
||||
// dispatch = Dispatch.borrow(player, baseMsg);
|
||||
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void RecommendNation(Guild fromGuild, Guild toGuild, RecommendNationMsg msg, ClientConnection origin) {
|
||||
|
||||
// Member variable declaration
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
if (fromGuild == null)
|
||||
return;
|
||||
|
||||
if (toGuild == null)
|
||||
return;
|
||||
|
||||
AllianceType allianceType;
|
||||
if (msg.getAlly() == 1)
|
||||
allianceType = AllianceType.RecommendedAlly;
|
||||
else
|
||||
allianceType = AllianceType.RecommendedEnemy;
|
||||
|
||||
if (!fromGuild.addGuildToAlliance(new AllianceChangeMsg(origin.getPlayerCharacter(),fromGuild.getObjectUUID(), toGuild.getObjectUUID(), (byte)0, 0), allianceType, toGuild, origin.getPlayerCharacter()))
|
||||
return;
|
||||
String alliance = msg.getAlly() == 1? "ally" : "enemy";
|
||||
|
||||
ChatManager.chatGuildInfo(fromGuild, origin.getPlayerCharacter().getFirstName() + " has recommended " + toGuild.getName() + " as an " + alliance );
|
||||
|
||||
// dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg);
|
||||
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.RemoveFriendMessage;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.PlayerFriends;
|
||||
|
||||
|
||||
|
||||
public class RemoveFriendHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public RemoveFriendHandler() {
|
||||
super(RemoveFriendMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
RemoveFriendMessage msg = (RemoveFriendMessage)baseMsg;
|
||||
|
||||
HandleRemoveFriend(player,msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void HandleRemoveFriend(PlayerCharacter player, RemoveFriendMessage msg){
|
||||
|
||||
//No friends in list. Early exit.
|
||||
PlayerFriends.RemoveFromFriends(player.getObjectUUID(), msg.friendID);
|
||||
PlayerFriends.RemoveFromFriends(msg.friendID, player.getObjectUUID());
|
||||
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
|
||||
msg = new RemoveFriendMessage(msg.friendID);
|
||||
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
import engine.net.client.msg.group.RemoveFromGroupMsg;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class RemoveFromGroupHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public RemoveFromGroupHandler() {
|
||||
super(RemoveFromGroupMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Declar member variables
|
||||
|
||||
PlayerCharacter source;
|
||||
PlayerCharacter target;
|
||||
RemoveFromGroupMsg msg;
|
||||
Group group;
|
||||
GroupUpdateMsg gim;
|
||||
ClientConnection gcc;
|
||||
Set<PlayerCharacter> groupMembers;
|
||||
|
||||
// Assign member variables
|
||||
|
||||
msg = (RemoveFromGroupMsg) baseMsg;
|
||||
|
||||
source = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
group = GroupManager.getGroup(source);
|
||||
|
||||
if (group == null)
|
||||
return false;
|
||||
|
||||
if (group.getGroupLead() != source) // Only group lead can remove
|
||||
return false;
|
||||
|
||||
target = SessionManager.getPlayerCharacterByID(msg.getTargetID());
|
||||
|
||||
if (target == null)
|
||||
return false;
|
||||
|
||||
if (target == source) { // can't remove self, must quit
|
||||
RemoveFromGroupMsg reply = new RemoveFromGroupMsg();
|
||||
reply.setResponse(1);
|
||||
Dispatch dispatch = Dispatch.borrow(source, reply);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY);
|
||||
return false;
|
||||
}
|
||||
|
||||
gcc = SessionManager.getClientConnection(target);
|
||||
|
||||
if (gcc != null) {
|
||||
|
||||
// Cleanup group window for player quiting
|
||||
|
||||
groupMembers = group.getMembers();
|
||||
|
||||
for (PlayerCharacter groupMember : groupMembers) {
|
||||
|
||||
if (groupMember == null)
|
||||
continue;
|
||||
|
||||
gim = new GroupUpdateMsg();
|
||||
gim.setGroup(group);
|
||||
gim.setPlayer(target);
|
||||
gim.setMessageType(3);
|
||||
gim.setPlayer(groupMember);
|
||||
Dispatch dispatch = Dispatch.borrow(target, gim);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Remove from group and clean up everyone elses window
|
||||
group.removeGroupMember(target);
|
||||
GroupManager.removeFromGroups(target);
|
||||
|
||||
gim = new GroupUpdateMsg();
|
||||
gim.setGroup(group);
|
||||
gim.setMessageType(3);
|
||||
gim.setPlayer(target);
|
||||
group.sendUpdate(gim);
|
||||
|
||||
String text = target.getFirstName() + " has left your group.";
|
||||
ChatManager.chatGroupInfo(source, text);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.BuildingGroup;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.RepairBuildingMsg;
|
||||
import engine.net.client.msg.UpdateObjectMsg;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Zone;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* protecting and unprotecting city assets
|
||||
*/
|
||||
public class RepairBuildingMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public RepairBuildingMsgHandler() {
|
||||
super(RepairBuildingMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
Building targetBuilding;
|
||||
RepairBuildingMsg msg;
|
||||
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
msg = (RepairBuildingMsg) baseMsg;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
switch (msg.getType()) {
|
||||
case 0:
|
||||
targetBuilding = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
RepairBuilding(targetBuilding, origin, msg);
|
||||
break;
|
||||
|
||||
// targetBuilding.createFurniture(item.getItemBase().getUseID(), 0, msg.getFurnitureLoc(), Vector3f.ZERO, 0, player);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// dispatch = Dispatch.borrow(player, baseMsg);
|
||||
// DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void RepairBuilding(Building targetBuilding, ClientConnection origin, RepairBuildingMsg msg) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
Zone serverZone;
|
||||
Dispatch dispatch;
|
||||
|
||||
// Member variable assignment
|
||||
|
||||
if (targetBuilding == null)
|
||||
return;
|
||||
|
||||
if (!targetBuilding.hasFunds(BuildingManager.GetRepairCost(targetBuilding)))
|
||||
return;
|
||||
|
||||
PlayerCharacter pc = origin.getPlayerCharacter();
|
||||
|
||||
serverZone = ZoneManager.findSmallestZone(pc.getLoc());
|
||||
|
||||
if (serverZone.getPlayerCityUUID() == 0 && targetBuilding.getBlueprint() != null && targetBuilding.getBlueprint().getBuildingGroup() != BuildingGroup.MINE)
|
||||
return;
|
||||
|
||||
|
||||
City city = City.GetCityFromCache(serverZone.getPlayerCityUUID());
|
||||
|
||||
if (city != null){
|
||||
if(city.getBane() != null && city.protectionEnforced == false)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
//cannot repair mines during 24/7 activity.
|
||||
|
||||
if (targetBuilding.getBlueprint() != null && targetBuilding.getBlueprint().getBuildingGroup() == BuildingGroup.MINE){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int maxHP = (int) targetBuilding.getMaxHitPoints();
|
||||
int repairCost = BuildingManager.GetRepairCost(targetBuilding);
|
||||
int missingHealth = (int) BuildingManager.GetMissingHealth(targetBuilding);
|
||||
|
||||
if (!targetBuilding.transferGold(-repairCost,false))
|
||||
return;
|
||||
|
||||
targetBuilding.modifyHealth(BuildingManager.GetMissingHealth(targetBuilding), null);
|
||||
|
||||
UpdateObjectMsg uom = new UpdateObjectMsg(targetBuilding,3);
|
||||
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), uom);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
|
||||
RepairBuildingMsg rbm = new RepairBuildingMsg( targetBuilding.getObjectUUID(), maxHP, missingHealth, repairCost, targetBuilding.getStrongboxValue());
|
||||
|
||||
|
||||
dispatch = Dispatch.borrow(origin.getPlayerCharacter(), rbm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.RequestBallListMessage;
|
||||
import engine.objects.PlayerCharacter;
|
||||
public class RequestBallListHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public RequestBallListHandler() {
|
||||
super(RequestBallListMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
RequestBallListMessage msg = (RequestBallListMessage)baseMsg;
|
||||
|
||||
HandleRequestBallList(player,msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void HandleRequestBallList(PlayerCharacter player, RequestBallListMessage msg){
|
||||
//currently not handled.
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.InterestManagement.InterestManager;
|
||||
import engine.InterestManagement.WorldGrid;
|
||||
import engine.db.archive.CharacterRecord;
|
||||
import engine.db.archive.DataWarehouse;
|
||||
import engine.db.archive.PvpRecord;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import engine.objects.Account;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.session.Session;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which requests
|
||||
* that a character enters the game world from login screen
|
||||
*/
|
||||
|
||||
public class RequestEnterWorldHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public RequestEnterWorldHandler() {
|
||||
super(RequestEnterWorldMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
RequestEnterWorldMsg msg;
|
||||
|
||||
msg = (RequestEnterWorldMsg) baseMsg;
|
||||
|
||||
Session session = SessionManager.getSession(origin);
|
||||
|
||||
if (session == null)
|
||||
return true;
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
WorldGrid.RemoveWorldObject(player);
|
||||
Dispatch dispatch;
|
||||
|
||||
if (player == null) {
|
||||
Logger.error("Unable to find player for session" + session.getSessionID());
|
||||
origin.kickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player not found.");
|
||||
return true;
|
||||
}
|
||||
|
||||
player.setEnteredWorld(false);
|
||||
|
||||
Account acc = SessionManager.getAccount(origin);
|
||||
|
||||
if (acc.status.ordinal() < MBServerStatics.worldAccessLevel.ordinal() || MBServerStatics.blockLogin) {
|
||||
origin.disconnect();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Brand new character. Send the city select screen
|
||||
|
||||
if (player.getLevel() == 1 && player.getBindBuildingID() == -1) {
|
||||
SelectCityMsg scm = new SelectCityMsg(player, true);
|
||||
dispatch = Dispatch.borrow(player, scm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
}
|
||||
|
||||
player.resetRegenUpdateTime();
|
||||
|
||||
// Map Data
|
||||
|
||||
try {
|
||||
WorldDataMsg wdm = new WorldDataMsg();
|
||||
dispatch = Dispatch.borrow(player, wdm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error("WORLDDATAMESSAGE" + e.getMessage());
|
||||
}
|
||||
|
||||
// Realm Data
|
||||
|
||||
try {
|
||||
WorldRealmMsg wrm = new WorldRealmMsg();
|
||||
dispatch = Dispatch.borrow(player, wrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error("REALMMESSAGE" + e.getMessage());
|
||||
}
|
||||
|
||||
// Object Data
|
||||
WorldObjectMsg wom = new WorldObjectMsg(session, true);
|
||||
dispatch = Dispatch.borrow(player, wom);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
|
||||
player.getTimestamps().put("EnterWorld", System.currentTimeMillis());
|
||||
|
||||
if (player.getLoc().equals(Vector3fImmutable.ZERO) || System.currentTimeMillis() > player.getTimeStamp("logout") + (15 * 60 * 1000)) {
|
||||
player.stopMovement(player.getBindLoc());
|
||||
player.setSafeMode();
|
||||
player.updateLocation();
|
||||
player.setRegion(AbstractWorldObject.GetRegionByWorldObject(player));
|
||||
}
|
||||
|
||||
player.setTimeStamp("logout", 0);
|
||||
player.respawnLock.writeLock().lock();
|
||||
try{
|
||||
if (!player.isAlive()){
|
||||
Logger.info("respawning player on enter world.");
|
||||
player.respawn(true, true,true);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
Logger.error(e);
|
||||
}finally{
|
||||
player.respawnLock.writeLock().unlock();
|
||||
}
|
||||
|
||||
|
||||
player.resetDataAtLogin();
|
||||
|
||||
InterestManager.INTERESTMANAGER.HandleLoadForEnterWorld(player);
|
||||
|
||||
// If this is a brand new character...
|
||||
// when they enter world is a great time to write their
|
||||
// character record to the data warehouse.
|
||||
|
||||
if (player.getHash() == null) {
|
||||
|
||||
if (DataWarehouse.recordExists(Enum.DataRecordType.CHARACTER, player.getObjectUUID()) == false) {
|
||||
CharacterRecord characterRecord = CharacterRecord.borrow(player);
|
||||
DataWarehouse.pushToWarehouse(characterRecord);
|
||||
}
|
||||
player.setHash();
|
||||
}
|
||||
|
||||
//
|
||||
// We will load the kill/death lists here as data is only pertinent
|
||||
// to characters actually logged into the game.
|
||||
//
|
||||
|
||||
player.pvpKills = PvpRecord.getCharacterPvPHistory(player.getObjectUUID(), Enum.PvpHistoryType.KILLS);
|
||||
player.pvpDeaths = PvpRecord.getCharacterPvPHistory(player.getObjectUUID(), Enum.PvpHistoryType.DEATHS);
|
||||
|
||||
SendOwnPlayerMsg sopm = new SendOwnPlayerMsg(SessionManager.getSession(origin));
|
||||
dispatch = Dispatch.borrow(player, sopm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.ReqGuildListMsg;
|
||||
import engine.net.client.msg.guild.SendGuildEntryMsg;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
|
||||
public class RequestGuildListHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public RequestGuildListHandler() {
|
||||
super(ReqGuildListMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
Dispatch dispatch;
|
||||
|
||||
// get PlayerCharacter of person accepting invite
|
||||
PlayerCharacter pc = SessionManager.getPlayerCharacter(
|
||||
origin);
|
||||
if (pc == null)
|
||||
return true;
|
||||
|
||||
if (GuildStatusController.isGuildLeader(pc.getGuildStatus()) == false){
|
||||
ErrorPopupMsg.sendErrorMsg(pc, "You do not have such authority!");
|
||||
}
|
||||
SendGuildEntryMsg msg = new SendGuildEntryMsg(pc);
|
||||
|
||||
|
||||
dispatch = Dispatch.borrow(pc, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.SendBallEntryMessage;
|
||||
import engine.objects.PlayerCharacter;
|
||||
public class SendBallEntryHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public SendBallEntryHandler() {
|
||||
super(SendBallEntryMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
SendBallEntryMessage msg = (SendBallEntryMessage)baseMsg;
|
||||
|
||||
HandleAddBall(player,msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void HandleAddBall(PlayerCharacter player, SendBallEntryMessage msg){
|
||||
//currently not handled.
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.GuildState;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.GuildManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.SendGuildEntryMsg;
|
||||
import engine.net.client.msg.guild.SwearInGuildMsg;
|
||||
import engine.objects.City;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SwearInGuildHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public SwearInGuildHandler() {
|
||||
super(SwearInGuildMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
PlayerCharacter player;
|
||||
SwearInGuildMsg swearInMsg;
|
||||
Guild targetGuild;
|
||||
Guild nation;
|
||||
Dispatch dispatch;
|
||||
|
||||
swearInMsg = (SwearInGuildMsg) baseMsg;
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
targetGuild = (Guild) DbManager.getObject(GameObjectType.Guild, swearInMsg.getGuildUUID());
|
||||
|
||||
if (targetGuild == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
nation = player.getGuild();
|
||||
|
||||
if (nation == null) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You do not belong to a guild!");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!nation.isNation()) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Your guild is not a nation!");
|
||||
return true;
|
||||
}
|
||||
if (!nation.getSubGuildList().contains(targetGuild)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Your do not have such authority!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Guild.canSwearIn(targetGuild)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, targetGuild.getGuildState().name() + "cannot be sworn in");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GuildStatusController.isGuildLeader(player.getGuildStatus()) == false){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Your do not have such authority!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!DbManager.GuildQueries.UPDATE_PARENT(targetGuild.getObjectUUID(), nation.getObjectUUID())) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "A Serious error has occured. Please post details for to ensure transaction integrity");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (targetGuild.getGuildState()) {
|
||||
case Petitioner:
|
||||
GuildManager.updateAllGuildBinds(targetGuild, nation.getOwnedCity());
|
||||
break;
|
||||
case Protectorate:
|
||||
break;
|
||||
default:
|
||||
//shouldn't get here.
|
||||
break;
|
||||
}
|
||||
|
||||
//update Guild state.
|
||||
targetGuild.setNation(nation);
|
||||
GuildManager.updateAllGuildTags(targetGuild);
|
||||
targetGuild.upgradeGuildState(false);
|
||||
|
||||
if (nation.getGuildState() == GuildState.Sovereign)
|
||||
nation.upgradeGuildState(true);
|
||||
|
||||
SendGuildEntryMsg msg = new SendGuildEntryMsg(player);
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
|
||||
ArrayList<PlayerCharacter> guildMembers = SessionManager.getActivePCsInGuildID(nation.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : guildMembers) {
|
||||
ChatManager.chatGuildInfo(member, "Your Guild is now a Nation!");
|
||||
}
|
||||
|
||||
ArrayList<PlayerCharacter> swornMembers = SessionManager.getActivePCsInGuildID(targetGuild.getObjectUUID());
|
||||
|
||||
for (PlayerCharacter member : swornMembers) {
|
||||
ChatManager.chatGuildInfo(member, "Your Guild has sword fealty to " + nation.getName() + '.');
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error( e.getMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.guild.GuildInfoMsg;
|
||||
import engine.net.client.msg.guild.GuildListMsg;
|
||||
import engine.net.client.msg.guild.SwearInMsg;
|
||||
import engine.objects.GuildStatusController;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class SwearInHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public SwearInHandler() {
|
||||
super(SwearInMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
SwearInMsg msg = (SwearInMsg) baseMsg;
|
||||
Dispatch dispatch;
|
||||
|
||||
// get source player
|
||||
PlayerCharacter source = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (source == null)
|
||||
return true;
|
||||
|
||||
// get target player
|
||||
PlayerCharacter target = SessionManager.getPlayerCharacterByID(msg.getTargetID());
|
||||
|
||||
if (target == null) {
|
||||
ChatManager.chatGuildError(source,
|
||||
"No such character found!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(source.getGuild() != target.getGuild()) {
|
||||
ChatManager.chatGuildError(source,
|
||||
"That player is not a member of " + source.getGuild().getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Verify source has authority to swear in
|
||||
if (GuildStatusController.isInnerCouncil(source.getGuildStatus()) == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(source, "Your do not have such authority!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Swear target in and send message to guild
|
||||
target.setFullMember(true);
|
||||
target.incVer();
|
||||
|
||||
ChatManager.chatGuildInfo(source,target.getFirstName() + " has been sworn in as a full member!");
|
||||
|
||||
dispatch = Dispatch.borrow(source, new GuildListMsg(source.getGuild()));
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
DispatchMessage.sendToAllInRange(target, new GuildInfoMsg(target, target.getGuild(), 2));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.InterestManagement.RealmMap;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.TaxCityMsg;
|
||||
import engine.net.client.msg.ViewResourcesMessage;
|
||||
import engine.objects.*;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* protecting and unprotecting city assets
|
||||
*/
|
||||
public class TaxCityMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public TaxCityMsgHandler() {
|
||||
super(TaxCityMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
TaxCityMsg msg;
|
||||
|
||||
player = origin.getPlayerCharacter();
|
||||
|
||||
|
||||
msg = (TaxCityMsg) baseMsg;
|
||||
|
||||
ViewTaxes(msg,player);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static boolean ViewTaxes(TaxCityMsg msg, PlayerCharacter player) {
|
||||
|
||||
// Member variable declaration
|
||||
Building building = BuildingManager.getBuildingFromCache(msg.getGuildID());
|
||||
Guild playerGuild = player.getGuild();
|
||||
|
||||
if (building == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!");
|
||||
return true;
|
||||
}
|
||||
|
||||
City city = building.getCity();
|
||||
if (city == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (city.getWarehouse() == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "This city does not have a warehouse!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (playerGuild == null || playerGuild.isErrant()){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You must belong to a guild to do that!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (playerGuild.getOwnedCity() == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a city!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (playerGuild.getOwnedCity().getWarehouse() == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a warehouse!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (playerGuild.getOwnedCity().getTOL() == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot find Tree of Life for your city!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// if (playerGuild.getOwnedCity().getTOL().getRank() != 8){
|
||||
// ErrorPopupMsg.sendErrorMsg(player, "Your City needs to Own a realm!");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
if (playerGuild.getOwnedCity().getRealm() == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for your city!");
|
||||
return true;
|
||||
}
|
||||
Realm targetRealm = RealmMap.getRealmForCity(city);
|
||||
|
||||
if (targetRealm == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot find realm for city you are attempting to tax!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// if (targetRealm.getRulingCity() == null){
|
||||
// ErrorPopupMsg.sendErrorMsg(player, "Realm Does not have a ruling city!");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// if (targetRealm.getRulingCity().getObjectUUID() != playerGuild.getOwnedCity().getObjectUUID()){
|
||||
// ErrorPopupMsg.sendErrorMsg(player, "Your guild does not rule this realm!");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// if (playerGuild.getOwnedCity().getObjectUUID() == city.getObjectUUID()){
|
||||
// ErrorPopupMsg.sendErrorMsg(player, "You cannot tax your own city!");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
if (!GuildStatusController.isTaxCollector(player.getGuildStatus())){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You Must be a tax Collector!");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// if (!city.isAfterTaxPeriod(DateTime.now(), player))
|
||||
// return true;
|
||||
|
||||
|
||||
|
||||
ViewResourcesMessage vrm = new ViewResourcesMessage(player);
|
||||
vrm.setGuild(building.getGuild());
|
||||
vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID()));
|
||||
vrm.configure();
|
||||
Dispatch dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
dispatch = Dispatch.borrow(player, vrm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.TaxResourcesMsg;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which handles
|
||||
* protecting and unprotecting city assets
|
||||
*/
|
||||
public class TaxResourcesMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public TaxResourcesMsgHandler() {
|
||||
super(TaxResourcesMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter player;
|
||||
TaxResourcesMsg msg;
|
||||
|
||||
player = origin.getPlayerCharacter();
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
msg = (TaxResourcesMsg) baseMsg;
|
||||
|
||||
TaxWarehouse(msg,player);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static boolean TaxWarehouse(TaxResourcesMsg msg, PlayerCharacter player) {
|
||||
|
||||
// Member variable declaration
|
||||
Building building = BuildingManager.getBuildingFromCache(msg.getBuildingID());
|
||||
|
||||
|
||||
if (building == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Not a valid Building!");
|
||||
return true;
|
||||
}
|
||||
|
||||
City city = building.getCity();
|
||||
if (city == null){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "This building does not belong to a city.");
|
||||
return true;
|
||||
}
|
||||
|
||||
city.TaxWarehouse(msg, player);
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.gameManager.GroupManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.group.GroupUpdateMsg;
|
||||
import engine.net.client.msg.group.ToggleGroupSplitMsg;
|
||||
import engine.objects.Group;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
public class ToggleGroupSplitHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public ToggleGroupSplitHandler() {
|
||||
super(ToggleGroupSplitMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
PlayerCharacter source;
|
||||
Group group;
|
||||
boolean split;
|
||||
|
||||
source = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
group = GroupManager.getGroup(source);
|
||||
|
||||
if (group == null)
|
||||
return false;
|
||||
|
||||
if (group.getGroupLead() != source) // Only group lead can toggle
|
||||
return false;
|
||||
|
||||
split = group.toggleSplitGold();
|
||||
|
||||
// update split button
|
||||
GroupUpdateMsg gum = new GroupUpdateMsg();
|
||||
gum.setGroup(group);
|
||||
gum.setMessageType(6);
|
||||
|
||||
group.sendUpdate(gum);
|
||||
|
||||
// Send split message
|
||||
|
||||
if (split)
|
||||
ChatManager.chatGroupInfo(source, "Treasure is now being split.");
|
||||
else
|
||||
ChatManager.chatGroupInfo(source, "Treasure is no longer being split.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.ChatManager;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.net.client.msg.TransferAssetMsg;
|
||||
import engine.objects.Blueprint;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which transers
|
||||
* assets between characters.
|
||||
*/
|
||||
|
||||
public class TransferAssetMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public TransferAssetMsgHandler() {
|
||||
super(TransferAssetMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
TransferAssetMsg transferAssetMsg = (TransferAssetMsg) baseMsg;
|
||||
|
||||
int Buildingid = transferAssetMsg.getObjectID();
|
||||
int BuildingType = transferAssetMsg.getObjectType(); //ToDue Later
|
||||
int TargetID = transferAssetMsg.getTargetID();
|
||||
int TargetType = transferAssetMsg.getTargetType(); //ToDue later
|
||||
|
||||
Building building = BuildingManager.getBuildingFromCache(Buildingid);
|
||||
PlayerCharacter newOwner = PlayerCharacter.getFromCache(TargetID);
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null || building == null || newOwner == null)
|
||||
return true;
|
||||
|
||||
Blueprint blueprint = building.getBlueprint();
|
||||
|
||||
if (blueprint == null)
|
||||
return true;
|
||||
|
||||
if (building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.MINE) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "You cannot transfer a mine!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Players cannot transfer shrines
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SHRINE)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer shrine!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Blueprint.isMeshWallPiece(building.getBlueprintUUID())) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer fortress asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer fortress asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BULWARK)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer siege asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SIEGETENT)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer siege asset!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((building.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BANESTONE)) {
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Cannot for to transfer banestone!");
|
||||
return true;
|
||||
}
|
||||
if (building.getOwnerUUID() != player.getObjectUUID()) {
|
||||
ChatManager.chatSystemError(player, "You do not own this asset.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (building.getOwnerUUID() == newOwner.getObjectUUID()) {
|
||||
ChatManager.chatSystemError(player, "You already own this asset.");
|
||||
return true;
|
||||
}
|
||||
|
||||
building.setOwner(newOwner);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.PlaceAssetMsg;
|
||||
import engine.net.client.msg.TransferGoldToFromBuildingMsg;
|
||||
import engine.net.client.msg.UpdateGoldMsg;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.CharacterItemManager;
|
||||
import engine.objects.Item;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
/*
|
||||
* @Author:
|
||||
* @Summary: Processes application protocol message which transfers
|
||||
* gold between a building's strongbox and a player character.
|
||||
*/
|
||||
|
||||
public class TransferGoldToFromBuildingMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public TransferGoldToFromBuildingMsgHandler() {
|
||||
super(TransferGoldToFromBuildingMsg.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player;
|
||||
Building building;
|
||||
CharacterItemManager itemMan;
|
||||
Item goldItem;
|
||||
TransferGoldToFromBuildingMsg msg;
|
||||
Dispatch dispatch;
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
msg = (TransferGoldToFromBuildingMsg) baseMsg;
|
||||
|
||||
building = BuildingManager.getBuildingFromCache(msg.getObjectID());
|
||||
|
||||
if (building == null)
|
||||
return true;
|
||||
|
||||
if (msg.getDirection() == 2){
|
||||
|
||||
if(!ManageCityAssetMsgHandler.playerCanManageNotFriends(player, building))
|
||||
return true;
|
||||
if (building.setReserve(msg.getUnknown01(),player)){
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// if (building.getTimeStamp(MBServerStatics.STRONGBOX_DELAY_STRING) > System.currentTimeMillis()){
|
||||
// ErrorPopupMsg.sendErrorMsg(player, MBServerStatics.STRONGBOX_DELAY_OUTPUT);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
//building.getTimestamps().put(MBServerStatics.STRONGBOX_DELAY_STRING, System.currentTimeMillis() + MBServerStatics.ONE_MINUTE);
|
||||
|
||||
itemMan = player.getCharItemManager();
|
||||
|
||||
goldItem = itemMan.getGoldInventory();
|
||||
|
||||
if (goldItem == null) {
|
||||
Logger.error("Could not access gold item");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Update in-game gold values for player and building
|
||||
|
||||
|
||||
try {
|
||||
|
||||
|
||||
if (!itemMan.transferGoldToFromBuilding(msg.getAmount(), building))
|
||||
return true;
|
||||
|
||||
|
||||
UpdateGoldMsg ugm = new UpdateGoldMsg(player);
|
||||
ugm.configure();
|
||||
dispatch = Dispatch.borrow(player, ugm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
// Refresh the player's inventory if it's currently open
|
||||
|
||||
// Refresh the tree's window to update strongbox
|
||||
|
||||
|
||||
msg.setAmount(building.getStrongboxValue());
|
||||
dispatch = Dispatch.borrow(player, msg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
} catch (Exception e) {
|
||||
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum.DispatchChannel;
|
||||
import engine.Enum.FriendStatus;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.ClientNetMsg;
|
||||
import engine.net.client.msg.UpdateFriendStatusMessage;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.PlayerFriends;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class UpdateFriendStatusHandler extends AbstractClientMsgHandler {
|
||||
|
||||
public UpdateFriendStatusHandler() {
|
||||
super(UpdateFriendStatusMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg,
|
||||
ClientConnection origin) throws MsgSendException {
|
||||
|
||||
PlayerCharacter player = origin.getPlayerCharacter();
|
||||
|
||||
if (player == null)
|
||||
return true;
|
||||
|
||||
|
||||
UpdateFriendStatusMessage msg = (UpdateFriendStatusMessage)baseMsg;
|
||||
|
||||
|
||||
HandleUpdateFriend(player,msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//change to Request
|
||||
public static void HandleUpdateFriend(PlayerCharacter player, UpdateFriendStatusMessage msg){
|
||||
FriendStatus friendStatus = FriendStatus.Available;
|
||||
|
||||
try {
|
||||
friendStatus = FriendStatus.values()[msg.statusType];
|
||||
}catch (Exception e){
|
||||
Logger.error(e);
|
||||
}
|
||||
player.friendStatus = friendStatus;
|
||||
SendUpdateToFriends(player);
|
||||
}
|
||||
|
||||
public static void SendUpdateToFriends(PlayerCharacter player){
|
||||
|
||||
HashSet<Integer> friends = PlayerFriends.PlayerFriendsMap.get(player.getObjectUUID());
|
||||
|
||||
if (friends == null)
|
||||
return;
|
||||
|
||||
UpdateFriendStatusMessage outMsg = new UpdateFriendStatusMessage(player);
|
||||
|
||||
for (int friendID : friends){
|
||||
PlayerCharacter playerFriend = SessionManager.getPlayerCharacterByID(friendID);
|
||||
if (playerFriend == null)
|
||||
return;
|
||||
Dispatch dispatch = Dispatch.borrow(playerFriend, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package engine.net.client.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.MsgSendException;
|
||||
import engine.gameManager.BuildingManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.msg.*;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static engine.net.client.msg.ErrorPopupMsg.sendErrorPopup;
|
||||
|
||||
/*
|
||||
*
|
||||
* @Summary: Processes application protocol message where a
|
||||
* client requests that a building be upgraded.
|
||||
*/
|
||||
public class UpgradeAssetMsgHandler extends AbstractClientMsgHandler {
|
||||
|
||||
// Constructor
|
||||
public UpgradeAssetMsgHandler() {
|
||||
|
||||
super(UpgradeAssetMessage.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
UpgradeAssetMessage msg;
|
||||
ManageCityAssetsMsg outMsg;
|
||||
PlayerCharacter player;
|
||||
int buildingUUID;
|
||||
Building buildingToRank;
|
||||
LocalDateTime dateToUpgrade;
|
||||
int nextRank;
|
||||
int rankCost;
|
||||
Dispatch dispatch;
|
||||
|
||||
// Assign member variables
|
||||
|
||||
msg = (UpgradeAssetMessage) baseMsg;
|
||||
|
||||
// Grab pointer to the requesting player
|
||||
|
||||
player = SessionManager.getPlayerCharacter(origin);
|
||||
|
||||
// Grab pointer to the building from the cache
|
||||
|
||||
buildingUUID = msg.getBuildingUUID();
|
||||
|
||||
buildingToRank = (Building) DbManager.getObject(GameObjectType.Building, buildingUUID);
|
||||
|
||||
// Early exit if building not in cache.
|
||||
|
||||
if (buildingToRank == null) {
|
||||
Logger.error("Attempt to upgrade null building by " + player.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Early exit for building that is already ranking
|
||||
|
||||
if (buildingToRank.isRanking()) {
|
||||
Logger.error("Attempt to upgrade a building already ranking by " + player.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Calculate and set time/cost to upgrade
|
||||
|
||||
nextRank = (buildingToRank.getRank() + 1);
|
||||
|
||||
if (buildingToRank.getBlueprint() == null)
|
||||
return true;
|
||||
if (buildingToRank.getBlueprint().getMaxRank() < nextRank || nextRank == 8){
|
||||
ErrorPopupMsg.sendErrorMsg(player, "Building is already at it's Max rank.");
|
||||
return true;
|
||||
}
|
||||
|
||||
rankCost = buildingToRank.getBlueprint().getRankCost(nextRank);
|
||||
|
||||
// SEND NOT ENOUGH GOLD ERROR
|
||||
|
||||
if (!buildingToRank.hasFunds(rankCost)){
|
||||
ErrorPopupMsg.sendErrorPopup(player, 127); // Not enough gold in strongbox
|
||||
return true;
|
||||
}
|
||||
|
||||
if (rankCost > buildingToRank.getStrongboxValue()) {
|
||||
sendErrorPopup(player, 127);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Validation appears good. Let's now process the upgrade
|
||||
|
||||
try {
|
||||
if (buildingToRank.getCity() != null){
|
||||
buildingToRank.getCity().transactionLock.writeLock().lock();
|
||||
try{
|
||||
if (!buildingToRank.transferGold(-rankCost,false)) {
|
||||
sendErrorPopup(player, 127);
|
||||
return true;
|
||||
}
|
||||
}catch(Exception e){
|
||||
Logger.error(e);
|
||||
}finally{
|
||||
buildingToRank.getCity().transactionLock.writeLock().unlock();
|
||||
}
|
||||
}else
|
||||
if (!buildingToRank.transferGold(-rankCost,false)) {
|
||||
sendErrorPopup(player, 127);
|
||||
return true;
|
||||
}
|
||||
|
||||
dateToUpgrade = LocalDateTime.now().plusHours(buildingToRank.getBlueprint().getRankTime(nextRank));
|
||||
|
||||
BuildingManager.setUpgradeDateTime(buildingToRank, dateToUpgrade, 0);
|
||||
|
||||
// Schedule upgrade job
|
||||
|
||||
BuildingManager.submitUpgradeJob(buildingToRank);
|
||||
|
||||
// Refresh the client's manage asset window
|
||||
// *** Refactor : We have some of these unknowns
|
||||
|
||||
outMsg = new ManageCityAssetsMsg(player, buildingToRank);
|
||||
|
||||
// Action TYPE
|
||||
outMsg.actionType = 3;
|
||||
outMsg.setTargetType(buildingToRank.getObjectType().ordinal());
|
||||
outMsg.setTargetID(buildingToRank.getObjectUUID());
|
||||
outMsg.setTargetType3(buildingToRank.getObjectType().ordinal());
|
||||
outMsg.setTargetID3(buildingToRank.getObjectUUID());
|
||||
outMsg.setAssetName1(buildingToRank.getName());
|
||||
outMsg.setUnknown54(1);
|
||||
|
||||
dispatch = Dispatch.borrow(player, outMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
} catch (Exception e) {
|
||||
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
|
||||
|
||||
public class AbandonAssetMsg extends ClientNetMsg {
|
||||
|
||||
private int pad = 0;
|
||||
private int objectType;
|
||||
private int objectUUID;
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AbandonAssetMsg(AbstractConnection origin, ByteBufferReader reader){
|
||||
super(Protocol.ABANDONASSET, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
this.pad = reader.getInt();
|
||||
this.objectType = reader.getInt();
|
||||
this.objectUUID = reader.getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
||||
writer.putInt(this.pad);
|
||||
writer.putInt(this.objectType);
|
||||
writer.putInt(this.objectUUID);
|
||||
}
|
||||
|
||||
public int getObjectType() {
|
||||
return objectType;
|
||||
}
|
||||
|
||||
public void setObjectType(int value) {
|
||||
this.objectType = value;
|
||||
}
|
||||
|
||||
public void setPad(int value) {
|
||||
this.pad = value;
|
||||
}
|
||||
|
||||
public int getUUID() {
|
||||
return objectUUID;
|
||||
|
||||
}
|
||||
|
||||
public int getPad() {
|
||||
return pad;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
HashSet<Integer> playerFriendSet = PlayerFriendsMap.get(playerUID);
|
||||
playerFriendSet.add(friendUID); * Copyright 2013 MagicBane Emulator Project
|
||||
* All Rights Reserved
|
||||
*/
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
|
||||
public class AcceptFriendMsg extends ClientNetMsg {
|
||||
|
||||
public String sourceName;
|
||||
public String friendName;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public AcceptFriendMsg(PlayerCharacter pc) {
|
||||
super(Protocol.FRIENDACCEPT);
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AcceptFriendMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.FRIENDACCEPT, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
public AcceptFriendMsg(AcceptFriendMsg msg) {
|
||||
super(Protocol.FRIENDACCEPT);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied ByteBufferReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
//Do we even want to try this?
|
||||
this.sourceName = reader.getString(); //This is source name.. this friends list must never been updated since launch, not using IDS.
|
||||
this.friendName = reader.getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied ByteBufferWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) {
|
||||
writer.putString(this.sourceName);
|
||||
writer.putString(this.friendName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.AbstractGameObject;
|
||||
|
||||
/**
|
||||
* Accept trade request
|
||||
*
|
||||
* @author Eighty
|
||||
*/
|
||||
public class AcceptTradeRequestMsg extends ClientNetMsg {
|
||||
|
||||
private int unknown01; //pad?
|
||||
private int playerType;
|
||||
private int playerID;
|
||||
private int targetType;
|
||||
private int targetID;
|
||||
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor
|
||||
*/
|
||||
public AcceptTradeRequestMsg(int unknown01, AbstractGameObject player, AbstractGameObject target) {
|
||||
super(Protocol.REQUESTTRADEOK);
|
||||
this.unknown01 = unknown01;
|
||||
this.playerType = player.getObjectType().ordinal();
|
||||
this.playerID =player.getObjectUUID();
|
||||
this.targetType = target.getObjectType().ordinal();
|
||||
this.targetID =target.getObjectUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AcceptTradeRequestMsg(AbstractConnection origin, ByteBufferReader reader)
|
||||
{
|
||||
super(Protocol.REQUESTTRADEOK, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader)
|
||||
{
|
||||
unknown01 = reader.getInt();
|
||||
playerType = reader.getInt();
|
||||
playerID = reader.getInt();
|
||||
targetType = reader.getInt();
|
||||
targetID = reader.getInt();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer)
|
||||
throws SerializationException {
|
||||
writer.putInt(unknown01);
|
||||
writer.putInt(playerType);
|
||||
writer.putInt(playerID);
|
||||
writer.putInt(targetType);
|
||||
writer.putInt(targetID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown01
|
||||
*/
|
||||
public int getUnknown01() {
|
||||
return unknown01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown01 the unknown01 to set
|
||||
*/
|
||||
public void setUnknown01(int unknown01) {
|
||||
this.unknown01 = unknown01;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public void setPlayerType(int playerType) {
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
public int getPlayerID() {
|
||||
return playerID;
|
||||
}
|
||||
|
||||
public void setPlayerID(int playerID) {
|
||||
this.playerID = playerID;
|
||||
}
|
||||
|
||||
public int getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public void setTargetType(int targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
public int getTargetID() {
|
||||
return targetID;
|
||||
}
|
||||
|
||||
public void setTargetID(int targetID) {
|
||||
this.targetID = targetID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
/**
|
||||
* Bank window opened
|
||||
*
|
||||
* @author Burfo
|
||||
*/
|
||||
public class AckBankWindowOpenedMsg extends ClientNetMsg {
|
||||
|
||||
private int playerType;
|
||||
private int playerID;
|
||||
private long unknown01; // possibly NPC ID?
|
||||
private long unknown02;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public AckBankWindowOpenedMsg(PlayerCharacter pc, long unknown01, long unknown02) {
|
||||
super(Protocol.COSTTOOPENBANK);
|
||||
this.playerType = pc.getObjectType().ordinal();
|
||||
this.playerID = pc.getObjectUUID();
|
||||
this.unknown01 = unknown01;
|
||||
this.unknown02 = unknown02;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AckBankWindowOpenedMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.COSTTOOPENBANK, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
playerType = reader.getInt();
|
||||
playerID = reader.getInt();
|
||||
unknown01 = reader.getLong();
|
||||
unknown02 = reader.getLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
||||
writer.putInt(playerType);
|
||||
writer.putInt(playerID);
|
||||
writer.putLong(unknown01);
|
||||
writer.putLong(unknown02);
|
||||
}
|
||||
public int getPlayerID() {
|
||||
return playerID;
|
||||
}
|
||||
|
||||
public void setPlayerID(int playerID) {
|
||||
this.playerID = playerID;
|
||||
}
|
||||
|
||||
public int getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public void setPlayerType(int playerType) {
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.AbstractNetMsg;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.Item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ActivateNPCMessage extends ClientNetMsg {
|
||||
|
||||
private ArrayList<Item> ItemList;
|
||||
private int unknown01;
|
||||
private int unknown02;
|
||||
private int buildingUUID;
|
||||
private int unknown03;
|
||||
private int unknown04;
|
||||
private int unknown05;
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public ActivateNPCMessage() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*
|
||||
*/
|
||||
public ActivateNPCMessage(ArrayList<Item> items) {
|
||||
super(Protocol.ACTIVATENPC);
|
||||
this.unknown01 = 0;
|
||||
this.size = 0;
|
||||
this.ItemList = items;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ActivateNPCMessage(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ACTIVATENPC, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AbstractNetMsg#getPowerOfTwoBufferSize()
|
||||
*/
|
||||
@Override
|
||||
protected int getPowerOfTwoBufferSize() {
|
||||
//Larger size for historically larger opcodes
|
||||
return (16); // 2^16 == 64k
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
writer.putInt(0);
|
||||
}
|
||||
writer.putInt(this.size);
|
||||
for (Item item : this.ItemList) {
|
||||
writer.putInt(item.getObjectType().ordinal());
|
||||
writer.putInt(item.getObjectUUID());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
unknown01 = reader.getInt();
|
||||
unknown02 = reader.getInt();
|
||||
reader.getInt(); // Object Type Padding
|
||||
buildingUUID = reader.getInt();
|
||||
unknown03 = reader.getInt();
|
||||
unknown04 = reader.getInt();
|
||||
unknown05 = reader.getInt();
|
||||
|
||||
}
|
||||
|
||||
// TODO fix ArrayList Accessability.
|
||||
|
||||
public int size() {
|
||||
return this.ItemList.size();
|
||||
}
|
||||
|
||||
public int getUnknown01() {
|
||||
return unknown01;
|
||||
}
|
||||
|
||||
public int getUnknown02() {
|
||||
return unknown02;
|
||||
}
|
||||
|
||||
public int getUnknown03() {
|
||||
return unknown03;
|
||||
}
|
||||
|
||||
public int getUnknown04() {
|
||||
return unknown04;
|
||||
}
|
||||
|
||||
public int getUnknown05() {
|
||||
return unknown05;
|
||||
}
|
||||
|
||||
public int buildingUUID() {
|
||||
return buildingUUID;
|
||||
}
|
||||
|
||||
public void setUnknown01(int unknown01) {
|
||||
this.unknown01 = unknown01;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void setUnknown02(int unknown02) {
|
||||
this.unknown02 = unknown02;
|
||||
}
|
||||
|
||||
public void setUnknown03(int unknown03) {
|
||||
this.unknown03 = unknown03;
|
||||
}
|
||||
|
||||
public void setUnknown04(int unknown04) {
|
||||
this.unknown04 = unknown04;
|
||||
}
|
||||
|
||||
public void setUnknown05(int unknown05) {
|
||||
this.unknown05 = unknown05;
|
||||
}
|
||||
|
||||
public void setItemList(ArrayList<Item> value) {
|
||||
this.ItemList = value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
HashSet<Integer> playerFriendSet = PlayerFriendsMap.get(playerUID);
|
||||
playerFriendSet.add(friendUID); * Copyright 2013 MagicBane Emulator Project
|
||||
* All Rights Reserved
|
||||
*/
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
|
||||
public class AddFriendMessage extends ClientNetMsg {
|
||||
|
||||
public PlayerCharacter friend;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public AddFriendMessage(PlayerCharacter pc) {
|
||||
super(Protocol.ADDFRIEND);
|
||||
friend = pc;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AddFriendMessage(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ADDFRIEND, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
public AddFriendMessage(AddFriendMessage msg) {
|
||||
super(Protocol.ADDFRIEND);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied ByteBufferReader.
|
||||
*/
|
||||
//message is serialize only, no need for deserialize.
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied ByteBufferWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) {
|
||||
writer.putInt(GameObjectType.PlayerCharacter.ordinal());
|
||||
writer.putInt(friend.getObjectUUID());
|
||||
writer.putString(friend.getName());
|
||||
writer.putInt(0); //possibly available, busy, away?
|
||||
writer.putInt(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
|
||||
|
||||
public class AddGoldToTradeWindowMsg extends ClientNetMsg {
|
||||
|
||||
private int unknown01;
|
||||
private long playerCompID;
|
||||
private int amount;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor
|
||||
*/
|
||||
public AddGoldToTradeWindowMsg(int unknown01, long playerCompID, int amount) {
|
||||
super(Protocol.TRADEADDGOLD);
|
||||
this.unknown01 = unknown01;
|
||||
this.playerCompID = playerCompID;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AddGoldToTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader)
|
||||
{
|
||||
super(Protocol.TRADEADDGOLD, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader)
|
||||
{
|
||||
unknown01 = reader.getInt();
|
||||
playerCompID = reader.getLong();
|
||||
amount = reader.getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer)
|
||||
throws SerializationException {
|
||||
writer.putInt(unknown01);
|
||||
writer.putLong(playerCompID);
|
||||
writer.putInt(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown01
|
||||
*/
|
||||
public int getUnknown01() {
|
||||
return unknown01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown01 the unknown01 to set
|
||||
*/
|
||||
public void setUnknown01(int unknown01) {
|
||||
this.unknown01 = unknown01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the amount
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setAmount(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.AbstractGameObject;
|
||||
|
||||
public class AddItemToTradeWindowMsg extends ClientNetMsg {
|
||||
|
||||
private int unknown01;
|
||||
private int playerType;
|
||||
private int playerID;
|
||||
private int itemID;
|
||||
private int itemType;
|
||||
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor
|
||||
*/
|
||||
public AddItemToTradeWindowMsg(int unknown01, AbstractGameObject player, AbstractGameObject item) {
|
||||
super(Protocol.TRADEADDOBJECT);
|
||||
this.unknown01 = unknown01;
|
||||
this.playerType = player.getObjectType().ordinal();
|
||||
this.playerID = player.getObjectUUID();
|
||||
this.itemType = item.getObjectType().ordinal();
|
||||
this.itemID = item.getObjectUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AddItemToTradeWindowMsg(AbstractConnection origin, ByteBufferReader reader)
|
||||
{
|
||||
super(Protocol.TRADEADDOBJECT, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader)
|
||||
{
|
||||
unknown01 = reader.getInt();
|
||||
playerType = reader.getInt();
|
||||
playerID = reader.getInt();
|
||||
itemType = reader.getInt();
|
||||
itemID = reader.getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer)
|
||||
throws SerializationException {
|
||||
writer.putInt(unknown01);
|
||||
writer.putInt(playerType);
|
||||
writer.putInt(playerID);
|
||||
writer.putInt(itemType);
|
||||
writer.putInt(itemID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown01
|
||||
*/
|
||||
public int getUnknown01() {
|
||||
return unknown01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown01 the unknown01 to set
|
||||
*/
|
||||
public void setUnknown01(int unknown01) {
|
||||
this.unknown01 = unknown01;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public int getPlayerType() {
|
||||
return playerType;
|
||||
}
|
||||
|
||||
public void setPlayerType(int playerType) {
|
||||
this.playerType = playerType;
|
||||
}
|
||||
|
||||
public int getPlayerID() {
|
||||
return playerID;
|
||||
}
|
||||
|
||||
public void setPlayerID(int playerID) {
|
||||
this.playerID = playerID;
|
||||
}
|
||||
|
||||
public int getItemID() {
|
||||
return itemID;
|
||||
}
|
||||
|
||||
public void setItemID(int itemID) {
|
||||
this.itemID = itemID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
|
||||
|
||||
public class AllianceChangeMsg extends ClientNetMsg {
|
||||
public final static int MAKE_ENEMY = 4;
|
||||
public final static int MAKE_ALLY = 6;
|
||||
public final static int REMOVE = 7;
|
||||
public final static byte INFO_SUCCESS = 0;
|
||||
public final static byte ERROR_NOT_RECOMMENDED = 1;
|
||||
public final static byte ERROR_NOT_SAME_GUILD = 2;
|
||||
public final static byte ERROR_NOT_AUTHORIZED = 4;
|
||||
public final static byte ERROR_NOT_SAME_FACTION = 7;
|
||||
public final static byte ERROR_TOO_MANY = 13;
|
||||
public final static byte ERROR_TO0_EARLY = 14;
|
||||
private byte msgType;
|
||||
private int sourceGuildID;
|
||||
private int targetGuildID;
|
||||
private int secondsToWait;
|
||||
private boolean ally;
|
||||
|
||||
|
||||
public AllianceChangeMsg(PlayerCharacter player, int sourceGuildID,int targetGuildID, byte msgType, int secondsToWait) {
|
||||
super(Protocol.ALLIANCECHANGE);
|
||||
this.sourceGuildID = sourceGuildID;
|
||||
this.targetGuildID = targetGuildID;
|
||||
this.msgType = msgType;
|
||||
this.secondsToWait = secondsToWait;
|
||||
|
||||
}
|
||||
|
||||
public AllianceChangeMsg() {
|
||||
super(Protocol.ALLIANCECHANGE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AllianceChangeMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ALLIANCECHANGE, origin, reader);
|
||||
}
|
||||
//CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD.
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
this.msgType = reader.get();
|
||||
|
||||
switch (this.msgType){
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case MAKE_ENEMY:
|
||||
case MAKE_ALLY:
|
||||
case REMOVE:
|
||||
case 5:
|
||||
reader.getInt(); //source guild type;
|
||||
this.sourceGuildID = reader.getInt();
|
||||
reader.getInt();
|
||||
this.targetGuildID = reader.getInt();
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Precache and configure this message before we serialize it
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
||||
writer.put(this.msgType);
|
||||
if (this.msgType == ERROR_TO0_EARLY)
|
||||
writer.putInt(this.secondsToWait);
|
||||
writer.putInt(GameObjectType.Guild.ordinal());
|
||||
writer.putInt(this.sourceGuildID);
|
||||
writer.putInt(GameObjectType.Guild.ordinal());
|
||||
writer.putInt(this.targetGuildID);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int getSecondsToWait() {
|
||||
return secondsToWait;
|
||||
}
|
||||
|
||||
public void setSecondsToWait(int secondsToWait) {
|
||||
this.secondsToWait = secondsToWait;
|
||||
}
|
||||
|
||||
public int getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
public int getSourceGuildID() {
|
||||
return sourceGuildID;
|
||||
}
|
||||
|
||||
public int getTargetGuildID() {
|
||||
return targetGuildID;
|
||||
}
|
||||
|
||||
public boolean isAlly() {
|
||||
return ally;
|
||||
}
|
||||
|
||||
public void setMsgType(byte msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.GuildAlliances;
|
||||
import engine.objects.GuildTag;
|
||||
import engine.objects.PlayerCharacter;
|
||||
|
||||
|
||||
|
||||
public class AllyEnemyListMsg extends ClientNetMsg {
|
||||
|
||||
|
||||
private int guildID;
|
||||
|
||||
|
||||
public AllyEnemyListMsg(PlayerCharacter player) {
|
||||
super(Protocol.ALLYENEMYLIST);
|
||||
this.guildID = player.getGuildUUID();
|
||||
|
||||
}
|
||||
|
||||
public AllyEnemyListMsg() {
|
||||
super(Protocol.ALLYENEMYLIST);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public AllyEnemyListMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ALLYENEMYLIST, origin, reader);
|
||||
}
|
||||
//CALL THIS AFTER SANITY CHECKS AND BEFORE UPDATING HEALTH/GOLD.
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
reader.getInt();
|
||||
this.guildID = reader.getInt();
|
||||
}
|
||||
|
||||
|
||||
// Precache and configure this message before we serialize it
|
||||
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
||||
|
||||
writer.putInt(GameObjectType.Guild.ordinal());
|
||||
writer.putInt(this.guildID);
|
||||
|
||||
Guild guild = Guild.getGuild(this.guildID);
|
||||
|
||||
writer.putInt(guild.getAllyList().size());
|
||||
|
||||
for (Guild ally: guild.getAllyList()){
|
||||
writer.putInt(GameObjectType.Guild.ordinal());//guildType
|
||||
writer.putInt(ally.getObjectUUID());//GuildID
|
||||
writer.putString(ally.getName());
|
||||
GuildTag._serializeForDisplay(ally.getGuildTag(),writer);
|
||||
writer.put((byte)0);
|
||||
}
|
||||
|
||||
|
||||
writer.putInt(guild.getEnemyList().size());
|
||||
|
||||
for (Guild enemy: guild.getEnemyList()){
|
||||
writer.putInt(GameObjectType.Guild.ordinal());//guildType
|
||||
writer.putInt(enemy.getObjectUUID());//GuildID
|
||||
writer.putString(enemy.getName());
|
||||
GuildTag._serializeForDisplay(enemy.getGuildTag(),writer);
|
||||
writer.put((byte)1);
|
||||
}
|
||||
|
||||
|
||||
writer.putInt(guild.getRecommendList().size());
|
||||
for (Guild recommended: guild.getRecommendList()){
|
||||
|
||||
GuildAlliances guildAlliance = guild.guildAlliances.get(recommended.getObjectUUID());
|
||||
writer.putInt(GameObjectType.Guild.ordinal());//guildType
|
||||
writer.putInt(recommended.getObjectUUID());//GuildID
|
||||
writer.putString(recommended.getName());
|
||||
GuildTag._serializeForDisplay(recommended.getGuildTag(),writer);
|
||||
writer.put((byte)1); // ?
|
||||
writer.putString(guildAlliance.getRecommender()); // recommender name.
|
||||
writer.put((byte) (guildAlliance.isAlly()?1:0)); //ally 1 enemy 0
|
||||
|
||||
}
|
||||
|
||||
writer.put((byte)1);
|
||||
|
||||
}
|
||||
|
||||
public int getGuildID() {
|
||||
return guildID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
|
||||
|
||||
public class ApplyBuildingEffectMsg extends ClientNetMsg {
|
||||
|
||||
protected int unknown01;
|
||||
protected int unknown02;
|
||||
protected int buildingType;
|
||||
protected int buildingID;
|
||||
protected int unknown03;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public ApplyBuildingEffectMsg() {
|
||||
super(Protocol.VISUALUPDATE);
|
||||
}
|
||||
|
||||
public ApplyBuildingEffectMsg(int unknown01, int unknown02, int buildingType, int buildingID, int unknown03) {
|
||||
super(Protocol.VISUALUPDATE);
|
||||
this.unknown01 = unknown01;
|
||||
this.unknown02 = unknown02;
|
||||
this.buildingType = buildingType;
|
||||
this.buildingID = buildingID;
|
||||
this.unknown03 = unknown03;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ApplyBuildingEffectMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.VISUALUPDATE, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) {
|
||||
writer.putInt(this.unknown01);
|
||||
writer.putInt(this.unknown02);
|
||||
if (this.unknown02 == 0){
|
||||
writer.putInt(this.unknown03);
|
||||
writer.putInt(this.buildingType);
|
||||
writer.putInt(this.buildingID);
|
||||
writer.putInt(0);
|
||||
return;
|
||||
}
|
||||
writer.putInt(this.buildingType);
|
||||
writer.putInt(this.buildingID);
|
||||
writer.putInt(this.unknown03);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
}
|
||||
|
||||
public void setUnknown01(int unknown01) {
|
||||
this.unknown01 = unknown01;
|
||||
}
|
||||
|
||||
public void setUnknown02(int unknown02) {
|
||||
this.unknown02 = unknown02;
|
||||
}
|
||||
|
||||
public void setBuildingID(int buildingID) {
|
||||
this.buildingID = buildingID;
|
||||
}
|
||||
|
||||
public void setUnknown03(int unknown03) {
|
||||
this.unknown03 = unknown03;
|
||||
}
|
||||
|
||||
public int getUnknown01() {
|
||||
return unknown01;
|
||||
}
|
||||
|
||||
public int getUnknown02() {
|
||||
return unknown02;
|
||||
}
|
||||
|
||||
public int getBuildingID() {
|
||||
return buildingID;
|
||||
}
|
||||
|
||||
public int getUnknown03() {
|
||||
return unknown03;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
|
||||
public class ApplyEffectMsg extends ClientNetMsg {
|
||||
|
||||
protected int numTrains;
|
||||
protected int effectID;
|
||||
protected int sourceType;
|
||||
protected int sourceID;
|
||||
protected int targetType;
|
||||
protected int targetID;
|
||||
|
||||
protected int unknown02;
|
||||
protected int unknown03;
|
||||
protected int duration;
|
||||
protected int unknown05;
|
||||
protected byte unknown06;
|
||||
|
||||
protected int powerUsedID;
|
||||
|
||||
protected String powerUsedName;
|
||||
private int effectSourceType = 0;
|
||||
private int effectSourceID = 0;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public ApplyEffectMsg() {
|
||||
super(Protocol.POWERACTION);
|
||||
this.numTrains = 0;
|
||||
this.effectID = 0;
|
||||
this.sourceType = 0;
|
||||
this.sourceID = 0;
|
||||
this.targetType = 0;
|
||||
this.targetID = 0;
|
||||
|
||||
this.unknown02 = 0;
|
||||
this.unknown03 = 0;
|
||||
this.duration = 0;
|
||||
this.unknown05 = 0;
|
||||
this.unknown06 = (byte) 0;
|
||||
|
||||
this.powerUsedID = 0;
|
||||
this.powerUsedName = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public ApplyEffectMsg(AbstractWorldObject source, AbstractWorldObject target, int numTrains, int effectID, int duration,
|
||||
int powerUsedID, String powerUsedName) {
|
||||
super(Protocol.POWERACTION);
|
||||
this.numTrains = numTrains;
|
||||
this.effectID = effectID;
|
||||
|
||||
if (source != null) {
|
||||
this.sourceType = source.getObjectType().ordinal();
|
||||
this.sourceID = source.getObjectUUID();
|
||||
} else {
|
||||
this.sourceType = 0;
|
||||
this.sourceID = 0;
|
||||
}
|
||||
|
||||
if (target != null) {
|
||||
this.targetType = target.getObjectType().ordinal();
|
||||
this.targetID = target.getObjectUUID();
|
||||
} else {
|
||||
this.targetType = 0;
|
||||
this.targetID = 0;
|
||||
}
|
||||
this.unknown02 = 0;
|
||||
this.unknown03 = 0;
|
||||
this.duration = duration;
|
||||
this.unknown05 = 0;
|
||||
this.unknown06 = (byte) 0;
|
||||
|
||||
this.powerUsedID = powerUsedID;
|
||||
this.powerUsedName = powerUsedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ApplyEffectMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.POWERACTION, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) {
|
||||
writer.putInt(this.numTrains);
|
||||
writer.putInt(this.effectID);
|
||||
|
||||
writer.putInt(this.sourceType);
|
||||
writer.putInt(this.sourceID);
|
||||
writer.putInt(this.targetType);
|
||||
writer.putInt(this.targetID);
|
||||
|
||||
writer.putInt(this.unknown02);
|
||||
writer.putInt(this.unknown03);
|
||||
writer.putInt(this.duration);
|
||||
writer.putInt(this.unknown05);
|
||||
writer.put(this.unknown06);
|
||||
|
||||
if (this.unknown06 == (byte) 1) {
|
||||
writer.putInt(this.effectSourceType);
|
||||
writer.putInt(this.effectSourceID);
|
||||
}
|
||||
|
||||
else {
|
||||
writer.putInt(this.powerUsedID);
|
||||
}
|
||||
|
||||
writer.putString(this.powerUsedName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
this.numTrains = reader.getInt();
|
||||
this.effectID = reader.getInt();
|
||||
|
||||
this.sourceType = reader.getInt();
|
||||
this.sourceID = reader.getInt();
|
||||
this.targetType = reader.getInt();
|
||||
this.targetID = reader.getInt();
|
||||
|
||||
this.unknown02 = reader.getInt();
|
||||
this.unknown03 = reader.getInt();
|
||||
this.duration = reader.getInt();
|
||||
this.unknown05 = reader.getInt();
|
||||
this.unknown06 = reader.get();
|
||||
|
||||
this.powerUsedID = reader.getInt();
|
||||
|
||||
this.powerUsedName = reader.getString();
|
||||
}
|
||||
|
||||
public int getNumTrains() {
|
||||
return this.numTrains;
|
||||
}
|
||||
|
||||
public int getEffectID() {
|
||||
return this.effectID;
|
||||
}
|
||||
|
||||
public int getSourceType() {
|
||||
return this.sourceType;
|
||||
}
|
||||
|
||||
public int getSourceID() {
|
||||
return this.sourceID;
|
||||
}
|
||||
|
||||
public int getTargetType() {
|
||||
return this.targetType;
|
||||
}
|
||||
|
||||
public int getTargetID() {
|
||||
return this.targetID;
|
||||
}
|
||||
|
||||
public int getUnknown02() {
|
||||
return this.unknown02;
|
||||
}
|
||||
|
||||
public int getUnknown03() {
|
||||
return this.unknown03;
|
||||
}
|
||||
|
||||
public int getDuration() {
|
||||
return this.duration;
|
||||
}
|
||||
|
||||
public int getUnknown05() {
|
||||
return this.unknown05;
|
||||
}
|
||||
|
||||
public byte getUnknown06() {
|
||||
return this.unknown06;
|
||||
}
|
||||
|
||||
public void setNumTrains(int value) {
|
||||
this.numTrains = value;
|
||||
}
|
||||
|
||||
public void setEffectID(int value) {
|
||||
this.effectID = value;
|
||||
}
|
||||
|
||||
public void setSourceType(int value) {
|
||||
this.sourceType = value;
|
||||
}
|
||||
|
||||
public void setSourceID(int value) {
|
||||
this.sourceID = value;
|
||||
}
|
||||
|
||||
public void setTargetType(int value) {
|
||||
this.targetType = value;
|
||||
}
|
||||
|
||||
public void setTargetID(int value) {
|
||||
this.targetID = value;
|
||||
}
|
||||
|
||||
public void setUnknown02(int value) {
|
||||
this.unknown02 = value;
|
||||
}
|
||||
|
||||
public void setUnknown03(int value) {
|
||||
this.unknown03 = value;
|
||||
}
|
||||
|
||||
public void setDuration(int value) {
|
||||
this.duration = value;
|
||||
}
|
||||
|
||||
public void setUnknown05(int value) {
|
||||
this.unknown05 = value;
|
||||
}
|
||||
|
||||
public void setUnknown06(byte value) {
|
||||
this.unknown06 = value;
|
||||
}
|
||||
|
||||
public void setPowerUsedID(int value) {
|
||||
this.powerUsedID = value;
|
||||
}
|
||||
|
||||
public void setPowerUsedName(String value) {
|
||||
this.powerUsedName = value;
|
||||
}
|
||||
|
||||
public void setEffectSourceType(int effectSourceType) {
|
||||
this.effectSourceType = effectSourceType;
|
||||
}
|
||||
|
||||
public void setEffectSourceID(int effectSourceID) {
|
||||
this.effectSourceID = effectSourceID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.net.*;
|
||||
import engine.net.client.ClientConnection;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.CharacterRune;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.RuneBase;
|
||||
import engine.objects.RuneBaseAttribute;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ApplyRuneMsg extends ClientNetMsg {
|
||||
|
||||
private int targetType;
|
||||
private int targetID;
|
||||
private int removeRuneBase;
|
||||
private int runeBase;
|
||||
private int runeType;
|
||||
private int runeID;
|
||||
private Boolean isPromo;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public ApplyRuneMsg(int targetType, int targetID, int runeBase, int runeType, int runeID, Boolean isPromo) {
|
||||
super(Protocol.SETRUNE);
|
||||
this.targetType = targetType;
|
||||
this.targetID = targetID;
|
||||
this.runeBase = runeBase;
|
||||
this.runeType = runeType;
|
||||
this.runeID = runeID;
|
||||
this.isPromo = isPromo;
|
||||
this.removeRuneBase = 0;
|
||||
}
|
||||
|
||||
public ApplyRuneMsg(int targetType, int targetID, int removeRuneBase) {
|
||||
super(Protocol.SETRUNE);
|
||||
this.targetType = targetType;
|
||||
this.targetID = targetID;
|
||||
this.runeBase = 0;
|
||||
this.runeType = 0;
|
||||
this.runeID = 0;
|
||||
this.isPromo = false;
|
||||
this.removeRuneBase = removeRuneBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ApplyRuneMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.SETRUNE, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) {
|
||||
writer.putInt(this.targetType);
|
||||
writer.putInt(this.targetID);
|
||||
writer.putInt(0);
|
||||
writer.putInt(this.removeRuneBase);
|
||||
writer.putInt(0);
|
||||
writer.putInt(this.runeBase);
|
||||
writer.putInt(this.runeType);
|
||||
writer.putInt(this.runeID);
|
||||
if (this.isPromo) {
|
||||
writer.put((byte) 1);
|
||||
} else {
|
||||
writer.put((byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
this.targetType = reader.getInt();
|
||||
this.targetID = reader.getInt();
|
||||
reader.getInt();
|
||||
this.removeRuneBase = reader.getInt();
|
||||
reader.getInt();
|
||||
this.runeBase = reader.getInt();
|
||||
this.runeType = reader.getInt();
|
||||
this.runeID = reader.getInt();
|
||||
this.isPromo = (reader.get() == 1) ? true : false;
|
||||
}
|
||||
|
||||
public int getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public void setTargetType(int value) {
|
||||
this.targetType = value;
|
||||
}
|
||||
|
||||
public int getTargetID() {
|
||||
return targetID;
|
||||
}
|
||||
|
||||
public void setTargetID(int value) {
|
||||
this.targetID = value;
|
||||
}
|
||||
|
||||
public int getRuneID() {
|
||||
return runeID;
|
||||
}
|
||||
|
||||
public void setRuneID(int value) {
|
||||
this.runeID = value;
|
||||
}
|
||||
|
||||
public static boolean applyRune(int runeID, ClientConnection origin, PlayerCharacter playerCharacter) {
|
||||
|
||||
RuneBase rb = RuneBase.getRuneBase(runeID);
|
||||
Dispatch dispatch;
|
||||
|
||||
if (playerCharacter == null || origin == null || rb == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Check race is met
|
||||
ConcurrentHashMap<Integer, Boolean> races = rb.getRace();
|
||||
if (races.size() > 0) {
|
||||
int raceID = playerCharacter.getRaceID();
|
||||
boolean valid = false;
|
||||
for (int validID : races.keySet()) {
|
||||
if (validID == raceID) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Check base class is met
|
||||
ConcurrentHashMap<Integer, Boolean> baseClasses = rb.getBaseClass();
|
||||
if (baseClasses.size() > 0) {
|
||||
int baseClassID = playerCharacter.getBaseClassID();
|
||||
boolean valid = false;
|
||||
for (int validID : baseClasses.keySet()) {
|
||||
if (validID == baseClassID) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Check promotion class is met
|
||||
ConcurrentHashMap<Integer, Boolean> promotionClasses = rb.getPromotionClass();
|
||||
if (promotionClasses.size() > 0) {
|
||||
int promotionClassID = playerCharacter.getPromotionClassID();
|
||||
boolean valid = false;
|
||||
for (int validID : promotionClasses.keySet()) {
|
||||
if (validID == promotionClassID) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Check disciplines are met
|
||||
ArrayList<CharacterRune> runes = playerCharacter.getRunes();
|
||||
ConcurrentHashMap<Integer, Boolean> disciplines = rb.getDiscipline();
|
||||
if (disciplines.size() > 0) {
|
||||
for (CharacterRune cr : runes) {
|
||||
int runeBaseID = cr.getRuneBaseID();
|
||||
for (Integer prohID : disciplines.keySet()) {
|
||||
if (runeBaseID == prohID) {
|
||||
return false; //Prohibited rune
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int discCount = 0;
|
||||
for (CharacterRune cr : runes) {
|
||||
int runeBaseID = cr.getRuneBaseID();
|
||||
//count number of discipline runes
|
||||
if (runeBaseID > 3000 && runeBaseID < 3049) {
|
||||
discCount++;
|
||||
}
|
||||
//see if rune is already applied
|
||||
if (runeBaseID == runeID) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Check level is met
|
||||
if (playerCharacter.getLevel() < rb.getLevelRequired()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int strTotal = 0;
|
||||
int dexTotal = 0;
|
||||
int conTotal = 0;
|
||||
int intTotal = 0;
|
||||
int spiTotal = 0;
|
||||
int cost = 0;
|
||||
|
||||
//Check any attributes are met
|
||||
ArrayList<RuneBaseAttribute> attrs = rb.getAttrs();
|
||||
|
||||
if (rb.getAttrs() != null)
|
||||
for (RuneBaseAttribute rba : attrs) {
|
||||
int attrID = rba.getAttributeID();
|
||||
int mod = rba.getModValue();
|
||||
switch (attrID) {
|
||||
case MBServerStatics.RUNE_COST_ATTRIBUTE_ID:
|
||||
if (mod > playerCharacter.getUnusedStatPoints()) {
|
||||
return false;
|
||||
}
|
||||
cost = mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID:
|
||||
if ((int) playerCharacter.statStrBase < mod) {
|
||||
return false;
|
||||
}
|
||||
strTotal = mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID:
|
||||
if ((int) playerCharacter.statDexBase < mod) {
|
||||
return false;
|
||||
}
|
||||
dexTotal = mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID:
|
||||
if ((int) playerCharacter.statConBase < mod) {
|
||||
return false;
|
||||
}
|
||||
conTotal = mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID:
|
||||
if ((int) playerCharacter.statIntBase < mod) {
|
||||
return false;
|
||||
}
|
||||
intTotal = mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID:
|
||||
if ((int) playerCharacter.statSpiBase < mod) {
|
||||
return false;
|
||||
}
|
||||
spiTotal = mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_STR_ATTRIBUTE_ID:
|
||||
strTotal += mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_DEX_ATTRIBUTE_ID:
|
||||
dexTotal += mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_CON_ATTRIBUTE_ID:
|
||||
conTotal += mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_INT_ATTRIBUTE_ID:
|
||||
intTotal += mod;
|
||||
break;
|
||||
case MBServerStatics.RUNE_SPI_ATTRIBUTE_ID:
|
||||
spiTotal += mod;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Check if max number runes already reached
|
||||
if (runes.size() > 12) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//if discipline, check number applied
|
||||
if (isDiscipline(runeID)) {
|
||||
if (playerCharacter.getLevel() < 70) {
|
||||
if (discCount > 2) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (discCount > 3) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Everything succeeded. Let's apply the rune
|
||||
//Attempt add rune to database
|
||||
CharacterRune runeWithoutID = new CharacterRune(rb, playerCharacter.getObjectUUID());
|
||||
CharacterRune cr;
|
||||
try {
|
||||
cr = DbManager.CharacterRuneQueries.ADD_CHARACTER_RUNE(runeWithoutID);
|
||||
} catch (Exception e) {
|
||||
cr = null;
|
||||
Logger.error(e);
|
||||
}
|
||||
if (cr == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//remove any overridden runes from player
|
||||
ArrayList<Integer> overwrite = rb.getOverwrite();
|
||||
CharacterRune toRemove = null;
|
||||
if (overwrite.size() > 0) {
|
||||
for (int overwriteID : overwrite) {
|
||||
toRemove = playerCharacter.removeRune(overwriteID);
|
||||
}
|
||||
}
|
||||
|
||||
//add rune to player
|
||||
playerCharacter.addRune(cr);
|
||||
|
||||
// recalculate all bonuses/formulas/skills/powers
|
||||
playerCharacter.recalculate();
|
||||
|
||||
//if overwriting a stat rune, add any amount granted from previous rune.
|
||||
if (toRemove != null) {
|
||||
RuneBase rbs = toRemove.getRuneBase();
|
||||
if (rbs != null && rbs.getObjectUUID() > 249999 && rbs.getObjectUUID() < 250045) {
|
||||
//add any additional stats to match old amount
|
||||
int dif = strTotal - (int) playerCharacter.statStrBase;
|
||||
if (dif > 0 && strTotal < (int) playerCharacter.statStrMax) {
|
||||
playerCharacter.addStr(dif);
|
||||
}
|
||||
dif = dexTotal - (int) playerCharacter.statDexBase;
|
||||
if (dif > 0 && dexTotal < (int) playerCharacter.statDexMax) {
|
||||
playerCharacter.addDex(dif);
|
||||
}
|
||||
dif = conTotal - (int) playerCharacter.statConBase;
|
||||
if (dif > 0 && conTotal < (int) playerCharacter.statConMax) {
|
||||
playerCharacter.addCon(dif);
|
||||
}
|
||||
dif = intTotal - (int) playerCharacter.statIntBase;
|
||||
if (dif > 0 && intTotal < (int) playerCharacter.statIntMax) {
|
||||
playerCharacter.addInt(dif);
|
||||
}
|
||||
dif = spiTotal - (int) playerCharacter.statSpiBase;
|
||||
if (dif > 0 && spiTotal < (int) playerCharacter.statSpiMax) {
|
||||
playerCharacter.addSpi(dif);
|
||||
}
|
||||
|
||||
// recalculate all bonuses/formulas/skills/powers
|
||||
playerCharacter.recalculate();
|
||||
}
|
||||
}
|
||||
|
||||
if (cost > 0) {
|
||||
ModifyStatMsg msm = new ModifyStatMsg((0 - cost), 0, 3);
|
||||
dispatch = Dispatch.borrow(playerCharacter, msm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
}
|
||||
|
||||
//send apply rune message to client
|
||||
ApplyRuneMsg arm = new ApplyRuneMsg(playerCharacter.getObjectType().ordinal(), playerCharacter.getObjectUUID(), runeID, cr.getObjectType().ordinal(), cr.getObjectUUID(), false);
|
||||
dispatch = Dispatch.borrow(playerCharacter, arm);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
|
||||
|
||||
|
||||
//alert them of success
|
||||
ErrorPopupMsg.sendErrorPopup(playerCharacter, 160);
|
||||
|
||||
//reapply bonuses
|
||||
playerCharacter.applyBonuses();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isDiscipline(int runeID) {
|
||||
|
||||
return runeID > 3000 && runeID < 3050;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
|
||||
public class ArcLoginNotifyMsg extends ClientNetMsg {
|
||||
|
||||
private int unknown01;
|
||||
private int unknown02;
|
||||
private int unknown03;
|
||||
private short unknown04;
|
||||
private byte unknown05;
|
||||
|
||||
/**
|
||||
* This is the general purpose constructor.
|
||||
*/
|
||||
public ArcLoginNotifyMsg() {
|
||||
super(Protocol.ARCLOGINNOTIFY);
|
||||
this.unknown01 = 0x40A5BDB0;
|
||||
this.unknown02 = 0x342AA9F0;
|
||||
this.unknown03 = 0;
|
||||
this.unknown04 = (short) 0;
|
||||
this.unknown05 = (byte) 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ArcLoginNotifyMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ARCLOGINNOTIFY, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) {
|
||||
writer.putInt(this.unknown01);
|
||||
writer.putInt(this.unknown02);
|
||||
writer.putInt(this.unknown03);
|
||||
writer.putShort(this.unknown04);
|
||||
writer.put(this.unknown05);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
this.unknown01 = reader.getInt();
|
||||
this.unknown02 = reader.getInt();
|
||||
this.unknown03 = reader.getInt();
|
||||
this.unknown04 = reader.getShort();
|
||||
this.unknown05 = reader.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown01
|
||||
*/
|
||||
public int getUnknown01() {
|
||||
return unknown01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown01
|
||||
* the unknown01 to set
|
||||
*/
|
||||
public void setUnknown01(int unknown01) {
|
||||
this.unknown01 = unknown01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown02
|
||||
*/
|
||||
public int getUnknown02() {
|
||||
return unknown02;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown02
|
||||
* the unknown02 to set
|
||||
*/
|
||||
public void setUnknown02(int unknown02) {
|
||||
this.unknown02 = unknown02;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown03
|
||||
*/
|
||||
public int getUnknown03() {
|
||||
return unknown03;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown03
|
||||
* the unknown03 to set
|
||||
*/
|
||||
public void setUnknown03(int unknown03) {
|
||||
this.unknown03 = unknown03;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown04
|
||||
*/
|
||||
public short getUnknown04() {
|
||||
return unknown04;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown04
|
||||
* the unknown04 to set
|
||||
*/
|
||||
public void setUnknown04(short unknown04) {
|
||||
this.unknown04 = unknown04;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the unknown05
|
||||
*/
|
||||
public byte getUnknown05() {
|
||||
return unknown05;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unknown05
|
||||
* the unknown05 to set
|
||||
*/
|
||||
public void setUnknown05(byte unknown05) {
|
||||
this.unknown05 = unknown05;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
|
||||
public class ArcMineChangeProductionMsg extends ClientNetMsg {
|
||||
|
||||
private int mineID;
|
||||
private int resourceHash;
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ArcMineChangeProductionMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ARCMINECHANGEPRODUCTION, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
this.mineID = reader.getInt();
|
||||
this.resourceHash = reader.getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
||||
writer.putInt(this.mineID);
|
||||
writer.putInt(this.resourceHash);
|
||||
}
|
||||
|
||||
public int getMineID() {
|
||||
return this.mineID;
|
||||
}
|
||||
|
||||
public int getResourceHash() {
|
||||
return this.resourceHash;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.Guild;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Seconds;
|
||||
|
||||
public class ArcMineWindowAvailableTimeMsg extends ClientNetMsg {
|
||||
|
||||
private int buildingUUID;
|
||||
private Building treeOfLife;
|
||||
|
||||
private int currentMineHour;
|
||||
private Seconds secondsLeft;
|
||||
private DateTime lateTime;
|
||||
private int late;
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ArcMineWindowAvailableTimeMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ARCMINEWINDOWAVAILABLETIME, origin, reader);
|
||||
}
|
||||
|
||||
public ArcMineWindowAvailableTimeMsg(Building treeOfLife, int timeLeft) {
|
||||
super(Protocol.ARCMINEWINDOWAVAILABLETIME);
|
||||
this.treeOfLife = treeOfLife;
|
||||
this.buildingUUID = treeOfLife.getObjectUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
reader.getInt();
|
||||
reader.getInt();
|
||||
reader.getInt();
|
||||
reader.getInt(); // Object type padding (We know it's a building)
|
||||
this.buildingUUID = reader.getInt();
|
||||
reader.getInt();
|
||||
|
||||
}
|
||||
|
||||
// Configures and pre-caches values for this message
|
||||
// so everything is already available during serialisation.
|
||||
|
||||
public void configure() {
|
||||
|
||||
Guild guild;
|
||||
guild = this.treeOfLife.getGuild();
|
||||
|
||||
if (guild != null)
|
||||
currentMineHour = guild.getMineTime();
|
||||
|
||||
late = MBServerStatics.MINE_LATE_WINDOW;
|
||||
lateTime = DateTime.now();
|
||||
|
||||
if (late == 0)
|
||||
lateTime = lateTime.plusDays(1);
|
||||
|
||||
lateTime = lateTime.hourOfDay().setCopy(late);
|
||||
|
||||
late = ((late > 23) ? (late - 24) : late);
|
||||
secondsLeft = Seconds.secondsBetween(DateTime.now(), lateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
||||
|
||||
writer.putInt(MBServerStatics.MINE_EARLY_WINDOW); //15);
|
||||
writer.putInt(late);
|
||||
writer.putInt(currentMineHour);
|
||||
|
||||
writer.putInt(this.treeOfLife.getObjectType().ordinal());
|
||||
writer.putInt(this.treeOfLife.getObjectUUID());
|
||||
|
||||
writer.putInt((int)secondsLeft.getSeconds());
|
||||
}
|
||||
|
||||
public int getBuildingUUID() {
|
||||
return buildingUUID;
|
||||
}
|
||||
|
||||
public void setBuildingUUID(int buildingUUID) {
|
||||
this.buildingUUID = buildingUUID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.net.client.msg;
|
||||
|
||||
|
||||
import engine.exception.SerializationException;
|
||||
import engine.net.AbstractConnection;
|
||||
import engine.net.ByteBufferReader;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.Protocol;
|
||||
|
||||
public class ArcMineWindowChangeMsg extends ClientNetMsg {
|
||||
|
||||
private int time;
|
||||
private int buildingType;
|
||||
private int buildingID;
|
||||
|
||||
/**
|
||||
* This constructor is used by NetMsgFactory. It attempts to deserialize the
|
||||
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
|
||||
* past the limit) then this constructor Throws that Exception to the
|
||||
* caller.
|
||||
*/
|
||||
public ArcMineWindowChangeMsg(AbstractConnection origin, ByteBufferReader reader) {
|
||||
super(Protocol.ARCMINEWINDOWCHANGE, origin, reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes the subclass specific items from the supplied NetMsgReader.
|
||||
*/
|
||||
@Override
|
||||
protected void _deserialize(ByteBufferReader reader) {
|
||||
this.time = reader.getInt();
|
||||
this.buildingType = reader.getInt();
|
||||
this.buildingID = reader.getInt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the subclass specific items to the supplied NetMsgWriter.
|
||||
*/
|
||||
@Override
|
||||
protected void _serialize(ByteBufferWriter writer) throws SerializationException {
|
||||
writer.putInt(this.time);
|
||||
writer.putInt(this.buildingType);
|
||||
writer.putInt(this.buildingID);
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
public int getBuildingID() {
|
||||
return this.buildingID;
|
||||
}
|
||||
|
||||
public void setTime(int value) {
|
||||
this.time = value;
|
||||
}
|
||||
|
||||
public void setBuildingID(int value) {
|
||||
this.buildingID = value;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user