Search in sources :

Example 1 with HardwareInformation

use of com.faforever.server.entity.HardwareInformation in project faf-java-server by FAForever.

the class UniqueIdService method verify.

public void verify(Player player, String uid) {
    if (!enabled) {
        log.debug("Skipping unique ID check for player '{}' because it is disabled", player);
        return;
    }
    if (player.getUniqueIdExempt() != null) {
        log.debug("Skipping unique ID check for player '{}' because: {}", player, player.getUniqueIdExempt().getReason());
        return;
    }
    if (player.getSteamId() != null) {
        log.debug("Skipping unique ID check for player '{}' because of steam ID: {}", player, player.getSteamId());
        return;
    }
    UidPayload uidPayload = noCatch(() -> extractPayload(uid));
    String hash = Hashing.md5().hashString(uidPayload.getMachine().getUuid() + uidPayload.getMachine().getMemory().getSerial0() + uidPayload.getMachine().getDisks().getControllerId() + uidPayload.getMachine().getBios().getManufacturer() + uidPayload.getMachine().getProcessor().getName() + uidPayload.getMachine().getProcessor().getId() + uidPayload.getMachine().getBios().getSmbbVersion() + uidPayload.getMachine().getBios().getSerial() + uidPayload.getMachine().getDisks().getVSerial(), UTF_8).toString();
    HardwareInformation information = hardwareInformationRepository.findOneByHash(hash).orElseGet(() -> hardwareInformationRepository.save(new HardwareInformation(0, hash, uidPayload.getMachine().getUuid(), uidPayload.getMachine().getMemory().getSerial0(), uidPayload.getMachine().getDisks().getControllerId(), uidPayload.getMachine().getBios().getManufacturer(), uidPayload.getMachine().getProcessor().getName(), uidPayload.getMachine().getProcessor().getId(), uidPayload.getMachine().getBios().getSmbbVersion(), uidPayload.getMachine().getBios().getSerial(), uidPayload.getMachine().getDisks().getVSerial(), Sets.newHashSet(player))));
    player.getHardwareInformations().add(information);
    Set<Player> players = information.getPlayers();
    int count = players.size();
    Requests.verify(count < 2, ErrorCode.UID_USED_BY_MULTIPLE_USERS, linkToSteamUrl);
    Requests.verify(count == 0 || Objects.equals(players.iterator().next().getId(), player.getId()), ErrorCode.UID_USED_BY_ANOTHER_USER, linkToSteamUrl);
    if (count == 0) {
        // This happens if hardware information is already present but the user associations have been deleted.
        information.getPlayers().add(player);
        hardwareInformationRepository.save(information);
    }
    log.debug("Player '{}' passed unique ID check", player);
}
Also used : Player(com.faforever.server.entity.Player) HardwareInformation(com.faforever.server.entity.HardwareInformation)

Example 2 with HardwareInformation

use of com.faforever.server.entity.HardwareInformation in project faf-java-server by FAForever.

the class UniqueIdServiceTest method setUp.

@Before
public void setUp() throws Exception {
    player = newPlayer(51234);
    properties = new ServerProperties();
    properties.getUid().setEnabled(true);
    properties.getUid().setPrivateKey(PRIVATE_KEY);
    hardwareInformation = new HardwareInformation();
    hardwareInformation.setPlayers(new HashSet<>());
    when(hardwareInformationRepository.save(any(HardwareInformation.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, HardwareInformation.class));
    instance = new UniqueIdService(properties, new ObjectMapper(), hardwareInformationRepository);
}
Also used : ServerProperties(com.faforever.server.config.ServerProperties) HardwareInformation(com.faforever.server.entity.HardwareInformation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with HardwareInformation

use of com.faforever.server.entity.HardwareInformation in project faf-java-server by FAForever.

the class UniqueIdServiceTest method verifyCreatesNewHardwareInformation.

@Test
public void verifyCreatesNewHardwareInformation() throws Exception {
    assertThat(hardwareInformation.getPlayers(), hasSize(0));
    when(hardwareInformationRepository.findOneByHash(anyString())).thenReturn(Optional.empty());
    instance.verify(player, toUid(JSON));
    ArgumentCaptor<HardwareInformation> captor = ArgumentCaptor.forClass(HardwareInformation.class);
    verify(hardwareInformationRepository).save(captor.capture());
    HardwareInformation hardwareInformation = captor.getValue();
    assertThat(hardwareInformation.getPlayers(), hasSize(1));
    assertThat(hardwareInformation.getPlayers().iterator().next(), is(player));
    assertThat(hardwareInformation.getDeviceId(), is("PCI\\VEN_8086&DEV_1C00&SUBSYS_B0021458&REV_05\\3&14C0B0C5&0&FA"));
    assertThat(hardwareInformation.getManufacturer(), is(nullValue()));
    assertThat(hardwareInformation.getMemSerialNumber(), is(nullValue()));
    assertThat(hardwareInformation.getName(), is("Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz"));
    assertThat(hardwareInformation.getProcessorId(), is("BFEBFBFF000306A7"));
    assertThat(hardwareInformation.getSerialNumber(), is(nullValue()));
    assertThat(hardwareInformation.getSmbiosbiosVersion(), is("F1"));
    assertThat(hardwareInformation.getUuid(), is("00000000-0000-0000-0000-1C7F65F99C54"));
    assertThat(hardwareInformation.getVolumeSerialNumber(), is("EE17B56E"));
    assertThat(hardwareInformation.getHash(), is("a41c191809f33ce0d447ffe74d443290"));
    verify(hardwareInformationRepository).save(hardwareInformation);
}
Also used : HardwareInformation(com.faforever.server.entity.HardwareInformation) Test(org.junit.Test)

Aggregations

HardwareInformation (com.faforever.server.entity.HardwareInformation)3 ServerProperties (com.faforever.server.config.ServerProperties)1 Player (com.faforever.server.entity.Player)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Before (org.junit.Before)1 Test (org.junit.Test)1