make config file and read server ip from him

This commit is contained in:
MaximZaitsev
2016-08-16 19:17:54 +03:00
parent 0a2fd84002
commit 2c7107f5ba
2 changed files with 32 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
/**
* Created by user on 8/16/16.
*/
class Config(val configFileName: String) {
private var serverIp = "127.0.0.1"
fun loadConfig(): Boolean {
val data: String = fs.readFileSync(configFileName, "utf8")
data.split("\n").forEach { line ->
val keyValue = line.split(":")
if (keyValue.size == 2) {
when (keyValue[0]) {
"ip" -> serverIp = keyValue[1]
}
} else {
return false
}
}
return true
}
fun getIp(): String {
return serverIp
}
}
+5 -2
View File
@@ -18,10 +18,13 @@ val serverIp: String = "127.0.0.1"
val mainServerAddress = "127.0.0.1"
val mainServerPort = 7925
val config = Config("config.cfg")
val fs = require("fs")
fun main(args: Array<String>) {
if (!config.loadConfig()) {
println("incorrect config format!")
return
}
val handlers: MutableMap<String, AbstractHandler> = mutableMapOf()
handlers.put("/rc/control", Control(DirectionRequest.BuilderDirectionRequest(DirectionRequest.Command.fromIntToCommand(0), 0), DirectionResponse.BuilderDirectionResponse(0)))
handlers.put("/rc/connect", Connect(SessionUpResponse.BuilderSessionUpResponse(0, 0)))