示例#1
0
def addResPlanet(spawn, planet, spawnName):
	# Add resource to a planet
	returnStr = ""
	conn = dbShared.ghConn()
	cursor = conn.cursor()
	cursor.execute("SELECT trp.enteredBy, trp.unavailable, tr.unavailable AS tru, trp.planetID, tr.enteredBy, trp.verified, trp.verifiedBy FROM tResources tr LEFT JOIN (SELECT * FROM tResourcePlanet WHERE tResourcePlanet.spawnID=" + str(spawn) + " AND tResourcePlanet.planetID=" + str(planet) + ") trp ON tr.spawnID = trp.spawnID WHERE tr.spawnID=" + str(spawn) + ";")
	row = cursor.fetchone()
	if row[3] == None:
		# insert spawn planet record
		tempSQL = "INSERT INTO tResourcePlanet (spawnID, planetID, entered, enteredBy) VALUES (" + str(spawn) + "," + str(planet) + ",NOW(),'" + currentUser + "');"
		cursor.execute(tempSQL)
		result = cursor.rowcount
		if (result < 1):
			returnStr = "Error: Could not add resource to planet."
		else:
			returnStr = spawnName + " added to " + str(ghNames.getPlanetName(planet))
		# add resource planet add event
		dbShared.logEvent("INSERT INTO tResourceEvents (spawnID, userID, eventTime, eventType, planetID) VALUES (" + str(spawn) + ",'" + currentUser + "',NOW(),'p'," + str(planet) + ");",'p',currentUser, galaxy, spawn)
		if row[2] != None:
			# update main resource table when becoming re-available
			tempSQL = "UPDATE tResources SET unavailable=NULL WHERE spawnID = " + str(spawn) + ";"
			cursor.execute(tempSQL)
			returnStr += " and marked re-available"
	else:
		if (row[1] == None and row[2] == None):
			if ((row[0] == None) or (row[0].lower() != currentUser.lower() and row[4].lower() != currentUser.lower())):
				if (row[6] == None or row[6].lower() != currentUser.lower()):
					tempSQL = "UPDATE tResourcePlanet SET verified=NOW(), verifiedBy='" + currentUser + "' WHERE spawnID=" + str(spawn) + " AND planetID=" + str(planet) + ";"
					result = cursor.execute(tempSQL)
					if (result < 1):
						returnStr = "Error: Resource " + spawnName + " was marked available on " + str(ghNames.getPlanetName(planet)) + " by " + row[0] + " and there was an error entering your verification."
					else:
						returnStr = "Resource " + spawnName + " has been verified by you.  It was marked available on " + str(ghNames.getPlanetName(planet)) + " by " + row[0] + "."
						# add event for verification
						dbShared.logEvent("INSERT INTO tResourceEvents (spawnID, userID, eventTime, eventType, planetID) VALUES (" + str(spawn) + ",'" + currentUser + "',NOW(),'v'," + str(planet) + ");",'v',currentUser,galaxy,spawn)
						# update main resource table when verifying
						tempSQL = "UPDATE tResources SET verified=NOW(), verifiedBy='" + currentUser + "' WHERE spawnID = " + str(spawn) + ";"
						cursor.execute(tempSQL)
				else:
					returnStr = "You already verified " + spawnName + " on " + str(row[5]) + "."
			else:
				returnStr = "You already entered resource " + spawnName
		else:
			# update resource status available for planet
			tempSQL = "UPDATE tResourcePlanet SET unavailable = NULL WHERE spawnID=" + str(spawn) + " AND planetID=" + str(planet) + ";"
			cursor.execute(tempSQL)
			result = cursor.rowcount

			# update main resource table when becoming re-available
			tempSQL = "UPDATE tResources SET unavailable=NULL WHERE spawnID = " + str(spawn) + ";"
			cursor.execute(tempSQL)
			returnStr = spawnName + " marked re-available on " + ghNames.getPlanetName(planet)
    
	cursor.close()
	conn.close()
	return returnStr
            if (row != None):
                spawnName = row[0]

        sqlStr = ""
        if (spawnID != '' and galaxy != ''):
            if (dbShared.galaxyState(galaxy) == 1):
                if (availability == "0"):
                    # mark unavailable on planet(s)
                    if (planets == "all"):
                        sqlStr = "UPDATE tResourcePlanet SET unavailable=NOW(), unavailableBy='" + currentUser + "' WHERE spawnID=" + spawnID + ";"
                        result = "Marked unavailable on all planets."
                    else:
                        sqlStr = "UPDATE tResourcePlanet SET unavailable=NOW(), unavailableBy='" + currentUser + "' WHERE spawnID=" + spawnID + " AND planetID=" + dbShared.dbInsertSafe(
                            planets) + ";"
                        result = "Marked unavailable on " + ghNames.getPlanetName(
                            planets)
                elif (availability == "1"):
                    # mark (re)available on planet
                    cursor.execute(
                        "SELECT enteredBy, unavailable FROM tResourcePlanet WHERE spawnID="
                        + str(spawnID) + " AND planetID=" + str(planets) + ";")
                    row = cursor.fetchone()
                    if row == None:
                        # insert spawn planet record
                        sqlStr = "INSERT INTO tResourcePlanet (spawnID, planetID, entered, enteredBy) VALUES (" + str(
                            spawnID) + "," + str(
                                planets) + ",NOW(),'" + currentUser + "');"
                        result = "Marked available on " + ghNames.getPlanetName(
                            planets)
                    else:
                        sqlStr = "UPDATE tResourcePlanet SET unavailable = NULL WHERE spawnID=" + str(
示例#3
0
def addResPlanet(spawn, planet, spawnName, userID, galaxy):
	# Add resource to a planet
	returnStr = ""
	detailCol = ""
	detailVal = ""
	conn = dbShared.ghConn()
	cursor = conn.cursor()
	cursor.execute("SELECT trp.enteredBy, trp.unavailable, tr.unavailable AS tru, trp.planetID, tr.enteredBy, trp.verified, trp.verifiedBy, tr.verified, tr.verifiedBy FROM tResources tr LEFT JOIN (SELECT * FROM tResourcePlanet WHERE tResourcePlanet.spawnID=" + str(spawn) + " AND tResourcePlanet.planetID=" + str(planet) + ") trp ON tr.spawnID = trp.spawnID WHERE tr.spawnID=" + str(spawn) + ";")
	row = cursor.fetchone()
	if row[3] == None:
		# insert spawn planet record
		tempSQL = "INSERT INTO tResourcePlanet (spawnID, planetID, entered, enteredBy) VALUES (" + str(spawn) + "," + str(planet) + ",NOW(),'" + userID + "');"
		cursor.execute(tempSQL)
		result = cursor.rowcount
		if (result < 1):
			returnStr = "Error: Could not add resource to planet."
		else:
			returnStr = spawnName + " added to " + str(ghNames.getPlanetName(planet))

		if row[2] != None:
			# update main resource table when becoming re-available
			tempSQL = "UPDATE tResources SET unavailable=NULL WHERE spawnID = " + str(spawn) + ";"
			cursor.execute(tempSQL)
			returnStr += " and marked re-available"
			detailCol = ", eventDetail"
			detailVal = ", 'previously unavailable'"

		# add resource planet add event
		dbShared.logEvent("INSERT INTO tResourceEvents (galaxy, spawnID, userID, eventTime, eventType, planetID" + detailCol + ") VALUES (" + str(galaxy) + "," + str(spawn) + ",'" + userID + "',NOW(),'p'," + str(planet) + detailVal + ");", 'p', userID, galaxy, spawn)
	else:
		if (row[1] == None and row[2] == None):
			if ((row[0] == None) or (row[0].lower() != userID.lower() and row[4].lower() != userID.lower())):
				if (row[6] == None or row[6].lower() != userID.lower()):
					tempSQL = "UPDATE tResourcePlanet SET verified=NOW(), verifiedBy='" + userID + "' WHERE spawnID=" + str(spawn) + " AND planetID=" + str(planet) + ";"
					result = cursor.execute(tempSQL)
					if (result < 1):
						returnStr = "Error: Resource " + spawnName + " was marked available on " + str(ghNames.getPlanetName(planet)) + " by " + row[0] + " and there was an error entering your verification."
					else:
						returnStr = "Resource " + spawnName + " has been verified by you.  It was marked available on " + str(ghNames.getPlanetName(planet)) + " by " + row[0] + "."
						# add event for verification
						if row[7] != None:
							detailCol = ", eventDetail"
							detailVal = ", 'previously verified by " + row[8] + " on " + str(row[7]) + "'"
						dbShared.logEvent("INSERT INTO tResourceEvents (galaxy, spawnID, userID, eventTime, eventType, planetID" + detailCol + ") VALUES (" + str(galaxy) + "," + str(spawn) + ",'" + userID + "',NOW(),'v'," + str(planet) + detailVal + ");",'v', userID, galaxy, spawn)
						# update main resource table when verifying
						tempSQL = "UPDATE tResources SET verified=NOW(), verifiedBy='" + userID + "' WHERE spawnID = " + str(spawn) + ";"
						cursor.execute(tempSQL)
				else:
					returnStr = "You already verified " + spawnName + " on " + str(row[5]) + "."
			else:
				returnStr = "You already entered resource " + spawnName
		else:
			# update resource status available for planet
			tempSQL = "UPDATE tResourcePlanet SET unavailable = NULL WHERE spawnID=" + str(spawn) + " AND planetID=" + str(planet) + ";"
			cursor.execute(tempSQL)
			result = cursor.rowcount
			# update main resource table when becoming re-available
			tempSQL = "UPDATE tResources SET unavailable=NULL WHERE spawnID = " + str(spawn) + ";"
			cursor.execute(tempSQL)
			returnStr = spawnName + " marked re-available on " + ghNames.getPlanetName(planet)
			detailCol = ", eventDetail"
			detailVal = ", 'previously unavailable'"
			# add resource planet add event
			dbShared.logEvent("INSERT INTO tResourceEvents (galaxy, spawnID, userID, eventTime, eventType, planetID" + detailCol + ") VALUES (" + str(galaxy) + "," + str(spawn) + ",'" + userID + "',NOW(),'p'," + str(planet) + detailVal + ");", 'p', userID, galaxy, spawn)

	cursor.close()
	conn.close()
	return returnStr