mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2025-01-23 16:11:27 +01:00
Fix attributes in several classes in connection.py which were erroneously defined in the class dictionary instead of the instance dictionary.
This commit is contained in:
parent
f1391ab29b
commit
9affeee041
@ -5,6 +5,7 @@ import threading
|
|||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import select
|
import select
|
||||||
|
import sys
|
||||||
|
|
||||||
from .types import VarInt
|
from .types import VarInt
|
||||||
from . import packets
|
from . import packets
|
||||||
@ -13,11 +14,16 @@ from .. import PROTOCOL_VERSION
|
|||||||
|
|
||||||
|
|
||||||
class _ConnectionOptions(object):
|
class _ConnectionOptions(object):
|
||||||
# TODO: allow these options to be overriden from a constructor below
|
def __init__(self,
|
||||||
address = None
|
address=None,
|
||||||
port = None
|
port=None,
|
||||||
compression_threshold = -1
|
compression_threshold=-1,
|
||||||
compression_enabled = False
|
compression_enabled=False
|
||||||
|
):
|
||||||
|
self.address = address
|
||||||
|
self.port = port
|
||||||
|
self.compression_threshold = compression_threshold
|
||||||
|
self.compression_enabled = compression_enabled
|
||||||
|
|
||||||
|
|
||||||
class Connection(object):
|
class Connection(object):
|
||||||
@ -25,18 +31,6 @@ class Connection(object):
|
|||||||
server, it handles everything from connecting, sending packets to
|
server, it handles everything from connecting, sending packets to
|
||||||
handling default network behaviour
|
handling default network behaviour
|
||||||
"""
|
"""
|
||||||
_outgoing_packet_queue = deque()
|
|
||||||
_write_lock = Lock()
|
|
||||||
networking_thread = None
|
|
||||||
options = _ConnectionOptions()
|
|
||||||
packet_listeners = []
|
|
||||||
|
|
||||||
# The reactor handles all the default responses to packets,
|
|
||||||
# it should be changed per networking state
|
|
||||||
reactor = None
|
|
||||||
#: Indicates if this connection is spawned in the Minecraft game world
|
|
||||||
spawned = False
|
|
||||||
|
|
||||||
def __init__(self, address, port, auth_token):
|
def __init__(self, address, port, auth_token):
|
||||||
"""Sets up an instance of this object to be able to connect to a
|
"""Sets up an instance of this object to be able to connect to a
|
||||||
minecraft server.
|
minecraft server.
|
||||||
@ -48,9 +42,22 @@ class Connection(object):
|
|||||||
:param port(int): port of the server to connect to
|
:param port(int): port of the server to connect to
|
||||||
:param auth_token: :class:`authentication.AuthenticationToken` object.
|
:param auth_token: :class:`authentication.AuthenticationToken` object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self._outgoing_packet_queue = deque()
|
||||||
|
self._write_lock = Lock()
|
||||||
|
self.networking_thread = None
|
||||||
|
self.packet_listeners = []
|
||||||
|
|
||||||
|
#: Indicates if this connection is spawned in the Minecraft game world
|
||||||
|
self.spawned = False
|
||||||
|
|
||||||
|
self.options = _ConnectionOptions()
|
||||||
self.options.address = address
|
self.options.address = address
|
||||||
self.options.port = port
|
self.options.port = port
|
||||||
self.auth_token = auth_token
|
self.auth_token = auth_token
|
||||||
|
|
||||||
|
# The reactor handles all the default responses to packets,
|
||||||
|
# it should be changed per networking state
|
||||||
self.reactor = PacketReactor(self)
|
self.reactor = PacketReactor(self)
|
||||||
|
|
||||||
def _start_network_thread(self):
|
def _start_network_thread(self):
|
||||||
@ -150,10 +157,9 @@ class Connection(object):
|
|||||||
self.write_packet(handshake)
|
self.write_packet(handshake)
|
||||||
|
|
||||||
class NetworkingThread(threading.Thread):
|
class NetworkingThread(threading.Thread):
|
||||||
interrupt = False
|
|
||||||
|
|
||||||
def __init__(self, connection):
|
def __init__(self, connection):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
self.interrupt = False
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
self.name = "Networking Thread"
|
self.name = "Networking Thread"
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
@ -161,8 +167,10 @@ class NetworkingThread(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self._run()
|
self._run()
|
||||||
except Exception as e:
|
except:
|
||||||
self.connection.exception = e
|
ty, ex, tb = sys.exc_info()
|
||||||
|
ex.exc_info = ty, ex, tb
|
||||||
|
self.connection.exception = ex
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
while True:
|
while True:
|
||||||
@ -203,7 +211,6 @@ class PacketReactor(object):
|
|||||||
"""
|
"""
|
||||||
state_name = None
|
state_name = None
|
||||||
clientbound_packets = None
|
clientbound_packets = None
|
||||||
|
|
||||||
TIME_OUT = 0
|
TIME_OUT = 0
|
||||||
|
|
||||||
def __init__(self, connection):
|
def __init__(self, connection):
|
||||||
|
Loading…
Reference in New Issue
Block a user