Skip to content

Commit

Permalink
Fixed: ConnectionClientList
Browse files Browse the repository at this point in the history
- Добавлена дополнительная проверка в RedstoneSignal
- Обновлен rhino 1.7.15
- Исправлен ConnectionClientList
  • Loading branch information
Reider745 committed May 10, 2024
1 parent 6dcb7d1 commit a965f2e
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
// https://central.sonatype.com/artifact/com.google.code.gson/gson/versions
implementation group: 'com.google.code.gson', name: 'gson', version: '2.7'
// https://central.sonatype.com/artifact/org.mozilla/rhino/versions
implementation group: 'org.mozilla', name: 'rhino', version: '1.7.14'
implementation group: 'org.mozilla', name: 'rhino', version: '1.7.15'
// https://central.sonatype.com/artifact/org.json/json/versions
implementation group: 'org.json', name: 'json', version: '20231013'

Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/reider745/event/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,8 @@ public void onBlockExplosion(BlockExplosionPrimeEvent event) {// TODO: deprecate
}

final Location pos = event.getBlock().getLocation();



consumeEvent(event, () -> NativeCallback.onExplode((float) pos.x, (float) pos.y, (float) pos.z,
(float) event.getForce(), -1, false, event.isBlockBreaking(), Float.MAX_VALUE));
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand Down Expand Up @@ -411,9 +410,9 @@ public void onBlockUpdate(BlockGrowEvent event) {
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityTeleport(EntityTeleportEvent event) {
final int from = FakeDimensions.getFakeIdForLevel(event.getFrom().level);
final int to = FakeDimensions.getFakeIdForLevel(event.getFrom().level);
final int to = FakeDimensions.getFakeIdForLevel(event.getTo().level);

if (CustomDimension.getDimensionById(to) != null || CustomDimension.getDimensionById(from) != null)
if(to != from)
NativeCallback.onCustomDimensionTransfer(EntityMethod.getIdForEntity(event.getEntity()), from, to);
}

Expand Down Expand Up @@ -535,7 +534,4 @@ public void onPlayerFormResponded(PlayerFormRespondedEvent event) {

// TODO: onItemUsedNoTarget (not only custom items)

// TODO: onItemUseReleased (not only custom items)

// TODO: onItemUseComplete (not only custom items)
}
15 changes: 13 additions & 2 deletions src/main/java/com/reider745/hooks/NetworkHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@Hooks(className = "cn.nukkit.network.Network")
public class NetworkHooks implements HookClass {

private static LinkedList<String> canSendInfo = new LinkedList<>();
private static final LinkedList<String> canSendInfo = new LinkedList<>();

public static void close(Player player){
canSendInfo.remove(NativeNetworking.getId(player));
Expand Down Expand Up @@ -94,8 +94,19 @@ public static void processBatch(Network network, byte[] payload, Collection<Data
pk.protocol = player == null ? Integer.MAX_VALUE : player.protocol;
pk.setBuffer(buf, buf.length - bais.available());

if (pk instanceof BasePacket)
if (pk instanceof BasePacket) {
if(player == null){
/*
TODO: Иногда player бывает null, иза этого не проходит подключение по нативному протоклу
Возможное решение:
Хранить все пакеты с null player
Хукнуть setPlayer из cn.nukkit.network.session.RakNetPlayerSession и в нем обрабатывать пакеты
*/
log.warning("processBatch player null, ignore packet "+packetId);
break;
}
((BasePacket) pk).player = player;
}

if(player != null){
final String id = NativeNetworking.getId(player);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/reider745/network/InnerCorePacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void decode() {

NativeNetworking.onServerPacketReceived(player, name, format_id, bytes);
} catch (Exception e) {
Server.getInstance().getLogger().warning("Native protocol decoding error!", e);
player.kick(e.getMessage());
Server.getInstance().getLogger().warning("Native protocol decoding error! player: "+(player == null), e);
if(player != null) player.kick(e.getMessage());
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/reider745/world/BlockSourceMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public static void setBlock(Level level, int x, int y, int z, int id, int data,
int updateType) {
Block block = level.getBlock(x, y, z);
defDestroy(level, block);
level.setBlock(x, y, z, Block.get(id, data), false, allowUpdate);
try{
level.setBlock(x, y, z, Block.get(id, data), false, allowUpdate);
}catch (Exception e){}
}

public static void setBlockByRuntimeId(Level level, int x, int y, int z, int runtimeId, boolean allowUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ private static void globalRefresh() {
}
}

public static void onTick(){
final List<ConnectedClientList> listsToRefresh = new ArrayList<>();
synchronized (allClientLists) {
Java8BackComp.removeIf(allClientLists, ref -> {
ConnectedClientList list = ref.get();
if (list != null) {
listsToRefresh.add(list);
return false;
}
return true;
});
}

for (ConnectedClientList list : listsToRefresh) {
list.refresh();
}
}

private static void clearOnShutdown() {
synchronized (allClientLists) {
allClientLists.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.zhekasmirnov.apparatus.multiplayer.ThreadTypeMarker;
import com.zhekasmirnov.apparatus.multiplayer.server.ConnectedClient;
import com.zhekasmirnov.apparatus.ecs.core.EntitySystem;
import com.zhekasmirnov.apparatus.multiplayer.util.list.ConnectedClientList;
import com.zhekasmirnov.horizon.runtime.logger.Logger;
import com.zhekasmirnov.innercore.api.commontypes.Coords;
import com.zhekasmirnov.innercore.api.commontypes.FullBlock;
Expand Down Expand Up @@ -369,6 +370,7 @@ public static void onTick() {
Updatable.getForServer().onTick();
executor.blockUntilExecuted();
Updatable.getForServer().onPostTick();
ConnectedClientList.onTick();

// run ecs
serverTickingSystem.run(ECS.getEntityManager());
Expand Down
25 changes: 11 additions & 14 deletions src/main/resources/innercore/coreengine/core-engine.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,8 @@ var TileEntityBasePrototype = {
return true;
}
}
} else {
var screen = this.getGuiScreen();
if (screen) {
this.container.openAs(screen);
return true;
}
}
return false;

},
selfDestroy: function() {
Expand Down Expand Up @@ -829,7 +824,7 @@ var TileEntity = {
Prototype.saverId = Saver.registerObjectSaver(saverName, {
read: function(obj) {
if (!obj || !obj.coords) {
print("Corrupted data "+JSON.stringify(obj));
print("Corrupted save "+JSON.stringify(obj));
return;
}

Expand All @@ -842,7 +837,14 @@ var TileEntity = {
for (var property in Prototype) {
instance[property] = Prototype[property];
}
instance.data = obj.data || {};
instance.data = obj.data;
if(!instance.data){
instance.data = {};
for (let property in Prototype.defaultValues) {
instance.data[property] = Prototype.defaultValues[property];
}
print("Corrupted save data "+JSON.stringify(obj));
}
instance.x = obj.coords.x || 0;
instance.y = obj.coords.y || 0;
instance.z = obj.coords.z || 0;
Expand Down Expand Up @@ -1149,9 +1151,6 @@ var TileEntity = {
tileEntity.noupdate = false; // tile entity must update at least once to initialize
}
tileEntity.onCheckerTick(tileEntity.__initialized, tileEntity.isLoaded, wasLoaded);
if (tileEntity.networkEntity) {
tileEntity.networkEntity.refreshClients();
}
if (tileEntity.isLoaded && tileEntity.blockSource) {
var isPlaced = tileEntity.blockSource.getBlockId(tileEntity.x, tileEntity.y, tileEntity.z) === tileEntity.blockID;
if (!isPlaced) {
Expand Down Expand Up @@ -1198,9 +1197,7 @@ Callback.addCallback("tick", function() {
});
Callback.addCallback("RedstoneSignal", function(coords, params, onLoad, region) {
var tileEntity = TileEntity.getTileEntity(coords.x, coords.y, coords.z, region);
if (tileEntity) {
tileEntity.redstone(params);
}
tileEntity && tileEntity.__initialized && tileEntity.redstone(params);
});
Callback.addCallback("BreakBlock", function(blockSource, coords, fullTile, isDropAllowed, player, item) {
if (GameAPI.isActionPrevented()) {
Expand Down

0 comments on commit a965f2e

Please sign in to comment.