Skip to content

Commit

Permalink
v0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Feb 6, 2025
1 parent c8243be commit 4d4874c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
13 changes: 7 additions & 6 deletions loginproxy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

__all__ = [
'Protocol',
'ON_CONNECT', 'ON_PING', 'ON_LOGIN', 'ON_PRELOGIN', 'ON_LOGOFF',
'ON_CONNECT', 'ON_PING', 'ON_LOGIN', 'ON_PRELOGIN', 'ON_POSTLOGIN', 'ON_LOGOFF',
'ON_PACKET_C2S', 'ON_PACKET_S2C',
]

ON_CONNECT = MCDR.LiteralEvent('login_proxy.on.connect')
ON_PING = MCDR.LiteralEvent('login_proxy.on.ping')
ON_PRELOGIN = MCDR.LiteralEvent('login_proxy.on.login.pre')
ON_LOGIN = MCDR.LiteralEvent('login_proxy.on.login')
ON_LOGOFF = MCDR.LiteralEvent('login_proxy.on.logoff')
ON_CONNECT = MCDR.LiteralEvent('login_proxy.on.connect')
ON_PING = MCDR.LiteralEvent('login_proxy.on.ping')
ON_LOGIN = MCDR.LiteralEvent('login_proxy.on.login')
ON_PRELOGIN = MCDR.LiteralEvent('login_proxy.on.login.pre')
ON_POSTLOGIN = MCDR.LiteralEvent('login_proxy.on.login.post')
ON_LOGOFF = MCDR.LiteralEvent('login_proxy.on.logoff')

ON_PACKET_C2S = MCDR.LiteralEvent('login_proxy.on.packet.c2s')
ON_PACKET_S2C = MCDR.LiteralEvent('login_proxy.on.packet.s2c')
12 changes: 8 additions & 4 deletions loginproxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def final0():
stream_forwarder(c2, c1, addr, final=final0, **kwargs)
return waiter

def handle_login_packet_c2s(c: Conn, reader: PacketReader, cancel):
def handle_login_packet_c2s(c: Conn, reader: PacketReader, event_dispatcher, cancel):
if reader.id == 0x01: # Encryption Response
cancel()
encrypted_secret = reader.read_bytearray()
Expand Down Expand Up @@ -839,7 +839,7 @@ def handle_login_packet_c2s(c: Conn, reader: PacketReader, cancel):
assert not isinstance(c._wrapped_conn_client, EncryptedConn)
c._wrapped_conn_client = EncryptedConn(c._wrapped_conn_client, encryptor)

def handle_login_packet_s2c(c: Conn, reader: PacketReader, cancel):
def handle_login_packet_s2c(c: Conn, reader: PacketReader, event_dispatcher, cancel):
if reader.id == 0x01: # Encryption Request
cancel()
server_id = reader.read_string()
Expand All @@ -866,6 +866,8 @@ def handle_login_packet_s2c(c: Conn, reader: PacketReader, cancel):
elif reader.id == 0x02: # Login Success
debug('Login success', c)
c._server_status = ConnStatus.PLAY
if c.client_status == ConnStatus.PLAY:
event_dispatcher(ON_POSTLOGIN, (c, ), on_executor_thread=False)
if 'client_verify_token' in c._custom_data:
cancel()
return
Expand All @@ -887,6 +889,8 @@ def handle_login_packet_s2c(c: Conn, reader: PacketReader, cancel):
c.send_client(buf.data)
cancel()
c._client_status = ConnStatus.PLAY
if c.server_status == ConnStatus.PLAY:
event_dispatcher(ON_POSTLOGIN, (c, ), on_executor_thread=False)
elif reader.id == 0x03: # Set compression
compress_threshold = reader.read_varint()
c._server_compress_threshold = compress_threshold
Expand All @@ -913,9 +917,9 @@ def cancel(replace: bytes | None = None):
next_packet = reader.data
if c2s:
if c.client_status == ConnStatus.LOGIN:
handle_login_packet_c2s(c, reader, cancel)
handle_login_packet_c2s(c, reader, event_dispatcher, cancel)
elif c.server_status == ConnStatus.LOGIN:
handle_login_packet_s2c(c, reader, cancel)
handle_login_packet_s2c(c, reader, event_dispatcher, cancel)
if c.client_status != c.server_status:
if next_packet is not None:
cached_packets.append(PacketReader(next_packet))
Expand Down
2 changes: 1 addition & 1 deletion mcdreforged.plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "loginproxy",
"version": "0.7.1",
"version": "0.7.2",
"name": "LoginProxy",
"description": {
"en_us": "A Minecraft login proxy Plugin",
Expand Down

0 comments on commit 4d4874c

Please sign in to comment.