Exemple #1
0
if (sess != ''):
    logged_state = 1
    currentUser = sess
    if (uiTheme == ''):
        uiTheme = dbShared.getUserAttr(currentUser, 'themeName')
    if (useCookies == 0):
        linkappend = 'gh_sid=' + sid
else:
    if (uiTheme == ''):
        uiTheme = 'crafter'

pictureName = dbShared.getUserAttr(currentUser, 'pictureName')
print 'Content-type: text/html\n'
env = Environment(loader=FileSystemLoader('templates'))
env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL
env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform(
    os.environ['HTTP_USER_AGENT'])
template = env.get_template('inventory.html')
print template.render(uiTheme=uiTheme,
                      loggedin=logged_state,
                      currentUser=currentUser,
                      loginResult=loginResult,
                      linkappend=linkappend,
                      url=url,
                      pictureName=pictureName,
                      imgNum=ghShared.imgNum,
                      galaxyList=ghLists.getGalaxyList(),
                      professionList=ghLists.getProfessionList(galaxy),
                      resourceGroupList=ghLists.getResourceGroupList(),
                      resourceTypeList=ghLists.getResourceTypeList(galaxy))
Exemple #2
0
def main():
    # Get current url
    try:
        url = os.environ['REQUEST_URI']
    except KeyError:
        url = ''
    uiTheme = ''
    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', '')
        try:
            uiTheme = cookies['uiTheme'].value
        except KeyError:
            uiTheme = ''
        try:
            avatarResult = cookies['avatarAttempt'].value
        except KeyError:
            avatarResult = ''
        try:
            galaxy = cookies['galaxy'].value
        except KeyError:
            galaxy = ghShared.DEFAULT_GALAXY
    else:
        currentUser = ''
        loginResult = form.getfirst('loginAttempt', '')
        avatarResult = form.getfirst('avatarAttempt', '')
        sid = form.getfirst('gh_sid', '')
        galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY)

    # escape input to prevent sql injection
    sid = dbShared.dbInsertSafe(sid)

    # Get a session
    logged_state = 0
    linkappend = ''
    disableStr = ''
    created = datetime.fromtimestamp(time.time())
    inGameInfo = ''
    pictureName = ''
    userPictureName = ''
    friendCountStr = ''
    donateTotal = ''
    userTitle = ''
    donorBadge = ''
    email = ''
    defaultAlertTypes = 0
    sharedInventory = 0
    sharedRecipes = 0
    siteAlertCheckStr = ''
    emailAlertCheckStr = ''
    mobileAlertCheckStr = ''
    reputation = 0
    resScore = 0
    mapScore = 0
    repColor = 'grey'
    resColor = 'grey'
    mapColor = 'grey'
    abilities = []

    if loginResult == None:
        loginResult = 'success'

    sess = dbSession.getSession(sid)
    if (sess != ''):
        logged_state = 1
        currentUser = sess
        if (useCookies == 0):
            linkappend = 'gh_sid=' + sid
        conn = dbShared.ghConn()
        cursor = conn.cursor()
        cursor.execute(
            'SELECT userID, emailAddress, themeName FROM tUsers WHERE userID="'
            + currentUser + '"')
        row = cursor.fetchone()
        if (row != None):
            email = row[1]
            uiTheme = row[2]
        cursor.close()
        conn.close()
    else:
        disableStr = ' disabled="disabled"'
        if (uiTheme == ''):
            uiTheme = 'crafter'

    path = []
    uid = ''
    template = 'user.html'
    userPage = 'root'
    if os.environ.has_key('PATH_INFO'):
        path = os.environ['PATH_INFO'].split('/')[1:]
        path = [p for p in path if p != '']

    # get user attributes
    if len(path) > 0:
        uid = dbShared.dbInsertSafe(path[0])
        if len(path) > 1:
            userPage = path[1]
        if userPage == 'inventory':
            template = 'inventory.html'
        else:
            created = dbShared.getUserAttr(uid, 'created')
            inGameInfo = dbShared.getUserAttr(uid, 'inGameInfo')
            userPictureName = dbShared.getUserAttr(uid, 'pictureName')
            defaultAlerts = dbShared.getUserAttr(uid, 'defaultAlertTypes')
            if defaultAlerts > 0:
                if defaultAlerts % 2 == 1:
                    siteAlertCheckStr = ' checked="checked"'
                if defaultAlerts >= 4:
                    mobileAlertCheckStr = ' checked="checked"'
                if defaultAlerts != 1 and defaultAlerts != 4 and defaultAlerts != 5:
                    emailAlertCheckStr = ' checked="checked"'
            sharedInventory = dbShared.getUserAttr(uid, 'sharedInventory')
            sharedRecipes = dbShared.getUserAttr(uid, 'sharedRecipes')

            donateTotal = dbShared.getUserDonated(uid)
            userTitle = dbShared.getUserTitle(uid)
            userStats = dbShared.getUserStats(uid, galaxy).split(',')
            resScore = int(userStats[0])
            mapScore = int(userStats[1])
            reputation = int(userStats[2])
            if resScore != None:
                if resScore > 2000:
                    resColor = '#ffcc00'
                elif resScore > 500:
                    resColor = '#3366ff'
                elif resScore > 25:
                    resColor = '#009933'

            if mapScore != None:
                if mapScore > 400:
                    mapColor = '#ffcc00'
                elif mapScore > 100:
                    mapColor = '#3366ff'
                elif mapScore > 5:
                    mapColor = '#009933'

            if reputation != None:
                if reputation > 100:
                    repColor = '#ffcc00'
                elif reputation > 50:
                    repColor = '#3366ff'
                elif reputation > 10:
                    repColor = '#009933'
                elif reputation < 0:
                    repColor = '#800000'

            if userPictureName == '':
                userPictureName = 'default.jpg'
            if donateTotal != '':
                donorBadge = '<img src="/images/coinIcon.png" width="16" title="This user has donated to the site" alt="coin" />'
            # get friend count
            conn = dbShared.ghConn()
            cursor = conn.cursor()
            cursor.execute(
                'SELECT Count(uf1.added) FROM tUserFriends uf1 INNER JOIN tUserFriends uf2 ON uf1.friendID=uf2.userID AND uf1.userID=uf2.friendID WHERE uf1.userID="'
                + uid + '"')
            row = cursor.fetchone()
            if (row != None):
                friendCountStr = '(' + str(row[0]) + ')'
            cursor.close()
            conn.close()

        # Load list of unlocked abilities
        for k, v in ghShared.ABILITY_DESCR.iteritems():
            if reputation >= ghShared.MIN_REP_VALS[
                    k] and ghShared.MIN_REP_VALS[k] != -99:
                a = userAbility(k, v, True)
                a.minReputation = ghShared.MIN_REP_VALS[k]
                abilities.append(a)

    convertGI = ghShared.convertText(inGameInfo, "js")
    tmpStat = dbShared.friendStatus(uid, currentUser)
    joinedStr = 'Joined ' + ghShared.timeAgo(created) + ' ago'
    pictureName = dbShared.getUserAttr(currentUser, 'pictureName')

    print 'Content-type: text/html\n'
    env = Environment(loader=FileSystemLoader('templates'))
    env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL
    env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform(
        os.environ['HTTP_USER_AGENT'])
    template = env.get_template(template)
    if userPage == 'inventory':
        print template.render(
            uiTheme=uiTheme,
            loggedin=logged_state,
            currentUser=currentUser,
            loginResult=loginResult,
            linkappend=linkappend,
            url=url,
            pictureName=pictureName,
            imgNum=ghShared.imgNum,
            galaxyList=ghLists.getGalaxyList(),
            professionList=ghLists.getProfessionList(galaxy),
            resourceGroupList=ghLists.getResourceGroupList(),
            resourceTypeList=ghLists.getResourceTypeList(galaxy),
            uid=uid,
            editable=(uid == currentUser and logged_state == 1))
    else:
        print template.render(uiTheme=uiTheme,
                              loggedin=logged_state,
                              currentUser=currentUser,
                              loginResult=loginResult,
                              linkappend=linkappend,
                              url=url,
                              pictureName=pictureName,
                              imgNum=ghShared.imgNum,
                              galaxyList=ghLists.getGalaxyList(),
                              themeList=ghLists.getThemeList(),
                              uid=uid,
                              convertGI=convertGI,
                              sid=sid,
                              avatarResult=avatarResult,
                              email=email,
                              donorBadge=donorBadge,
                              joinedStr=joinedStr,
                              userPictureName=userPictureName,
                              tmpStat=tmpStat,
                              userTitle=userTitle,
                              friendCountStr=friendCountStr,
                              userAbilities=abilities,
                              resScore=resScore,
                              mapScore=mapScore,
                              reputation=reputation,
                              resColor=resColor,
                              mapColor=mapColor,
                              repColor=repColor,
                              siteAlertCheckStr=siteAlertCheckStr,
                              emailAlertCheckStr=emailAlertCheckStr,
                              mobileAlertCheckStr=mobileAlertCheckStr,
                              sharedInventory=sharedInventory,
                              sharedRecipes=sharedRecipes)
Exemple #3
0
def main():
    # Get current url
    try:
        url = os.environ['SCRIPT_NAME']
    except KeyError:
        url = ''
    uiTheme = ''
    schematicID = ''
    schemImageAttempt = ''
    schemHTML = '<h2>That schematic does not exist.</h2>'
    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', '')
        try:
            uiTheme = cookies['uiTheme'].value
        except KeyError:
            uiTheme = ''
        try:
            schemImageAttempt = cookies['schemImageAttempt'].value
        except KeyError:
            schemImageAttempt = ''
        try:
            galaxy = cookies['galaxy'].value
        except KeyError:
            galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY)
    else:
        currentUser = ''
        loginResult = form.getfirst('loginAttempt', '')
        sid = form.getfirst('gh_sid', '')
        schemImageAttempt = form.getfirst('schemImageAttempt', '')
        galaxy = form.getfirst('galaxy', ghShared.DEFAULT_GALAXY)

    # escape input to prevent sql injection
    sid = dbShared.dbInsertSafe(sid)
    # Get a session
    logged_state = 0
    linkappend = ''
    disableStr = ''
    if loginResult == None:
        loginResult = 'success'

    sess = dbSession.getSession(sid, 2592000)
    if (sess != ''):
        logged_state = 1
        currentUser = sess
        if (uiTheme == ''):
            uiTheme = dbShared.getUserAttr(currentUser, 'themeName')
        if (useCookies == 0):
            linkappend = 'gh_sid=' + sid
    else:
        disableStr = ' disabled="disabled"'
        if (uiTheme == ''):
            uiTheme = 'crafter'

    path = []
    s = None
    if os.environ.has_key('PATH_INFO'):
        path = os.environ['PATH_INFO'].split('/')[1:]
        path = [p for p in path if p != '']

    favHTML = ''
    if len(path) > 0:
        schematicID = dbShared.dbInsertSafe(path[0])
        url = url + '/' + schematicID
        if (schematicID != 'index') and (schematicID != 'home'):
            # Build the schematic object
            try:
                conn = dbShared.ghConn()
                cursor = conn.cursor()
            except Exception:
                errorstr = "Error: could not connect to database"

            if (cursor):
                cursor.execute(
                    'SELECT schematicName, complexity, xpAmount, (SELECT imageName FROM tSchematicImages tsi WHERE tsi.schematicID=tSchematic.schematicID AND tsi.imageType=1) AS schemImage FROM tSchematic WHERE schematicID="'
                    + schematicID + '";')
                row = cursor.fetchone()

                if (row != None):
                    # main schematic data
                    if (row[3] != None):
                        schemImageName = row[3]
                    else:
                        schemImageName = 'none.jpg'

                    s = ghObjectSchematic.schematic()
                    s.schematicID = schematicID
                    s.schematicName = row[0]
                    s.complexity = row[1]
                    s.xpAmount = row[2]
                    s.schematicImage = schemImageName

                    ingCursor = conn.cursor()
                    ingCursor.execute(
                        'SELECT ingredientName, ingredientType, ingredientObject, ingredientQuantity, res.resName FROM tSchematicIngredients LEFT JOIN (SELECT resourceGroup AS resID, groupName AS resName FROM tResourceGroup UNION ALL SELECT resourceType, resourceTypeName FROM tResourceType) res ON ingredientObject = res.resID WHERE schematicID="'
                        + schematicID +
                        '" ORDER BY ingredientType, ingredientQuantity DESC;')
                    ingRow = ingCursor.fetchone()
                    while (ingRow != None):
                        tmpName = ingRow[2]
                        tmpName = tmpName.replace('shared_', '')
                        if (ingRow[1] == 0):
                            # resource
                            if (ingRow[4] != None):
                                tmpLink = '</td><td><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + ingRow[
                                    2] + '">' + ingRow[4] + '</a>'
                            else:
                                tmpLink = '</td><td><a href="' + ghShared.BASE_SCRIPT_URL + 'resourceType.py/' + ingRow[
                                    2] + '">' + ingRow[2] + '</a>'
                        else:
                            # component
                            tmpLink = getComponentLink(conn, tmpName,
                                                       ingRow[1])

                        s.ingredients.append(
                            ghObjectSchematic.schematicIngredient(
                                ingRow[0], ingRow[1], tmpName, ingRow[3],
                                ingRow[4], tmpLink))
                        ingRow = ingCursor.fetchone()

                    ingCursor.close()

                    # schematic quality data
                    expGroup = ''
                    expProp = ''
                    qg = None
                    qp = None
                    expCursor = conn.cursor()
                    expCursor.execute(
                        'SELECT tSchematicQualities.expQualityID, expProperty, expGroup, statName, statWeight, weightTotal FROM tSchematicQualities INNER JOIN tSchematicResWeights ON tSchematicQualities.expQualityID = tSchematicResWeights.expQualityID WHERE schematicID="'
                        + schematicID +
                        '" ORDER BY expGroup, expProperty, statName;')
                    expRow = expCursor.fetchone()
                    while (expRow != None):
                        if expRow[1] != expProp:
                            if qp != None:
                                qg.properties.append(qp)
                                qp = None
                            qp = ghObjectSchematic.schematicQualityProperty(
                                expRow[1], expRow[5])
                            expProp = expRow[1]

                        if expRow[2] != expGroup:
                            if qg != None:
                                s.qualityGroups.append(qg)
                                qg = None
                            qg = ghObjectSchematic.schematicQualityGroup(
                                expRow[2])
                            expGroup = expRow[2]

                        sw = ghObjectSchematic.schematicStatWeight(
                            expRow[0], expRow[3], expRow[4], expRow[5])
                        qp.statWeights.append(sw)
                        expRow = expCursor.fetchone()
                    if qp != None:
                        qg.properties.append(qp)
                    if qg != None:
                        s.qualityGroups.append(qg)
                    expCursor.close()

                    # Get list of schematics this one can be used in
                    useCursor = conn.cursor()
                    useCursor.execute(
                        'SELECT tSchematicIngredients.schematicID, s2.schematicName FROM tSchematicIngredients INNER JOIN tSchematic ON tSchematicIngredients.ingredientObject = tSchematic.objectPath OR tSchematicIngredients.ingredientObject = tSchematic.objectGroup INNER JOIN tSchematic s2 ON tSchematicIngredients.schematicID=s2.schematicID WHERE tSchematic.schematicID = "'
                        + schematicID +
                        '" GROUP BY tSchematicIngredients.schematicID;')
                    useRow = useCursor.fetchone()
                    while (useRow != None):
                        s.schematicsUsedIn.append([useRow[0], useRow[1]])
                        useRow = useCursor.fetchone()

                    useCursor.close()

                    if logged_state > 0:
                        favCursor = conn.cursor()
                        favSQL = ''.join((
                            'SELECT itemID FROM tFavorites WHERE favType=4 AND userID="',
                            currentUser, '" AND favGroup="', schematicID,
                            '" AND galaxy=', galaxy))
                        favCursor.execute(favSQL)
                        favRow = favCursor.fetchone()
                        if favRow != None:
                            favHTML = '  <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 4, \'' + schematicID + '\', $(\'#galaxySel\').val());"><img src="/images/favorite16On.png" /></a></div>'
                        else:
                            favHTML = '  <div class="inlineBlock" style="width:3%;float:left;"><a alt="Favorite" title="Favorite" style="cursor: pointer;" onclick="toggleFavorite(this, 4, \'' + schematicID + '\', $(\'#galaxySel\').val());"><img src="/images/favorite16Off.png" /></a></div>'
                        favCursor.close()

                cursor.close()

            conn.close()

    pictureName = dbShared.getUserAttr(currentUser, 'pictureName')
    print 'Content-type: text/html\n'
    env = Environment(loader=FileSystemLoader('templates'))
    env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL
    env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform(
        os.environ['HTTP_USER_AGENT'])
    template = env.get_template('schematics.html')
    print template.render(
        uiTheme=uiTheme,
        loggedin=logged_state,
        currentUser=currentUser,
        loginResult=loginResult,
        linkappend=linkappend,
        url=url,
        pictureName=pictureName,
        imgNum=ghShared.imgNum,
        galaxyList=ghLists.getGalaxyList(),
        professionList=ghLists.getProfessionList(),
        schematicTabList=ghLists.getSchematicTabList(),
        objectTypeList=ghLists.getObjectTypeList(),
        noenergyTypeList=ghLists.getOptionList(
            'SELECT resourceType, resourceTypeName FROM tResourceType WHERE resourceCategory != "energy" ORDER BY resourceTypeName;'
        ),
        resourceGroupList=ghLists.getResourceGroupList(),
        schematicID=schematicID,
        schematic=s,
        favHTML=favHTML)
Exemple #4
0
	sid = form.getfirst('gh_sid', '')

# escape input to prevent sql injection
sid = dbShared.dbInsertSafe(sid)

# Get a session
logged_state = 0
linkappend = ''
if loginResult == None:
	loginResult = 'success'

sess = dbSession.getSession(sid, 2592000)
if (sess != ''):
	logged_state = 1
	currentUser = sess
	if (uiTheme == ''):
		uiTheme = dbShared.getUserAttr(currentUser, 'themeName')
	if (useCookies == 0):
		linkappend = 'gh_sid=' + sid
else:
	if (uiTheme == ''):
		uiTheme = 'crafter'

pictureName = dbShared.getUserAttr(currentUser, 'pictureName')
print 'Content-type: text/html\n'
env = Environment(loader=FileSystemLoader('templates'))
env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL
env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform(os.environ['HTTP_USER_AGENT'])
template = env.get_template('inventory.html')
print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(), resourceGroupList=ghLists.getResourceGroupList(), resourceTypeList=ghLists.getResourceTypeList())
cursor = conn.cursor()
if (cursor):
	sqlStr = 'SELECT Sum(paymentGross) AS totalAmt FROM tPayments WHERE YEAR(completedDate)=YEAR(NOW()) AND MONTH(completedDate)=MONTH(NOW());'
	cursor.execute(sqlStr)
	row = cursor.fetchone()
	if row[0] != None:
		totalAmt = float(row[0])
cursor.close()

adminList = dbShared.getGalaxyAdminList(conn, currentUser).split('/option')[0]
if len(adminList) > 0:
	galaxyAdmin = int(adminList[15:adminList.rfind('"')])
else:
	galaxyAdmin = 0
conn.close()

percentOfGoal = totalAmt/20
totalAmt = str(int(totalAmt))
pictureName = dbShared.getUserAttr(currentUser, 'pictureName')
print 'Content-type: text/html\n'
env = Environment(loader=FileSystemLoader('templates'))
env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL

userAgent = 'unknown'
if 'HTTP_USER_AGENT' in os.environ:
	userAgent = os.environ['HTTP_USER_AGENT']
env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform(os.environ['HTTP_USER_AGENT'])

template = env.get_template('home.html')
print template.render(uiTheme=uiTheme, galaxy=galaxy, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, totalAmt=totalAmt, percentOfGoal=percentOfGoal, imgNum=ghShared.imgNum, resourceGroupListShort=ghLists.getResourceGroupListShort(), professionList=ghLists.getProfessionList(galaxy), planetList=ghLists.getPlanetList(galaxy), resourceGroupList=ghLists.getResourceGroupList(), resourceTypeList=ghLists.getResourceTypeList(galaxy), galaxyList=ghLists.getGalaxyList(), galaxyAdmin=galaxyAdmin)
	sid = form.getfirst('gh_sid', '')

# escape input to prevent sql injection
sid = dbShared.dbInsertSafe(sid)

# Get a session
logged_state = 0
linkappend = ''
if loginResult == None:
	loginResult = 'success'

sess = dbSession.getSession(sid, 2592000)
if (sess != ''):
	logged_state = 1
	currentUser = sess
	if (uiTheme == ''):
		uiTheme = dbShared.getUserAttr(currentUser, 'themeName')
	if (useCookies == 0):
		linkappend = 'gh_sid=' + sid
else:
	if (uiTheme == ''):
		uiTheme = 'crafter'

pictureName = dbShared.getUserAttr(currentUser, 'pictureName')
print 'Content-type: text/html\n'
env = Environment(loader=FileSystemLoader('templates'))
env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL
template = env.get_template('inventory.html')
print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, planetList=ghLists.getPlanetList(), galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(), resourceGroupList=ghLists.getResourceGroupList(), resourceTypeList=ghLists.getResourceTypeList())