make config file and read server ip from him
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user