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 planetPositionDebug(task): log.debug("===== Day: " + str(universals.day) + " =====") for bod in sandbox.getSystem(solarSystem.SolarSystemSystem).bodies: log.debug(bod.getName() + ": " + str(bod.getPos())) return task.again
# if we're running a normal client, not one of the server # processes.) loadPrcFileData('', 'window-type none\naudio-library-name null') #pass else: loadPrcFileData('', 'frame-rate-meter-scale 0.035') loadPrcFileData('', 'frame-rate-meter-side-margin 0.1') loadPrcFileData('', 'show-frame-rate-meter 1') loadPrcFileData('', 'window-title ' + "ITF") loadPrcFileData('', "sync-video 0") loadPrcFileData('', 'task-timer-verbose 1') loadPrcFileData('', 'pstats-tasks 1') loadPrcFileData('', 'want-pstats 1') # After initial setup we can now start sandbox log.debug("Loading sandbox") 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