19 02 25
Лобавил пинг
This commit is contained in:
parent
6949fd8a2f
commit
c7440e2b5c
@ -42,12 +42,14 @@ import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_GetUserPar
|
||||
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_ListUserParams_Request;
|
||||
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_UpsertUserParam_Request;
|
||||
|
||||
// --- subscriptions ---
|
||||
|
||||
// --- NEW: connections friends lists ---
|
||||
import server.logic.ws_protocol.JSON.handlers.connections.Net_GetFriendsLists_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_GetFriendsLists_Request;
|
||||
|
||||
// --- NEW: Ping ---
|
||||
import server.logic.ws_protocol.JSON.handlers.system.Net_Ping_Handler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_Ping_Request;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -80,7 +82,10 @@ public final class JsonHandlerRegistry {
|
||||
Map.entry("ListUserParams", new Net_ListUserParams_Handler()),
|
||||
|
||||
// --- connections ---
|
||||
Map.entry("GetFriendsLists", new Net_GetFriendsLists_Handler())
|
||||
Map.entry("GetFriendsLists", new Net_GetFriendsLists_Handler()),
|
||||
|
||||
// --- system ---
|
||||
Map.entry("Ping", new Net_Ping_Handler())
|
||||
|
||||
// --- subscriptions ---
|
||||
// Map.entry("ListSubscribedChannels", new Net_GetSubscribedChannels_Handler())
|
||||
@ -109,9 +114,11 @@ public final class JsonHandlerRegistry {
|
||||
Map.entry("GetUserParam", Net_GetUserParam_Request.class),
|
||||
Map.entry("ListUserParams", Net_ListUserParams_Request.class),
|
||||
|
||||
|
||||
// --- connections ---
|
||||
Map.entry("GetFriendsLists", Net_GetFriendsLists_Request.class)
|
||||
Map.entry("GetFriendsLists", Net_GetFriendsLists_Request.class),
|
||||
|
||||
// --- system ---
|
||||
Map.entry("Ping", Net_Ping_Request.class)
|
||||
);
|
||||
|
||||
private JsonHandlerRegistry() { }
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.system;
|
||||
|
||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_Ping_Request;
|
||||
import server.logic.ws_protocol.JSON.handlers.system.entyties.Net_Ping_Response;
|
||||
import server.logic.ws_protocol.WireCodes;
|
||||
|
||||
/**
|
||||
* Ping — keep-alive.
|
||||
* В ответ кладём только ts (текущее время сервера в мс).
|
||||
*/
|
||||
public class Net_Ping_Handler implements JsonMessageHandler {
|
||||
|
||||
@Override
|
||||
public Net_Response handle(Net_Request baseRequest, ConnectionContext ctx) {
|
||||
Net_Ping_Request req = (Net_Ping_Request) baseRequest;
|
||||
|
||||
Net_Ping_Response resp = new Net_Ping_Response();
|
||||
resp.setOp(req.getOp()); // "Ping"
|
||||
resp.setRequestId(req.getRequestId());
|
||||
resp.setStatus(WireCodes.Status.OK);
|
||||
|
||||
// ничего не проверяем, просто отдаём серверное время
|
||||
resp.setTs(System.currentTimeMillis());
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.system.entyties;
|
||||
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
||||
|
||||
/**
|
||||
* Ping:
|
||||
* {
|
||||
* "op": "Ping",
|
||||
* "requestId": "req-1",
|
||||
* "payload": { "ts": 1700000000000 }
|
||||
* }
|
||||
*
|
||||
* Сервер ничего не проверяет, поле ts можно слать любое.
|
||||
*/
|
||||
public class Net_Ping_Request extends Net_Request {
|
||||
|
||||
private long ts;
|
||||
|
||||
public long getTs() { return ts; }
|
||||
public void setTs(long ts) { this.ts = ts; }
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package server.logic.ws_protocol.JSON.handlers.system.entyties;
|
||||
|
||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
||||
|
||||
/**
|
||||
* Pong-ответ:
|
||||
* {
|
||||
* "op": "Ping",
|
||||
* "requestId": "req-1",
|
||||
* "status": 200,
|
||||
* "payload": { "ts": 1700000000123 }
|
||||
* }
|
||||
*/
|
||||
public class Net_Ping_Response extends Net_Response {
|
||||
|
||||
private long ts;
|
||||
|
||||
public long getTs() { return ts; }
|
||||
public void setTs(long ts) { this.ts = ts; }
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user