-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from LossyDragon/defaultprotocols
Use GetCMListForConnect and allow WebSockets in default protocols
- Loading branch information
Showing
27 changed files
with
1,539 additions
and
1,010 deletions.
There are no files selected for viewing
88 changes: 0 additions & 88 deletions
88
src/main/java/in/dragonbra/javasteam/steam/discovery/FileServerListProvider.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
src/main/java/in/dragonbra/javasteam/steam/discovery/FileServerListProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
13 changes: 4 additions & 9 deletions
13
.../steam/discovery/IServerListProvider.java → ...am/steam/discovery/IServerListProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) | ||
} |
32 changes: 0 additions & 32 deletions
32
src/main/java/in/dragonbra/javasteam/steam/discovery/MemoryServerListProvider.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/main/java/in/dragonbra/javasteam/steam/discovery/MemoryServerListProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
src/main/java/in/dragonbra/javasteam/steam/discovery/NullServerListProvider.java
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
src/main/java/in/dragonbra/javasteam/steam/discovery/NullServerListProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>) { | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
src/main/java/in/dragonbra/javasteam/steam/discovery/ServerInfo.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
src/main/java/in/dragonbra/javasteam/steam/discovery/ServerInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.