mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-27 00:40:52 +01:00
Merge branch 'fix/machine-id' into 'dev'
Fixes MachineID sometimes not unique #620. See merge request morningstar/Arcturus-Community!213
This commit is contained in:
commit
c0249a39ff
@ -73,17 +73,8 @@ public class GameClient {
|
||||
if (machineId == null) {
|
||||
throw new RuntimeException("Cannot set machineID to NULL");
|
||||
}
|
||||
this.machineId = machineId;
|
||||
|
||||
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.machineId);
|
||||
statement.setInt(2, this.habbo.getHabboInfo().getId());
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Caught SQL exception", e);
|
||||
}
|
||||
}
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
public void sendResponse(MessageComposer composer) {
|
||||
|
@ -3,14 +3,26 @@ package com.eu.habbo.messages.incoming.handshake;
|
||||
import com.eu.habbo.messages.NoAuthMessage;
|
||||
import com.eu.habbo.messages.incoming.MessageHandler;
|
||||
import com.eu.habbo.messages.outgoing.handshake.MachineIDComposer;
|
||||
import com.eu.habbo.util.HexUtils;
|
||||
|
||||
@NoAuthMessage
|
||||
public class MachineIDEvent extends MessageHandler {
|
||||
|
||||
private static final int HASH_LENGTH = 64;
|
||||
|
||||
@Override
|
||||
public void handle() throws Exception {
|
||||
String unknown = this.packet.readString();
|
||||
this.client.setMachineId(this.packet.readString());
|
||||
this.client.sendResponse(new MachineIDComposer(this.client));
|
||||
String storedMachineId = this.packet.readString();
|
||||
String clientFingerprint = this.packet.readString();
|
||||
String capabilities = this.packet.readString();
|
||||
|
||||
// Update stored machine id if it doesn't match our requirements.
|
||||
if (storedMachineId.startsWith("~") || storedMachineId.length() != HASH_LENGTH) {
|
||||
storedMachineId = HexUtils.getRandom(HASH_LENGTH);
|
||||
this.client.sendResponse(new MachineIDComposer(storedMachineId));
|
||||
}
|
||||
|
||||
this.client.setMachineId(storedMachineId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,22 @@
|
||||
package com.eu.habbo.messages.outgoing.handshake;
|
||||
|
||||
import com.eu.habbo.habbohotel.gameclients.GameClient;
|
||||
import com.eu.habbo.messages.ServerMessage;
|
||||
import com.eu.habbo.messages.outgoing.MessageComposer;
|
||||
import com.eu.habbo.messages.outgoing.Outgoing;
|
||||
|
||||
public class MachineIDComposer extends MessageComposer {
|
||||
private final GameClient client;
|
||||
|
||||
public MachineIDComposer(GameClient client) {
|
||||
this.client = client;
|
||||
private final String machineId;
|
||||
|
||||
public MachineIDComposer(String machineId) {
|
||||
this.machineId = machineId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerMessage composeInternal() {
|
||||
this.response.init(Outgoing.MachineIDComposer);
|
||||
this.response.appendString(this.client.getMachineId());
|
||||
this.response.appendString(this.machineId);
|
||||
return this.response;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.eu.habbo.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class HexUtils {
|
||||
|
||||
private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
|
||||
@ -24,4 +27,15 @@ public class HexUtils {
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String getRandom(int length){
|
||||
Random r = ThreadLocalRandom.current();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
while(sb.length() < length){
|
||||
sb.append(Integer.toHexString(r.nextInt()));
|
||||
}
|
||||
|
||||
return sb.toString().substring(0, length);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user