Revert "Started fixing teleporters - credits to quadral"

This reverts commit d77d18b27f
This commit is contained in:
Harmonic 2019-12-18 14:49:02 -05:00
parent 2d83bca513
commit ca54316715
5 changed files with 71 additions and 192 deletions

View File

@ -37,7 +37,7 @@ public final class Emulator {
public final static int BUILD = 0;
public final static String PREVIEW = "RC-3";
public final static String PREVIEW = "RC-2";
public static final String version = "Arcturus Morningstar" + " " + MAJOR + "." + MINOR + "." + BUILD + " " + PREVIEW;
private static final String logo =
@ -49,7 +49,7 @@ public final class Emulator {
" / / / / /_/ / / / / / / / / / / /_/ (__ ) /_/ /_/ / / \n" +
"/_/ /_/\\____/_/ /_/ /_/_/_/ /_/\\__, /____/\\__/\\__,_/_/ \n" +
" /____/ \n" +
" 'the only emulator with broken teleporters' \n" ;
" 'RC Stands for Race Car.' \n" ;
public static String build = "";
public static boolean isReady = false;
public static boolean isShuttingDown = false;

View File

@ -1,22 +1,3 @@
/*
* Morning Star
* Copyright (C) 2019
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.eu.habbo.habbohotel.gameclients;
import com.eu.habbo.Emulator;
@ -35,134 +16,114 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
public class GameClient
{
/// Constructor
/// @p_Channel : Channel
public GameClient(Channel p_Channel) {
this.m_Channel = p_Channel;
public class GameClient {
public final ConcurrentHashMap<Integer, Integer> incomingPacketCounter = new ConcurrentHashMap<>(25);
private final Channel channel;
public long lastPacketCounterCleared = Emulator.getIntUnixTimestamp();
private Habbo habbo;
private String machineId = "";
public GameClient(Channel channel) {
this.channel = channel;
}
/// Composer class - Abstract class
/// @p_Composer : Composer
public void sendResponse(MessageComposer p_Composer) {
if (this.m_Channel.isOpen())
{
try
{
ServerMessage l_ServerMessage = p_Composer.compose();
this.sendResponse(l_ServerMessage);
} catch (Exception l_Exception)
{
Emulator.getLogging().logPacketError(l_Exception);
public void sendResponse(MessageComposer composer) {
if (this.channel.isOpen()) {
try {
ServerMessage msg = composer.compose();
this.sendResponse(msg);
} catch (Exception e) {
Emulator.getLogging().logPacketError(e);
}
}
}
/// Send Raw Response
/// @p_Response : Response
public void sendResponse(ServerMessage p_Response)
{
if (this.m_Channel.isOpen())
{
if (p_Response == null || p_Response.getHeader() <= 0)
{
public void sendResponse(ServerMessage response) {
if (this.channel.isOpen()) {
if (response == null || response.getHeader() <= 0) {
return;
}
if (PacketManager.DEBUG_SHOW_PACKETS)
Emulator.getLogging().logPacketLine("[" + Logging.ANSI_PURPLE + "SERVER" + Logging.ANSI_RESET + "] => [" + p_Response.getHeader() + "] -> " + p_Response.getBodyString());
Emulator.getLogging().logPacketLine("[" + Logging.ANSI_PURPLE + "SERVER" + Logging.ANSI_RESET + "] => [" + response.getHeader() + "] -> " + response.getBodyString());
this.m_Channel.write(p_Response.get(), this.m_Channel.voidPromise());
this.m_Channel.flush();
this.channel.write(response.get(), this.channel.voidPromise());
this.channel.flush();
}
}
/// Send packed response
/// @p_Responses : Response Array
public void sendResponses(ArrayList<ServerMessage> p_Responses)
{
ByteBuf l_Buffer = Unpooled.buffer();
if (this.m_Channel.isOpen()) {
for (ServerMessage l_Itr : p_Responses)
{
if (l_Itr == null || l_Itr.getHeader() <= 0) {
public void sendResponses(ArrayList<ServerMessage> responses) {
ByteBuf buffer = Unpooled.buffer();
if (this.channel.isOpen()) {
for (ServerMessage response : responses) {
if (response == null || response.getHeader() <= 0) {
return;
}
if (PacketManager.DEBUG_SHOW_PACKETS)
Emulator.getLogging().logPacketLine("[" + Logging.ANSI_PURPLE + "SERVER" + Logging.ANSI_RESET + "] => [" + l_Itr.getHeader() + "] -> " + l_Itr.getBodyString());
Emulator.getLogging().logPacketLine("[" + Logging.ANSI_PURPLE + "SERVER" + Logging.ANSI_RESET + "] => [" + response.getHeader() + "] -> " + response.getBodyString());
l_Buffer.writeBytes(l_Itr.get());
buffer.writeBytes(response.get());
}
this.m_Channel.write(l_Buffer.copy(), this.m_Channel.voidPromise());
this.m_Channel.flush();
this.channel.write(buffer.copy(), this.channel.voidPromise());
this.channel.flush();
}
l_Buffer.release();
buffer.release();
}
/// Dispose Habbo
public void dispose() {
try {
this.channel.close();
try
{
this.m_Channel.close();
if (this.m_Habbo != null) {
if (this.m_Habbo.isOnline())
{
this.m_Habbo.getHabboInfo().setOnline(false);
this.m_Habbo.disconnect();
if (this.habbo != null) {
if (this.habbo.isOnline()) {
this.habbo.getHabboInfo().setOnline(false);
this.habbo.disconnect();
}
this.m_Habbo = null;
this.habbo = null;
}
} catch (Exception e)
{
} catch (Exception e) {
Emulator.getLogging().logErrorLine(e);
}
}
///////////////////////////////////////////
// GETTERS/SETTERS
///////////////////////////////////////////
public Channel getChannel() {
return this.channel;
}
public Channel getChannel() { return this.m_Channel; }
public String getMachineId() { return this.m_MachineId; }
public Habbo getHabbo() { return this.m_Habbo; }
public Habbo getHabbo() {
return this.habbo;
}
public void setHabbo(Habbo p_Habbo) { this.m_Habbo = p_Habbo; }
public void setMachineId(String p_MachineId)
{
if (p_MachineId == null)
{
public void setHabbo(Habbo habbo) {
this.habbo = habbo;
}
public String getMachineId() {
return this.machineId;
}
public void setMachineId(String machineId) {
if (machineId == null) {
throw new RuntimeException("Cannot set machineID to NULL");
}
this.m_MachineId = p_MachineId;
this.machineId = machineId;
if (this.m_MachineId != null)
{
if (this.habbo != null) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE users SET machine_id = ? WHERE id = ? LIMIT 1")) {
statement.setString(1, this.m_MachineId);
statement.setInt(2, this.m_Habbo.getHabboInfo().getId());
statement.setString(1, this.machineId);
statement.setInt(2, this.habbo.getHabboInfo().getId());
statement.execute();
} catch (SQLException e)
{
} catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
public final ConcurrentHashMap<Integer, Integer> incomingPacketCounter = new ConcurrentHashMap<>(25);
public long lastPacketCounterCleared = Emulator.getIntUnixTimestamp();
private final Channel m_Channel;
private Habbo m_Habbo;
private String m_MachineId;
}

View File

@ -17,8 +17,6 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/// how u find files? where is file search bar on this ide
public class InteractionTeleport extends HabboItem {
private int targetId;
private int targetRoomId;
@ -64,37 +62,27 @@ public class InteractionTeleport extends HabboItem {
Habbo habbo = client.getHabbo();
/// Habbo must exist
if (habbo == null)
return;
/// Get Unit of habbo (extension class)
RoomUnit unit = habbo.getRoomUnit();
/// Unit must exit - this should be logged as this should never happen
if (unit == null)
return;
/// Get current tile habbo is standing on
RoomTile currentLocation = room.getLayout().getTile(this.getX(), this.getY());
/// dont proceed is our current tile is null - this should never happen
if (currentLocation == null)
return;
/// Get the tile infront
RoomTile infrontTile = room.getLayout().getTileInFront(currentLocation, this.getRotation());
/// Check whether we can use the teleport
if (!canUseTeleport(client, room))
return;
if (this.roomUnitID == unit.getId() && unit.getCurrentLocation().equals(currentLocation))
{
if (this.roomUnitID == unit.getId() && unit.getCurrentLocation().equals(currentLocation)) {
startTeleport(room, habbo);
} else if (unit.getCurrentLocation().equals(currentLocation) || unit.getCurrentLocation().equals(infrontTile))
{
} else if (unit.getCurrentLocation().equals(currentLocation) || unit.getCurrentLocation().equals(infrontTile)) {
// set state 1 and walk on item
this.roomUnitID = unit.getId();
this.setExtradata("1");
@ -199,25 +187,19 @@ public class InteractionTeleport extends HabboItem {
public boolean canUseTeleport(GameClient client, Room room) {
/// Get habbo
Habbo habbo = client.getHabbo();
/// this should never happen....
if (habbo == null)
return false;
/// Get extension class
RoomUnit unit = habbo.getRoomUnit();
/// this should never happen...
if (unit == null)
return false;
/// Habbo cannot use the teleport if riding
if (habbo.getHabboInfo().getRiding() != null)
return false;
/// check whether the room unit Id is valid
return this.roomUnitID == -1 || this.roomUnitID == unit.getId();
}
@ -226,7 +208,6 @@ public class InteractionTeleport extends HabboItem {
}
public void startTeleport(Room room, Habbo habbo, int delay) {
/// dont teleport if we are already teleporting
if (habbo.getRoomUnit().isTeleporting)
return;

View File

@ -4318,60 +4318,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return FurnitureMovementError.NO_RIGHTS;
}
public HabboItem OverrideItem(HabboItem p_Item, Habbo p_Owner)
{
if (p_Item instanceof InteractionTeleport)
{
TIntObjectIterator<HabboItem> l_Itr = this.roomItems.iterator();
for (int l_I = 0; l_I < this.roomItems.size(); l_I++)
{
l_Itr.advance();
if (l_Itr.value() instanceof InteractionTeleport)
{
InteractionTeleport l_Item = (InteractionTeleport)l_Itr.value();
/// If the item matches our hand item, then we have the correct item
if (p_Item.getId() == l_Item.getTargetId())
{
return p_Item;
}
/// If the pair item is not placed in the room, check whether its placed in any other rooms
if (this.getHabboItem(l_Item.getTargetId()) == null)
{
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT room_id FROM items WHERE id = ?"))
{
statement.setInt(1, l_Item.getTargetId());
try (ResultSet set = statement.executeQuery())
{
set.next();
/// Check if pair item is placed in any rooms, if not then return that i
if (set.getInt("room_id") == 0)
{
HabboItem l_HandItem = p_Owner.getInventory().getItemsComponent().getHabboItem(l_Item.getTargetId());
if (l_HandItem != null)
{
return l_HandItem;
}
}
}
}
catch (SQLException e) {
Emulator.getLogging().logSQLException(e);
}
}
}
}
}
return p_Item;
}
public FurnitureMovementError furnitureFitsAt(RoomTile tile, HabboItem item, int rotation) {
if (!this.layout.fitsOnMap(tile, item.getBaseItem().getWidth(), item.getBaseItem().getLength(), rotation))
return FurnitureMovementError.INVALID_MOVE;
@ -4422,14 +4368,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return fits;
}
if (item instanceof InteractionTeleport)
{
InteractionTeleport l_Test = (InteractionTeleport)item;
int hello = 0;
}
item = this.OverrideItem(item, owner);
item.setZ(tile.getStackHeight());
item.setX(tile.x);
item.setY(tile.y);

View File

@ -65,9 +65,8 @@ class TeleportActionThree implements Runnable {
targetTeleport.setExtradata("2");
targetRoom.updateItem(targetTeleport);
targetRoom.updateHabbo(this.client.getHabbo());
//System.out.println(targetTeleport.getX() + " | " + tokay so basically
// after goargetTeleport.getY());
//targetRoom.updateHabbo(this.client.getHabbo());
//System.out.println(targetTeleport.getX() + " | " + targetTeleport.getY());
this.client.getHabbo().getHabboInfo().setCurrentRoom(targetRoom);
//Emulator.getThreading().run(new HabboItemNewState(this.currentTeleport, this.room, "0"), 500);
Emulator.getThreading().run(new TeleportActionFour(targetTeleport, targetRoom, this.client), this.currentTeleport instanceof InteractionTeleportTile ? 0 : 500);