Реализация пакетов связанных с группами (17-22)
This commit is contained in:
@@ -29,7 +29,13 @@ import com.rosetta.im.packet.Packet10RequestUpdate;
|
|||||||
import com.rosetta.im.packet.Packet11Typeing;
|
import com.rosetta.im.packet.Packet11Typeing;
|
||||||
import com.rosetta.im.packet.Packet15RequestTransport;
|
import com.rosetta.im.packet.Packet15RequestTransport;
|
||||||
import com.rosetta.im.packet.Packet16PushNotification;
|
import com.rosetta.im.packet.Packet16PushNotification;
|
||||||
|
import com.rosetta.im.packet.Packet17CreateGroup;
|
||||||
|
import com.rosetta.im.packet.Packet18GroupInfo;
|
||||||
|
import com.rosetta.im.packet.Packet19GroupInviteInfo;
|
||||||
import com.rosetta.im.packet.Packet1UserInfo;
|
import com.rosetta.im.packet.Packet1UserInfo;
|
||||||
|
import com.rosetta.im.packet.Packet20GroupJoin;
|
||||||
|
import com.rosetta.im.packet.Packet21GroupLeave;
|
||||||
|
import com.rosetta.im.packet.Packet22GroupBan;
|
||||||
import com.rosetta.im.packet.Packet23DeviceList;
|
import com.rosetta.im.packet.Packet23DeviceList;
|
||||||
import com.rosetta.im.packet.Packet24DeviceResolve;
|
import com.rosetta.im.packet.Packet24DeviceResolve;
|
||||||
import com.rosetta.im.packet.Packet2Result;
|
import com.rosetta.im.packet.Packet2Result;
|
||||||
@@ -167,9 +173,14 @@ public class Boot {
|
|||||||
//RESERVED 14 PACKET APP UPDATE (unused)
|
//RESERVED 14 PACKET APP UPDATE (unused)
|
||||||
this.packetManager.registerPacket(15, Packet15RequestTransport.class);
|
this.packetManager.registerPacket(15, Packet15RequestTransport.class);
|
||||||
this.packetManager.registerPacket(16, Packet16PushNotification.class);
|
this.packetManager.registerPacket(16, Packet16PushNotification.class);
|
||||||
|
this.packetManager.registerPacket(17, Packet17CreateGroup.class);
|
||||||
|
this.packetManager.registerPacket(18, Packet18GroupInfo.class);
|
||||||
|
this.packetManager.registerPacket(19, Packet19GroupInviteInfo.class);
|
||||||
|
this.packetManager.registerPacket(20, Packet20GroupJoin.class);
|
||||||
|
this.packetManager.registerPacket(21, Packet21GroupLeave.class);
|
||||||
|
this.packetManager.registerPacket(22, Packet22GroupBan.class);
|
||||||
this.packetManager.registerPacket(23, Packet23DeviceList.class);
|
this.packetManager.registerPacket(23, Packet23DeviceList.class);
|
||||||
this.packetManager.registerPacket(24, Packet24DeviceResolve.class);
|
this.packetManager.registerPacket(24, Packet24DeviceResolve.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerAllExecutors() {
|
private void registerAllExecutors() {
|
||||||
|
|||||||
39
src/main/java/com/rosetta/im/packet/Packet17CreateGroup.java
Normal file
39
src/main/java/com/rosetta/im/packet/Packet17CreateGroup.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package com.rosetta.im.packet;
|
||||||
|
|
||||||
|
import io.orprotocol.Stream;
|
||||||
|
import io.orprotocol.packet.Packet;
|
||||||
|
|
||||||
|
public class Packet17CreateGroup extends Packet {
|
||||||
|
|
||||||
|
private String groupId;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(Stream stream) {
|
||||||
|
this.groupId = stream.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream write() {
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.writeInt16(this.packetId);
|
||||||
|
stream.writeString(this.groupId);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить id группы, которую нужно создать
|
||||||
|
* @return id группы, которую нужно создать
|
||||||
|
*/
|
||||||
|
public String getGroupId() {
|
||||||
|
return this.groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить id группы, которую нужно создать
|
||||||
|
* @param groupId id группы, которую нужно создать
|
||||||
|
*/
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
67
src/main/java/com/rosetta/im/packet/Packet18GroupInfo.java
Normal file
67
src/main/java/com/rosetta/im/packet/Packet18GroupInfo.java
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package com.rosetta.im.packet;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.orprotocol.Stream;
|
||||||
|
import io.orprotocol.packet.Packet;
|
||||||
|
|
||||||
|
public class Packet18GroupInfo extends Packet {
|
||||||
|
|
||||||
|
private String groupId;
|
||||||
|
private List<String> membersPKs;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(Stream stream) {
|
||||||
|
this.groupId = stream.readString();
|
||||||
|
int membersCount = stream.readInt16();
|
||||||
|
this.membersPKs = new java.util.ArrayList<>();
|
||||||
|
for(int i = 0; i < membersCount; i++) {
|
||||||
|
this.membersPKs.add(stream.readString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream write() {
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.writeInt16(this.packetId);
|
||||||
|
stream.writeString(this.groupId);
|
||||||
|
stream.writeInt16(this.membersPKs.size());
|
||||||
|
for(String memberPK : this.membersPKs) {
|
||||||
|
stream.writeString(memberPK);
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить id группы
|
||||||
|
* @return id группы
|
||||||
|
*/
|
||||||
|
public String getGroupId() {
|
||||||
|
return this.groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить id группы
|
||||||
|
* @param groupId id группы
|
||||||
|
*/
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить публичные ключи участников группы
|
||||||
|
* @return список публичных ключей участников группы
|
||||||
|
*/
|
||||||
|
public List<String> getMembersPKs() {
|
||||||
|
return this.membersPKs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить публичные ключи участников группы
|
||||||
|
* @param membersPKs список публичных ключей участников группы
|
||||||
|
*/
|
||||||
|
public void setMembersPKs(List<String> membersPKs) {
|
||||||
|
this.membersPKs = membersPKs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package com.rosetta.im.packet;
|
||||||
|
|
||||||
|
import com.rosetta.im.packet.runtime.NetworkGroupStatus;
|
||||||
|
|
||||||
|
import io.orprotocol.Stream;
|
||||||
|
import io.orprotocol.packet.Packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Пакет который бросается клиентом для определения статуса приглашения в группу
|
||||||
|
*/
|
||||||
|
public class Packet19GroupInviteInfo extends Packet {
|
||||||
|
|
||||||
|
private String groupId;
|
||||||
|
private int membersCount;
|
||||||
|
private NetworkGroupStatus status;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(Stream stream) {
|
||||||
|
this.groupId = stream.readString();
|
||||||
|
this.membersCount = stream.readInt16();
|
||||||
|
this.status = NetworkGroupStatus.fromCode(stream.readInt8());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream write() {
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.writeInt16(this.packetId);
|
||||||
|
stream.writeString(this.groupId);
|
||||||
|
stream.writeInt16(this.membersCount);
|
||||||
|
stream.writeInt8(this.status.getCode());
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить id группы
|
||||||
|
* @return id группы
|
||||||
|
*/
|
||||||
|
public String getGroupId() {
|
||||||
|
return this.groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить id группы
|
||||||
|
* @param groupId id группы
|
||||||
|
*/
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить количество участников в группе
|
||||||
|
* @return количество участников в группе
|
||||||
|
*/
|
||||||
|
public int getMembersCount() {
|
||||||
|
return this.membersCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить количество участников в группе
|
||||||
|
* @param membersCount количество участников в группе
|
||||||
|
*/
|
||||||
|
public void setMembersCount(int membersCount) {
|
||||||
|
this.membersCount = membersCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить статус приглашения в группу
|
||||||
|
* @return статус приглашения в группу
|
||||||
|
*/
|
||||||
|
public NetworkGroupStatus getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить статус приглашения в группу
|
||||||
|
* @param status статус приглашения в группу
|
||||||
|
*/
|
||||||
|
public void setStatus(NetworkGroupStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
65
src/main/java/com/rosetta/im/packet/Packet20GroupJoin.java
Normal file
65
src/main/java/com/rosetta/im/packet/Packet20GroupJoin.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package com.rosetta.im.packet;
|
||||||
|
|
||||||
|
import com.rosetta.im.packet.runtime.NetworkGroupStatus;
|
||||||
|
|
||||||
|
import io.orprotocol.Stream;
|
||||||
|
import io.orprotocol.packet.Packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вызывается клиентом для вступления в группу.
|
||||||
|
* Сервер модифицирует этот пакет, устанавливая статус группы, и отправляет его обратно
|
||||||
|
* клиенту
|
||||||
|
*/
|
||||||
|
public class Packet20GroupJoin extends Packet {
|
||||||
|
|
||||||
|
private String groupId;
|
||||||
|
private NetworkGroupStatus status;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(Stream stream) {
|
||||||
|
this.groupId = stream.readString();
|
||||||
|
this.status = NetworkGroupStatus.fromCode(stream.readInt8());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream write() {
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.writeInt16(this.packetId);
|
||||||
|
stream.writeString(this.groupId);
|
||||||
|
stream.writeInt8(this.status.getCode());
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить id группы
|
||||||
|
* @return id группы
|
||||||
|
*/
|
||||||
|
public String getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить id группы
|
||||||
|
* @param groupId id группы
|
||||||
|
*/
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить статус группы
|
||||||
|
* @return статус группы
|
||||||
|
*/
|
||||||
|
public NetworkGroupStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить статус группы
|
||||||
|
* @param status статус группы
|
||||||
|
*/
|
||||||
|
public void setStatus(NetworkGroupStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
42
src/main/java/com/rosetta/im/packet/Packet21GroupLeave.java
Normal file
42
src/main/java/com/rosetta/im/packet/Packet21GroupLeave.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package com.rosetta.im.packet;
|
||||||
|
|
||||||
|
import io.orprotocol.Stream;
|
||||||
|
import io.orprotocol.packet.Packet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Вызывается клиентом для выхода из группы. Содержит id группы, которую нужно покинуть
|
||||||
|
*/
|
||||||
|
public class Packet21GroupLeave extends Packet {
|
||||||
|
|
||||||
|
private String groupId;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(Stream stream) {
|
||||||
|
this.groupId = stream.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream write() {
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.writeInt16(this.packetId);
|
||||||
|
stream.writeString(this.groupId);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить id группы, которую нужно покинуть
|
||||||
|
* @return id группы, которую нужно покинуть
|
||||||
|
*/
|
||||||
|
public String getGroupId() {
|
||||||
|
return this.groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить id группы, которую нужно покинуть
|
||||||
|
* @param groupId id группы, которую нужно покинуть
|
||||||
|
*/
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
58
src/main/java/com/rosetta/im/packet/Packet22GroupBan.java
Normal file
58
src/main/java/com/rosetta/im/packet/Packet22GroupBan.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package com.rosetta.im.packet;
|
||||||
|
|
||||||
|
import io.orprotocol.Stream;
|
||||||
|
import io.orprotocol.packet.Packet;
|
||||||
|
|
||||||
|
public class Packet22GroupBan extends Packet {
|
||||||
|
|
||||||
|
private String groupId;
|
||||||
|
private String publicKey;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(Stream stream) {
|
||||||
|
this.groupId = stream.readString();
|
||||||
|
this.publicKey = stream.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream write() {
|
||||||
|
Stream stream = new Stream();
|
||||||
|
stream.writeInt16(this.packetId);
|
||||||
|
stream.writeString(this.groupId);
|
||||||
|
stream.writeString(this.publicKey);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить id группы, в которой нужно забанить пользователя
|
||||||
|
* @return id группы
|
||||||
|
*/
|
||||||
|
public String getGroupId() {
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить id группы, в которой нужно забанить пользователя
|
||||||
|
* @param groupId id группы
|
||||||
|
*/
|
||||||
|
public void setGroupId(String groupId) {
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Получить публичный ключ пользователя, которого нужно забанить в группе
|
||||||
|
* @return публичный ключ пользователя
|
||||||
|
*/
|
||||||
|
public String getPublicKey() {
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Установить публичный ключ пользователя, которого нужно забанить в группе
|
||||||
|
* @param publicKey публичный ключ
|
||||||
|
*/
|
||||||
|
public void setPublicKey(String publicKey) {
|
||||||
|
this.publicKey = publicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.rosetta.im.packet.runtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Используется в Packet19GroupInviteInfo для указания статуса пользователя в группе.
|
||||||
|
*/
|
||||||
|
public enum NetworkGroupStatus {
|
||||||
|
/**
|
||||||
|
* Пользователь уже в группе
|
||||||
|
*/
|
||||||
|
JOINED(0),
|
||||||
|
/**
|
||||||
|
* Пользователь не может вступить в группу, так как она не существует или произошла ошибка
|
||||||
|
*/
|
||||||
|
INVALID(1),
|
||||||
|
/**
|
||||||
|
* Пользователь не вступил в группу, но может вступить, так как она существует и он не был из нее исключен
|
||||||
|
*/
|
||||||
|
NOT_JOINED(2),
|
||||||
|
/**
|
||||||
|
* Пользователь исключен из группы и не может вступить в нее, так как он был из нее исключен администратором
|
||||||
|
*/
|
||||||
|
BANNED(3);
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
|
||||||
|
NetworkGroupStatus(int code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NetworkGroupStatus fromCode(int code) {
|
||||||
|
for (NetworkGroupStatus status : values()) {
|
||||||
|
if (status.code == code) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown NetworkGroupStatus code: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user