Started server code refactor

This commit is contained in:
danielyxie
2019-03-02 19:15:10 -08:00
parent af3323a111
commit e1b8a23f1e
13 changed files with 868 additions and 717 deletions
+25
View File
@@ -0,0 +1,25 @@
import {AllServers} from "../src/Server";
import {getRandomByte} from "./helpers/getRandomByte";
/* Functions to deal with manipulating IP addresses*/
//Generate a random IP address
//Will not return an IP address that already exists in the AllServers array
export function createRandomIp(): string {
const ip: string = getRandomByte(99) + '.' +
getRandomByte(9) + '.' +
getRandomByte(9) + '.' +
getRandomByte(9);
// If the Ip already exists, recurse to create a new one
if (ipExists(ip)) {
return createRandomIp();
}
return ip;
}
// Returns true if the IP already exists in one of the game's servers
export function ipExists(ip: string) {
return (AllServers[ip] != null);
}