Пример #1
0
    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")
Пример #2
0
import sandbox

sandbox.base.setSleep(0.001)
sandbox.base.disableMouse()

import physics
import shipSystem
import shipComponents
import solarSystem

if universals.runClient:
    import clientNet
    import graphicsComponents
    import guiSystem
    import renderSystem
    log.info("Setting up client network")
    clinet = clientNet.NetworkSystem()
    clinet.serverAddress = '127.0.0.1'
    sandbox.addSystem(clinet)
    log.info("Setting up gui system")
    sandbox.addSystem(guiSystem.GUISystem())
    log.info("Setting up render system")
    sandbox.addSystem(renderSystem.RenderSystem(graphicsComponents.RenderComponent))
    sandbox.base.render.setShaderAuto()
    
if universals.runServer:
    import serverNet
    log.info("Setting up server network")
    servnet = serverNet.NetworkSystem()
    servnet.port = 1999
    sandbox.addSystem(servnet)
Пример #3
0
import sandbox

sandbox.base.setSleep(0.001)
sandbox.base.disableMouse()

import physics
import shipSystem
import shipComponents
import solarSystem

if universals.runClient:
    import clientNet
    import graphicsComponents
    import guiSystem
    import renderSystem
    log.info("Setting up client network")
    clinet = clientNet.NetworkSystem()
    clinet.serverAddress = '127.0.0.1'
    sandbox.addSystem(clinet)
    log.info("Setting up gui system")
    sandbox.addSystem(guiSystem.GUISystem())
    log.info("Setting up render system")
    sandbox.addSystem(
        renderSystem.RenderSystem(graphicsComponents.RenderComponent))
    sandbox.base.render.setShaderAuto()

if universals.runServer:
    import serverNet
    log.info("Setting up server network")
    servnet = serverNet.NetworkSystem()
    servnet.port = 1999