Пример #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 tskDisconnectPolling(self, task):
        if not self.connected:
            return Task.done

        # TODO: Hacky sending nothing to force disconnect triggers
        #self.sendData()
        # Also checking for dataAvailable on reader will trigger the connection disconnected
        self.cReader.dataAvailable()
        # TODO: Confirm this works for client side (to both game server and master server)
        while self.cManager.resetConnectionAvailable():
            connPointer = PointerToConnection()
            self.cManager.getResetConnection(connPointer)
            connection = connPointer.p()

            # Remove the connection we just found to be "reset" or "disconnected"
            self.cReader.removeConnection(connection)

            # Let us know that we are not connected
            self.connected = False
            print "disconnected"

            if self.connectionStateChangedHandler:
                self.connectionStateChangedHandler.handleDisconnection()

        return Task.again
Пример #3
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
Пример #4
0
 def handle_dropped_connections(self, task_data: Task) -> Task:
     if self.manager.resetConnectionAvailable():
         connection_pointer = PointerToConnection()
         self.manager.getResetConnection(connection_pointer)
         lost_connection = connection_pointer.p()
         print("% s disconnected from server" % str(lost_connection))
         del self.active_connections[str(lost_connection.this)]
         self.manager.closeConnection(lost_connection)
     return Task.cont
Пример #5
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
Пример #6
0
    def tskDisconnectPolling(self, task):
        while self.cManager.resetConnectionAvailable():
            connPointer = PointerToConnection()
            self.cManager.getResetConnection(connPointer)
            connection = connPointer.p()

            # Remove the connection we just found to be "reset" or "disconnected"
            self.cReader.removeConnection(connection)

            if self.handleLostConnection:
                self.handleLostConnection(connection)

        return Task.cont
Пример #7
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
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
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
Пример #12
0
    def tcpDisconnectionHandler(self, task):
        # Check for resets
        if self.tcpManager.resetConnectionAvailable():
            resetConnection = PointerToConnection()
            self.tcpManager.getResetConnection(resetConnection)
            print(str(resetConnection.p()))
            #for client in self.core.server.clients:
            #    if self.core.server.clients[client].connection == resetConnection.p():
            #        del self.core.server.clients[client]
            #        self.tcpReader.removeConnection(resetConnection.p())
            #        print ("Removed Connection:", resetConnection.p())
            #        print ('Current Clients:', self.core.server.clients)
            #        break

        return Task.cont
Пример #13
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
Пример #14
0
    def tcpDisconnectionHandler(self, task):
        # Check for resets
        if self.tcpManager.resetConnectionAvailable():
            resetConnection = PointerToConnection()
            self.tcpManager.getResetConnection(resetConnection)
            
            for client in self.core.server.clients:
                if self.core.server.clients[client].connection == resetConnection.p():
                    del self.core.server.clients[client]
                    self.tcpReader.removeConnection(resetConnection.p())
                    print ("Removed Connection:", resetConnection.p())
                    print ('Current Clients:', self.core.server.clients)
                    break

        return Task.cont
Пример #15
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
Пример #16
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
Пример #17
0
    def updateListener(self, task):
        """
        """
        if self.listener.newConnectionAvailable():
            connection = PointerToConnection()
            if self.listener.getNewConnection(connection):
                connection = connection.p()
                self.connections.append(connection)
                self.reader.addConnection(connection)
                logging.info("New connection established")
                self.players.append(Player(connection))

        for conn in self.connections[:]:
            if not self.reader.isConnectionOk(conn):
                logging.warning("Non-ok connection detected")
                for player in self.players:
                    if player.connection == conn:
                        self.players.remove(player)
                        nick = player.nick
                        logging.info("Removed player with non-ok connection")
                        messenger.send("player_disconnected", sentArgs=[nick])
                self.connections.remove(conn)
        return task.cont
Пример #18
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)
Пример #19
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
Пример #20
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