def process(self, data):
        it = PyDatagramIterator(data)
        mssgID = it.getUint8()
        if mssgID == 42:
            return None
        vel = it.getFloat32()
        z = it.getFloat32()
        x = it.getFloat32()
        y = it.getFloat32()
        checksum = it.getFloat32()
        
        #print "velocity:" , vel ,
        #" Z position:" , z , " Checksum " , checksum
        
        newx = x
        zdiff = z - self.smiley.getZ()
        self.smiley.setPythonTag("velocity", vel + zdiff * 0.03)
        
        #self.smiley.setX(x)
        #self.smiley.setZ(z)
        #self.smiley.setY(y)
        

        data = PyDatagram()
        data.addUint8(0)
        data.addString("w") #change this to key being pressed forward
        
        
        data.addString("OH HI MARTK!!")
        
        
        return data

        
        
Beispiel #2
0
 def sendChatMessage(self, message, target="all"):
     datagram = PyDatagram()
     datagram.addUint8(protocols.ClientMsgId.chatMsg)
     datagram.addString("server")
     datagram.addString(message)
     if target == "all":
         self.server.broadcast(datagram)
    def updateListener(self, task):
        if self.listener.newConnectionAvailable():
            connection = PointerToConnection()
            if self.listener.getNewConnection(connection):
                connection = connection.p()
                connection.setNoDelay(True)
                self.connections.append(connection)
                self.reader.addConnection(connection)
                print "Server: New connection established."

                self.tempClientID = -1
                for client in range(0,len(direction)):
                    if direction[client] == -1:
                        direction[client] = 0
                        #print "Client ID ",client
                        self.tempClientID = client
                        break
                if self.tempClientID == -1:
                    print "Server is full, keeping connection but giving fake ID!"
                    
                reply = PyDatagram()
                reply.addUint8(42)
                reply.addInt8(self.tempClientID)
                self.writer.send(reply,connection)
                print "Giving new client ID: ",self.tempClientID
                
                
        return task.cont
	def handle_create_account_request(self, netmgr, connection, username, password):
		file_path = self.directory_path + str(username) + self.database_file_ext
		self.netmgr = netmgr

		data = {
			"account_name": str(username),
			"account_password": str(password)
		}

		if os.path.exists(file_path):
			print ("Could not create account with username %s because it already exists." % username)
			return

		with open(file_path, 'w+') as file:
			json.dump(data, file)

			if os.path.exists(file_path):
				datagram = PyDatagram()
				datagram.addUint16(REQUEST_FOR_REGISTER_RESP)
				datagram.addUint8(0)
				datagram.addString("Successfully registered account! Now try to login!")
				self.netmgr.send_response(connection, datagram)
				print ("Database: Client %s Successfully registered an account with the name %s" % (connection, username))
			else:
				datagram = PyDatagram()
				datagram.addUint16(REQUEST_FOR_REGISTER_RESP)
				datagram.addUint8(1)
				datagram.addString("Failed to create account, please contact customer support!")
				self.netmgr.send_response(connection, datagram)
				return

			file.close()
Beispiel #5
0
 def makeCommandStringDatagram(self, commandString):
     datagram = PyDatagram()
     datagram.addUint32(self.packetNumber)
     self.packetNumber = self.packetNumber + 1
     datagram.addUint8(CLUSTER_COMMAND_STRING)
     datagram.addString(commandString)
     return datagram
Beispiel #6
0
    def makeNamedMovementDone(self):

        datagram = PyDatagram()
        datagram.addUint32(self.packetNumber)
        self.packetNumber = self.packetNumber + 1
        datagram.addUint8(CLUSTER_NAMED_MOVEMENT_DONE)
        return datagram
Beispiel #7
0
 def ATTACK_SUCCESS(self, charid1, charid2, damages, player):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('ATTACK_SUCCESS')
     myPyDatagram.addString(charid1)
     myPyDatagram.addString(charid2)
     myPyDatagram.addUint8(damages)
     self.cWriter.send(myPyDatagram, player)
Beispiel #8
0
 def WAIT(self, charid, direction):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('WAIT')
     myPyDatagram.addString(charid)
     # seem direction became str
     myPyDatagram.addUint8(int(direction))
     self.cWriter.send(myPyDatagram, self.myConnection)
Beispiel #9
0
    def makeNamedMovementDone(self):

        datagram = PyDatagram()
        datagram.addUint32(self.packetNumber)
        self.packetNumber = self.packetNumber + 1
        datagram.addUint8(CLUSTER_NAMED_MOVEMENT_DONE)
        return datagram
Beispiel #10
0
 def scoreDatagram(self):
     # Send the player's score
     myPyDatagram = PyDatagram()
     myPyDatagram.addUint8(END_MESSAGE)
     myPyDatagram.addString(self.playername)
     myPyDatagram.addInt32(self.carData.carlist[self.carData.index].deaths)
     return myPyDatagram
	def handleToonInfoReq(self, name, connection, doId):
		numAvs = 0
		avatars = {}
		for i in range(6):
			acc = self.jsonAccInfo.get(name)
			toonnum = "toon" + str(i)
			toons = acc.get("toons")
			toon = toons.get(toonnum)
			dna = toon.get("dna")
			avname = toon.get("name")
			avatars[toonnum] = {"name": "", "dna": "", "slot": 0}
			avatars[toonnum]["name"] = avname
			avatars[toonnum]["dna"] = dna
			avatars[toonnum]["slot"] = i
			numAvs += 1
			if dna == None or avname == None:
				del avatars[toonnum]
				numAvs -= 1
		dg = PyDatagram()
		dg.addUint16(TDB_TOON_INFO)
		dg.addUint32(doId)
		dg.addUint8(numAvs)
		for av in range(6):
			toonnum = "toon" + str(av)
			if avatars.get(toonnum) != None:
				dg.addUint8(avatars[toonnum]["slot"])
				dg.addString(avatars[toonnum]["dna"])
				dg.addString(avatars[toonnum]["name"])
		self.cWriter.send(dg, connection)
Beispiel #12
0
 def CLIENT_CREATE_AVATAR(self, connection, di):
     datagram = PyDatagram()
     datagram.addUint16(CLIENT_CREATE_AVATAR_RESP)
     datagram.addUint16(0)
     datagram.addUint8(0)
     datagram.addUint32(1)
     self.cw.send(datagram, connection)
Beispiel #13
0
 def update_winner(self,task):
     closest=0
     closestDist = 999999
     for i in range(1,len(self.Server.players)):
         x=self.Server.players[i].getX()
         y=self.Server.players[i].getY()
         z=self.Server.players[i].getZ()
         mx=self.Server.players[0].getX()
         my=self.Server.players[0].getY()
         mz=self.Server.players[0].getZ()
         dist=math.sqrt((x-mx)**2+(y-my)**2+(z-mz)**2)
         
         #print i, dist
         if dist <closestDist:
             closest = i
             closestDist=dist
                 
     #print closest, " is the closest"
     self.poloScores[closest]+=100.0/24.0/10000.0
                 
     update = PyDatagram()
     update.addUint8(101)
     
     for score in self.poloScores:
         update.addFloat32(score)
     self.broadcast(update)
     return task.cont
Beispiel #14
0
    def prepare(self, message, sentArgs=[]):
        """
        Prepare the datagram that would get sent in order to send this message
        to its designated channel.
        """
        assert self.notify.debugCall()

        # Make sure the message is registered:
        if message not in self.__message2type:
            self.notify.error('Tried to send unregistered message %s!' %
                              message)
            return

        datagram = PyDatagram()
        # To:
        datagram.addUint8(1)
        datagram.addChannel(self.__message2channel[message])
        # From:
        datagram.addChannel(self.air.ourChannel)

        messageType = self.__message2type[message]
        datagram.addUint16(messageType)
        datagram.addString(str(dumps(sentArgs)))

        return datagram
Beispiel #15
0
 def makeCommandStringDatagram(self, commandString):
     datagram = PyDatagram()
     datagram.addUint32(self.packetNumber)
     self.packetNumber = self.packetNumber + 1
     datagram.addUint8(CLUSTER_COMMAND_STRING)
     datagram.addString(commandString)
     return datagram
Beispiel #16
0
 def ATTACK_SUCCESS(self, charid1, charid2, damages, player):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('ATTACK_SUCCESS')
     myPyDatagram.addString(charid1)
     myPyDatagram.addString(charid2)
     myPyDatagram.addUint8(damages)
     self.cWriter.send(myPyDatagram, player)
Beispiel #17
0
def dg_send_heartbeat(pid):
    if pid is not None:
        dg = PyDatagram()
        dg.addUint8(HEARTBEAT)
        dg.addUint16(pid)
        return dg
    else:
        print("!! TRIED TO SEND DATAGRAM WITH NO PID !!")
Beispiel #18
0
    def updateGardenData(self):
        gardenData = PyDatagram()

        gardenData.addUint8(len(self.plots))
        for plot in self.plots:
            plot.pack(gardenData)

        self.house.b_setGardenData(gardenData.getMessage())
 def __handleFetchDLList(self, connection):
     dg = PyDatagram()
     dg.addUint16(DL_LIST)
     dg.addString(baseLink)
     dg.addUint8(len(fileNames))
     for fileName in fileNames:
         dg.addString(fileName)
     self.cWriter.send(dg, connection)
Beispiel #20
0
def dg_goodbye(pid):
    if pid is not None:
        dg = PyDatagram()
        dg.addUint8(GOODBYE)
        dg.addUint16(pid)
        return dg
    else:
        print("!! TRIED TO SEND DATAGRAM WITH NO PID !!")
Beispiel #21
0
 def ATTACK_PASSIVE(self, charid1, charid2, damages, attackables, player):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('ATTACK_PASSIVE')
     myPyDatagram.addString(charid1)
     myPyDatagram.addString(charid2)
     myPyDatagram.addUint8(damages)
     myPyDatagram.addString(json.dumps(attackables))
     self.cWriter.send(myPyDatagram, player)
Beispiel #22
0
 def MOVED(self, charid, x, y, z, player):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('MOVED')
     myPyDatagram.addString(charid)
     myPyDatagram.addUint8(x)
     myPyDatagram.addUint8(y)
     myPyDatagram.addUint8(z)
     self.cWriter.send(myPyDatagram, player)
Beispiel #23
0
def dg_request_game(pid):
    if pid is not None:
        dg = PyDatagram()
        dg.addUint8(REQUEST_GAME)
        dg.addUint16(pid)
        return dg
    else:
        print("!! TRIED TO SEND DATAGRAM WITH NO PID !!")
def createMapMessage(command):
    """
        Returns a new map message of the given type.
    """
    newPyDatagram = PyDatagram()
    newPyDatagram.addUint8(MAP_MESSAGE)
    newPyDatagram.addString32(command)
    return newPyDatagram
Beispiel #25
0
    def sendStartGame(self, players):
        datagram = PyDatagram()
        datagram.addUint8(protocols.ClientMsgId.gameStarted)
        #nicks = [p.nick for p in players]

        datagram.addString(players[0].nick)
        datagram.addString(players[1].nick)
        self.server.broadcast(datagram)
Beispiel #26
0
    def updateGardenData(self):
        gardenData = PyDatagram()

        gardenData.addUint8(len(self.plots))
        for plot in self.plots:
            plot.pack(gardenData)

        self.house.b_setGardenData(gardenData.getMessage())
Beispiel #27
0
    def __makeBlob(self, store):
        dg = PyDatagram()
        if self.__list:
            dg.addUint8(CatalogItem.CatalogItemVersion)
            for item in self.__list:
                CatalogItem.encodeCatalogItem(dg, item, store)

        return dg.getMessage()
Beispiel #28
0
def dg_vote_to_start(pid):
    if pid is not None:
        dg = PyDatagram()
        dg.addUint8(VOTE_TO_START)
        dg.addUint16(pid)
        return dg
    else:
        print("!! TRIED TO SEND DATAGRAM WITH NO PID !!")
Beispiel #29
0
 def MOVED(self, charid, x, y, z, player):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('MOVED')
     myPyDatagram.addString(charid)
     myPyDatagram.addUint8(x)
     myPyDatagram.addUint8(y)
     myPyDatagram.addUint8(z)
     self.cWriter.send(myPyDatagram, player)
Beispiel #30
0
def dg_leave_lobby(pid):
    if pid is not None:
        dg = PyDatagram()
        dg.addUint8(LEAVE_LOBBY)
        dg.addUint16(pid)
        return dg
    else:
        print("!! TRIED TO SEND DATAGRAM WITH NO PID !!")
Beispiel #31
0
 def ATTACK_PASSIVE(self, charid1, charid2, damages, attackables, player):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('ATTACK_PASSIVE')
     myPyDatagram.addString(charid1)
     myPyDatagram.addString(charid2)
     myPyDatagram.addUint8(damages)
     myPyDatagram.addString(json.dumps(attackables))
     self.cWriter.send(myPyDatagram, player)
def createMessage(msgType, command):
    """
        Returns a new string command of the given type.
    """
    newPyDatagram = PyDatagram()
    newPyDatagram.addUint8(msgType)
    newPyDatagram.addString(command)
    return newPyDatagram
def trackExperienceToNetString(tracks):
    dg = PyDatagram()

    for track, exp in tracks.iteritems():
        dg.addUint8(TrackNameById.values().index(track))
        dg.addInt16(exp)
    dgi = PyDatagramIterator(dg)
    return dgi.getRemainingBytes()
Beispiel #34
0
    def __makeBlob(self, store):
        dg = PyDatagram()
        if self.__list:
            dg.addUint8(CatalogItem.CatalogItemVersion)
            for item in self.__list:
                CatalogItem.encodeCatalogItem(dg, item, store)

        return dg.getMessage()
Beispiel #35
0
 def makeTimeDataDatagram(self, frameCount, frameTime, dt):
     datagram = PyDatagram()
     datagram.addUint32(self.packetNumber)
     self.packetNumber = self.packetNumber + 1
     datagram.addUint8(CLUSTER_TIME_DATA)
     datagram.addUint32(frameCount)
     datagram.addFloat32(frameTime)
     datagram.addFloat32(dt)
     return datagram
Beispiel #36
0
def dg_set_room(pid, room):
    if pid is not None:
        dg = PyDatagram()
        dg.addUint8(SET_ROOM)
        dg.addUint16(pid)
        dg.addUint8(room)
        return dg
    else:
        print("!! TRIED TO SEND DATAGRAM WITH NO PID !!")
Beispiel #37
0
def dg_set_kill(pid, kill):
    if pid is not None:
        dg = PyDatagram()
        dg.addUint8(SET_KILL)
        dg.addUint16(pid)
        dg.addBool(kill)
        return dg
    else:
        print("!! TRIED TO SEND DATAGRAM WITH NO PID !!")
Beispiel #38
0
 def GET_PATH(self, charid, dest):
     (x, y, z) = dest
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('GET_PATH')
     myPyDatagram.addString(charid)
     myPyDatagram.addUint8(x)
     myPyDatagram.addUint8(y)
     myPyDatagram.addUint8(z)
     self.cWriter.send(myPyDatagram, self.myConnection)
Beispiel #39
0
 def scoreDatagram(self):
     # Send a test message
     myPyDatagram = PyDatagram()
     myPyDatagram.addUint8(END_MESSAGE)
     myPyDatagram.addInt32(len(self.playerscores))
     for pair in self.playerscores:
         myPyDatagram.addString(pair[0])
         myPyDatagram.addInt32(pair[1])
     return myPyDatagram
Beispiel #40
0
 def MOVE_TO(self, charid, dest):
     (x2, y2, z2) = dest
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('MOVE_TO')
     myPyDatagram.addString(charid)
     myPyDatagram.addUint8(x2)
     myPyDatagram.addUint8(y2)
     myPyDatagram.addUint8(z2)
     self.cWriter.send(myPyDatagram, self.myConnection)
Beispiel #41
0
def dg_has_died(local_id):
    """
    :param local_id: The local_id of the player who has died
    :type local_id: Uint8
    """
    dg = PyDatagram()
    dg.addUint8(HAS_DIED)
    dg.addUint8(local_id)
    return dg
Beispiel #42
0
 def GET_PATH(self, charid, dest):
     (x, y, z) = dest
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('GET_PATH')
     myPyDatagram.addString(charid)
     myPyDatagram.addUint8(x)
     myPyDatagram.addUint8(y)
     myPyDatagram.addUint8(z)
     self.cWriter.send(myPyDatagram, self.myConnection)
 def send_server_info(self):
     pkg = PyDatagram()
     pkg.addUint16(SMSG_INFO)
     for id in self.CLIENTS_ID:
         pkg.addUint8(id)
         pkg.addString(self.CLIENTS_USER_NAMES[id])
         pkg.addString(self.CLIENTS_IP[id])
         pkg.addBool(self.CLIENTS_READY[id])
     self.broadcast_pkg(pkg)
Beispiel #44
0
 def makeTimeDataDatagram(self, frameCount, frameTime, dt):
     datagram = PyDatagram()
     datagram.addUint32(self.packetNumber)
     self.packetNumber = self.packetNumber + 1
     datagram.addUint8(CLUSTER_TIME_DATA)
     datagram.addUint32(frameCount)
     datagram.addFloat32(frameTime)
     datagram.addFloat32(dt)
     return datagram
Beispiel #45
0
	def sendMove(self, fr, to):
		dg = PyDatagram()
		dg.addUint8(fr[0])
		dg.addUint8(fr[1])
		dg.addUint8(to[0])
		dg.addUint8(to[1])
		
		print "Sent move (%d, %d) -> (%d, %d)" % (fr[0], fr[1], to[0], to[1])
		self.cWriter.send(dg, self.oppConnection)
def getDefaultBackpackNetString(isAI=False):
    bp = getDefaultBackpack(isAI)

    dg = PyDatagram()
    for gagId, supply in bp.items():
        dg.addUint8(gagId)
        dg.addUint8(supply)
    dgi = PyDatagramIterator(dg)
    return dgi.getRemainingBytes()
 def sendHello(self, password=""):
     dg = PyDatagram()
     dg.addUint16(NetMessages.CL_Hello)
     dg.addString(password)
     # DC hash verification
     dg.addUint32(self.hashVal)
     dg.addUint8(cl_updaterate.getValue())
     dg.addUint8(cl_cmdrate.getValue())
     self.sendDatagram(dg)
Beispiel #48
0
 def MOVE_TO(self, charid, dest):
     (x2, y2, z2) = dest
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('MOVE_TO')
     myPyDatagram.addString(charid)
     myPyDatagram.addUint8(x2)
     myPyDatagram.addUint8(y2)
     myPyDatagram.addUint8(z2)
     self.cWriter.send(myPyDatagram, self.myConnection)
Beispiel #49
0
 def getCollisionDatagrams(self):
     myDatagrams = []
     for data in self.collisionData:
         newDatagram = PyDatagram()
         newDatagram.addUint8(COLLIDED_MESSAGE)
         newDatagram.addUint8(data[0])
         newDatagram.addUint8(data[1])
         myDatagrams.append(newDatagram)
     return myDatagrams
    def makeNetString(self):
        dataList = self.inventory
        datagram = PyDatagram()
        for track in range(0, len(Tracks)):
            for level in range(0, len(Levels[track])):
                datagram.addUint8(dataList[track][level])

        dgi = PyDatagramIterator(datagram)
        return dgi.getRemainingBytes()
Beispiel #51
0
 def PATH(self, charid, orig, direction, dest, path, player):
     myPyDatagram = PyDatagram()
     myPyDatagram.addString('PATH')
     myPyDatagram.addString(charid)
     myPyDatagram.addString(json.dumps(orig))
     myPyDatagram.addUint8(direction)
     myPyDatagram.addString(json.dumps(dest))
     myPyDatagram.addString(json.dumps(path))
     self.cWriter.send(myPyDatagram, player)
Beispiel #52
0
    def makeNetString(self):
        dataList = self.inventory
        datagram = PyDatagram()
        for track in xrange(0, len(Tracks)):
            for level in xrange(0, len(Levels[track])):
                datagram.addUint8(dataList[track][level])

        dgi = PyDatagramIterator(datagram)
        return dgi.getRemainingBytes()
Beispiel #53
0
 def __makeBlob(self, store):
     # Construct a new datagram and fill it up with the items in
     # the list.
     dg = PyDatagram()
     if self.__list:  # empty list or None means nothing on the list.
         dg.addUint8(CatalogItem.CatalogItemVersion)
         for item in self.__list:
             CatalogItem.encodeCatalogItem(dg, item, store)
     return dg.getMessage()
Beispiel #54
0
    def revertToPlot(self, plotIndex):
        dg = PyDatagram()
        dg.addUint8(plotIndex)
        gardenData = PyDatagramIterator(dg)

        plot = occupier2Class[GardenGlobals.EmptyPlot](self.air, self, self.house.housePos)
        plot.construct(gardenData)
        self.plots[plotIndex] = plot

        self.updateGardenData()
Beispiel #55
0
 def sendUpdateBattleground(self, battleground, player):
     datagram = PyDatagram()
     datagram.addUint8(protocols.ClientMsgId.sendUpdateBattleground)
     names = []
     for card in battleground:
         names.append(card.name)
     dataStr = self.buildListStr(names)
     datagram.addString(dataStr)
     datagram.addString(player.nick)
     self.server.broadcast(datagram)
Beispiel #56
0
    def sendHand(self, player, hand):
        datagram = PyDatagram()
        datagram.addUint8(protocols.ClientMsgId.sendHand)
        names = []
        for card in hand:
            names.append(card.name)

        dataStr = self.buildListStr(names)
        datagram.addString(dataStr)
        self.server.writer.send(datagram, player.connection)
Beispiel #57
0
 def getCarPosDatagram(self, num, data):
     newDatagram = PyDatagram()
     newDatagram.addUint8(CAR_MESSAGE)
     newDatagram.addUint8(num)
     for j in range(5):
         newDatagram.addFloat32(float(data[j]))
     for j in range(5):
         newDatagram.addBool(data[5][j])
     newDatagram.addInt32(data[6])
     return newDatagram
Beispiel #58
0
 def handleChatMsg(self, it, player):
     nick = player.nick
     message = it.getString()
     self.server.addToChatLog(nick, message)
     messenger.send("received_chat_message", sentArgs=[nick, message])
     datagram = PyDatagram()
     datagram.addUint8(ClientMsgId.chatMsg)
     datagram.addString(nick)
     datagram.addString(message)
     self.server.broadcast(datagram)
 def sendAvatarGenerate(self):
     datagram = PyDatagram()
     # Message type is 1
     datagram.addUint16(ALL_OBJECT_GENERATE_WITH_REQUIRED)
     # Avatar class type is 2
     datagram.addUint8(2)
     # A sample id
     datagram.addUint32(10)
     # The only required field is the zone field
     datagram.addUint32(999)
     self.cw.send(datagram, self.lastConnection)
Beispiel #60
0
 def makeCamFrustumDatagram(self, focalLength, filmSize, filmOffset):
     datagram = PyDatagram()
     datagram.addUint32(self.packetNumber)
     self.packetNumber = self.packetNumber + 1
     datagram.addUint8(CLUSTER_CAM_FRUSTUM)
     datagram.addFloat32(focalLength)
     datagram.addFloat32(filmSize[0])
     datagram.addFloat32(filmSize[1])
     datagram.addFloat32(filmOffset[0])
     datagram.addFloat32(filmOffset[1])
     return datagram