mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-07 00:32:06 +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);
|
||||
|
||||
Reference in New Issue
Block a user