Exemple #1
0
 def __init__(self, duration=70):
     self._expirationset = expirationset(duration, self._remove_callback)
     self._server_id_dict = {}
     self._endpoint_dict = {}
     self._lobby_dict = {}
Exemple #2
0
 def __init__(self, duration=70):
     self._expirationset = expirationset(duration, self._remove_callback)
     self._server_id_dict = {}
     self._endpoint_dict = {}
     self._lobby_dict = {}
Exemple #3
0
class SimpleTCPReachabilityCheckFactory(ClientFactory):
    def __init__(self, server, host, port, serverList):
        self.__server = server
        self.__host = host
        self.__port = port
        self.__serverList = serverList

    def buildProtocol(self, addr):
        return SimpleTCPReachabilityCheck(self.__server, self.__host, self.__port, self.__serverList)

    def clientConnectionFailed(self, connector, reason):
        print "Connection check failed for %s" % (self.__server)

# TODO: Better flood control using a leaky bucket counter
RECENT_ENDPOINTS = expirationset(10)
        
class GG2LobbyRegV1(DatagramProtocol):
    MAGIC_NUMBERS = chr(4)+chr(8)+chr(15)+chr(16)+chr(23)+chr(42)
    INFO_PATTERN = re.compile(r"\A(!private!)?(?:\[([^\]]*)\])?\s*(.*?)\s*(?:\[(\d+)/(\d+)\])?(?: - (.*))?\Z", re.DOTALL)
    CONN_CHECK_FACTORY = Factory()
    CONN_CHECK_FACTORY.protocol = SimpleTCPReachabilityCheck
        
    def __init__(self, serverList):
        self.serverList = serverList
    
    def datagramReceived(self, data, (host, origport)):
        if((host, origport) in RECENT_ENDPOINTS): return
        RECENT_ENDPOINTS.add((host, origport))
        
        if(not data.startswith(GG2LobbyRegV1.MAGIC_NUMBERS)): return
Exemple #4
0
    def __init__(self, server, host, port, serverList):
        self.__server = server
        self.__host = host
        self.__port = port
        self.__serverList = serverList

    def buildProtocol(self, addr):
        return SimpleTCPReachabilityCheck(self.__server, self.__host,
                                          self.__port, self.__serverList)

    def clientConnectionFailed(self, connector, reason):
        print "Connection check failed for %s" % (self.__server)


# TODO: Better flood control using a leaky bucket counter
RECENT_ENDPOINTS = expirationset(10)


class GG2LobbyRegV1(DatagramProtocol):
    MAGIC_NUMBERS = chr(4) + chr(8) + chr(15) + chr(16) + chr(23) + chr(42)
    INFO_PATTERN = re.compile(
        r"\A(!private!)?(?:\[([^\]]*)\])?\s*(.*?)\s*(?:\[(\d+)/(\d+)\])?(?: - (.*))?\Z",
        re.DOTALL)
    CONN_CHECK_FACTORY = Factory()
    CONN_CHECK_FACTORY.protocol = SimpleTCPReachabilityCheck

    def __init__(self, serverList):
        self.serverList = serverList

    def datagramReceived(self, data, (host, origport)):
        if ((host, origport) in RECENT_ENDPOINTS): return