mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-12 16:57:32 -04:00
Improved parameter validation for internet.connect
, closes #533.
This commit is contained in:
parent
9ae5fbc512
commit
4f2b942f73
@ -68,7 +68,7 @@ class InternetCard extends component.ManagedComponent {
|
||||
if (connections.size >= Settings.get.maxConnections) {
|
||||
throw new IOException("too many open connections")
|
||||
}
|
||||
val uri = checkUri(address)
|
||||
val uri = checkUri(address, port)
|
||||
val handle = newHandle()
|
||||
connections += handle -> new InternetCard.Socket(uri, port)
|
||||
result(handle)
|
||||
@ -173,10 +173,10 @@ class InternetCard extends component.ManagedComponent {
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
private def checkUri(address: String): URI = {
|
||||
private def checkUri(address: String, port: Int): URI = {
|
||||
try {
|
||||
val parsed = new URI(address)
|
||||
if (parsed.getHost != null && parsed.getPort != -1) {
|
||||
if (parsed.getHost != null && (parsed.getPort > 0 || port > 0)) {
|
||||
return parsed
|
||||
}
|
||||
}
|
||||
@ -185,11 +185,14 @@ class InternetCard extends component.ManagedComponent {
|
||||
}
|
||||
|
||||
val simple = new URI("oc://" + address)
|
||||
if (simple.getHost != null && simple.getPort != -1) {
|
||||
return simple
|
||||
if (simple.getHost != null) {
|
||||
if (simple.getPort > 0)
|
||||
return simple
|
||||
else if (port > 0)
|
||||
return new URI(simple.toString + ":" + port)
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("address could not be parsed")
|
||||
throw new IllegalArgumentException("address could not be parsed or no valid port given")
|
||||
}
|
||||
|
||||
private def checkAddress(address: String) = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user