Улученный decline устройств, теперь не требуется рвать сокет
This commit is contained in:
@@ -7,10 +7,14 @@ import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Index;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "devices")
|
||||
@Table(name = "devices", indexes = {
|
||||
@Index(name = "idx_public_key", columnList = "publicKey, deviceId", unique = true)
|
||||
})
|
||||
|
||||
public class Device extends CreateUpdateEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.rosetta.im.packet.Packet0Handshake;
|
||||
import com.rosetta.im.packet.Packet24DeviceResolve;
|
||||
import com.rosetta.im.packet.runtime.DeviceSolution;
|
||||
import com.rosetta.im.packet.runtime.HandshakeStage;
|
||||
import com.rosetta.im.service.dispatch.DeviceDispatcher;
|
||||
|
||||
import io.orprotocol.ProtocolException;
|
||||
import io.orprotocol.client.Client;
|
||||
@@ -24,10 +25,12 @@ public class Executor24DeviceResolve extends PacketExecutor<Packet24DeviceResolv
|
||||
private final ClientManager clientManager;
|
||||
private final EventManager eventManager;
|
||||
private final DeviceRepository deviceRepository = new DeviceRepository();
|
||||
private final DeviceDispatcher deviceDispatcher;
|
||||
|
||||
public Executor24DeviceResolve(ClientManager clientManager, EventManager eventManager) {
|
||||
this.clientManager = clientManager;
|
||||
this.eventManager = eventManager;
|
||||
this.deviceDispatcher = new DeviceDispatcher(clientManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,7 +108,16 @@ public class Executor24DeviceResolve extends PacketExecutor<Packet24DeviceResolv
|
||||
* Отклонено, отправляем отклонение
|
||||
*/
|
||||
c.send(packet);
|
||||
c.disconnect(Failures.HANDSHAKE_NOT_COMPLETED);
|
||||
/**
|
||||
* И удаляем теги аутентификации и устройства, так как клиент в момент отклонения
|
||||
* должен поймать разлогин
|
||||
*/
|
||||
c.clearTags();
|
||||
/**
|
||||
* Отправяем всем устройствам этого пользователя информацию о том, что устройство было отключено (чтобы клиент мог скрыть уведомление
|
||||
* о присоединении нового устройства)
|
||||
*/
|
||||
this.deviceDispatcher.sendDevices(eciAuthentificate.getPublicKey());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,27 @@ public class Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Очищает все ECI теги клиента и удаляет его из индекса клиентов.
|
||||
*/
|
||||
public void clearTags() {
|
||||
for (Class<? extends ECITag> tagClass : this.eciTags.keySet()) {
|
||||
if (this.clientIndexer != null) {
|
||||
this.clientIndexer.removeTagIndex(this, tagClass);
|
||||
}
|
||||
}
|
||||
this.eciTags.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаляет данные клиента по указанному ключу.
|
||||
* @param <T> Тип данных.
|
||||
* @param tagClass Класс данных для удаления.
|
||||
*/
|
||||
public <T extends ECITag> void removeTag(Class<T> tagClass) {
|
||||
this.addTag(tagClass, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Переиндексирует тег клиента в индексе клиентов.
|
||||
|
||||
Reference in New Issue
Block a user