def asteroidTrackResponder(asteroidName, user, webSock, OOIs):
    # responds to asteroid track requests by sending html for a tile to be added to the content section
    message = '{"cmd":"addToContent","data":"'
    
    if user.purchase('asteroidTrack'):
        print 'request to track '+asteroidName+' accepted.'
        
        OOIs.addObject(byName(asteroidName), user.name)
        # write the new js file(s)
        OOIs.write2JSON(Settings('default').asteroidDB,Settings('default').ownersDB)
        print 'object '+asteroidName+' added to OOIs'
        message+= template('tpl/content/tiles/asteroidAdd',
            objectName=asteroidName,
            chunks=CHUNKS,
            config=Settings('default'),
            pageTitle='Asteroid Add Request Approved',
            user=user)
    else:
        print 'request to track '+asteroidName+' denied. insufficient funds.'
        message+= template('tpl/content/tiles/insufficientFunds',
            objectName=asteroidName,
            chunks=CHUNKS,
            config=Settings('default'),
            pageTitle='Asteroid Add Request Denied',
            user=user)
    
    message+='"}'
    webSock.send(message)
Пример #2
0
def systemView():
    return template('tpl/systemView',
                    user=User(),
                    chunks=CHUNKS,
                    config=Settings('test',showFrame=False,showResources=False,showBG=False,controlBG=True),
                    pageTitle="ViewTest"
        )
Пример #3
0
def makeResourceUpdater():
    # check for user login token in cookies
    _user = getLoggedInUser(request)
    if _user != None:
        return template('tpl/js/resourceUpdate', user=_user)
    else: 
        redirect('/userLogin')
Пример #4
0
 def advance(self):
     # advances to next research age...
     self.research.advance()
     if self.websocket != None:
         self.websocket.send(createMessage('updateResources',data=template('tpl/page_chunks/resourcebar',user=self)))
         return True
     else:
         print 'no websocket connected to user ',self.name
def researchResponder(user,ws,researchType):
    message = '{"cmd":"addToContent","data":"'
    
    if user.purchase('research_'+researchType):
        user.research.advance()
        message+= template('tpl/content/tiles/purchase_success',
            chunks=CHUNKS,
            config=Settings('default'),
            pageTitle='research complete',
            user=user)
    else:
        message+= template('tpl/content/tiles/insufficientFunds',
            chunks=CHUNKS,
            config=Settings('default'),
            pageTitle='research denied',
            user=user)
    message+='"}'
    ws.send(message)
Пример #6
0
def error404(error):
    _user = getLoggedInUser(request)
    if _user != None:
        return template('tpl/pages/404',
                        chunks=CHUNKS,
                        user=_user,
                        config=Settings(MASTER_CONFIG, showBG=False),
                        pageTitle="LOST IN SPACE")
    else:
        redirect('/userLogin')
Пример #7
0
def systemView():
    _user = getLoggedInUser(request)
    if _user != None:
        return template('tpl/systemView',
                        user=_user,
                        chunks=CHUNKS,
                        config=Settings('default',showFrame=False,showResources=False,showBG=False,controlBG=True),
                        pageTitle="system View"
                        )
    else: 
        redirect('/userLogin')
Пример #8
0
 def payFor(self,bal):
     # deducts item cost from resources,
     # returns true if purchase is sucessful 
     # assumes that user can afford item
         
     self.resources.applyBalance(bal)
     
     if self.websocket != None:
         self.websocket.send(createMessage('updateResources',data=template('tpl/page_chunks/resourcebar',user=self)))
         return True
     else:
         print 'no websocket connected to user ',self.name
Пример #9
0
def makeContentHTML():
    name=request.query.name # content page name
    subDir = request.query.section=request.query.section # specific section of page (like type of research page)

    # check for user login token in cookies
    if request.get_cookie("cosmosium_login"):
        userLoginToken = request.get_cookie("cosmosium_login")
        try:
            _user = USERS.getUserByToken(userLoginToken)
        except (KeyError, ReferenceError) as E: # user token not found or user has been garbage-collected
            redirect('/userLogin')

        treeimg=''
        if name == 'research': # then get research subDir info
            if subDir=='spaceIndustry':
                treeimg="img/space_industry_tech_tree_images.svg";
            elif subDir=='humanHabitation':
                treeimg="img/space_industry_tech_tree.svg";
            elif subDir=='roboticsAndAI':
                treeimg="img/space_industry_tech_tree_images.svg";
            else:
                return template('tpl/content/404') # error404('404')

        fileName='tpl/content/'+name
        if os.path.isfile(fileName+'.tpl'): #if file exists, use it
            return template(fileName,
                            tree_src=treeimg, #used only for research pages
                            chunks=CHUNKS,
                            user=_user,
                            oois=GAMES.games[0].OOIs,
                            config=Settings(MASTER_CONFIG),
                            pageTitle=name)
        else: # else show content under construction
            print 'unknown content request: '+fileName
            return template('tpl/content/under_construction')
    else:
        redirect('/userLogin')
Пример #10
0
def makeGamePage():
    # check for user login token in cookies
    if request.get_cookie("cosmosium_login"):
        userLoginToken = request.get_cookie("cosmosium_login")
        try:
            _user = USERS.getUserByToken(userLoginToken)
        except (KeyError, ReferenceError) as E: # user token not found or user has been garbage-collected
            return userLogin('user token not found')

        if _user.game == None:
            GAMES.joinGame(_user)

        return template('tpl/pages/play',
                        chunks=CHUNKS,
                        user=_user,
                        oois=GAMES.games[0].OOIs,
                        config=Settings(MASTER_CONFIG),
                        pageTitle="Cosmosium Asteriod Ventures!")
    else: return userLogin('user login cookie not found')
Пример #11
0
def searchKuipers():
    return template('tpl/searchView',asteroidDB="db/KuiperBelt.js")
Пример #12
0
def searchMains():
    return template('tpl/searchView',asteroidDB="db/MainBelt.js")
Пример #13
0
def searchNEOs():
    return template('tpl/searchView',asteroidDB="db/NEOs.js")
Пример #14
0
def searchTest():
    return template('tpl/searchView',asteroidDB="db/test_asteroids.js")
Пример #15
0
def makeSplash():
    return template('tpl/pages/splash', gameList=GAMES, demoIDs=demoIDs)
Пример #16
0
def processReq():
    q = request.query.query
    lim = request.query.limit
    print 'q=',q,' l=',lim
    return template('type: {{datatype}} (response {{res}})', datatype="asterank", res=asterankAPI(q,lim))
Пример #17
0
def userLogin(specialMessage=''):
    return template('tpl/pages/userLogin', demoIDs=demoIDs, message=specialMessage)
Пример #18
0
def makeSocketSetup():
    return template('tpl/js/webSocketSetup', client_id='0', DOMAIN=DOMAIN)