Exemplo n.º 1
0
	def _doGet(self):
		try:

			PM = QRzarPlayerMapper()

			if self.arg is not None:
				if self.arg.isdigit():
					# Get the user by ID
					player = PM.find(self.arg)
				else:
					raise BadRequest("Players must be requested by ID")

				if player is not None:
					return self._response(Depth.build(player, self.depth), CODE.OK)
				else:
					raise NotFound("This player does not exist")

			else:

				offset = 0
				players = PM.findAll(offset, offset+50)

				if players is None:
					raise NotFound("There are no players on this system.")

				playerslist = []
				for player in playerslist:
					playerslist.append(Depth.build(player, self.depth))

				playerslist = {"players": playerslist, "pagination_offset": offset, "max_perpage": 50}

				return self._response(playerslist, CODE.OK)

		except mdb.DatabaseError, e:
				raise ServerError("Unable to search the player database (%s: %s)" % e.args[0], e.args[1])
Exemplo n.º 2
0
	def _doPost(self, dataObject):
		if "killer" and "victim_qrcode" in dataObject:
			KM = KillMapper()
			PM = QRzarPlayerMapper()

			if dataObject["killer"] is not None and dataObject["victim_qrcode"] is not None:

				if "id" in dataObject["killer"]:
					try:
						# Get the player by ID
						killer = PM.find(dataObject["killer"]["id"])		
					except mdb.DatabaseError, e:
						raise ServerError("Unable to search the player database for the killer (%s)" % e.args[1])

					if killer is None:
						raise NotFound("Either the victim or the killer were invalid player objects")

					try:
						victim = PM.getPlayerByQrcode(killer.getTeam().getGame(), dataObject["victim_qrcode"])
					except mdb.DatabaseError, e:
						raise ServerError("Unable to search the player database for the victim (%s)" % e.args[1])

					if victim is None:
						raise NotFound("Either the victim or the killer were invalid player objects")
				else:
					raise BadRequest("Arguments provided for this kill are invalid.")
Exemplo n.º 3
0
	def _doPut(self, dataObject):

		if  "id" in dataObject:
			try:

				PM = QRzarPlayerMapper()

				if type(dataObject["id"]) is int:
					# Get the user by ID

					player = PM.find(dataObject["id"])

					if player is None:
						raise NotFound("The specified player type does not exist.")
				else:
					raise BadRequest("Argument provided for this player type is invalid.")

				player_user_id= player.getUser().getId()
				authenticated_user_id = self.user.getId()


 				if player_user_id == authenticated_user_id or self.user.accessLevel('super_user'):

					if dataObject.has_key("respawn_code"):

						if dataObject["respawn_code"] == player.getTeam().getRespawnCode() or self.user.accessLevel('super_user'):
							player.setAlive(True)

						else:
							raise Forbidden("Incorrect respawn QRcode")

					if "name" in dataObject:
						player.setName(dataObject["name"])

					if "latitude" in dataObject:
						player.setLat(dataObject["latitude"])

					if "longitude" in dataObject:
						player.setLon(dataObject["longitude"])

					if "flashed" in dataObject and "degree" in dataObject:
							player.setFlashed(dataObject["flashed"], dataObject["degree"])



					PM.update(player)

				return self._response(Depth.build(player, self.depth), CODE.CREATED)

			except mdb.DatabaseError, e:
				raise ServerError("Unable to search the player database (%s)" % e.args[1])
Exemplo n.º 4
0
	def _doDelete(self):
		if self.arg is None:
			raise BadRequest("You must provide the ID of the player to be deleted")

		PM = QRzarPlayerMapper()

		# get the user if it exists
		try:
			if self.arg.isdigit():
				# Get the player by ID
				player = PM.find(self.arg)
			else:
				raise BadRequest("Players must be requested by ID")

		except mdb.DatabaseError, e:
			raise ServerError("Unable to search the player database (%s: %s)" % e.args[0], e.args[1])
def main():
    from Common.config import TopHatConfig

    # setup the config
    kwargs = {"path": "/home/specialk/Dev/tophat/config.py"}
    TopHatConfig(**kwargs)

    # do the other stuff
    from Model.Mapper.qrzargamemapper import QRzarGameMapper
    from Model.Mapper.usermapper import UserMapper
    from Model.Mapper.killmapper import KillMapper
    from Model.Mapper.qrzarplayermapper import QRzarPlayerMapper
    from Model.Mapper.apitokenmapper import ApitokenMapper
    from Model.Mapper.objectwatcher import ObjectWatcher

    # Get All the current Users from the database
    UM = UserMapper()
    users = UM.findAll()
    for usr in users:
        print usr

    GM = QRzarGameMapper()
    games = GM.findAll()
    for game_ in games:
        print game_

    KM = KillMapper()
    kills = KM.findAll()

    for kill_ in kills:
        print kill_

    PM = QRzarPlayerMapper()
    players = PM.findAll()

    for player_ in players:
        print player_

    ATM = ApitokenMapper()
    tokens = ATM.findAll()
    for token in tokens:
        print token

    usr1 = UM.find(1)
Exemplo n.º 6
0
	def _doGet(self):	
		PM = QRzarPlayerMapper()
		
		if self.arg is not None and self.arg.isdigit():
			try:
				# Get the player by ID
				player = PM.find(self.arg)

			except mdb.DatabaseError, e:
				raise ServerError("Unable to search the player database (%s: %s)" % e.args[0], e.args[1])

			if player is None:
				raise NotFound("This player does not exist")

			rdata = {
				"alive": player.getAlive(),
				"score": player.getScore()
			}

			return self._response(rdata, CODE.OK)