Update NPC protocol tests for validated active sessions
This commit is contained in:
+18
-13
@@ -6,7 +6,7 @@ import time
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from client_session import ClientSession
|
from client_session import ClientSession
|
||||||
from server_core import FalloutTogetherServer
|
from server_core import FalloutTogetherServer, MAX_NPCS_PER_PACKET
|
||||||
|
|
||||||
|
|
||||||
class NpcProtocolTests(unittest.TestCase):
|
class NpcProtocolTests(unittest.TestCase):
|
||||||
@@ -16,6 +16,10 @@ class NpcProtocolTests(unittest.TestCase):
|
|||||||
self.server = FalloutTogetherServer()
|
self.server = FalloutTogetherServer()
|
||||||
self.host = ClientSession(self.host_server, ("local", 1), 1, time.time())
|
self.host = ClientSession(self.host_server, ("local", 1), 1, time.time())
|
||||||
self.client = ClientSession(self.client_server, ("local", 2), 2, time.time())
|
self.client = ClientSession(self.client_server, ("local", 2), 2, time.time())
|
||||||
|
self.host.mark_gameplay_active(1)
|
||||||
|
self.client.mark_gameplay_active(1)
|
||||||
|
self.server._init_rate_state(self.host, time.monotonic())
|
||||||
|
self.server._init_rate_state(self.client, time.monotonic())
|
||||||
self.server._clients = {
|
self.server._clients = {
|
||||||
self.host_server: self.host,
|
self.host_server: self.host,
|
||||||
self.client_server: self.client,
|
self.client_server: self.client,
|
||||||
@@ -31,6 +35,17 @@ class NpcProtocolTests(unittest.TestCase):
|
|||||||
):
|
):
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
def _npc(self, index: int) -> dict:
|
||||||
|
return {
|
||||||
|
"npcId": index,
|
||||||
|
"sourceFormId": "0001A4D7",
|
||||||
|
"x": float(index),
|
||||||
|
"y": 2.0,
|
||||||
|
"z": 3.0,
|
||||||
|
"angleZ": 0.5,
|
||||||
|
"cellId": "0000003C",
|
||||||
|
}
|
||||||
|
|
||||||
def test_host_npc_state_is_authoritative_and_broadcast(self) -> None:
|
def test_host_npc_state_is_authoritative_and_broadcast(self) -> None:
|
||||||
self.server._handle_line(
|
self.server._handle_line(
|
||||||
self.host,
|
self.host,
|
||||||
@@ -38,17 +53,7 @@ class NpcProtocolTests(unittest.TestCase):
|
|||||||
{
|
{
|
||||||
"type": "npcState",
|
"type": "npcState",
|
||||||
"playerId": 999,
|
"playerId": 999,
|
||||||
"npcs": [
|
"npcs": [self._npc(1)],
|
||||||
{
|
|
||||||
"npcId": 1,
|
|
||||||
"baseFormId": "0001A4D7",
|
|
||||||
"x": 1.0,
|
|
||||||
"y": 2.0,
|
|
||||||
"z": 3.0,
|
|
||||||
"angleZ": 0.5,
|
|
||||||
"cellId": "0000003C",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -104,7 +109,7 @@ class NpcProtocolTests(unittest.TestCase):
|
|||||||
json.dumps(
|
json.dumps(
|
||||||
{
|
{
|
||||||
"type": "npcState",
|
"type": "npcState",
|
||||||
"npcs": [{"npcId": index + 1} for index in range(17)],
|
"npcs": [self._npc(index + 1) for index in range(MAX_NPCS_PER_PACKET + 1)],
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user