示例#1
0
class WorldServerProtocol(Protocol, CloudBoxProtocolMixin, TickMixin):
    """
    I am a Protocol for the World Server.
    """

    PACKET_LIMIT_NAME = "outgoing"

    ### Twisted-related functions ###

    def __init__(self, logger):
        self.logger = logger
        self.ready = False  # Set to False to prevent new connections
        self.loops = LoopRegistry()

    def connectionMade(self):
        self.factory.instance = self
        self.gpp = MSGPackPacketProcessor(self, self.factory.handlers, self.transport)
        self.loops.registerLoop("packets", self.gpp.packetLoop).start(self.getTickInterval("outgoing"))
        self.logger.info("Connecting to Hub Server...")
        self.sendHandshake()
        self.ready = True

    def dataReceived(self, data):
        self.gpp.feed(data)
        self.gpp.parseFirstPacket()

    def connectionLost(self, reason):
        self.logger.error("Connection to Hub Server lost: {reason}".format(reason=reason))

    @property
    def remoteServerType(self):
        return self.factory.remoteServerType
示例#2
0
class WorldServerCommServerProtocol(Protocol, CloudBoxProtocolMixin, WorldServerProtocolMixin, TickMixin):
    """
    The protocol class for the WorldServer communicator factory.
    """

    remoteServerType = SERVER_TYPES["WorldServer"]
    PACKET_LIMIT_NAME = "outgoing-world"

    def __init__(self):
        self.id = None
        self.logger = logging.getLogger("cloudbox.hub.world.protocol._default") # Will be replaced when we get a proper ID
        self.loops = LoopRegistry()

    def connectionMade(self):
        """
        Triggered when connection is established.
        """
        self.gpp = MSGPackPacketProcessor(self, self.factory.handlers, self.transport)
        self.loops.registerLoop("packets", self.gpp.packetLoop).start(self.getTickInterval("outgoing-world"))

    def dataReceived(self, data):
        """
        Triggered when data is received.
        """
        # Pass on the data to the GPP
        # First, add the data we got onto our internal buffer
        self.gpp.feed(data)
        # Ask the GPP to decode the data, if possible
        self.gpp.parseFirstPacket()

    ### World Server related functions ###

    def getStats(self):
        # TODO
        return {
            "players": 0
        }

    ### End-client related functions ###

    def protoDoJoinServer(self, proto, world=None):
        """
        Makes the protocol join the server.
        """
        # Send the basic information over
        def afterNewPlayer():
            d = self.sendStateUpdate(proto.sessionID, proto.player, requireResponse=True)
            self.logger.info("Sent request for {} to join worldServer {}".format(proto.player["username"], self.id))
            return d
        return self.sendNewPlayer(proto.sessionID).addCallback(noArgs(afterNewPlayer))

    def protoDoLeaveServer(self, proto):
        """
示例#3
0
class WorldServerCommServerProtocol(Protocol):
    """
    The protocol class for the WorldServer communicator factory.
    """

    def __init__(self):
        self.wsID = None

    def getServerType(self):
        return self.factory.getServerType

    def connectionMade(self):
        """
        Triggered when connection is established.
        """
        self.gpp = MSGPackPacketProcessor(self, self.factory.handlers)

    def dataReceived(self, data):
        """
        Triggered when data is received.
        """
        # Pass on the data to the GPP
        # First, add the data we got onto our internal buffer
        self.gpp.feed(data)
        # Ask the GPP to decode the data, if possible
        self.gpp.parseFirstPacket()

    ### World Server related functions ###

    def getStats(self):
        # TODO
        return {
            "players": 0
        }

    ### End-client related functions ###

    def protoDoJoinServer(self, proto):
        """
        Makes the protocol join the server.
        """
        pass

    def protoDoLeaveServer(self, proto):
        """
        Makes the protocol leave the server.
        """
        pass
示例#4
0
 def connectionMade(self):
     self.factory.instance = self
     self.gpp = MSGPackPacketProcessor(self, self.factory.handlers, self.transport)
     self.loops.registerLoop("packets", self.gpp.packetLoop).start(self.getTickInterval("outgoing"))
     self.logger.info("Connecting to Hub Server...")
     self.sendHandshake()
     self.ready = True
示例#5
0
class WorldServerProtocol(Protocol):
    """
    I am a Protocol for the World Server.
    """

    ### Twisted-related functions ###

    def connectionMade(self):
        self.available = True  # Set to False to prevent new connections
        self.gpp = MSGPackPacketProcessor(self, self.handlers)

    def dataReceived(self, data):
        self.gpp.feed(data)
        self.gpp.parseFirstPacket()

    def sendPacket(self, packetID, packetData):
        self.transport.write(self.handlers[packetID].packData(packetData))

    def sendServerShutdown(self):
        self.sendPacket(TYPE_SERVERDISCONNECT, {})
示例#6
0
 def connectionMade(self):
     self.available = True  # Set to False to prevent new connections
     self.gpp = MSGPackPacketProcessor(self, self.handlers)
示例#7
0
 def connectionMade(self):
     """
     Triggered when connection is established.
     """
     self.gpp = MSGPackPacketProcessor(self, self.factory.handlers, self.transport)
     self.loops.registerLoop("packets", self.gpp.packetLoop).start(self.getTickInterval("outgoing-world"))
示例#8
0
 def connectionMade(self):
     """
     Triggered when connection is established.
     """
     self.gpp = MSGPackPacketProcessor(self, self.factory.handlers)