mirror of
https://github.com/jie65535/gc-opencommand-plugin.git
synced 2025-06-02 17:49:12 +08:00
Fix send code failed
This commit is contained in:
parent
1439139404
commit
b3bc0f051a
@ -26,10 +26,8 @@ import com.github.jie65535.opencommand.socket.packet.HttpPacket;
|
|||||||
import com.github.jie65535.opencommand.socket.packet.RunConsoleCommand;
|
import com.github.jie65535.opencommand.socket.packet.RunConsoleCommand;
|
||||||
import com.github.jie65535.opencommand.socket.packet.player.Player;
|
import com.github.jie65535.opencommand.socket.packet.player.Player;
|
||||||
import com.github.jie65535.opencommand.socket.packet.player.PlayerEnum;
|
import com.github.jie65535.opencommand.socket.packet.player.PlayerEnum;
|
||||||
import emu.grasscutter.command.CommandMap;
|
|
||||||
import emu.grasscutter.server.http.Router;
|
import emu.grasscutter.server.http.Router;
|
||||||
import emu.grasscutter.utils.Crypto;
|
import emu.grasscutter.utils.Crypto;
|
||||||
import emu.grasscutter.utils.MessageHandler;
|
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import express.Express;
|
import express.Express;
|
||||||
import express.http.Request;
|
import express.http.Request;
|
||||||
@ -41,7 +39,6 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.FutureTask;
|
|
||||||
|
|
||||||
public final class OpenCommandOnlyHttpHandler implements Router {
|
public final class OpenCommandOnlyHttpHandler implements Router {
|
||||||
|
|
||||||
@ -189,7 +186,7 @@ public final class OpenCommandOnlyHttpHandler implements Router {
|
|||||||
player.type = PlayerEnum.RunCommand;
|
player.type = PlayerEnum.RunCommand;
|
||||||
player.data = command;
|
player.data = command;
|
||||||
|
|
||||||
if (!SocketServer.sendUidPacket(playerId, player, socketDataWait)) {
|
if (!SocketServer.sendUidPacketAndWait(playerId, player, socketDataWait)) {
|
||||||
response.json(new JsonResponse(404, "Player Not Found."));
|
response.json(new JsonResponse(404, "Player Not Found."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,9 @@ public class SocketServer {
|
|||||||
// 向全部客户端发送数据
|
// 向全部客户端发送数据
|
||||||
public static boolean sendAllPacket(BasePacket packet) {
|
public static boolean sendAllPacket(BasePacket packet) {
|
||||||
var p = SocketUtils.getPacket(packet);
|
var p = SocketUtils.getPacket(packet);
|
||||||
HashMap<String, ClientThread> old = (HashMap<String, ClientThread>) clientList.clone();
|
HashMap<String, ClientInfo> old = (HashMap<String, ClientInfo>) clientList.clone();
|
||||||
for (var client : old.entrySet()) {
|
for (var client : old.entrySet()) {
|
||||||
if (!client.getValue().sendPacket(p)) {
|
if (!client.getValue().clientThread.sendPacket(p)) {
|
||||||
mLogger.warn("[OpenCommand] Send packet to client {} failed", client.getKey());
|
mLogger.warn("[OpenCommand] Send packet to client {} failed", client.getKey());
|
||||||
clientList.remove(client.getKey());
|
clientList.remove(client.getKey());
|
||||||
}
|
}
|
||||||
@ -90,8 +90,24 @@ public class SocketServer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean sendUidPacket(Integer playerId, BasePacket player) {
|
||||||
|
var p = SocketUtils.getPacket(player);
|
||||||
|
var clientID = SocketData.getPlayerInServer(playerId);
|
||||||
|
if (clientID == null) return false;
|
||||||
|
var client = clientList.get(clientID);
|
||||||
|
if (client != null) {
|
||||||
|
if (!client.clientThread.sendPacket(p)) {
|
||||||
|
mLogger.warn("[OpenCommand] Send packet to client {} failed", clientID);
|
||||||
|
clientList.remove(clientID);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 根据Uid发送到相应的客户端异步返回数据
|
// 根据Uid发送到相应的客户端异步返回数据
|
||||||
public static boolean sendUidPacket(Integer playerId, BasePacket player, SocketDataWait<?> socketDataWait) {
|
public static boolean sendUidPacketAndWait(Integer playerId, BasePacket player, SocketDataWait<?> socketDataWait) {
|
||||||
var p = SocketUtils.getPacketAndPackID(player);
|
var p = SocketUtils.getPacketAndPackID(player);
|
||||||
var clientID = SocketData.getPlayerInServer(playerId);
|
var clientID = SocketData.getPlayerInServer(playerId);
|
||||||
if (clientID == null) return false;
|
if (clientID == null) return false;
|
||||||
|
@ -26,6 +26,6 @@ public class Player extends BasePacket {
|
|||||||
p.type = PlayerEnum.DropMessage;
|
p.type = PlayerEnum.DropMessage;
|
||||||
p.uid = uid;
|
p.uid = uid;
|
||||||
p.data = str;
|
p.data = str;
|
||||||
SocketServer.sendAllPacket(p);
|
SocketServer.sendUidPacket(uid, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user