Skip to content

Commit

Permalink
Revert "支持文件服务器"
Browse files Browse the repository at this point in the history
This reverts commit c0c2d63
  • Loading branch information
CuteReimu committed Jan 13, 2025
1 parent 379c148 commit f47ba05
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 44 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/files/
*.dat
*.csv
/bin/
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ push.push_qq_groups=12345678
*纯人机局不会推送,至少要有2名真人玩家时才会推送。*

## 关于文件服务器

提供了一个文件服务器端口,供客户端下载资源文件,`file_server_port`字段配成0就是不启用文件服务器。

启动后,访问`http://ip:port/`即可看到`files`文件夹(事先自行创建一个`files`文件夹)下的文件列表,点击文件名即可下载。(目前暂不支持嵌套文件夹)

## 开发相关

### gradle镜像
Expand Down
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ dependencies {
testImplementation("junit:junit:4.13.2")
implementation("com.typesafe.akka:akka-actor_2.13:2.8.8")
implementation("io.netty:netty-all:4.1.116.Final")
implementation("io.ktor:ktor-server-netty:3.0.3")
implementation("io.ktor:ktor-server-core:3.0.3")
implementation("com.google.protobuf:protobuf-java-util:4.29.3")
implementation("com.google.protobuf:protobuf-kotlin:4.29.3")
implementation("org.apache.logging.log4j:log4j-api:2.24.3")
Expand Down
4 changes: 0 additions & 4 deletions src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicReference

object Config {
val FileServerPort: Int
val ListenWebSocketPort: Int
val TotalPlayerCount: Int
val RecordMaxInterval: Int
Expand Down Expand Up @@ -41,7 +40,6 @@ object Config {
} catch (e: Exception) {
throw RuntimeException(e)
}
pps.putIfAbsent("file_server_port", "9091")
pps.putIfAbsent("listen_websocket_port", "12222")
pps.putIfAbsent("player.total_count", "5")
pps.putIfAbsent("rule.record_max_interval", "3")
Expand All @@ -60,7 +58,6 @@ object Config {
pps.putIfAbsent("push.robot_qq", "12345678")
pps.putIfAbsent("push.push_qq_groups", "")
pps.putIfAbsent("waiting_second", "15")
FileServerPort = pps.getProperty("file_server_port").toInt()
ListenWebSocketPort = pps.getProperty("listen_websocket_port").toInt()
RecordMaxInterval = pps.getProperty("rule.record_max_interval").toInt()
TotalPlayerCount = pps.getProperty("player.total_count").toInt()
Expand Down Expand Up @@ -98,7 +95,6 @@ object Config {
fun save() {
synchronized(this) {
val pps = Properties()
pps["file_server_port"] = FileServerPort.toString()
pps["listen_websocket_port"] = ListenWebSocketPort.toString()
pps["player.total_count"] = TotalPlayerCount.toString()
pps["rule.record_max_interval"] = RecordMaxInterval.toString()
Expand Down
32 changes: 1 addition & 31 deletions src/main/kotlin/network/Network.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package com.fengsheng.network

import com.fengsheng.Config
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.http.content.*
import io.ktor.server.netty.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.netty.bootstrap.ServerBootstrap
import io.netty.channel.EventLoopGroup
import io.netty.channel.nio.NioEventLoopGroup
Expand All @@ -16,7 +9,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File

object Network {
fun init() {
Expand All @@ -25,8 +17,7 @@ object Network {
// launch(Dispatchers.IO) { initGameNetwork() },
launch(Dispatchers.IO) { initGameWebSocketNetwork() },
launch(Dispatchers.IO) { initGmNetwork() },
if (Config.FileServerPort != 0) launch(Dispatchers.IO) { initFileServer(Config.FileServerPort) } else null
).filterNotNull().joinAll()
).joinAll()
}
}

Expand Down Expand Up @@ -86,25 +77,4 @@ object Network {
workerGroup.shutdownGracefully()
}
}

private fun initFileServer(port: Int) {
embeddedServer(Netty, port = port) {
routing {
get("/") {
val directory = File("files")
val files = directory.listFiles()
val response = buildString {
append("<html><body>")
files?.forEach { file ->
append("<a href=\"/${file.name}\">${file.name}</a><br/>")
}
append("</body></html>")
}
call.respondText(response, ContentType.Text.Html)
}

staticFiles("", File("files"))
}
}.start(wait = true)
}
}

0 comments on commit f47ba05

Please sign in to comment.