Esempio n. 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
Esempio n. 2
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
Esempio n. 3
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()
Esempio n. 4
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
Esempio n. 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
    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
Esempio n. 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
Esempio n. 8
0
    def init(self, port=2000, server="127.0.0.1", serverPort=1999, backlog=1000, compress=False):
        self.packetCount = 0
        self.port = port
        self.serverPort = serverPort
        self.serverIP = server
        self.serverAddress = NetAddress()
        self.serverAddress.setHost(server, serverPort)
        self.cManager = QueuedConnectionManager()
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager, 0)

        self.udpSocket = self.cManager.openUDPConnection(self.port)
        self.cReader.addConnection(self.udpSocket)
Esempio n. 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
Esempio n. 10
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
Esempio n. 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
Esempio n. 12
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
Esempio n. 13
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
Esempio n. 14
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)
Esempio n. 15
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
Esempio n. 16
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
Esempio n. 17
0
from direct.distributed.PyDatagram import PyDatagram

import protocol

port_address=9099  # same for client and server
ip_address="127.0.0.1"

packetCount = 0
 
cManager = QueuedConnectionManager()
cReader = QueuedConnectionReader(cManager, 0)
cWriter = ConnectionWriter(cManager,0)
 
myConnection=cManager.openUDPConnection()
   
myPyDatagram = PyDatagram()
myPyDatagram.addUint8(protocol.LOGIN)
myPyDatagram.addUint8(packetCount)
myPyDatagram.addUint8(0)
myPyDatagram.addUint16(0)
myPyDatagram.addUint16(0)
myPyDatagram.addString("HUser name")
myPyDatagram.addString("Hashed password")

serverAddress = NetAddress()
serverAddress.setHost(ip_address, port_address)

cWriter.send(myPyDatagram, myConnection, serverAddress) 
print "Sending packet"

Esempio n. 18
0
class OldNetworkSystem(sandbox.EntitySystem):
    def init(self, port=2000, server="127.0.0.1", serverPort=1999, backlog=1000, compress=False):
        self.packetCount = 0
        self.port = port
        self.serverPort = serverPort
        self.serverIP = server
        self.serverAddress = NetAddress()
        self.serverAddress.setHost(server, serverPort)
        self.cManager = QueuedConnectionManager()
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager, 0)

        self.udpSocket = self.cManager.openUDPConnection(self.port)
        self.cReader.addConnection(self.udpSocket)

    def begin(self):
        if self.cReader.dataAvailable():
            datagram = NetDatagram()  # catch the incoming data in this instance
            # Check the return value; if we were threaded, someone else could have
            # snagged this data before we did
            if self.cReader.getData(datagram):
                myIterator = PyDatagramIterator(datagram)
                msgID = myIterator.getUint8()

                #If not in our protocol range then we just reject
                if msgID < 0 or msgID > 200:
                    return

                #Order of these will need to be optimized later
                #We now pull out the rest of our headers
                remotePacketCount = myIterator.getUint8()
                ack = myIterator.getUint8()
                acks = myIterator.getUint16()
                hashID = myIterator.getUint16()
                sourceOfMessage = datagram.getConnection()

                if msgID == protocol.NEW_SHIP:
                    log.info("New ship")
                    playerPilotID = myIterator.getUint16()
                    shipID = myIterator.getUint16()
                    shipName = myIterator.getString()
                    health = myIterator.getUint8()
                    position = Point3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    linearVelocity = Vec3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    rotiation = VBase3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    angularVelocity = Vec3(myIterator.getFloat32(), myIterator.getFloat32(), myIterator.getFloat32())
                    ship = sandbox.addEntity(shipID)
                    component = ships.PilotComponent()
                    component.accountEntityID = playerPilotID
                    ship.addComponent(component)
                    component = ships.BulletPhysicsComponent()
                    messenger.send("addSpaceShip", [component, shipName, position, linearVelocity])
                    ship.addComponent(component)
                    component = ships.ThrustComponent()
                    ship.addComponent(component)
                    component = ships.InfoComponent()
                    component.health = health
                    component.name = shipName
                    ship.addComponent(component)
                elif msgID == protocol.PLAYER_MOVED_SHIP:
                    log.debug("Player moved ship")
                    accountID = myIterator.getUint16()
                    shipID = myIterator.getUint16()
                    print sandbox.components[shipID]
                    universals.shipNode = sandbox.components[shipID][ships.BulletPhysicsComponent].nodePath
                elif msgID == protocol.LOGIN_ACCEPTED:
                    log.info("Login accepted")
                    entityID = myIterator.getUint8()
                    universals.day = myIterator.getFloat32()
                elif msgID == protocol.LOGIN_DENIED:
                    log.info("Login failed")

    def genBasicData(self, proto):
        myPyDatagram = PyDatagram()
        myPyDatagram.addUint8(proto)
        myPyDatagram.addUint8(self.packetCount)
        myPyDatagram.addUint8(0)
        myPyDatagram.addUint16(0)
        myPyDatagram.addUint16(0)
        self.packetCount += 1
        return myPyDatagram

    def sendLogin(self, username, hashpassword):
        datagram = self.genBasicData(protocol.LOGIN)
        datagram.addString(username)
        datagram.addString(hashpassword)
        universals.log.debug("sending login")
        self.sendData(datagram)

    def sendData(self, datagram):
        sent = self.cWriter.send(datagram, self.udpSocket, self.serverAddress)
        while not sent:
            print "resending"
            sent = self.cWriter.send(datagram, self.udpSocket, self.serverAddress)