예제 #1
0
    def tcpListenerTask(self, task):
        """
        Accept new incoming connection from clients, related to TCP
        """
        # Handle new connection
        if self.tcpListener.newConnectionAvailable():
            rendezvous = PointerToConnection()
            netAddress = NetAddress()
            newConnection = PointerToConnection()

            if self.tcpListener.getNewConnection(rendezvous, netAddress,
                                                 newConnection):
                newConnection = newConnection.p()

                # Tell the reader about the new TCP connection
                self.tcpReader.addConnection(newConnection)

                # Handle the connection depending on persistent or not
                if self.core.server.isPersistent:
                    self.core.handleConnection(generateUUID(), newConnection,
                                               netAddress)
                else:
                    self.core.createPlayerObject(generateUUID(), newConnection,
                                                 netAddress)

                print("Server: New Connection from -",
                      str(netAddress.getIpString()))
            else:
                print("Server: Connection Failed from -",
                      str(netAddress.getIpString()))

        return Task.cont
예제 #2
0
 def tskListenerPolling(self, taskdata):
     if self.cListener.newConnectionAvailable():
         rendezvous = PointerToConnection()
         netAddress = NetAddress()
         newConnection = PointerToConnection()
         if self.cListener.getNewConnection(rendezvous,netAddress,newConnection):
             newConnection = newConnection.p()
             self.activeConnections.append(newConnection) # Remember connection
             self.cReader.addConnection(newConnection)     # Begin reading connection
     return Task.cont
예제 #3
0
    def listen_suggestions(self, task):
        if self.cListener.newConnectionAvailable():
            rendezvous = PointerToConnection()
            net_addr = NetAddress()
            new_conn = PointerToConnection()

            if self.cListener.getNewConnection(rendezvous, net_addr, new_conn):
                new_conn = new_conn.p()

                self.logger.warn("new connection from %s" % str(net_addr))
                self.active_connections.append(new_conn)
                self.cReader.addConnection(new_conn)
        return task.cont
예제 #4
0
	def tsk_listener_pol(self, taskdata):
		if self.c_listener.newConnectionAvailable():

			rendezvous = PointerToConnection()
			netAddress = NetAddress()
			newConnection = PointerToConnection()

			if self.c_listener.getNewConnection(rendezvous,netAddress,newConnection):
				print("Connected: "+str(netAddress))
				newConnection = newConnection.p()
				self.active_conns.append(newConnection) # Remember connection
				self.c_reader.addConnection(newConnection)     # Begin reading connection
		return Task.cont
예제 #5
0
 def connect(self, url):
     self.notify.info("Attemping to connect to %s" % (url))
     urlSpec = URLSpec(url)
     addr = NetAddress()
     addr.setHost(urlSpec.getServer(), urlSpec.getPort())
     self.serverAddress = addr
     self.connectionHandle = self.netSys.connectByIPAddress(addr)
     if not self.connectionHandle:
         messenger.send('connectFailure', [self.serverAddress])
         self.serverAddress = None
         self.connectionHandle = None
     else:
         self.startClientLoop()
예제 #6
0
 def handle_incoming_connections(self, task_data: Task) -> Task:
     if self.listener.newConnectionAvailable():
         rendezvous = PointerToConnection()
         net_addr = NetAddress()
         new_connection = PointerToConnection()
         if self.listener.getNewConnection(rendezvous, net_addr, new_connection):
             new_connection = new_connection.p()
             # Keep track of our active connections
             self.active_connections[str(
                 new_connection.this)] = new_connection
             # Start reading the new connection
             self.reader.addConnection(new_connection)
             print("%s just connected" % str(new_connection))
     return Task.cont
예제 #7
0
 def tsk_listener(self, task):
     if not self.c_listener.newConnectionAvailable():
         return task.cont
     net_address = NetAddress()
     new_connection = PointerToConnection()
     args = PointerToConnection(), net_address, new_connection
     if not self.c_listener.get_new_connection(*args):
         return task.cont
     self.connections.append(new_connection.p())
     self.c_reader.add_connection(self.connections[-1])
     self.connection_cb(net_address.get_ip_string())
     msg = 'received a connection from ' + net_address.getIpString()
     eng.log_mgr.log(msg)
     return task.cont
예제 #8
0
    def __listen_incoming(self, task):
        """
        Polls for incoming connections
        """

        if self.__listener.new_connection_available():
            rendezvous = PointerToConnection()
            address = NetAddress()
            connection = PointerToConnection()

            if self.__listener.get_new_connection(rendezvous, address,
                                                  connection):
                self.__handle_connection(rendezvous, address, connection.p())

        return task.cont
예제 #9
0
    def _socketListener(self, task):
        if self.cListener.newConnectionAvailable():
            rendezvous = PointerToConnection()
            netAddress = NetAddress()
            newConnection = PointerToConnection()

            if self.cListener.getNewConnection(rendezvous, netAddress,
                                               newConnection):
                newConnection = newConnection.p()
                base.activeConnections[newConnection] = NetworkedClient()
                self.cReader.addConnection(newConnection)
                self.notify.warning("New Unauthed Client Connected: %s" %
                                    (netAddress))

        return Task.cont
예제 #10
0
    def tskListenerPolling(self, task):
        if self.cListener.newConnectionAvailable():
            rendezvous = PointerToConnection()
            netAddress = NetAddress()
            newConnection = PointerToConnection()

            if self.cListener.getNewConnection(rendezvous, netAddress,
                                               newConnection):
                newConnection = newConnection.p()
                newConnection.setNoDelay(True)
                newConnection.setKeepAlive(True)
                if self.handleNewConnection:
                    self.handleNewConnection(newConnection)
                self.cReader.addConnection(
                    newConnection)  # Begin reading connection
        return Task.cont
예제 #11
0
 def tskListenerPolling(self, taskdata):
     # listen for new connections
     # TODO(victor): what happens if a client shuts down?
     # print("server.tskListenerPolling()")
     if self.cListener.newConnectionAvailable():
         rendezvous = PointerToConnection()
         netAddress = NetAddress()
         newConnection = PointerToConnection()
         if self.cListener.getNewConnection(rendezvous, netAddress,
                                            newConnection):
             newConnection = newConnection.p()
             self.activeConnections.append(
                 newConnection)  # Remember connection
             self.cReader.addConnection(
                 newConnection)  # Begin reading connection
             print("server: received new connection!")
     return Task.cont
예제 #12
0
 def _onListenerPoll(self, taskdata):
     """
         Updates list of connections based on the listener's current
          findings.
         Does not read messages. See onReaderPoll().
         (Assumes self._connListener has been initialized)
     """
     # Check for new connections:
     if self._connListener.newConnectionAvailable():
         rendezvous = PointerToConnection()
         netAddress = NetAddress()
         newConnection = PointerToConnection()
         # If we have a new connection, add it to our list:
         if self._connListener.getNewConnection(rendezvous,netAddress,
                                                newConnection):
             newConnection = newConnection.p()
             print ("[Host Received New Connection: %s]" % netAddress)
             self._activeConns.append(newConnection)
             # Begin reading messages from this new connection:
             self._connReader.addConnection(newConnection)
             # activate the onClientConnected functionalities:
             self.onClientConnected(newConnection)
     return Task.cont # Repeat this call on an interval
예제 #13
0
    def listen_for_new_connections(self):
        """
        Listens to new connections, when avalibe, creates new session
        and event notifier
        """
        while True:
            if self.listener.new_connection_available():
                rendezvous = PointerToConnection()
                net_address = NetAddress()
                new_connection = PointerToConnection()
                if self.listener.get_new_connection(
                    rendezvous, net_address, new_connection
                ):
                    new_connection = new_connection.p()

                    session = self.session_manager.new_session(
                        new_connection,
                    )

                    self.connections.append(new_connection)
                    self.notifier_manager.new_notifier(session, new_connection)
                    self.task_manager.new_session_task_manager(session, new_connection)
                    self.reader.add_connection(new_connection)
예제 #14
0
    def check_for_new_players(self, taskdata):
        """
        Called repeatedly to check if there's any new connections
        If there are, add them to self.active_connections
        """
        if self.cListener.newConnectionAvailable():
            rendezvous = PointerToConnection()
            net_address = NetAddress()
            new_connection = PointerToConnection()

            if self.cListener.getNewConnection(rendezvous, net_address,
                                               new_connection):
                self.notify.debug("[check_for_new_players] New connection")
                new_connection = new_connection.p()

                pid = self.create_pid()

                new_connection_holder = ConnectionHolder(new_connection, pid)
                self.active_connections[pid] = new_connection_holder

                self.cReader.add_connection(new_connection)

                self.cWriter.send(dg_deliver_pid(pid), new_connection)
        return Task.cont