Example #1
0
def addResource(resName, galaxy, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, userID):
	returnStr = ""
	spawnID = dbShared.getSpawnID(resName,galaxy)
	if spawnID < 0:
		# Add new resource
		conn = dbShared.ghConn()
		cursor = conn.cursor()
		# clear invalid stat values incase type was switched in the UI
		tempSQL = "SELECT CRmin, CRMax, CDmin, CDmax, DRmin, DRmax, FLmin, FLmax, HRmin, HRmax, MAmin, MAmax, PEmin, PEmax, OQmin, OQmax, SRmin, SRmax, UTmin, UTmax, ERmin, ERmax FROM tResourceType WHERE resourceType='" + resType + "';"
		cursor.execute(tempSQL)
		row = cursor.fetchone()
		if row != None:
			if row[0] == 0: CR = ''
			if row[2] == 0: CD = ''
			if row[4] == 0: DR = ''
			if row[6] == 0: FL = ''
			if row[8] == 0: HR = ''
			if row[10] == 0: MA = ''
			if row[12] == 0: PE = ''
			if row[14] == 0: OQ = ''
			if row[16] == 0: SR = ''
			if row[18] == 0: UT = ''
			if row[20] == 0: ER = ''


		tempSQL = "INSERT INTO tResources (spawnName, galaxy, entered, enteredBy, resourceType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER) VALUES ('" + resName + "'," + n2n(galaxy) + ",NOW(),'" + userID + "','" + resType + "'," + n2n(CR) + "," + n2n(CD) + "," + n2n(DR) + "," + n2n(FL) + "," + n2n(HR) + "," + n2n(MA) + "," + n2n(PE) + "," + n2n(OQ) + "," + n2n(SR) + "," + n2n(UT) + "," + n2n(ER) + ");"
		cursor.execute(tempSQL)
		result = cursor.rowcount
		if (result < 1):
			returnStr = "Error: resource not added."
		else:
			returnStr = "1st entry."
		# add event for add if stats included
		if OQ.isdigit() and OQ != '0':
			spawnID = dbShared.getSpawnID(resName,galaxy)
			dbShared.logEvent("INSERT INTO tResourceEvents (galaxy, spawnID, userID, eventTime, eventType) VALUES (" + str(galaxy) + "," + str(spawnID) + ",'" + userID + "',NOW(),'a');","a", userID, galaxy, spawnID)

		cursor.close()
		conn.close()
	else:
		returnStr = "Error: A resource with that name already exists in that galaxy."

	return returnStr
Example #2
0
def addResource(resName, galaxy, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER):
	# Add new resource
	returnStr = ""
	conn = dbShared.ghConn()
	cursor = conn.cursor()
	# clear invalid stat values incase type was switched in the UI
	tempSQL = "SELECT CRmin, CRMax, CDmin, CDmax, DRmin, DRmax, FLmin, FLmax, HRmin, HRmax, MAmin, MAmax, PEmin, PEmax, OQmin, OQmax, SRmin, SRmax, UTmin, UTmax, ERmin, ERmax FROM tResourceType WHERE resourceType='" + resType + "';"
	cursor.execute(tempSQL)
	row = cursor.fetchone()
	if row != None:
		if row[0] == 0: CR = ''
		if row[2] == 0: CD = ''
		if row[4] == 0: DR = ''
		if row[6] == 0: FL = ''
		if row[8] == 0: HR = ''
		if row[10] == 0: MA = ''
		if row[12] == 0: PE = ''
		if row[14] == 0: OQ = ''
		if row[16] == 0: SR = ''
		if row[18] == 0: UT = ''
		if row[20] == 0: ER = ''
			

	tempSQL = "INSERT INTO tResources (spawnName, galaxy, entered, enteredBy, resourceType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER) VALUES ('" + resName + "'," + n2n(galaxy) + ",NOW(),'" + currentUser + "','" + resType + "'," + n2n(CR) + "," + n2n(CD) + "," + n2n(DR) + "," + n2n(FL) + "," + n2n(HR) + "," + n2n(MA) + "," + n2n(PE) + "," + n2n(OQ) + "," + n2n(SR) + "," + n2n(UT) + "," + n2n(ER) + ");"
	cursor.execute(tempSQL)
	result = cursor.rowcount
	if (result < 1):
		returnStr = "Error: resource not added."
	else:
		returnStr = "1st entry."
	# add event for add if stats included
	if OQ.isdigit():
		spawnID = dbShared.getSpawnID(resName,galaxy)
		dbShared.logEvent("INSERT INTO tResourceEvents (spawnID, userID, eventTime, eventType) VALUES (" + str(spawnID) + ",'" + currentUser + "',NOW(),'a');","a",currentUser, galaxy,spawnID)

	cursor.close()
	conn.close()
	return returnStr
Example #3
0
def main():
    # Get current url
    try:
        url = os.environ['SCRIPT_NAME']
    except KeyError:
        url = ''

    form = cgi.FieldStorage()
    # Get Cookies
    useCookies = 1
    cookies = Cookie.SimpleCookie()
    try:
        cookies.load(os.environ['HTTP_COOKIE'])
    except KeyError:
        useCookies = 0

    if useCookies:
        try:
            currentUser = cookies['userID'].value
        except KeyError:
            currentUser = ''
        try:
            loginResult = cookies['loginAttempt'].value
        except KeyError:
            loginResult = 'success'
        try:
            sid = cookies['gh_sid'].value
        except KeyError:
            sid = form.getfirst('gh_sid', '')
    else:
        currentUser = ''
        sid = form.getfirst('gh_sid', '')

    spawnName = form.getfirst('spawn', '')
    galaxy = form.getfirst('galaxy', '')
    planets = form.getfirst('planets', '')
    # escape input to prevent sql injection
    sid = dbShared.dbInsertSafe(sid)
    spawnName = dbShared.dbInsertSafe(spawnName)
    galaxy = dbShared.dbInsertSafe(galaxy)
    planets = dbShared.dbInsertSafe(planets)

    # Get a session
    logged_state = 0

    sess = dbSession.getSession(sid)
    if (sess != ''):
        logged_state = 1
        currentUser = sess

    # Main program
    print 'Content-type: text/html\n'
    if (logged_state > 0):
        if (dbShared.galaxyState(galaxy) == 1):
            spawnID = dbShared.getSpawnID(spawnName, galaxy)
            result = removeSpawn(spawnID, planets, currentUser, galaxy)
        else:
            result = "Error: That Galaxy is Inactive."

    else:
        result = "Error: You must be logged in to mark a resource unavailable."

    print result
    if (result.find("Error:") > -1):
        sys.exit(500)
    else:
        sys.exit(200)
Example #4
0
def main():
	# Get current url
	try:
		url = os.environ['SCRIPT_NAME']
	except KeyError:
		url = ''

	form = cgi.FieldStorage()
	# Get Cookies
	useCookies = 1
	cookies = Cookie.SimpleCookie()
	try:
		cookies.load(os.environ['HTTP_COOKIE'])
	except KeyError:
		useCookies = 0

	if useCookies:
		try:
			currentUser = cookies['userID'].value
		except KeyError:
			currentUser = ''
		try:
			loginResult = cookies['loginAttempt'].value
		except KeyError:
			loginResult = 'success'
		try:
			sid = cookies['gh_sid'].value
		except KeyError:
			sid = form.getfirst('gh_sid', '')
	else:
		currentUser = ''
		loginResult = 'success'
		sid = form.getfirst('gh_sid', '')

	numRows = form.getfirst("numRows", "")
	# Get form info
	galaxy = form.getfirst("galaxy", "")
	planet = form.getfirst("planet", "")
	spawnID = form.getfirst("resID", "")
	spawnName = form.getfirst("resName", "")
	resType = form.getfirst("resType", "")
	forceOp = form.getfirst("forceOp", "")
	sourceRow = form.getfirst("sourceRow", "")
	CR = form.getfirst("CR", "")
	CD = form.getfirst("CD", "")
	DR = form.getfirst("DR", "")
	FL = form.getfirst("FL", "")
	HR = form.getfirst("HR", "")
	MA = form.getfirst("MA", "")
	PE = form.getfirst("PE", "")
	OQ = form.getfirst("OQ", "")
	SR = form.getfirst("SR", "")
	UT = form.getfirst("UT", "")
	ER = form.getfirst("ER", "")
	# escape input to prevent sql injection
	sid = dbShared.dbInsertSafe(sid)
	numRows = dbShared.dbInsertSafe(numRows)
	galaxy = dbShared.dbInsertSafe(galaxy)
	planet = dbShared.dbInsertSafe(planet)
	spawnID = dbShared.dbInsertSafe(spawnID)
	spawnName = dbShared.dbInsertSafe(spawnName)
	resType = dbShared.dbInsertSafe(resType)
	forceOp = dbShared.dbInsertSafe(forceOp)
	sourceRow = dbShared.dbInsertSafe(sourceRow)
	CR = dbShared.dbInsertSafe(CR)
	CD = dbShared.dbInsertSafe(CD)
	DR = dbShared.dbInsertSafe(DR)
	FL = dbShared.dbInsertSafe(FL)
	HR = dbShared.dbInsertSafe(HR)
	MA = dbShared.dbInsertSafe(MA)
	PE = dbShared.dbInsertSafe(PE)
	OQ = dbShared.dbInsertSafe(OQ)
	SR = dbShared.dbInsertSafe(SR)
	UT = dbShared.dbInsertSafe(UT)
	ER = dbShared.dbInsertSafe(ER)

	spawnName = spawnName.lower()

	# Get a session
	logged_state = 0

	sess = dbSession.getSession(sid)
	if (sess != ''):
		logged_state = 1
		currentUser = sess

	#  Check for errors
	errstr = ""
	if (len(spawnName) < 1 and spawnID == ""):
		errstr = errstr + "Error: no resource name. \r\n"
	if ((resType == "none" or len(resType) < 1) and spawnID == "" and forceOp != "verify"):
		errstr = errstr + "Error: no resource type. \r\n"
	else:
		#  Some automated updaters post reptillian meat as 'reptilian', normalize
		resType = resType.replace("reptilian", "reptillian")

	if spawnID == "":
		if galaxy == "":
			errstr = errstr + "Error: no galaxy selected. \r\n"
		else:
			# try to look up spawnID for editing and verifying
			spawnID = dbShared.getSpawnID(spawnName, galaxy)

	if re.search('\W', spawnName):
		errstr = errstr + "Error: spawn name contains illegal characters."
	if (forceOp != "edit" and planet.isdigit() == False):
		# attempt to lookup planet by name
		if planet != "":
			planet = dbShared.getPlanetID(planet)
		if planet.isdigit() == False:
			errstr = errstr + "Error: planet must be provided to post resource unless editing."

	postBlockedSeconds = dbShared.getUserPostBlockedSecondsRemaining(currentUser, 'r')
	if dbShared.getUserPostBlockedSecondsRemaining(currentUser, 'r') > 0:
		errstr = errstr + "Error: You are currently blocked from adding or updating resources due to recent activity.  Your cooldown ends in less than " + str((postBlockedSeconds / 3600) + 1) + " hours."

	if (errstr == ""):
		result = ""
		galaxyState = dbShared.galaxyState(galaxy)
		if (logged_state > 0 and galaxyState == 1):
			if (spawnName == "" or spawnName == None):
				spawnName = ghNames.getSpawnName(spawnID)

			if (spawnID>-1):
				# spawn already entered
				if (forceOp == "edit"):
					result = "edit: "
					result = result + addResStats(spawnID, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, forceOp, currentUser, galaxy)
				else:
					result = addResPlanet(spawnID, planet, spawnName, currentUser, galaxy)
					result = result + '  ' + addResStats(spawnID, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, forceOp, currentUser, galaxy)
			else:
				# new spawn
				result = addResource(spawnName, galaxy, resType, CR, CD, DR, FL, HR, MA, PE, OQ, SR, UT, ER, currentUser)
				spawnID = dbShared.getSpawnID(spawnName, galaxy)
				result = addResPlanet(spawnID, planet, spawnName, currentUser, galaxy) + '  ' + result

		else:
			if logged_state > 0:
				result = "Error: You cannot add resource data for an Inactive Galaxy."
			else:
				result = "Error: must be logged in to add resources"
	else:
		result = errstr

	print 'Content-type: text/xml\n'
	doc = minidom.Document()
	eRoot = doc.createElement("result")
	doc.appendChild(eRoot)

	eName = doc.createElement("spawnName")
	tName = doc.createTextNode(spawnName)
	eName.appendChild(tName)
	eRoot.appendChild(eName)
	eText = doc.createElement("resultText")
	tText = doc.createTextNode(result)
	eText.appendChild(tText)
	eRoot.appendChild(eText)
	eSource = doc.createElement("sourceRow")
	tSource = doc.createTextNode(sourceRow)
	eSource.appendChild(tSource)
	eRoot.appendChild(eSource)
	print doc.toxml()

	if (result.find("Error:") > -1):
		sys.exit(500)
	else:
		sys.exit(200)
Example #5
0
        unitsTest = int(units)
        if unitsTest > 2147483648 or unitsTest < -2147483648:
            errstr = errstr + "Error: That value for units is outside the range I can store."
    except:
        errstr = errstr + "Error: The value you entered for units could not be converted to a number."

# Only process if no errors
if (errstr == ""):
    result = ""
    favGroup = favGroup.replace(" ", "_")
    if (logged_state > 0):
        # Find favorite record and update/add as needed
        conn = dbShared.ghConn()
        # Lookup spawn id if we dont have it
        if favType == "1" and itemID.isdigit() == False:
            itemID = str(dbShared.getSpawnID(itemName, galaxyID))
            if itemID == "-1":
                result = "Error: The spawn name you entered cannot be found in this galaxy."

        if itemID != "-1":
            if units != "" or favGroup != "" or despawnAlert != "":
                # Just updating favorite property
                if units != "":
                    udStr = "units=" + str(units)
                if favGroup != "":
                    udStr = "favGroup='" + favGroup + "'"
                if despawnAlert != "":
                    if favoriteExists(conn, currentUser, favType, itemID,
                                      galaxyID) != True:
                        result = addFavorite(conn, currentUser, favType,
                                             itemID, galaxyID)
Example #6
0
		if unitsTest > 2147483648 or unitsTest < -2147483648:
			errstr = errstr + "Error: That value for units is outside the range I can store."
	except:
		errstr = errstr + "Error: The value you entered for units could not be converted to a number."

# Only process if no errors
if (errstr == ""):
	result = ""
	favGroup = favGroup.replace(" ", "_")
	if (logged_state > 0):
		# Find favorite record and update/add as needed
		conn = dbShared.ghConn()
		# Lookup spawn id if we dont have it
		if itemID.isdigit() == False:
			#sys.stderr.write("__" + itemName + "__" + galaxyID)
			itemID = dbShared.getSpawnID(itemName, galaxyID)
			if itemID == -1:
				result = "Error: The spawn name you entered cannot be found in this galaxy."
		else:
			itemID = int(itemID)

		if itemID > -1:
			cursor = conn.cursor()
			cursor.execute("SELECT favGroup FROM tFavorites WHERE itemID=" + str(itemID) + " AND userID='" + currentUser + "' AND favType=" + str(favType) + ";")
			row = cursor.fetchone()
			cursor2 = conn.cursor()
			if row != None:
				if operation != "2" and units == "":
					if operation != "1":
						# not changing group, must be removing
						tempSQL = "DELETE FROM tFavorites WHERE itemID=" + str(itemID) + " AND userID='" + currentUser + "' AND favType=" + str(favType) + ";"
Example #7
0
#  Check for errors
errstr = ""
if (len(spawnName) < 1 and spawnID == ""):
    errstr = errstr + "Error: no resource name. \r\n"
if ((resType == "none" or len(resType) < 1) and spawnID == ""
        and forceOp != "verify"):
    errstr = errstr + "Error: no resource type. \r\n"
else:
    #  Some automated updaters post reptillian meat as 'reptilian', normalize
    resType = resType.replace("reptilian", "reptillian")
if (spawnID == "" and galaxy == ""):
    errstr = errstr + "Error: no galaxy selected. \r\n"
else:
    # try to look up spawnID for editing and verifying
    if (spawnID == ""):
        spawnID = dbShared.getSpawnID(spawnName, galaxy)
if re.search('\W', spawnName):
    errstr = errstr + "Error: spawn name contains illegal characters."
if (forceOp != "edit" and planet.isdigit() == False):
    # attempt to lookup planet by name
    if planet != "":
        planet = dbShared.getPlanetID(planet)
    if planet.isdigit() == False:
        errstr = errstr + "Error: planet must be provided to post resource unless editing."

postBlockedSeconds = dbShared.getUserPostBlockedSecondsRemaining(
    currentUser, 'r')
if dbShared.getUserPostBlockedSecondsRemaining(currentUser, 'r') > 0:
    errstr = errstr + "Error: You are currently blocked from adding or updating resources due to recent activity.  Your cooldown ends in less than " + str(
        (postBlockedSeconds / 3600) + 1) + " hours."
if operation not in ['-','+']:
	errstr = errstr + "Error: Invalid operation ({0}).  - or + are allowed.".format(operation)

udCount = 0
# Only process if no errors
if (errstr == ""):
	result = ""
	if (logged_state > 0):
		# Alter inventory
		conn = dbShared.ghConn()
		# Open each item
		for x in range(fc):
			if updateList[x] != "":
				thisUpdate = updateList[x].split(":")
				resName = thisUpdate[0]
				resID = dbShared.getSpawnID(resName, galaxy)
				qtyAdjust = thisUpdate[1]
				cursor = conn.cursor()
				cursor.execute("SELECT units FROM tFavorites WHERE galaxy=%s AND userID=%s and favType=1 AND itemID=%s;", [galaxy, currentUser, resID])
				row = cursor.fetchone()
				if row != None:
					if row[0] == None:
						currentAmount = 0
					else:
						currentAmount = row[0]
					adjustedAmount = eval("{0} {1} {2}".format(str(currentAmount), operation, qtyAdjust))
					if adjustedAmount < -2147483647 or adjustedAmount > 2147483647:
						result = result + "I can't handle numbers that big for (" + resName + ")\n "
						break
					if adjustedAmount <= 0:
						result = result + " Warning: adjustment for " + resName + " resulted in depletion of inventory (" + str(adjustedAmount) + " units."
def updatePlanetSpawns(planetID, classID, resources, galaxyID, userID):
    result = ''
    conn = dbShared.ghConn()
    cursor = conn.cursor()
    spawnAddCount = 0
    spawnVerifyCount = 0
    spawnRemovedCount = 0
    spawnErrorCount = 0
    errors = ''

    for spawn in resources:
        # first check if spawn has been reported or not
        cursor.execute(
            "SELECT unavailable, spawnID, OQ FROM tResources WHERE galaxy=%s AND spawnName=%s;",
            [galaxyID, spawn.spawnName])
        row = cursor.fetchone()
        if row != None:
            if row[0] != None:
                # Resource was previously unavailable - bringing it back
                timeSinceRemoved = datetime.fromtimestamp(time.time()) - row[0]
                # only add back if recently but not too recently marked unavailable
                if (timeSinceRemoved.days < 3 and timeSinceRemoved.days > 0
                    ) or (timeSinceRemoved.days == 0
                          and timeSinceRemoved.seconds > 7200):
                    status = postResource.addResPlanet(row[1], planetID,
                                                       spawn.spawnName, userID,
                                                       galaxyID)
                    if (status.find("Error:") > -1):
                        spawnErrorCount += 1
                        errors = errors + status + '\n<br />'
                    else:
                        spawnAddCount += 1
            else:
                # Verify already listed resource
                status = postResource.addResPlanet(row[1], planetID,
                                                   spawn.spawnName, userID,
                                                   galaxyID)
                if row[2] == None and spawn.stats.OQ > 0:
                    status = postResource.addResStats(
                        row[1], '', spawn.stats.CR, spawn.stats.CD,
                        spawn.stats.DR, spawn.stats.FL, spawn.stats.HR,
                        spawn.stats.MA, spawn.stats.PE, spawn.stats.OQ,
                        spawn.stats.SR, spawn.stats.UT, spawn.stats.ER, '',
                        userID, galaxyID) + '  ' + status
                if (status.find("Error:") > -1):
                    spawnErrorCount += 1
                    errors = errors + status + '\n<br />'
                else:
                    spawnVerifyCount += 1
        else:
            # Post as new resource
            status = postResource.addResource(spawn.spawnName, galaxyID,
                                              spawn.resourceType,
                                              str(spawn.stats.CR),
                                              str(spawn.stats.CD),
                                              str(spawn.stats.DR),
                                              str(spawn.stats.FL),
                                              str(spawn.stats.HR),
                                              str(spawn.stats.MA),
                                              str(spawn.stats.PE),
                                              str(spawn.stats.OQ),
                                              str(spawn.stats.SR),
                                              str(spawn.stats.UT),
                                              str(spawn.stats.ER), userID)
            spawnID = dbShared.getSpawnID(spawn.spawnName, galaxyID)
            status = postResource.addResPlanet(spawnID, planetID,
                                               spawn.spawnName, userID,
                                               galaxyID) + '   ' + status
            if (status.find("Error:") > -1):
                spawnErrorCount += 1
                errors = errors + status + '\n<br />'
            else:
                spawnAddCount += 1

    # Check for resources that have despawned
    if len(resources) > 0 and classID != '' and spawnErrorCount == 0:
        cursor.execute(
            "SELECT tResources.spawnID, spawnName FROM tResources INNER JOIN tResourcePlanet ON tResources.spawnID = tResourcePlanet.spawnID INNER JOIN (SELECT resourceType FROM tResourceTypeGroup WHERE resourceGroup='"
            + classID +
            "' GROUP BY resourceType) rtg ON tResources.resourceType = rtg.resourceType WHERE tResources.galaxy=%s AND tResourcePlanet.unavailable IS NULL AND tResourcePlanet.planetID=%s;",
            [galaxyID, planetID])
        row = cursor.fetchone()
        while row != None:
            stillAvailable = False
            for spawn in resources:
                if row[1] == spawn.spawnName:
                    stillAvailable = True
            if not stillAvailable:
                # available spawn was not in report, so mark it unavailable
                status = markUnavailable.removeSpawn(row[0], planetID, userID,
                                                     galaxyID)
                if (status.find("Error:") > -1):
                    spawnErrorCount += 1
                    errors = errors + status + '\n<br />'
                else:
                    spawnRemovedCount += 1

            row = cursor.fetchone()

    cursor.close()
    conn.close()

    result = "Report Upload Complete...\n<br/>{0} Errors\n<br/>{1} Spawns Added\n<br/>{2} Spawns Verified\n<br/>{3} Spawns Removed.\n<br/>{4}".format(
        spawnErrorCount, spawnAddCount, spawnVerifyCount, spawnRemovedCount,
        errors)
    return result
Example #10
0
	conn.close()
	return returnStr


#  Check for errors
errstr = ""
if (len(spawnName) < 1 and spawnID == ""):
	errstr = errstr + "Error: no resource name. \r\n"
if ((resType == "none" or len(resType) < 1) and spawnID == "" and forceOp != "verify"):
	errstr = errstr + "Error: no resource type. \r\n"
if (spawnID == "" and galaxy == ""):
	errstr = errstr + "Error: no galaxy selected. \r\n"
else:
	# try to look up spawnID for editing and verifying
	if (spawnID == ""):
		spawnID = dbShared.getSpawnID(spawnName, galaxy)
if re.search('\W', spawnName):
	errstr = errstr + "Error: spawn name contains illegal characters."
if (forceOp != "edit" and planet.isdigit() == False):
	# attempt to lookup planet by name
	if planet != "":
		planet = dbShared.getPlanetID(planet)
	if planet.isdigit() == False:
		errstr = errstr + "Error: planet must be provided to post resource unless editing."

if (errstr == ""):
	result = ""
	galaxyState = dbShared.galaxyState(galaxy)
	if (logged_state > 0 and galaxyState == 1):
		if (spawnName == "" or spawnName == None):
			spawnName = ghNames.getSpawnName(spawnID)