63 lines
2.4 KiB
Java
63 lines
2.4 KiB
Java
package im.rosetta.packet;
|
||
|
||
import java.util.List;
|
||
|
||
import im.rosetta.packet.runtime.DeviceSolution;
|
||
import im.rosetta.packet.runtime.NetworkDevice;
|
||
import im.rosetta.packet.runtime.NetworkStatus;
|
||
|
||
import io.orprotocol.Stream;
|
||
import io.orprotocol.packet.Packet;
|
||
|
||
/**
|
||
* Пакет, который содержит список устройств, с которых был произведен вход в систему.
|
||
* Этот пакет может быть отправлен сервером в ответ на запрос клиента о получении списка устройств,
|
||
* или может быть отправлен сервером при обнаружении нового входа в систему с нового устройства, чтобы уведомить клиента о новом устройстве.
|
||
*/
|
||
public class Packet23DeviceList extends Packet {
|
||
|
||
private List<NetworkDevice> devices;
|
||
|
||
@Override
|
||
public void read(Stream stream) {
|
||
int deviceCount = stream.readInt16();
|
||
this.devices = new java.util.ArrayList<>();
|
||
for(int i = 0; i < deviceCount; i++) {
|
||
NetworkDevice netDevice = new NetworkDevice();
|
||
netDevice.setDeviceId(stream.readString());
|
||
netDevice.setDeviceName(stream.readString());
|
||
netDevice.setDeviceOs(stream.readString());
|
||
/**
|
||
* TODO: Использовать boolean для обозначения статуса сети, а не int8.
|
||
*/
|
||
netDevice.setNetworkStatus(NetworkStatus.fromCode(stream.readInt8()));
|
||
netDevice.setDeviceSolution(DeviceSolution.fromCode(stream.readInt8()));
|
||
this.devices.add(netDevice);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public Stream write() {
|
||
Stream stream = new Stream();
|
||
stream.writeInt16(this.packetId);
|
||
stream.writeInt16(this.devices.size());
|
||
for(NetworkDevice device : this.devices) {
|
||
stream.writeString(device.getDeviceId());
|
||
stream.writeString(device.getDeviceName());
|
||
stream.writeString(device.getDeviceOs());
|
||
stream.writeInt8(device.getNetworkStatus().getCode());
|
||
stream.writeInt8(device.getDeviceSolution().getCode());
|
||
}
|
||
return stream;
|
||
}
|
||
|
||
public List<NetworkDevice> getDevices() {
|
||
return devices;
|
||
}
|
||
|
||
public void setDevices(List<NetworkDevice> devices) {
|
||
this.devices = devices;
|
||
}
|
||
|
||
}
|