mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 00:31:51 +00:00
more stuff
This commit is contained in:
@@ -6,14 +6,19 @@ import redone.game.players.Client;
|
||||
import redone.game.players.Player;
|
||||
import redone.game.players.PlayerHandler;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static redone.game.players.PlayerSave.loadPlayerInfo;
|
||||
|
||||
public class Bot {
|
||||
|
||||
private Client botClient;
|
||||
static Timer timer = new Timer();
|
||||
|
||||
public Bot(String username) {
|
||||
botClient = new Client(null, -1);
|
||||
botClient = new Client(null);
|
||||
botClient.playerName = username;
|
||||
|
||||
botClient.playerName = username;
|
||||
@@ -31,9 +36,26 @@ public class Bot {
|
||||
System.out.println(botClient.getPlayerAssistant().getTotalLevel());
|
||||
Server.playerHandler.newPlayerClient(botClient);
|
||||
loadPlayerInfo(botClient, username, "bot_password", false);
|
||||
new TradeChat().run();
|
||||
}
|
||||
|
||||
public Client getBotClient() {
|
||||
return botClient;
|
||||
}
|
||||
|
||||
class TradeChat extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
sendTradeChat();
|
||||
int delay = (15 + new Random().nextInt(25)) * 1000;
|
||||
timer.schedule(new TradeChat(), delay);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendTradeChat() {
|
||||
botClient.setChatTextColor(9);
|
||||
botClient.setChatTextEffects(2);
|
||||
botClient.forcedChat("<col=#FF0033>Selling Rune Platebody 210k ea - " + botClient.playerName + "</col>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class BotHandler
|
||||
return;
|
||||
}
|
||||
|
||||
final String botName = "bot" + random.nextInt(9999) + random.nextInt(9999);
|
||||
final String botName = "bot" + random.nextInt(9999);
|
||||
|
||||
bot = new Bot(botName);
|
||||
botList.add(bot);
|
||||
|
||||
@@ -1804,7 +1804,8 @@ public class ItemAssistant {
|
||||
}
|
||||
|
||||
if (totalItems != totalItemsAfter) {
|
||||
c.disconnected = true;
|
||||
if (!c.isBot)
|
||||
c.disconnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1826,15 +1827,19 @@ public class ItemAssistant {
|
||||
|
||||
public void resetBank() {
|
||||
synchronized (c) {
|
||||
c.getOutStream().createFrameVarSizeWord(53);
|
||||
c.getOutStream().writeWord(5382); // bank
|
||||
c.getOutStream().writeWord(Constants.BANK_SIZE);
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().createFrameVarSizeWord(53);
|
||||
c.getOutStream().writeWord(5382); // bank
|
||||
c.getOutStream().writeWord(Constants.BANK_SIZE);
|
||||
}
|
||||
for (int i = 0; i < Constants.BANK_SIZE; i++) {
|
||||
if (c.bankItemsN[i] > 254) {
|
||||
c.getOutStream().writeByte(255);
|
||||
c.getOutStream().writeDWord_v2(c.bankItemsN[i]);
|
||||
} else {
|
||||
c.getOutStream().writeByte(c.bankItemsN[i]);
|
||||
if (c.getOutStream() != null) {
|
||||
if (c.bankItemsN[i] > 254) {
|
||||
c.getOutStream().writeByte(255);
|
||||
c.getOutStream().writeDWord_v2(c.bankItemsN[i]);
|
||||
} else {
|
||||
c.getOutStream().writeByte(c.bankItemsN[i]);
|
||||
}
|
||||
}
|
||||
if (c.bankItemsN[i] < 1) {
|
||||
c.bankItems[i] = 0;
|
||||
@@ -1842,10 +1847,15 @@ public class ItemAssistant {
|
||||
if (c.bankItems[i] > Constants.ITEM_LIMIT || c.bankItems[i] < 0) {
|
||||
c.bankItems[i] = Constants.ITEM_LIMIT;
|
||||
}
|
||||
c.getOutStream().writeWordBigEndianA(c.bankItems[i]);
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().writeWordBigEndianA(c.bankItems[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().endFrameVarSizeWord();
|
||||
c.flushOutStream();
|
||||
}
|
||||
c.getOutStream().endFrameVarSizeWord();
|
||||
c.flushOutStream();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1857,24 +1867,32 @@ public class ItemAssistant {
|
||||
itemCount = i;
|
||||
}
|
||||
}
|
||||
c.getOutStream().createFrameVarSizeWord(53);
|
||||
c.getOutStream().writeWord(5064);
|
||||
c.getOutStream().writeWord(itemCount + 1);
|
||||
if (c.getOutStream() != null){
|
||||
c.getOutStream().createFrameVarSizeWord(53);
|
||||
c.getOutStream().writeWord(5064);
|
||||
c.getOutStream().writeWord(itemCount + 1);
|
||||
}
|
||||
for (int i = 0; i < itemCount + 1; i++) {
|
||||
if (c.playerItemsN[i] > 254) {
|
||||
c.getOutStream().writeByte(255);
|
||||
c.getOutStream().writeDWord_v2(c.playerItemsN[i]);
|
||||
} else {
|
||||
c.getOutStream().writeByte(c.playerItemsN[i]);
|
||||
|
||||
if (c.getOutStream() != null) {
|
||||
if (c.playerItemsN[i] > 254) {
|
||||
c.getOutStream().writeByte(255);
|
||||
c.getOutStream().writeDWord_v2(c.playerItemsN[i]);
|
||||
} else {
|
||||
c.getOutStream().writeByte(c.playerItemsN[i]);
|
||||
}
|
||||
}
|
||||
if (c.playerItems[i] > Constants.ITEM_LIMIT || c.playerItems[i] < 0) {
|
||||
c.playerItems[i] = Constants.ITEM_LIMIT;
|
||||
}
|
||||
c.getOutStream().writeWordBigEndianA(c.playerItems[i]);
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().writeWordBigEndianA(c.playerItems[i]);
|
||||
}
|
||||
}
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().endFrameVarSizeWord();
|
||||
c.flushOutStream();
|
||||
}
|
||||
c.getOutStream().endFrameVarSizeWord();
|
||||
c.flushOutStream();
|
||||
// }
|
||||
}
|
||||
|
||||
public boolean bankItem(int itemID, int fromSlot, int amount) {
|
||||
@@ -2287,18 +2305,20 @@ public class ItemAssistant {
|
||||
|
||||
public void setEquipment(int wearID, int amount, int targetSlot) {
|
||||
// synchronized(c) {
|
||||
c.getOutStream().createFrameVarSizeWord(34);
|
||||
c.getOutStream().writeWord(1688);
|
||||
c.getOutStream().writeByte(targetSlot);
|
||||
c.getOutStream().writeWord(wearID + 1);
|
||||
if (amount > 254) {
|
||||
c.getOutStream().writeByte(255);
|
||||
c.getOutStream().writeDWord(amount);
|
||||
} else {
|
||||
c.getOutStream().writeByte(amount);
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().createFrameVarSizeWord(34);
|
||||
c.getOutStream().writeWord(1688);
|
||||
c.getOutStream().writeByte(targetSlot);
|
||||
c.getOutStream().writeWord(wearID + 1);
|
||||
if (amount > 254) {
|
||||
c.getOutStream().writeByte(255);
|
||||
c.getOutStream().writeDWord(amount);
|
||||
} else {
|
||||
c.getOutStream().writeByte(amount);
|
||||
}
|
||||
c.getOutStream().endFrameVarSizeWord();
|
||||
c.flushOutStream();
|
||||
}
|
||||
c.getOutStream().endFrameVarSizeWord();
|
||||
c.flushOutStream();
|
||||
c.playerEquipment[targetSlot] = wearID;
|
||||
c.playerEquipmentN[targetSlot] = amount;
|
||||
c.updateRequired = true;
|
||||
@@ -2385,12 +2405,15 @@ public class ItemAssistant {
|
||||
|
||||
c.playerEquipment[j] = -1;
|
||||
c.playerEquipmentN[j] = c.playerEquipmentN[j] - 1;
|
||||
c.getOutStream().createFrame(34);
|
||||
c.getOutStream().writeWord(6);
|
||||
c.getOutStream().writeWord(1688);
|
||||
c.getOutStream().writeByte(j);
|
||||
c.getOutStream().writeWord(0);
|
||||
c.getOutStream().writeByte(0);
|
||||
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().createFrame(34);
|
||||
c.getOutStream().writeWord(6);
|
||||
c.getOutStream().writeWord(1688);
|
||||
c.getOutStream().writeByte(j);
|
||||
c.getOutStream().writeWord(0);
|
||||
c.getOutStream().writeByte(0);
|
||||
}
|
||||
getBonus();
|
||||
if (j == c.playerWeapon) {
|
||||
sendWeapon(-1, "Unarmed");
|
||||
|
||||
@@ -97,24 +97,27 @@ public class Npc {
|
||||
|
||||
|
||||
public void updateNPCMovement(Stream str) {
|
||||
if (direction == -1) {
|
||||
|
||||
if (updateRequired) {
|
||||
if (str != null) {
|
||||
if (direction == -1) {
|
||||
|
||||
if (updateRequired) {
|
||||
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 0);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
}
|
||||
} else {
|
||||
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 0);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
}
|
||||
} else {
|
||||
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 1);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[direction]);
|
||||
if (updateRequired) {
|
||||
str.writeBits(1, 1);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
str.writeBits(2, 1);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[direction]);
|
||||
if (updateRequired) {
|
||||
str.writeBits(1, 1);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,6 +439,16 @@ public class Client extends Player {
|
||||
public int timeOutCounter = 0;
|
||||
public int returnCode = 2;
|
||||
|
||||
// used for bots
|
||||
public Client(IoSession s) {
|
||||
super(-1);
|
||||
isBot = true;
|
||||
session = null;
|
||||
inStream = new Stream(new byte[Constants.BUFFER_SIZE]);
|
||||
inStream.currentOffset = 0;
|
||||
buffer = new byte[Constants.BUFFER_SIZE];
|
||||
}
|
||||
|
||||
public Client(IoSession s, int _playerId) {
|
||||
super(_playerId);
|
||||
session = s;
|
||||
@@ -478,7 +488,7 @@ public class Client extends Player {
|
||||
}
|
||||
|
||||
public void flushOutStream() {
|
||||
if (disconnected || outStream.currentOffset == 0) {
|
||||
if (disconnected || outStream == null || outStream.currentOffset == 0) {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
@@ -492,12 +502,14 @@ public class Client extends Player {
|
||||
}
|
||||
|
||||
public void sendClan(String name, String message, String clan, int rights) {
|
||||
outStream.createFrameVarSizeWord(217);
|
||||
outStream.writeString(name);
|
||||
outStream.writeString(message);
|
||||
outStream.writeString(clan);
|
||||
outStream.writeWord(rights);
|
||||
outStream.endFrameVarSize();
|
||||
if (outStream != null) {
|
||||
outStream.createFrameVarSizeWord(217);
|
||||
outStream.writeString(name);
|
||||
outStream.writeString(message);
|
||||
outStream.writeString(clan);
|
||||
outStream.writeWord(rights);
|
||||
outStream.endFrameVarSize();
|
||||
}
|
||||
}
|
||||
|
||||
public static final int PACKET_SIZES[] = { 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, // 0
|
||||
@@ -603,17 +615,18 @@ public class Client extends Player {
|
||||
return;
|
||||
}
|
||||
synchronized (this) {
|
||||
outStream.createFrame(249);
|
||||
outStream.writeByteA(membership ? 1 : 0);
|
||||
outStream.writeWordBigEndianA(playerId);
|
||||
for (int j = 0; j < PlayerHandler.players.length; j++) {
|
||||
if (j == playerId) {
|
||||
continue;
|
||||
}
|
||||
if (PlayerHandler.players[j] != null) {
|
||||
if (PlayerHandler.players[j].playerName
|
||||
.equalsIgnoreCase(playerName)) {
|
||||
disconnected = true;
|
||||
if (getOutStream() != null) {
|
||||
outStream.createFrame(249);
|
||||
outStream.writeByteA(membership ? 1 : 0);
|
||||
outStream.writeWordBigEndianA(playerId);
|
||||
for (int j = 0; j < PlayerHandler.players.length; j++) {
|
||||
if (j == playerId) {
|
||||
continue;
|
||||
}
|
||||
if (PlayerHandler.players[j] != null) {
|
||||
if (PlayerHandler.players[j].playerName.equalsIgnoreCase(playerName)) {
|
||||
disconnected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1242,10 +1255,12 @@ public class Client extends Player {
|
||||
System.out.println("Playing sound " + c.playerName
|
||||
+ ", Id: " + SOUNDID + ", Vol: "
|
||||
+ c.soundVolume);
|
||||
c.getOutStream().createFrame(174);
|
||||
c.getOutStream().writeWord(SOUNDID);
|
||||
c.getOutStream().writeByte(c.soundVolume);
|
||||
c.getOutStream().writeWord( /* delay */0);
|
||||
if (c.getOutStream() != null) {
|
||||
c.getOutStream().createFrame(174);
|
||||
c.getOutStream().writeWord(SOUNDID);
|
||||
c.getOutStream().writeByte(c.soundVolume);
|
||||
c.getOutStream().writeWord( /* delay */0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class Player {
|
||||
|
||||
public String currentTime, date, creationAddress = "", slayerMaster;
|
||||
|
||||
public boolean lostCannon = false, refresh = false;
|
||||
public boolean lostCannon = false, refresh = false, isBot = false;
|
||||
|
||||
public ArrayList<String> killedPlayers = new ArrayList<String>();
|
||||
public ArrayList<Integer> attackedPlayers = new ArrayList<Integer>();
|
||||
@@ -1079,65 +1079,75 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY,
|
||||
}
|
||||
|
||||
public void updateThisPlayerMovement(Stream str) {
|
||||
if (mapRegionDidChange) {
|
||||
str.createFrame(73);
|
||||
str.writeWordA(mapRegionX + 6);
|
||||
str.writeWord(mapRegionY + 6);
|
||||
}
|
||||
|
||||
if (didTeleport) {
|
||||
str.createFrameVarSizeWord(81);
|
||||
str.initBitAccess();
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 3);
|
||||
str.writeBits(2, heightLevel);
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(1, updateRequired ? 1 : 0);
|
||||
str.writeBits(7, currentY);
|
||||
str.writeBits(7, currentX);
|
||||
return;
|
||||
}
|
||||
if (str != null) {
|
||||
if (mapRegionDidChange) {
|
||||
str.createFrame(73);
|
||||
str.writeWordA(mapRegionX + 6);
|
||||
str.writeWord(mapRegionY + 6);
|
||||
}
|
||||
|
||||
if (didTeleport) {
|
||||
str.createFrameVarSizeWord(81);
|
||||
str.initBitAccess();
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 3);
|
||||
str.writeBits(2, heightLevel);
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(1, updateRequired ? 1 : 0);
|
||||
str.writeBits(7, currentY);
|
||||
str.writeBits(7, currentX);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (dir1 == -1) {
|
||||
// don't have to update the character position, because we're
|
||||
// just standing
|
||||
str.createFrameVarSizeWord(81);
|
||||
str.initBitAccess();
|
||||
isMoving = false;
|
||||
if (updateRequired) {
|
||||
// tell client there's an update block appended at the end
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 0);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
if (str != null){
|
||||
str.createFrameVarSizeWord(81);
|
||||
str.initBitAccess();
|
||||
isMoving = false;
|
||||
if (updateRequired) {
|
||||
// tell client there's an update block appended at the end
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 0);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
}
|
||||
}
|
||||
if (DirectionCount < 50) {
|
||||
DirectionCount++;
|
||||
}
|
||||
} else {
|
||||
DirectionCount = 0;
|
||||
str.createFrameVarSizeWord(81);
|
||||
str.initBitAccess();
|
||||
str.writeBits(1, 1);
|
||||
if (str != null) {
|
||||
str.createFrameVarSizeWord(81);
|
||||
str.initBitAccess();
|
||||
str.writeBits(1, 1);
|
||||
}
|
||||
|
||||
if (dir2 == -1) {
|
||||
isMoving = true;
|
||||
str.writeBits(2, 1);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
|
||||
if (updateRequired) {
|
||||
str.writeBits(1, 1);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
if (str != null) {
|
||||
str.writeBits(2, 1);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
|
||||
if (updateRequired) {
|
||||
str.writeBits(1, 1);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isMoving = true;
|
||||
str.writeBits(2, 2);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
|
||||
if (updateRequired) {
|
||||
str.writeBits(1, 1);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
if (str != null) {
|
||||
str.writeBits(2, 2);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
|
||||
if (updateRequired) {
|
||||
str.writeBits(1, 1);
|
||||
} else {
|
||||
str.writeBits(1, 0);
|
||||
}
|
||||
}
|
||||
if (playerEnergy > 0 && playerRights < 2) {
|
||||
// calculations from https://oldschool.runescape.wiki/w/Energy
|
||||
@@ -1156,9 +1166,11 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY,
|
||||
}
|
||||
|
||||
public void updatePlayerMovement(Stream str) {
|
||||
if (str == null)
|
||||
return;
|
||||
|
||||
if (dir1 == -1) {
|
||||
if (updateRequired || isChatTextUpdateRequired()) {
|
||||
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 0);
|
||||
} else {
|
||||
@@ -1169,16 +1181,14 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY,
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 1);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
|
||||
str.writeBits(1, updateRequired || isChatTextUpdateRequired() ? 1
|
||||
: 0);
|
||||
str.writeBits(1, updateRequired || isChatTextUpdateRequired() ? 1 : 0);
|
||||
} else {
|
||||
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 2);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir1]);
|
||||
str.writeBits(3, Misc.xlateDirectionToClient[dir2]);
|
||||
str.writeBits(1, updateRequired || isChatTextUpdateRequired() ? 1
|
||||
: 0);
|
||||
str.writeBits(1, updateRequired || isChatTextUpdateRequired() ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1189,35 +1199,50 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY,
|
||||
npcInListBitmap[id >> 3] |= 1 << (id & 7);
|
||||
npcList[npcListSize++] = npc;
|
||||
|
||||
str.writeBits(14, id);
|
||||
if (str != null) {
|
||||
str.writeBits(14, id);
|
||||
}
|
||||
|
||||
int z = npc.absY - absY;
|
||||
if (z < 0) {
|
||||
z += 32;
|
||||
}
|
||||
str.writeBits(5, z);
|
||||
|
||||
if (str != null) {
|
||||
str.writeBits(5, z);
|
||||
}
|
||||
|
||||
z = npc.absX - absX;
|
||||
if (z < 0) {
|
||||
z += 32;
|
||||
}
|
||||
str.writeBits(5, z);
|
||||
|
||||
str.writeBits(1, 0);
|
||||
str.writeBits(12, npc.npcType);
|
||||
if (str != null) {
|
||||
str.writeBits(5, z);
|
||||
|
||||
str.writeBits(1, 0);
|
||||
str.writeBits(12, npc.npcType);
|
||||
}
|
||||
|
||||
boolean savedUpdateRequired = npc.updateRequired;
|
||||
npc.updateRequired = true;
|
||||
npc.appendNPCUpdateBlock(updateBlock);
|
||||
npc.updateRequired = savedUpdateRequired;
|
||||
str.writeBits(1, 1);
|
||||
|
||||
if (str != null) {
|
||||
str.writeBits(1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewPlayer(Player plr, Stream str, Stream updateBlock) {
|
||||
int id = plr.playerId;
|
||||
playerInListBitmap[id >> 3] |= 1 << (id & 7);
|
||||
playerList[playerListSize++] = plr;
|
||||
str.writeBits(11, id);
|
||||
str.writeBits(1, 1);
|
||||
|
||||
if (str != null) {
|
||||
str.writeBits(11, id);
|
||||
str.writeBits(1, 1);
|
||||
}
|
||||
boolean savedFlag = plr.isAppearanceUpdateRequired();
|
||||
boolean savedUpdateRequired = plr.updateRequired;
|
||||
plr.setAppearanceUpdateRequired(true);
|
||||
@@ -1225,17 +1250,26 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY,
|
||||
plr.appendPlayerUpdateBlock(updateBlock);
|
||||
plr.setAppearanceUpdateRequired(savedFlag);
|
||||
plr.updateRequired = savedUpdateRequired;
|
||||
str.writeBits(1, 1);
|
||||
if (str != null) {
|
||||
str.writeBits(1, 1);
|
||||
}
|
||||
int z = plr.absY - absY;
|
||||
if (z < 0) {
|
||||
z += 32;
|
||||
}
|
||||
str.writeBits(5, z);
|
||||
|
||||
if (str != null) {
|
||||
str.writeBits(5, z);
|
||||
}
|
||||
|
||||
z = plr.absX - absX;
|
||||
if (z < 0) {
|
||||
z += 32;
|
||||
}
|
||||
str.writeBits(5, z);
|
||||
|
||||
if (str != null) {
|
||||
str.writeBits(5, z);
|
||||
}
|
||||
}
|
||||
|
||||
public int headIcon = -1, bountyIcon = 0;
|
||||
@@ -1920,8 +1954,7 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY,
|
||||
continue;
|
||||
}
|
||||
if (PlayerHandler.players[j] != null) {
|
||||
if (PlayerHandler.players[j].playerName
|
||||
.equalsIgnoreCase(playerName)) {
|
||||
if (PlayerHandler.players[j].playerName.equalsIgnoreCase(playerName)) {
|
||||
disconnected = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ public class PlayerHandler {
|
||||
client1.playerId = slot;
|
||||
players[slot] = client1;
|
||||
players[slot].isActive = true;
|
||||
players[slot].connectedFrom = ((InetSocketAddress) client1.getSession()
|
||||
.getRemoteAddress()).getAddress().getHostAddress();
|
||||
players[slot].connectedFrom = client1.isBot ? "127.0.0.1" : ((InetSocketAddress) client1.getSession().getRemoteAddress()).getAddress().getHostAddress();
|
||||
if (Constants.SERVER_DEBUG) {
|
||||
Misc.println("Player Slot " + slot + " slot 0 " + players[0]
|
||||
+ " Player Hit " + players[slot]);
|
||||
@@ -265,24 +264,26 @@ public class PlayerHandler {
|
||||
public void updateNPC(Player plr, Stream str) {
|
||||
// synchronized(plr) {
|
||||
updateBlock.currentOffset = 0;
|
||||
if (str != null) {
|
||||
str.createFrameVarSizeWord(65);
|
||||
str.initBitAccess();
|
||||
|
||||
str.createFrameVarSizeWord(65);
|
||||
str.initBitAccess();
|
||||
|
||||
str.writeBits(8, plr.npcListSize);
|
||||
str.writeBits(8, plr.npcListSize);
|
||||
}
|
||||
int size = plr.npcListSize;
|
||||
plr.npcListSize = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (plr.RebuildNPCList == false
|
||||
&& plr.withinDistance(plr.npcList[i]) == true) {
|
||||
if (plr.RebuildNPCList == false && plr.withinDistance(plr.npcList[i]) == true) {
|
||||
plr.npcList[i].updateNPCMovement(str);
|
||||
plr.npcList[i].appendNPCUpdateBlock(updateBlock);
|
||||
plr.npcList[plr.npcListSize++] = plr.npcList[i];
|
||||
} else {
|
||||
int id = plr.npcList[i].npcId;
|
||||
plr.npcInListBitmap[id >> 3] &= ~(1 << (id & 7));
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 3);
|
||||
if (str != null) {
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Npc i : NpcHandler.npcs) {
|
||||
@@ -299,32 +300,36 @@ public class PlayerHandler {
|
||||
|
||||
plr.RebuildNPCList = false;
|
||||
|
||||
if (updateBlock.currentOffset > 0) {
|
||||
str.writeBits(14, 16383);
|
||||
str.finishBitAccess();
|
||||
str.writeBytes(updateBlock.buffer, updateBlock.currentOffset, 0);
|
||||
} else {
|
||||
str.finishBitAccess();
|
||||
if (str != null) {
|
||||
if (updateBlock.currentOffset > 0) {
|
||||
str.writeBits(14, 16383);
|
||||
str.finishBitAccess();
|
||||
str.writeBytes(updateBlock.buffer, updateBlock.currentOffset, 0);
|
||||
} else {
|
||||
str.finishBitAccess();
|
||||
}
|
||||
str.endFrameVarSizeWord();
|
||||
}
|
||||
str.endFrameVarSizeWord();
|
||||
}
|
||||
|
||||
private final Stream updateBlock = new Stream(
|
||||
new byte[Constants.BUFFER_SIZE]);
|
||||
|
||||
public void updatePlayer(Player plr, Stream str) {
|
||||
public void updatePlayer(Player plr, Stream outStr) {
|
||||
// synchronized(plr) {
|
||||
updateBlock.currentOffset = 0;
|
||||
if (updateRunning && !updateAnnounced) {
|
||||
str.createFrame(114);
|
||||
str.writeWordBigEndian(updateSeconds * 50 / 30);
|
||||
if (updateRunning && !updateAnnounced && outStr != null) {
|
||||
outStr.createFrame(114);
|
||||
outStr.writeWordBigEndian(updateSeconds * 50 / 30);
|
||||
}
|
||||
plr.updateThisPlayerMovement(str);
|
||||
plr.updateThisPlayerMovement(outStr);
|
||||
boolean saveChatTextUpdate = plr.isChatTextUpdateRequired();
|
||||
plr.setChatTextUpdateRequired(false);
|
||||
plr.appendPlayerUpdateBlock(updateBlock);
|
||||
plr.setChatTextUpdateRequired(saveChatTextUpdate);
|
||||
str.writeBits(8, plr.playerListSize);
|
||||
if (outStr != null) {
|
||||
outStr.writeBits(8, plr.playerListSize);
|
||||
}
|
||||
int size = plr.playerListSize;
|
||||
if (size > 255) {
|
||||
size = 255;
|
||||
@@ -333,14 +338,17 @@ public class PlayerHandler {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (!plr.didTeleport && !plr.playerList[i].didTeleport
|
||||
&& plr.withinDistance(plr.playerList[i])) {
|
||||
plr.playerList[i].updatePlayerMovement(str);
|
||||
plr.playerList[i].updatePlayerMovement(outStr);
|
||||
plr.playerList[i].appendPlayerUpdateBlock(updateBlock);
|
||||
plr.playerList[plr.playerListSize++] = plr.playerList[i];
|
||||
} else {
|
||||
int id = plr.playerList[i].playerId;
|
||||
plr.playerInListBitmap[id >> 3] &= ~(1 << (id & 7));
|
||||
str.writeBits(1, 1);
|
||||
str.writeBits(2, 3);
|
||||
|
||||
if (outStr != null) {
|
||||
outStr.writeBits(1, 1);
|
||||
outStr.writeBits(2, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < PlayerHandler.players.length; i++) {
|
||||
@@ -354,17 +362,19 @@ public class PlayerHandler {
|
||||
if (!plr.withinDistance(players[i])) {
|
||||
continue;
|
||||
}
|
||||
plr.addNewPlayer(players[i], str, updateBlock);
|
||||
}
|
||||
if (updateBlock.currentOffset > 0) {
|
||||
str.writeBits(11, 2047);
|
||||
str.finishBitAccess();
|
||||
str.writeBytes(updateBlock.buffer, updateBlock.currentOffset, 0);
|
||||
} else {
|
||||
str.finishBitAccess();
|
||||
plr.addNewPlayer(players[i], outStr, updateBlock);
|
||||
}
|
||||
if (outStr != null) {
|
||||
if (updateBlock.currentOffset > 0) {
|
||||
outStr.writeBits(11, 2047);
|
||||
outStr.finishBitAccess();
|
||||
outStr.writeBytes(updateBlock.buffer, updateBlock.currentOffset, 0);
|
||||
} else {
|
||||
outStr.finishBitAccess();
|
||||
}
|
||||
|
||||
str.endFrameVarSizeWord();
|
||||
outStr.endFrameVarSizeWord();
|
||||
}
|
||||
|
||||
if (plr.refresh) {
|
||||
GlobalDropsHandler.reset((Client)plr);
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ActionSender {
|
||||
|
||||
|
||||
public ActionSender sendClan(String name, String message, String clan, int rights) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
player.outStream.createFrameVarSizeWord(217);
|
||||
player.outStream.writeString(name);
|
||||
player.outStream.writeString(message);
|
||||
@@ -28,6 +29,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender createPlayersObjectAnim(int X, int Y, int animationID, int tileObjectType, int orientation) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
try{
|
||||
player.getOutStream().createFrame(85);
|
||||
player.getOutStream().writeByteC(Y - (player.mapRegionY * 8));
|
||||
@@ -58,6 +60,7 @@ public class ActionSender {
|
||||
|
||||
public ActionSender shakeScreen(int verticleAmount, int verticleSpeed,
|
||||
int horizontalAmount, int horizontalSpeed) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
player.getOutStream().createFrame(35); // Creates frame 35.
|
||||
player.getOutStream().writeByte(verticleAmount);
|
||||
player.getOutStream().writeByte(verticleSpeed);
|
||||
@@ -101,8 +104,10 @@ public class ActionSender {
|
||||
public ActionSender flashSideBarIcon(int i1) {
|
||||
// Makes the sidebar Icons flash
|
||||
// Usage: i1 = 0 through -12 inorder to work
|
||||
player.outStream.createFrame(24);
|
||||
player.outStream.writeByteA(i1);
|
||||
if (player.getOutStream() != null) {
|
||||
player.outStream.createFrame(24);
|
||||
player.outStream.writeByteA(i1);
|
||||
}
|
||||
player.updateRequired = true;
|
||||
player.appearanceUpdateRequired = true;
|
||||
return this;
|
||||
@@ -210,6 +215,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender object(int objectId, int objectX, int objectY, int objectH, int face, int objectType) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player.heightLevel != objectH) {
|
||||
return this;
|
||||
}
|
||||
@@ -234,6 +240,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender tempSong(int songID, int songID2) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
player.outStream.createFrame(121);
|
||||
player.outStream.writeWordBigEndian(songID);
|
||||
player.outStream.writeWordBigEndian(songID2);
|
||||
@@ -242,6 +249,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender frame174(int sound, int vol, int delay) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
player.outStream.createFrame(174);
|
||||
player.outStream.writeWord(sound);
|
||||
player.outStream.writeWord(delay);
|
||||
@@ -250,6 +258,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender writeWeight(int weight) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
player.outStream.createFrame(240);
|
||||
DecimalFormat twoDForm = new DecimalFormat("#.##");
|
||||
player.outStream.writeWord(Integer.valueOf(twoDForm.format(weight)));
|
||||
@@ -257,10 +266,8 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender sendConfig(int id, int state) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (state < 128) {
|
||||
|
||||
}
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
if (state < Byte.MIN_VALUE || state > Byte.MAX_VALUE) {
|
||||
player.getOutStream().createFrame(87);
|
||||
player.getOutStream().writeWordBigEndian_dup(id);
|
||||
@@ -277,15 +284,18 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender multiWay(int i1) {
|
||||
player.outStream.createFrame(61);
|
||||
player.outStream.writeByte(i1);
|
||||
if (player.getOutStream() != null) {
|
||||
player.outStream.createFrame(61);
|
||||
player.outStream.writeByte(i1);
|
||||
}
|
||||
player.updateRequired = true;
|
||||
player.setAppearanceUpdateRequired(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActionSender sendColor(int id, int color) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.outStream.createFrame(122);
|
||||
player.outStream.writeWordBigEndianA(id);
|
||||
player.outStream.writeWordBigEndianA(color);
|
||||
@@ -293,17 +303,16 @@ public class ActionSender {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActionSender sendCrashFrame() { // used for crashing cheat
|
||||
// clients
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
public ActionSender sendCrashFrame() {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(123);
|
||||
player.flushOutStream();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActionSender createStillGfx(int id, int x, int y, int height,
|
||||
int time) {
|
||||
public ActionSender createStillGfx(int id, int x, int y, int height, int time) {
|
||||
for (Player p : PlayerHandler.players) {
|
||||
if (p != null) {
|
||||
Client person = (Client) p;
|
||||
@@ -320,9 +329,9 @@ public class ActionSender {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActionSender object(int objectId, int objectX, int objectY,
|
||||
int objectType) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
public ActionSender object(int objectId, int objectX, int objectY, int objectType) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(85);
|
||||
player.getOutStream().writeByteC(
|
||||
objectY - player.getMapRegionY() * 8);
|
||||
@@ -343,7 +352,8 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender itemOnInterface(int interfaceChild, int zoom, int itemId) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(246);
|
||||
player.getOutStream().writeWordBigEndian(interfaceChild);
|
||||
player.getOutStream().writeWord(zoom);
|
||||
@@ -354,6 +364,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender setConfig(int id, int state) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
player.outStream.createFrame(36);
|
||||
player.outStream.writeWordBigEndian(id);
|
||||
player.outStream.writeByte(state);
|
||||
@@ -361,7 +372,8 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender sendLink(String s) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrameVarSizeWord(187);
|
||||
player.getOutStream().writeString(s);
|
||||
}
|
||||
@@ -369,7 +381,8 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender setSkillLevel(int skillNum, int currentLevel, int XP) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(134);
|
||||
player.getOutStream().writeByte(skillNum);
|
||||
player.getOutStream().writeDWord_v1(XP);
|
||||
@@ -388,6 +401,8 @@ public class ActionSender {
|
||||
* @Param l - Keep this set as 0
|
||||
*/
|
||||
public ActionSender drawHeadicon(int i, int j, int k, int l) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
|
||||
// synchronized(c) {
|
||||
player.outStream.createFrame(254);
|
||||
player.outStream.writeByte(i);
|
||||
@@ -407,6 +422,7 @@ public class ActionSender {
|
||||
// object
|
||||
|
||||
public ActionSender createArrow(int x, int y, int height, int pos) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(254); // The packet ID
|
||||
player.getOutStream().writeByte(pos); // Position on Square(2 =
|
||||
@@ -424,6 +440,7 @@ public class ActionSender {
|
||||
// npc
|
||||
|
||||
public ActionSender createArrow(int type, int id) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(254); // The packet ID
|
||||
player.getOutStream().writeByte(type); // 1=NPC, 10=Player
|
||||
@@ -462,11 +479,12 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender createObjectSpawn(int objectId, int objectX, int objectY, int height, int face, int objectType) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player.heightLevel != height) {
|
||||
return this;
|
||||
}
|
||||
if (player.distanceToPoint(objectX, objectY) < 60) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(85);
|
||||
player.getOutStream().writeByteC(objectY - player.getMapRegionY() * 8);
|
||||
player.getOutStream().writeByteC(objectX - player.getMapRegionX() * 8);
|
||||
@@ -491,8 +509,8 @@ public class ActionSender {
|
||||
public String optionType = "null";
|
||||
|
||||
public ActionSender showOption(int i, int l, String s, int a) {
|
||||
// synchronized(c) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
if (!optionType.equalsIgnoreCase(s)) {
|
||||
optionType = s;
|
||||
player.getOutStream().createFrameVarSize(104);
|
||||
@@ -511,7 +529,8 @@ public class ActionSender {
|
||||
*/
|
||||
|
||||
public ActionSender sendSong(int id) {
|
||||
if (player.getOutStream() != null && player != null && id != -1) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null && id != -1) {
|
||||
player.getOutStream().createFrame(74);
|
||||
player.getOutStream().writeWordBigEndian(id);
|
||||
}
|
||||
@@ -523,7 +542,8 @@ public class ActionSender {
|
||||
*/
|
||||
|
||||
public ActionSender sendQuickSong(int id, int songDelay) {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(121);
|
||||
player.getOutStream().writeWordBigEndian(id);
|
||||
player.getOutStream().writeWordBigEndian(songDelay);
|
||||
@@ -537,7 +557,8 @@ public class ActionSender {
|
||||
*/
|
||||
|
||||
public ActionSender sendSound(int id, int type, int delay, int volume) {
|
||||
if (player.getOutStream() != null && player != null && id != -1) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null && id != -1) {
|
||||
player.getOutStream().createFrame(174);
|
||||
player.getOutStream().writeWord(id);
|
||||
player.getOutStream().writeByte(type);
|
||||
@@ -558,7 +579,8 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender sendClearScreen() {
|
||||
if (player.getOutStream() != null && player != null) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player != null) {
|
||||
player.getOutStream().createFrame(219);
|
||||
player.flushOutStream();
|
||||
}
|
||||
@@ -566,6 +588,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender createGroundItem(int itemID, int itemX, int itemY, int itemAmount) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
player.getOutStream().createFrame(85);
|
||||
player.getOutStream().writeByteC(itemY - 8 * player.mapRegionY);
|
||||
player.getOutStream().writeByteC(itemX - 8 * player.mapRegionX);
|
||||
@@ -578,6 +601,7 @@ public class ActionSender {
|
||||
}
|
||||
|
||||
public ActionSender createGroundItem(int itemID, int itemX, int itemY, int itemAmount, int height) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player.heightLevel != height) {
|
||||
return this;
|
||||
}
|
||||
@@ -598,6 +622,7 @@ public class ActionSender {
|
||||
**/
|
||||
|
||||
public ActionSender removeGroundItem(int itemID, int itemX, int itemY, int Amount) {
|
||||
if (player.getOutStream() == null) return this;
|
||||
if (player == null) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ public class ConnectionHandler implements IoHandler {
|
||||
public void sessionClosed(IoSession arg0) throws Exception {
|
||||
if (arg0.getAttachment() != null) {
|
||||
Client plr = (Client) arg0.getAttachment();
|
||||
plr.disconnected = true;
|
||||
if (!plr.isBot)
|
||||
plr.disconnected = true;
|
||||
}
|
||||
HostList.getHostList().remove(arg0);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class IdleLogout implements PacketType {
|
||||
|
||||
@Override
|
||||
public void processPacket(Client player, int packetType, int packetSize) {
|
||||
if (player.underAttackBy > 0 || player.underAttackBy2 > 0) {
|
||||
if (player.underAttackBy > 0 || player.underAttackBy2 > 0 || player.isBot) {
|
||||
return;
|
||||
} else {
|
||||
player.logout();
|
||||
|
||||
Reference in New Issue
Block a user