-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run file server earlier on startup & rename forceWalk to exactMove (#467
) * Remove unused VisualEncoder variable * Rename ForceMovement to ExactMovement * Rename forceWalk to exactMove * Split ConnectionGatekeeper into ClientManager and LoginManager to allow loading the Game and File server before Login for faster client connection startup times closes #465
- Loading branch information
Showing
29 changed files
with
345 additions
and
161 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
engine/src/main/kotlin/world/gregs/voidps/engine/client/ClientManager.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,31 @@ | ||
package world.gregs.voidps.engine.client | ||
|
||
import world.gregs.voidps.network.SessionManager | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
/** | ||
* Keeps track of number of clients per ip address | ||
*/ | ||
class ClientManager : SessionManager { | ||
private val connections = ConcurrentHashMap<String, Int>() | ||
|
||
override fun count(key: String) = connections[key] ?: 0 | ||
|
||
override fun add(key: String): Int? { | ||
connections[key] = count(key) + 1 | ||
return null | ||
} | ||
|
||
override fun remove(key: String) { | ||
val count = count(key) - 1 | ||
if (count <= 0) { | ||
connections.remove(key) | ||
} else { | ||
connections[key] = count | ||
} | ||
} | ||
|
||
override fun clear() { | ||
connections.clear() | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
engine/src/main/kotlin/world/gregs/voidps/engine/client/LoginManager.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,34 @@ | ||
package world.gregs.voidps.engine.client | ||
|
||
import world.gregs.voidps.engine.client.ui.chat.toInt | ||
import world.gregs.voidps.engine.entity.character.IndexAllocator | ||
import world.gregs.voidps.network.SessionManager | ||
import java.util.concurrent.ConcurrentHashMap | ||
|
||
/** | ||
* Keeps track of the players online, prevents duplicate login attempts | ||
*/ | ||
class LoginManager( | ||
private val indices: IndexAllocator | ||
) : SessionManager { | ||
|
||
private val online = ConcurrentHashMap.newKeySet<String>() | ||
|
||
override fun count(key: String) = online.contains(key).toInt() | ||
|
||
override fun add(key: String): Int? { | ||
if (!online.add(key)) { | ||
return null | ||
} | ||
return indices.obtain() | ||
} | ||
|
||
override fun remove(key: String) { | ||
online.remove(key) | ||
} | ||
|
||
override fun clear() { | ||
indices.clear() | ||
online.clear() | ||
} | ||
} |
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
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
70 changes: 70 additions & 0 deletions
70
engine/src/test/kotlin/world/gregs/voidps/engine/client/ClientManagerTest.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,70 @@ | ||
package world.gregs.voidps.engine.client | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class ClientManagerTest { | ||
|
||
private lateinit var manager: ClientManager | ||
|
||
@BeforeEach | ||
fun setup() { | ||
manager = ClientManager() | ||
} | ||
|
||
@Test | ||
fun `Same addresses are counted`() { | ||
val address = "123.456.789" | ||
assertEquals(0, manager.count(address)) | ||
manager.add(address) | ||
assertEquals(1, manager.count(address)) | ||
manager.add(address) | ||
assertEquals(2, manager.count(address)) | ||
manager.add(address) | ||
assertEquals(3, manager.count(address)) | ||
} | ||
|
||
@Test | ||
fun `Different addresses are separate`() { | ||
assertEquals(0, manager.count("123.456.789")) | ||
manager.add("123.456.789") | ||
assertEquals(0, manager.count("100.000.000")) | ||
manager.add("100.000.000") | ||
|
||
assertEquals(1, manager.count("100.000.000")) | ||
assertEquals(1, manager.count("123.456.789")) | ||
} | ||
|
||
@Test | ||
fun `Disconnections aren't counted`() { | ||
val address = "123.456.789" | ||
assertEquals(0, manager.count(address)) | ||
manager.add(address) | ||
manager.add(address) | ||
assertEquals(2, manager.count(address)) | ||
manager.remove(address) | ||
assertEquals(1, manager.count(address)) | ||
} | ||
|
||
@Test | ||
fun `Too many disconnections isn't negative`() { | ||
val address = "123.456.789" | ||
assertEquals(0, manager.count(address)) | ||
manager.add(address) | ||
assertEquals(1, manager.count(address)) | ||
manager.remove(address) | ||
assertEquals(0, manager.count(address)) | ||
manager.remove(address) | ||
assertEquals(0, manager.count(address)) | ||
} | ||
|
||
@Test | ||
fun `Clearing removes all counts`() { | ||
val address = "123.456.789" | ||
manager.add(address) | ||
assertEquals(1, manager.count(address)) | ||
manager.clear() | ||
assertEquals(0, manager.count(address)) | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
engine/src/test/kotlin/world/gregs/voidps/engine/client/ConnectionGatekeeperTest.kt
This file was deleted.
Oops, something went wrong.
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
70 changes: 70 additions & 0 deletions
70
engine/src/test/kotlin/world/gregs/voidps/engine/client/LoginManagerTest.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,70 @@ | ||
package world.gregs.voidps.engine.client | ||
|
||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import world.gregs.voidps.engine.entity.character.IndexAllocator | ||
|
||
class LoginManagerTest { | ||
|
||
private lateinit var manager: LoginManager | ||
private lateinit var indices: IndexAllocator | ||
|
||
@BeforeEach | ||
fun setup() { | ||
indices = IndexAllocator(5) | ||
manager = LoginManager(indices) | ||
} | ||
|
||
@Test | ||
fun `Same names can't be added twice`() { | ||
val name = "player" | ||
assertEquals(0, manager.count(name)) | ||
assertEquals(1, manager.add(name)) | ||
assertEquals(1, manager.count(name)) | ||
assertNull(manager.add(name)) | ||
assertEquals(1, manager.count(name)) | ||
} | ||
|
||
@Test | ||
fun `Different names different count`() { | ||
val name1 = "player1" | ||
val name2 = "player2" | ||
assertEquals(0, manager.count(name1)) | ||
assertEquals(1, manager.add(name1)) | ||
assertEquals(1, manager.count(name1)) | ||
assertEquals(0, manager.count(name2)) | ||
assertEquals(2, manager.add(name2)) | ||
assertEquals(1, manager.count(name2)) | ||
} | ||
|
||
@Test | ||
fun `Removed named clear count`() { | ||
val name = "player" | ||
assertEquals(1, manager.add(name)) | ||
assertEquals(1, manager.count(name)) | ||
manager.remove(name) | ||
assertEquals(0, manager.count(name)) | ||
} | ||
|
||
@Test | ||
fun `Removing name twice doesn't cause negative count`() { | ||
val name = "player" | ||
assertEquals(1, manager.add(name)) | ||
assertEquals(1, manager.count(name)) | ||
manager.remove(name) | ||
assertEquals(0, manager.count(name)) | ||
manager.remove(name) | ||
assertEquals(0, manager.count(name)) | ||
} | ||
|
||
@Test | ||
fun `Clear names removes count`() { | ||
val name = "player" | ||
assertEquals(1, manager.add(name)) | ||
assertEquals(1, manager.count(name)) | ||
manager.clear() | ||
assertEquals(0, manager.count(name)) | ||
assertEquals(1, manager.add(name)) | ||
} | ||
} |
Oops, something went wrong.