29
29
# #
30
30
################################################################################
31
31
32
- import asyncio
33
32
from rak_net .connection import Connection
34
33
from rak_net .protocol .handler .offline_ping_handler import OfflinePingHandler
35
34
from rak_net .protocol .handler .open_connection_request_1_handler import OpenConnectionRequest1Handler
43
42
44
43
45
44
class Server :
46
- def __init__ (self , is_async : bool , protocol_version : int , hostname : str , port : int , ipv : int = 4 , tps : int = 100 ) -> None :
45
+ def __init__ (self , protocol_version : int , hostname : str , port : int , ipv : int = 4 , tps : int = 100 ) -> None :
47
46
self .tick_sleep_time : float = 1 / tps
48
47
self .protocol_version : int = protocol_version
49
48
self .address : InternetAddress = InternetAddress (hostname , port , ipv )
50
49
self .guid : int = random .randint (0 , sys .maxsize )
51
50
self .socket : UdpSocket = UdpSocket (True , ipv , hostname , port )
52
51
self .connections : dict [(str , Connection )] = {}
53
52
self .start_time : int = int (time .time () * 1000 )
54
- if is_async :
55
- asyncio .get_event_loop ().create_task (self .tick_task ())
56
- asyncio .get_event_loop ().create_task (self .handle_task ())
57
53
58
54
def get_time_ms (self ) -> int :
59
55
return int (time .time () * 1000 ) - self .start_time
@@ -71,16 +67,6 @@ def get_connection(self, address: InternetAddress) -> Connection:
71
67
72
68
def send_data (self , data : bytes , address : InternetAddress ) -> None :
73
69
self .socket .send (data , address .hostname , address .port )
74
-
75
- async def tick_task (self ) -> None :
76
- while True :
77
- self .tick ()
78
- await asyncio .sleep (self .tick_sleep_time )
79
-
80
- async def handle_task (self ) -> None :
81
- while True :
82
- self .handle ()
83
- await asyncio .sleep (self .tick_sleep_time )
84
70
85
71
def tick (self ) -> None :
86
72
for connection in dict (self .connections ).values ():
0 commit comments