refactoring
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,11 +1,11 @@
|
|||||||
target/
|
target/
|
||||||
!.mvn/wrapper/maven-wrapper.jar
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
.mvn
|
|
||||||
!**/src/main/**/target/
|
!**/src/main/**/target/
|
||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
.kotlin
|
.kotlin
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
.idea/modules.xml
|
.idea/modules.xml
|
||||||
.idea/jarRepositories.xml
|
.idea/jarRepositories.xml
|
||||||
.idea/compiler.xml
|
.idea/compiler.xml
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
package com.github.netricecake;
|
package com.github.netricecake;
|
||||||
|
|
||||||
|
import com.github.netricecake.kakao.KakaoApi;
|
||||||
import com.github.netricecake.kakao.TalkClient;
|
import com.github.netricecake.kakao.TalkClient;
|
||||||
import com.github.netricecake.kakao.TalkHandler;
|
import com.github.netricecake.kakao.TalkHandler;
|
||||||
|
import com.github.netricecake.kakao.exception.*;
|
||||||
import com.github.netricecake.kakao.structs.ChatRoom;
|
import com.github.netricecake.kakao.structs.ChatRoom;
|
||||||
import com.github.netricecake.kakao.structs.Member;
|
import com.github.netricecake.kakao.structs.Member;
|
||||||
import com.github.netricecake.kakao.structs.Message;
|
import com.github.netricecake.kakao.structs.Message;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
//TIP 코드를 <b>실행</b>하려면 <shortcut actionId="Run"/>을(를) 누르거나
|
import java.util.Map;
|
||||||
// 에디터 여백에 있는 <icon src="AllIcons.Actions.Execute"/> 아이콘을 클릭하세요.
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
static String email = "invalid@example.com";
|
static String email = "invalid@example.com"; // 이메일 말고 전화번호도 가능
|
||||||
static String password = "example";
|
static String password = "example";
|
||||||
static String deviceName = "SM-X930"; // 갤럭시 탭 s11 울트라, 지원되는 태블릿 모델명 넣으세요
|
static String deviceName = "SM-X930"; // 갤럭시 탭 s11 울트라, 지원되는 태블릿 모델명 넣으세요
|
||||||
static String deviceUuid = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; // 64자 랜덤 hex-string, 이것도 에시니까 무조건 다른걸로 바꾸세요.
|
static String deviceUuid = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; // 64자 랜덤 hex-string
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
TalkClient client = new TalkClient(email, password, deviceName, deviceUuid, new TalkHandler() {
|
TalkClient client = new TalkClient(email, password, deviceName, deviceUuid, new TalkHandler() {
|
||||||
@@ -60,6 +62,28 @@ public class Main {
|
|||||||
getTalkClient().sendMessage(room, member.getName() + "님이 나갔습니다.");
|
getTalkClient().sendMessage(room, member.getName() + "님이 나갔습니다.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
client.connect();
|
|
||||||
|
try {
|
||||||
|
client.connect();
|
||||||
|
} catch (InvalidDeviceNameException e) {
|
||||||
|
System.out.println("서브 디바이스 로그인을 지원하지 않는 디바이스입니다.");
|
||||||
|
} catch (InvalidDeviceUUIDException e) {
|
||||||
|
System.out.println("Device UUID는 64자리 hex string이어야 합니다.");
|
||||||
|
} catch (BadCredentialsException e) {
|
||||||
|
System.out.println("이메일(전화번호)이나 비밀번호가 틀렸습니다.");
|
||||||
|
} catch (BookingFailedException e) {
|
||||||
|
System.out.println("Booking 서버와의 통신을 실패했습니다.");
|
||||||
|
} catch (LoginFailedException e) {
|
||||||
|
System.out.println("카카오톡 서버와 연결을 실패했습니다. 로그인 정보 파일을 삭제 후 다시 시도해보세요.");
|
||||||
|
} catch (UnregisteredDeviceException e) {
|
||||||
|
System.out.println("디바이스 등록이 필요합니다.");
|
||||||
|
Map.Entry<String, Integer> registerInfo = KakaoApi.generatePasscode(email, password, deviceName, deviceUuid);
|
||||||
|
System.out.println("카카오톡 앱에서 " + registerInfo.getValue() + "초 안에 코드를 입력해주세요. 코드 : " + registerInfo.getKey());
|
||||||
|
boolean registerResult = KakaoApi.registerDevice(email, password, deviceUuid);
|
||||||
|
if (!registerResult) {
|
||||||
|
System.out.println("디바이스 등록 실패");
|
||||||
|
}
|
||||||
|
System.out.println("디바이스 등록 성공, 다시 실행하세요.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package com.github.netricecake.kakao;
|
package com.github.netricecake.kakao;
|
||||||
|
|
||||||
|
import com.github.netricecake.kakao.exception.BadCredentialsException;
|
||||||
|
import com.github.netricecake.kakao.exception.InvalidDeviceNameException;
|
||||||
|
import com.github.netricecake.kakao.exception.InvalidDeviceUUIDException;
|
||||||
|
import com.github.netricecake.kakao.exception.UnregisteredDeviceException;
|
||||||
import com.github.netricecake.loco.packet.inbound.GetConfIn;
|
import com.github.netricecake.loco.packet.inbound.GetConfIn;
|
||||||
import com.github.netricecake.loco.packet.outbound.GetConfOut;
|
import com.github.netricecake.loco.packet.outbound.GetConfOut;
|
||||||
import com.github.netricecake.loco.util.ByteUtil;
|
import com.github.netricecake.loco.util.ByteUtil;
|
||||||
@@ -48,9 +52,9 @@ public class KakaoApi {
|
|||||||
|
|
||||||
private final static Gson gson = new Gson();
|
private final static Gson gson = new Gson();
|
||||||
|
|
||||||
public static LoginData loginRequest(String email, String password, String deviceName, String deviceUuid) throws IOException, InvalidParameterException, IllegalStateException {
|
public static LoginData loginRequest(String email, String password, String deviceName, String deviceUuid) throws IOException, InvalidDeviceNameException, InvalidDeviceUUIDException, BadCredentialsException, UnregisteredDeviceException {
|
||||||
if (deviceUuid == null || deviceUuid.length() != UUID_LENGTH) throw new InvalidParameterException("invalid deviceUuid");
|
if (deviceUuid == null || deviceUuid.length() != UUID_LENGTH) throw new InvalidDeviceUUIDException();
|
||||||
if (!checkAllowedDevice(deviceName)) throw new InvalidParameterException("This device does not support sub device login");
|
if (!checkAllowedDevice(deviceName)) throw new InvalidDeviceNameException();
|
||||||
RequestBody body = new FormBody.Builder().add("password", password)
|
RequestBody body = new FormBody.Builder().add("password", password)
|
||||||
.add("device_name", deviceName)
|
.add("device_name", deviceName)
|
||||||
.add("foced", "false")
|
.add("foced", "false")
|
||||||
@@ -68,10 +72,9 @@ public class KakaoApi {
|
|||||||
int status = jsonObject.get("status").getAsInt();
|
int status = jsonObject.get("status").getAsInt();
|
||||||
|
|
||||||
// 12 비번 틀림 30 이메일 틀림
|
// 12 비번 틀림 30 이메일 틀림
|
||||||
if (status == 12 || status == 30) throw new InvalidParameterException("Email or password is invalid");
|
if (status == 12 || status == 30) throw new BadCredentialsException();
|
||||||
if (status == -100) throw new IllegalStateException("Register device before login");
|
if (status == -100) throw new UnregisteredDeviceException();
|
||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
|
|
||||||
LoginData data = new LoginData();
|
LoginData data = new LoginData();
|
||||||
data.userId = jsonObject.get("userId").getAsLong();
|
data.userId = jsonObject.get("userId").getAsLong();
|
||||||
data.countryIso = jsonObject.get("countryIso").getAsString();
|
data.countryIso = jsonObject.get("countryIso").getAsString();
|
||||||
@@ -218,7 +221,7 @@ public class KakaoApi {
|
|||||||
public String mainDeviceAppVersion;
|
public String mainDeviceAppVersion;
|
||||||
public String recipe;
|
public String recipe;
|
||||||
|
|
||||||
public void fromJson(String json) {
|
public LoginData(String json) {
|
||||||
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
||||||
userId = jsonObject.get("userId").getAsLong();
|
userId = jsonObject.get("userId").getAsLong();
|
||||||
countryIso = jsonObject.get("countryIso").getAsString();
|
countryIso = jsonObject.get("countryIso").getAsString();
|
||||||
@@ -234,6 +237,8 @@ public class KakaoApi {
|
|||||||
recipe = jsonObject.get("recipe").getAsString();
|
recipe = jsonObject.get("recipe").getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LoginData() {}
|
||||||
|
|
||||||
public String toJson() {
|
public String toJson() {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("userId", userId);
|
jsonObject.addProperty("userId", userId);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import com.github.netricecake.loco.packet.outbound.InfoLinkOut;
|
|||||||
import com.github.netricecake.loco.packet.outbound.MessageOut;
|
import com.github.netricecake.loco.packet.outbound.MessageOut;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public class LocoSocketHandlerImpl implements LocoSocektHandler {
|
public class LocoSocketHandlerImpl extends LocoSocektHandler {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private TalkClient client;
|
private TalkClient client;
|
||||||
@@ -79,7 +79,8 @@ public class LocoSocketHandlerImpl implements LocoSocektHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect() {
|
public void onDisconnect() {
|
||||||
|
client.connected = false;
|
||||||
|
System.out.println("연결 끊어짐");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.github.netricecake.kakao;
|
package com.github.netricecake.kakao;
|
||||||
|
|
||||||
|
import com.github.netricecake.kakao.exception.*;
|
||||||
import com.github.netricecake.kakao.structs.ChatRoom;
|
import com.github.netricecake.kakao.structs.ChatRoom;
|
||||||
import com.github.netricecake.loco.LocoPacket;
|
import com.github.netricecake.loco.LocoPacket;
|
||||||
import com.github.netricecake.loco.LocoSocektHandler;
|
import com.github.netricecake.loco.LocoSocektHandler;
|
||||||
@@ -18,6 +19,7 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.awt.print.Book;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -39,7 +41,7 @@ public class TalkClient {
|
|||||||
private Map<Long, ChatRoom> chatRooms = new HashMap<>();
|
private Map<Long, ChatRoom> chatRooms = new HashMap<>();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private boolean connected;
|
protected boolean connected;
|
||||||
|
|
||||||
private KakaoApi.LoginData loginData;
|
private KakaoApi.LoginData loginData;
|
||||||
private GetConfIn bookingData;
|
private GetConfIn bookingData;
|
||||||
@@ -54,7 +56,7 @@ public class TalkClient {
|
|||||||
@Getter
|
@Getter
|
||||||
private LocoSocket socket;
|
private LocoSocket socket;
|
||||||
|
|
||||||
public TalkClient(String email, String password, String deviceName, String deviceUuid, TalkHandler talkHandler) {
|
public TalkClient(String email, String password, String deviceName, String deviceUuid, TalkHandler talkHandler) throws IOException {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.deviceName = deviceName;
|
this.deviceName = deviceName;
|
||||||
@@ -63,77 +65,48 @@ public class TalkClient {
|
|||||||
this.talkHandler = talkHandler;
|
this.talkHandler = talkHandler;
|
||||||
talkHandler.setTalkClient(this);
|
talkHandler.setTalkClient(this);
|
||||||
|
|
||||||
new File(sessionDir).mkdir();
|
new File(sessionDir).mkdirs();
|
||||||
loginData = readLoginData();
|
File loginDataFile = new File(sessionDir + "loginData.json");
|
||||||
|
if (!loginDataFile.exists()) return;
|
||||||
|
String loginDataJson = Files.readString(Paths.get(loginDataFile.getAbsolutePath()));
|
||||||
|
loginData = new KakaoApi.LoginData(loginDataJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() throws Exception {
|
public void connect() throws IOException, InvalidDeviceNameException, InvalidDeviceUUIDException, BadCredentialsException, UnregisteredDeviceException, BookingFailedException, LoginFailedException {
|
||||||
if (this.connected) throw new Exception("이미 연결되어 있습니다.");
|
if (this.connected) throw new IOException("Already connected.");
|
||||||
if (loginData == null) {
|
if (loginData == null) { // 저장된 로그인 데이터가 없는 경우 로그인 시도
|
||||||
System.out.println("로그인 데이터가 없습니다. 새로 로그인을 시도합니다.");
|
loginData = KakaoApi.loginRequest(email, password, deviceName, deviceUuid);
|
||||||
try {
|
File loginDataFile = new File(sessionDir + "loginData.json");
|
||||||
loginData = KakaoApi.loginRequest(email, password, deviceName, deviceUuid);
|
if (!loginDataFile.exists()) loginDataFile.createNewFile();
|
||||||
} catch (IllegalStateException e) {
|
Files.write(Paths.get(loginDataFile.getAbsolutePath()), loginData.toJson().getBytes());
|
||||||
Map.Entry<String, Integer> registerInfo = KakaoApi.generatePasscode(email, password, deviceName, deviceUuid);
|
|
||||||
System.out.println("기기 등록이 필요합니다.");
|
|
||||||
System.out.println("카카오톡 앱에서 " + registerInfo.getValue() + "초 안에 코드를 입력해주세요. 코드 : " + registerInfo.getKey());
|
|
||||||
boolean registerResult = KakaoApi.registerDevice(email, password, deviceUuid);
|
|
||||||
if (!registerResult) throw new IllegalStateException("기기등록 실패");
|
|
||||||
System.out.println("기기 등록 성공");
|
|
||||||
loginData = KakaoApi.loginRequest(email, password, deviceName, deviceUuid);
|
|
||||||
}
|
|
||||||
System.out.println("로그인이 완료되었습니다.");
|
|
||||||
writeLoginData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bookingData = KakaoApi.getBookingData(loginData.userId);
|
bookingData = KakaoApi.getBookingData(loginData.userId);
|
||||||
|
if (bookingData == null || bookingData.getStatus() != 0) throw new BookingFailedException();
|
||||||
|
|
||||||
LocoSocket checkInSocket = new LocoSocket(bookingData.getAddr(), bookingData.getPort(), new LocoSocektHandler() {
|
LocoSocket checkInSocket = new LocoSocket(bookingData.getAddr(), bookingData.getPort(), new LocoSocektHandler() {
|
||||||
@Override
|
|
||||||
public void onPacket(LocoPacket packet) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnect() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisconnect() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception e) {
|
public void onError(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, Executors.newFixedThreadPool(1));
|
}, Executors.newFixedThreadPool(1));
|
||||||
CheckInOut checkInRequest = new CheckInOut(loginData.userId);
|
byte[] body = new CheckInOut(loginData.userId).toBson();
|
||||||
byte[] body = checkInRequest.toBson();
|
|
||||||
checkInSocket.connect();
|
checkInSocket.connect();
|
||||||
LocoPacket checkinResponse = checkInSocket.writeAndRead(new LocoPacket(1000, checkInRequest.getMethod(), body));
|
LocoPacket checkinResponse = checkInSocket.writeAndRead(new LocoPacket(1000, "CHECKIN", body));
|
||||||
checkInData = new CheckInIn();
|
checkInData = new CheckInIn(checkinResponse.getBody());
|
||||||
checkInData.fromBson(checkinResponse.getBody());
|
|
||||||
checkInSocket.close();
|
checkInSocket.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long lastTokenId = 0;
|
long lastTokenId = 0;
|
||||||
long lbk = 0;
|
long lbk = 0;
|
||||||
byte[] rp = ByteUtil.hexStringToByteArray("0000ffff0000");
|
byte[] rp = ByteUtil.hexStringToByteArray("0000ffff0000");
|
||||||
|
|
||||||
try {
|
File loginListDataFile = new File(sessionDir + "loginListData.json");
|
||||||
File loginListDataFile = new File(sessionDir + "loginListData.json");
|
if (loginListDataFile.exists()) {
|
||||||
if (loginListDataFile.exists()) {
|
String loginDataJson = Files.readString(Paths.get(loginListDataFile.getAbsolutePath()));
|
||||||
String loginDataJson = Files.readString(Paths.get(loginListDataFile.getAbsolutePath()));
|
JsonObject loginListData = JsonParser.parseString(loginDataJson).getAsJsonObject();
|
||||||
JsonObject loginListData = JsonParser.parseString(loginDataJson).getAsJsonObject();
|
lastTokenId = loginListData.getAsJsonPrimitive("lastTokenId").getAsLong();
|
||||||
lastTokenId = loginListData.getAsJsonPrimitive("lastTokenId").getAsLong();
|
lbk = loginListData.getAsJsonPrimitive("lbk").getAsLong();
|
||||||
lbk = loginListData.getAsJsonPrimitive("lbk").getAsLong();
|
rp = ByteUtil.hexStringToByteArray("0100ffff0100"); // 이게 도대체 뭐임
|
||||||
rp = ByteUtil.hexStringToByteArray("0100ffff0100"); // 이게 도당체 뭐임
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
locoHandlerPool = Executors.newFixedThreadPool(1);
|
locoHandlerPool = Executors.newFixedThreadPool(1);
|
||||||
@@ -149,21 +122,16 @@ public class TalkClient {
|
|||||||
loginListData = new LoginListIn();
|
loginListData = new LoginListIn();
|
||||||
loginListData.fromBson(socket.writeAndRead(new LocoPacket("LOGINLIST", req.toBson())).getBody());
|
loginListData.fromBson(socket.writeAndRead(new LocoPacket("LOGINLIST", req.toBson())).getBody());
|
||||||
if (loginListData.getStatus() != 0) {
|
if (loginListData.getStatus() != 0) {
|
||||||
System.out.println("카카오톡 서버와 연결을 실패했습니다. 로그인 정보 파일을 삭제 후 다시 시도해보세요.");
|
throw new LoginFailedException();
|
||||||
throw new Exception("카카오톡 서버와 연결을 실패했습니다. 로그인 정보 파일을 삭제 후 다시 시도해보세요.");
|
|
||||||
}
|
}
|
||||||
System.out.println("연결 성공");
|
|
||||||
|
|
||||||
try {
|
if (!loginListDataFile.exists()) loginListDataFile.createNewFile();
|
||||||
File loginListDataFile = new File(sessionDir + "loginListData.json");
|
JsonObject jsonObject = new JsonObject();
|
||||||
if (!loginListDataFile.exists()) loginListDataFile.createNewFile();
|
jsonObject.addProperty("lastTokenId", loginListData.getLastTokenId());
|
||||||
JsonObject jsonObject = new JsonObject();
|
jsonObject.addProperty("lbk", loginListData.getLbk());
|
||||||
jsonObject.addProperty("lastTokenId", loginListData.getLastTokenId());
|
Files.write(Paths.get(loginListDataFile.getAbsolutePath()), new Gson().toJson(jsonObject).getBytes());
|
||||||
jsonObject.addProperty("lbk", loginListData.getLbk());
|
|
||||||
Files.write(Paths.get(loginListDataFile.getAbsolutePath()), new Gson().toJson(jsonObject).getBytes());
|
connected = true;
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@@ -179,31 +147,6 @@ public class TalkClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private KakaoApi.LoginData readLoginData() {
|
|
||||||
try {
|
|
||||||
File loginDataFile = new File(sessionDir + "loginData.json");
|
|
||||||
if (!loginDataFile.exists()) return null;
|
|
||||||
String loginDataJson = Files.readString(Paths.get(loginDataFile.getAbsolutePath()));
|
|
||||||
KakaoApi.LoginData loginData = new KakaoApi.LoginData();
|
|
||||||
loginData.fromJson(loginDataJson);
|
|
||||||
return loginData;
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeLoginData() {
|
|
||||||
try {
|
|
||||||
File loginDataFile = new File(sessionDir + "loginData.json");
|
|
||||||
if (!loginDataFile.exists()) loginDataFile.createNewFile();
|
|
||||||
Files.write(Paths.get(loginDataFile.getAbsolutePath()), loginData.toJson().getBytes());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean sendMessage(ChatRoom room, int type, String message, String extra) {
|
public boolean sendMessage(ChatRoom room, int type, String message, String extra) {
|
||||||
WriteOut wo = new WriteOut();
|
WriteOut wo = new WriteOut();
|
||||||
wo.setChatId(room.getChatId());
|
wo.setChatId(room.getChatId());
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.github.netricecake.kakao.exception;
|
||||||
|
|
||||||
|
public class BadCredentialsException extends Exception {
|
||||||
|
/*
|
||||||
|
email, password mismatch
|
||||||
|
*/
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.github.netricecake.kakao.exception;
|
||||||
|
|
||||||
|
public class BookingFailedException extends Exception {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.github.netricecake.kakao.exception;
|
||||||
|
|
||||||
|
public class InvalidDeviceNameException extends Exception {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.github.netricecake.kakao.exception;
|
||||||
|
|
||||||
|
public class InvalidDeviceUUIDException extends Exception {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.github.netricecake.kakao.exception;
|
||||||
|
|
||||||
|
public class LoginFailedException extends Exception {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package com.github.netricecake.kakao.exception;
|
||||||
|
|
||||||
|
public class UnregisteredDeviceException extends Exception {}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package com.github.netricecake.loco;
|
package com.github.netricecake.loco;
|
||||||
|
|
||||||
public interface LocoSocektHandler {
|
public class LocoSocektHandler {
|
||||||
|
|
||||||
void onPacket(LocoPacket packet);
|
public void onPacket(LocoPacket packet) {}
|
||||||
|
|
||||||
void onConnect();
|
public void onConnect() {}
|
||||||
|
|
||||||
void onDisconnect();
|
public void onDisconnect() {}
|
||||||
|
|
||||||
void onError(Exception e);
|
public void onError(Exception e) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.github.netricecake.loco.packet;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
public class InboundPacket {
|
||||||
|
|
||||||
|
public String getStringOrNull(JsonObject jsonObject, String key) {
|
||||||
|
JsonElement jsonElement = jsonObject.get(key);
|
||||||
|
return jsonElement == null ? null : jsonElement.getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntOrNull(JsonObject jsonObject, String key) {
|
||||||
|
JsonElement jsonElement = jsonObject.get(key);
|
||||||
|
return jsonElement == null ? 0 : jsonElement.getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBoolOrNull(JsonObject jsonObject, String key) {
|
||||||
|
JsonElement jsonElement = jsonObject.get(key);
|
||||||
|
return jsonElement == null || jsonElement.getAsBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLongOrNull(JsonObject jsonObject, String key) {
|
||||||
|
JsonElement jsonElement = jsonObject.get(key);
|
||||||
|
return jsonElement == null ? 0L : jsonElement.getAsLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ChatInfoIn {
|
public class ChatInfoIn extends InboundPacket {
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class CheckInIn {
|
public class CheckInIn extends InboundPacket {
|
||||||
|
|
||||||
private int status;
|
private int status;
|
||||||
|
|
||||||
@@ -32,21 +33,20 @@ public class CheckInIn {
|
|||||||
|
|
||||||
private String MCCMNC;
|
private String MCCMNC;
|
||||||
|
|
||||||
public void fromBson(byte[] bson)
|
public CheckInIn(byte[] bson) {
|
||||||
{
|
|
||||||
JsonObject json = BsonUtil.bsonToJsonObject(bson);
|
JsonObject json = BsonUtil.bsonToJsonObject(bson);
|
||||||
status = json.get("status").getAsInt();
|
status = getIntOrNull(json, "status");
|
||||||
host = json.get("host").getAsString();
|
host = getStringOrNull(json, "host");
|
||||||
host6 = json.get("host6").getAsString();
|
host6 = getStringOrNull(json, "host6");
|
||||||
port = json.get("port").getAsInt();
|
port = getIntOrNull(json, "port");
|
||||||
cshost = json.get("cshost").getAsString();
|
cshost = getStringOrNull(json, "cshost");
|
||||||
cshost6 = json.get("cshost6").getAsString();
|
cshost6 = getStringOrNull(json, "cshost6");
|
||||||
csport = json.get("csport").getAsInt();
|
csport = getIntOrNull(json, "csport");
|
||||||
vsshost = json.get("vsshost").getAsString();
|
vsshost = getStringOrNull(json, "vsshost");
|
||||||
vsshost6 = json.get("vsshost6").getAsString();
|
vsshost6 = getStringOrNull(json, "vsshost6");
|
||||||
vssport = json.get("vssport").getAsInt();
|
vssport = getIntOrNull(json, "vssport");
|
||||||
cacheExpire = json.get("cacheExpire").getAsLong();
|
cacheExpire = getLongOrNull(json, "cacheExpire");
|
||||||
MCCMNC = json.get("MCCMNC").getAsString();
|
MCCMNC = getStringOrNull(json, "MCCMNC");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class DelMemIn {
|
public class DelMemIn extends InboundPacket {
|
||||||
|
|
||||||
private long chatId;
|
private long chatId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class GetConfIn {
|
public class GetConfIn extends InboundPacket {
|
||||||
|
|
||||||
private int status;
|
private int status;
|
||||||
|
|
||||||
@@ -17,8 +18,10 @@ public class GetConfIn {
|
|||||||
public void fromBson(byte[] bson) {
|
public void fromBson(byte[] bson) {
|
||||||
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
|
JsonObject jsonObject = BsonUtil.bsonToJsonObject(bson);
|
||||||
status = jsonObject.get("status").getAsInt();
|
status = jsonObject.get("status").getAsInt();
|
||||||
addr = jsonObject.get("ticket").getAsJsonObject().get("lsl").getAsJsonArray().get(0).getAsString();
|
try {
|
||||||
port = jsonObject.get("wifi").getAsJsonObject().get("ports").getAsJsonArray().get(0).getAsInt();
|
addr = jsonObject.get("ticket").getAsJsonObject().get("lsl").getAsJsonArray().get(0).getAsString();
|
||||||
|
port = jsonObject.get("wifi").getAsJsonObject().get("ports").getAsJsonArray().get(0).getAsInt();
|
||||||
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class InfoLinkIn {
|
public class InfoLinkIn extends InboundPacket {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@@ -8,7 +9,7 @@ import lombok.Getter;
|
|||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class LoginListIn {
|
public class LoginListIn extends InboundPacket {
|
||||||
|
|
||||||
private int status;
|
private int status;
|
||||||
|
|
||||||
@@ -45,21 +46,23 @@ public class LoginListIn {
|
|||||||
public void fromBson(byte[] bson) {
|
public void fromBson(byte[] bson) {
|
||||||
JsonObject json = BsonUtil.bsonToJsonObject(bson);
|
JsonObject json = BsonUtil.bsonToJsonObject(bson);
|
||||||
status = json.get("status").getAsInt();
|
status = json.get("status").getAsInt();
|
||||||
userId = json.get("userId").getAsLong();
|
try {
|
||||||
revision = json.get("revision").getAsInt();
|
userId = json.get("userId").getAsLong();
|
||||||
revisionInfo = json.get("revisionInfo").getAsString();
|
revision = json.get("revision").getAsInt();
|
||||||
rp = Base64.getDecoder().decode(json.get("rp").getAsJsonObject().get("$binary").getAsJsonObject().get("base64").getAsString());
|
revisionInfo = json.get("revisionInfo").getAsString();
|
||||||
minLogId = json.get("minLogId").getAsLong();
|
rp = Base64.getDecoder().decode(json.get("rp").getAsJsonObject().get("$binary").getAsJsonObject().get("base64").getAsString());
|
||||||
sb = json.get("sb").getAsInt();
|
minLogId = json.get("minLogId").getAsLong();
|
||||||
chatDatas = json.get("chatDatas").getAsJsonArray();
|
sb = json.get("sb").getAsInt();
|
||||||
delChatIds = json.get("delChatIds").getAsJsonArray();
|
chatDatas = json.get("chatDatas").getAsJsonArray();
|
||||||
kc = json.get("kc").getAsJsonArray();
|
delChatIds = json.get("delChatIds").getAsJsonArray();
|
||||||
mcmRevision = json.get("mcmRevision").getAsInt();
|
kc = json.get("kc").getAsJsonArray();
|
||||||
lastTokenId = json.get("lastTokenId").getAsLong();
|
mcmRevision = json.get("mcmRevision").getAsInt();
|
||||||
lastChatId = json.get("lastChatId").getAsLong();
|
lastTokenId = json.get("lastTokenId").getAsLong();
|
||||||
ltk = json.get("ltk").getAsLong();
|
lastChatId = json.get("lastChatId").getAsLong();
|
||||||
lbk = json.get("lbk").getAsLong();
|
ltk = json.get("ltk").getAsLong();
|
||||||
eof = json.get("eof").getAsBoolean();
|
lbk = json.get("lbk").getAsLong();
|
||||||
|
eof = json.get("eof").getAsBoolean();
|
||||||
|
} catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class MessageIn {
|
public class MessageIn extends InboundPacket {
|
||||||
|
|
||||||
private long chatId;
|
private long chatId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class NewMemIn {
|
public class NewMemIn extends InboundPacket {
|
||||||
|
|
||||||
private long chatId;
|
private long chatId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
public class PingIn {
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
|
|
||||||
|
public class PingIn extends InboundPacket {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.github.netricecake.loco.packet.inbound;
|
package com.github.netricecake.loco.packet.inbound;
|
||||||
|
|
||||||
|
import com.github.netricecake.loco.packet.InboundPacket;
|
||||||
import com.github.netricecake.loco.util.BsonUtil;
|
import com.github.netricecake.loco.util.BsonUtil;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class WriteIn {
|
public class WriteIn extends InboundPacket {
|
||||||
|
|
||||||
private int status;
|
private int status;
|
||||||
|
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ public class CheckInOut {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMethod() {
|
|
||||||
return "CHECKIN";
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] toBson() {
|
public byte[] toBson() {
|
||||||
JsonObject checkInObject = new JsonObject();
|
JsonObject checkInObject = new JsonObject();
|
||||||
checkInObject.addProperty("userId", userId);
|
checkInObject.addProperty("userId", userId);
|
||||||
|
|||||||
Reference in New Issue
Block a user