MCPcopy Create free account
hub / github.com/demoth/jake2 / fromString

Method fromString

qcommon/src/main/java/jake2/qcommon/network/netadr_t.java:45–65  ·  view source on GitHub ↗

@param s String address, like 10.132.12.54:4312 @return null if the string s is not a valid address

(String s, int defaultPort)

Source from the content-addressed store, hash-verified

43 * @return null if the string s is not a valid address
44 */
45 public static netadr_t fromString(String s, int defaultPort) {
46 if (s.equalsIgnoreCase("localhost") || s.equalsIgnoreCase("loopback")) {
47 return net_local_adr;
48 } else {
49 try {
50 netadr_t result = new netadr_t();
51 String[] address = s.split(":");
52 InetAddress ia = InetAddress.getByName(address[0]);
53 result.ip = ia.getAddress();
54 result.type = NetAddrType.NA_IP;
55 if (address.length == 2)
56 result.port = Lib.atoi(address[1]);
57 if (result.port == 0)
58 result.port = defaultPort;
59 return result;
60 } catch (Exception e) {
61 Com.Println(e.getMessage());
62 return null;
63 }
64 }
65 }
66
67 public netadr_t() {
68 this.type = NetAddrType.NA_LOOPBACK;

Callers 4

CLClass · 0.45
SendConnectPacketMethod · 0.45
CheckForResendMethod · 0.45
SV_MAINMethod · 0.45

Calls 2

atoiMethod · 0.95
PrintlnMethod · 0.95

Tested by

no test coverage detected