-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework Internet Card filtering system.
- Loading branch information
1 parent
5a685f8
commit d13c015
Showing
10 changed files
with
515 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/typesafe/config/impl/OpenComputersConfigCommentManipulationHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.typesafe.config.impl; | ||
|
||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigValue; | ||
import org.luaj.vm2.ast.Str; | ||
|
||
import java.util.List; | ||
|
||
public final class OpenComputersConfigCommentManipulationHook { | ||
private OpenComputersConfigCommentManipulationHook() { | ||
|
||
} | ||
|
||
public static Config setComments(Config config, String path, List<String> comments) { | ||
return config.withValue(path, setComments(config.getValue(path), comments)); | ||
} | ||
|
||
public static ConfigValue setComments(ConfigValue value, List<String> comments) { | ||
if (value.origin() instanceof SimpleConfigOrigin && value instanceof AbstractConfigValue) { | ||
return ((AbstractConfigValue) value).withOrigin( | ||
((SimpleConfigOrigin) value.origin()).setComments(comments) | ||
); | ||
} else { | ||
return value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
package li.cil.oc.util; | ||
|
||
import com.google.common.net.InetAddresses; | ||
|
||
import java.net.InetAddress; | ||
|
||
// Originally by SquidDev | ||
public final class InetAddressRange { | ||
private final byte[] min; | ||
private final byte[] max; | ||
|
||
InetAddressRange(byte[] min, byte[] max) { | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public boolean matches(InetAddress address) { | ||
byte[] entry = address.getAddress(); | ||
if (entry.length != min.length) return false; | ||
|
||
for (int i = 0; i < entry.length; i++) { | ||
int value = 0xFF & entry[i]; | ||
if (value < (0xFF & min[i]) || value > (0xFF & max[i])) return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static InetAddressRange parse(String addressStr, String prefixSizeStr) { | ||
int prefixSize; | ||
try { | ||
prefixSize = Integer.parseInt(prefixSizeStr); | ||
} catch (NumberFormatException e) { | ||
throw new IllegalArgumentException(String.format("Malformed address range entry '%s': Cannot extract size of CIDR mask from '%s'.", | ||
addressStr + '/' + prefixSizeStr, prefixSizeStr)); | ||
} | ||
|
||
InetAddress address; | ||
try { | ||
address = InetAddresses.forString(addressStr); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException(String.format("Malformed address range entry '%s': Cannot extract IP address from '%s'.", | ||
addressStr + '/' + prefixSizeStr, addressStr)); | ||
} | ||
|
||
// Mask the bytes of the IP address. | ||
byte[] minBytes = address.getAddress(), maxBytes = address.getAddress(); | ||
int size = prefixSize; | ||
for (int i = 0; i < minBytes.length; i++) { | ||
if (size <= 0) { | ||
minBytes[i] = (byte) 0; | ||
maxBytes[i] = (byte) 0xFF; | ||
} else if (size < 8) { | ||
minBytes[i] = (byte) (minBytes[i] & 0xFF << (8 - size)); | ||
maxBytes[i] = (byte) (maxBytes[i] | ~(0xFF << (8 - size))); | ||
} | ||
|
||
size -= 8; | ||
} | ||
|
||
return new InetAddressRange(minBytes, maxBytes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.