Skip to content

Commit

Permalink
Merge pull request #281 from LossyDragon/defaultprotocols
Browse files Browse the repository at this point in the history
Use GetCMListForConnect and allow WebSockets in default protocols
  • Loading branch information
LossyDragon authored Oct 1, 2024
2 parents c74e349 + d71928c commit 08690d0
Show file tree
Hide file tree
Showing 27 changed files with 1,539 additions and 1,010 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package `in`.dragonbra.javasteam.steam.discovery

import `in`.dragonbra.javasteam.networking.steam3.ProtocolTypes
import `in`.dragonbra.javasteam.protobufs.steam.discovery.BasicServerListProtos.BasicServer
import `in`.dragonbra.javasteam.protobufs.steam.discovery.BasicServerListProtos.BasicServerList
import `in`.dragonbra.javasteam.util.log.LogManager
import `in`.dragonbra.javasteam.util.log.Logger
import java.io.File
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.io.IOException

/**
* Server provider that stores servers in a file using protobuf.
*/
class FileServerListProvider(private val file: File) : IServerListProvider {

/**
* Instantiates a [FileServerListProvider] object.
* @param file the file that will store the servers
*/
init {
try {
file.absoluteFile.parentFile?.mkdirs()
file.createNewFile()
} catch (e: IOException) {
logger.error(e)
}
}

override fun fetchServerList(): List<ServerRecord> = try {
FileInputStream(file).use { fis ->
val serverList = BasicServerList.parseFrom(fis)
List(serverList.serversCount) { i ->
val server: BasicServer = serverList.getServers(i)
ServerRecord.createServer(
server.getAddress(),
server.port,
ProtocolTypes.from(server.protocol)
)
}
}
} catch (e: FileNotFoundException) {
logger.error("servers list file not found", e)
emptyList()
} catch (e: IOException) {
logger.error("Failed to read server list file ${file.absolutePath}", e)
emptyList()
}

override fun updateServerList(endpoints: List<ServerRecord>) {
val builder = BasicServerList.newBuilder().apply {
endpoints.forEach { endpoint ->
addServers(
BasicServer.newBuilder().apply {
address = endpoint.host
port = endpoint.port
protocol = ProtocolTypes.code(endpoint.protocolTypes)
}
)
}
}

try {
FileOutputStream(file, false).use { fos ->
builder.build().writeTo(fos)
fos.flush()
}
} catch (e: IOException) {
logger.error("Failed to write servers to file ${file.absolutePath}", e)
}
}

companion object {
private val logger: Logger = LogManager.getLogger(FileServerListProvider::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package in.dragonbra.javasteam.steam.discovery;

import java.util.List;
package `in`.dragonbra.javasteam.steam.discovery

/**
* An interface for persisting the server list for connection discovery
*/
public interface IServerListProvider {

interface IServerListProvider {
/**
* Ask a provider to fetch any servers that it has available
*
* @return A list of IPEndPoints representing servers
*/
List<ServerRecord> fetchServerList();
fun fetchServerList(): List<ServerRecord>

/**
* Update the persistent list of endpoints
*
* @param endpoints List of endpoints
*/
void updateServerList(List<ServerRecord> endpoints);
fun updateServerList(endpoints: List<ServerRecord>)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package `in`.dragonbra.javasteam.steam.discovery

/**
* A server list provider that uses an in-memory list
*/
class MemoryServerListProvider : IServerListProvider {

var servers: List<ServerRecord> = listOf()

/**
* Returns the stored server list in memory
* @return List of servers if persisted, otherwise an empty list
*/
override fun fetchServerList(): List<ServerRecord> = servers

/**
* Stores the supplied list of servers in memory
* @param endpoints List of endpoints (servers)
*/
override fun updateServerList(endpoints: List<ServerRecord>) {
servers = endpoints
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package `in`.dragonbra.javasteam.steam.discovery

/**
* @author lngtr
* @since 2018-02-20
*
* @constructor A server list provider that returns an empty list, for consumers that populate the server list themselves
*/
@Suppress("unused")
class NullServerListProvider : IServerListProvider {

/**
* No-op implementation that returns an empty server list
* @return an Empty server list
*/
override fun fetchServerList(): List<ServerRecord> = emptyList<ServerRecord>()

/**
* No-op implementation that does not persist server list
* @param endpoints Server list
*/
override fun updateServerList(endpoints: List<ServerRecord>) {
}
}

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/in/dragonbra/javasteam/steam/discovery/ServerInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package `in`.dragonbra.javasteam.steam.discovery

import `in`.dragonbra.javasteam.networking.steam3.ProtocolTypes
import java.time.Instant

/**
* @author lngtr
* @since 2018-02-20
*/
class ServerInfo(val record: ServerRecord, val protocol: ProtocolTypes) {
var lastBadConnectionTimeUtc: Instant? = null
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package in.dragonbra.javasteam.steam.discovery;
package `in`.dragonbra.javasteam.steam.discovery

/**
* Currently marked quality of a server. All servers start off as Undetermined.
*/
public enum ServerQuality {

enum class ServerQuality {
/**
* Known good server.
*/
Expand All @@ -13,5 +12,5 @@ public enum ServerQuality {
/**
* Known bad server.
*/
BAD
BAD,
}
Loading

0 comments on commit 08690d0

Please sign in to comment.