Exemple #1
0
def parseArgs(args):
    '''
    Parse arguments using online database functions
    '''
    if args.user:
        # login user if username provided
        loginUser(args.user)
    else:
        # prompt login if no user given
        loginUser()

    if args.add:
        addServicePrompt(args.add)
    if args.edit:
        editServicePrompt(args.edit)
    if args.list:
        listServicesPrompt()
    if args.name:
        getNamePrompt(args.name)
    if args.password:
        getPassPrompt(args.password)
    if args.remove:
        removeServicePrompt(args.remove)
    if args.www:
        getUrlPrompt(args.www)
    quit()
Exemple #2
0
def handle_input():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            functions.quit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                functions.quit()
            elif event.key == pygame.K_UP:
                data.player.direction = direction.NORTH
            elif event.key == pygame.K_DOWN:
                data.player.direction = direction.SOUTH
            elif event.key == pygame.K_LEFT:
                data.player.direction = direction.WEST
            elif event.key == pygame.K_RIGHT:
                data.player.direction = direction.EAST

        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_UP and data.player.direction == direction.NORTH:
                data.player.direction = direction.NONE
            elif event.key == pygame.K_DOWN and data.player.direction == direction.SOUTH:
                data.player.direction = direction.NONE
            elif event.key == pygame.K_LEFT and data.player.direction == direction.WEST:
                data.player.direction = direction.NONE
            elif event.key == pygame.K_RIGHT and data.player.direction == direction.EAST:
                data.player.direction = direction.NONE
Exemple #3
0
def handleOfflineLogin(username=""):
    '''
    Logs in users to local database in lieu of internet connection
    '''
    print("NOTE: No connection")
    print("Continuing in offline mode. \nYou can retrieve any service data, " \
            +"but you will not be \nable to edit or upload data\n\n")

    username  = getOfflineUsername(username)
    file_path = os.path.expanduser("~/.passman/{}.json".format(username))
    dir_path  = os.path.expanduser("~/.passman")

    if not os.path.isdir(dir_path):
        print("Sorry, no local users found")
        quit()

    with open(file_path) as data_file:
        data = data_file.read()

    data = ast.literal_eval(data) # from string to dict

    key = getOfflinePassword(data)

    setOfflineUsername(username, key)
    return True
Exemple #4
0
def getServicesOffline():
    '''
    Get an array of services for a user
    '''

    global name

    dir_path = os.path.expanduser("~/.passman")
    file_path = os.path.expanduser("~/.passman/{}.json".format(name))

    if not os.path.isfile(file_path) or \
            not os.path.isdir(dir_path):
        print("No local file found - exiting")
        quit()

    with open(file_path) as data_file:
        data = data_file.read()
    data = ast.literal_eval(data)['data']

    for service in data:
        service['service'] = decrypt(service['service'], key)
        service['serviceUserName'] = decrypt(service['serviceUserName'], key)
        service['servicePassword'] = decrypt(service['servicePassword'], key)
        service['serviceUrl'] = decrypt(service['serviceUrl'], key)

    return data
Exemple #5
0
def changeMasterPrompt():
    '''
    Menu for changing the master password to the passman application
    '''
    oldPass = getUserInput("Enter your old password", True)
    isUser = checkUserCredentials(oldPass)  # check the name/pw
    inc = 0

    while (not isUser) and inc < 2:
        print("That didn't work")
        oldPass = getUserInput("Enter your old password", True)
        isUser = checkUserCredentials(oldPass)
        inc += 1
    if (inc >= 2):  # three strikes; you're out
        quit()

    newPass = getUserInput("Enter your new password", True)
    newPassCheck = getUserInput("Once more, with feeling", True)

    while newPass != newPassCheck:
        print("Sorry. Those didn't match.")
        newPass = getUserInput("Enter your new password", True)
        newPassCheck = getUserInput("Once more, with feeling", True)

    changePassword(newPass)
    return True
Exemple #6
0
def handle_input():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            functions.quit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                functions.quit()
            elif event.key == pygame.K_UP:
                data.player.direction = direction.NORTH
            elif event.key == pygame.K_DOWN:
                data.player.direction = direction.SOUTH
            elif event.key == pygame.K_LEFT:
                data.player.direction = direction.WEST
            elif event.key == pygame.K_RIGHT:
                data.player.direction = direction.EAST
                
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_UP and data.player.direction == direction.NORTH:
                data.player.direction = direction.NONE
            elif event.key == pygame.K_DOWN and data.player.direction == direction.SOUTH:
                data.player.direction = direction.NONE
            elif event.key == pygame.K_LEFT and data.player.direction == direction.WEST:
                data.player.direction = direction.NONE
            elif event.key == pygame.K_RIGHT and data.player.direction == direction.EAST:                 
                data.player.direction = direction.NONE
 def update():
     while True:
         if pressed('enter') or pressed('return'):
             play('startsound')
             return True
         
         if pressed('escape'):
             quit()
             
         time.sleep(0.05)
Exemple #8
0
def lake_room():

  data['Room'] = 2

  # clears page for new room
  clear()

  # room's title
  print(f.GREEN +'LAKE OF DREAMS'+ s.RESET_ALL)

  #checks if you have been here before
  if data['fe2'] == 0:
    print('\nyou re-enter the Lake of Dreams')
    if data['torch'] == 0:

      print('\nOn the wall there is an lit Torch with something behind it')
      
  if data['fe2'] == 1:
    
    data['fe2'] = 0

    t.sleep(1)

    #room outline
    print('\nYou walk into a dimly lit room. in the center is a glowing blue lake which does not appear to relfect the cave. On the wall there is an lit Torch with something behind it ')

  #room game loop
  while True:
    answer = input('\n>')

    #check for torch command
    if 'torch' in answer:
      
      #checks torch status
      if data['torch'] == 0:
        
        #changes torch status
        data['torch'] = 1
        print('You grab the torch, as it comes away from the wall something drops on the floor')

    #sends the player to the previous room
    elif 'go back' in answer:
        go_back()

    #saves the game
    elif 'save' in answer:
      with open('save.json', 'w') as save:
        json.dump(data, save)
        print('Saved!')

    #quits the game
    elif 'quit' in answer:
      quit()
Exemple #9
0
    def update(self):
        vector = [0, 0]
        if self.direction == direction.NONE:
            vector = [0, 0]
        elif self.direction == direction.EAST:
            vector = [self.SPEED, 0]
        elif self.direction == direction.WEST:
            vector = [-self.SPEED, 0]
        elif self.direction == direction.NORTH:
            vector = [0, -self.SPEED]
        elif self.direction == direction.SOUTH:
            vector = [0, self.SPEED]

        self.move(vector)
        if len(pygame.sprite.spritecollide(self, data.monsters, False)) > 0:
            functions.quit()
Exemple #10
0
    def update(self):
        vector = [0,0]
        if self.direction == direction.NONE:
            vector = [0,0]
        elif self.direction == direction.EAST:
            vector = [self.SPEED,0]
        elif self.direction == direction.WEST:
            vector = [-self.SPEED,0]
        elif self.direction == direction.NORTH:
            vector = [0,-self.SPEED]
        elif self.direction == direction.SOUTH:
            vector = [0,self.SPEED]

        self.move(vector)
        if len(pygame.sprite.spritecollide(self,data.monsters, False)) > 0:
            functions.quit()
Exemple #11
0
def signUpUser():
    '''
    Handles sign up for new users
    '''
    if not checkConnection("test"):
        print("Sorry - cannot create user without internet connection")
        quit()

    username = getUserInput("Please enter your username")
    pw       = getUserInput("Please enter your password", True)

    if addUser(username, pw):
        setDBUsername(pw, username)
        pullDatabase()
        return True
    else:
        print("Sorry, that username is already taken")
        signUpUser()
Exemple #12
0
def getOfflinePassword(data):
    '''
    Checks a password against that stored in the local database
    '''
    pw       = getUserInput("Please enter your password", True)
    key      = hashlib.sha256(pw.encode()).digest()
    hashedpw = hashlib.sha512(pw.encode('utf-8')).hexdigest()
    inc      = 0

    while hashedpw != data['password'] and inc < 2:
        print("Wrong password")
        pw       = getUserInput("Please enter your password", True)
        key      = hashlib.sha256(pw.encode()).digest()
        hashedpw = hashlib.sha512(pw.encode('utf-8')).hexdigest()
        inc     += 1
    if inc >= 2: # three strikes; you're out
        quit()

    return key
Exemple #13
0
def parseArgsOffline(args):
    '''
    Parse arguments using offline database functions
    '''
    if args.user:
        # login user if username provided
        handleOfflineLogin(args.user)
    else:
        # prompt login if no user given
        handleOfflineLogin()

    if args.list:
        listServicesOffline()
    if args.name:
        getUserNameOffline(args.name)
    if args.password:
        getPasswordOffline(args.password)
    if args.www:
        getURLOffline(args.www)
    quit()
Exemple #14
0
 def __init__(self):
  application.frame = self
  self.last_review = [0.0, None, None]
  super(MainFrame, self).__init__(None, title = application.name)
  self._review = 0 # The current position of the review cursor.
  self.commands = [] # Command history.
  self._command_pos = 0 # The current position in the command history.
  p = wx.Panel(self)
  self.CreateStatusBar()
  self.SetStatusText('Not connected.')
  s = wx.BoxSizer(wx.VERTICAL)
  self.output = MyTextCtrl(p, style = wx.TE_READONLY | wx.TE_MULTILINE)
  s.Add(self.output, 1, wx.GROW)
  s1 = wx.BoxSizer(wx.HORIZONTAL)
  self.prompt = wx.StaticText(p, label = '&Entry')
  s1.Add(self.prompt, 0, wx.GROW)
  self.entry = wx.TextCtrl(p, style = wx.TE_RICH2)
  self.entry.SetFocus()
  s1.Add(self.entry, 1, wx.GROW)
  s.Add(s1, 0, wx.GROW)
  p.SetSizerAndFit(s)
  keys.add_accelerator(self.entry, 'RETURN', self.do_send)
  keys.add_accelerator(self.entry, 'ESCAPE', lambda event: self.do_clear(save = True))
  keys.add_accelerator(self.entry, 'UP', lambda event: self.do_command_history(self._command_pos - 1)) # Commands are entered using append.
  keys.add_accelerator(self.entry, 'DOWN', lambda event: self.do_command_history(self._command_pos + 1))
  keys.add_accelerator(self.entry, 'CTRL+HOME', lambda event: self.do_command_history(-1))
  keys.add_accelerator(self.entry, 'CTRL+END', lambda event: self.do_command_history(0))
  keys.add_accelerator(self.entry, 'SHIFT+RETURN', lambda event: self.do_send(event, clear = False))
  keys.add_accelerator(self.entry, 'CTRL+RETURN', lambda event: functions.send(self.commands[0]) if self.commands else functions.bell())
  for x in xrange(10):
   keys.add_accelerator(self, 'ALT+%s' % x, lambda event, i = x: self.do_review(-10 if not i else (i * -1), move = False))
   keys.add_accelerator(self, 'ALT+%s' % x, lambda event, i = x: self.output.SpeakLineText(10 if not i else i))
  keys.add_accelerator(self, 'CTRL+SHIFT+Y', lambda event: self.do_review(0))
  keys.add_accelerator(self, 'CTRL+SHIFT+P', lambda event: self.do_review(-1))
  keys.add_accelerator(self, 'CTRL+SHIFT+U', lambda event: self.do_review(max(self._review - 1, 0)))
  keys.add_accelerator(self, 'CTRL+SHIFT+I', lambda event: self.do_review(self._review))
  keys.add_accelerator(self, 'CTRL+SHIFT+O', lambda event: self.do_review(self._review + 1))
  functions.output('Welcome to %s (V%s).\nType %scommands() for help with builtin functions.' % (application.name, application.version, application.config.get('application', 'command_char')))
  mb = wx.MenuBar()
  self.file_menu = wx.Menu()
  self.Bind(wx.EVT_MENU, self.do_load, self.file_menu.Append(wx.ID_ANY, '&Load Script...', 'Load a script.'))
  self.Bind(wx.EVT_MENU, lambda event: application.config.get_gui().Show(True), self.file_menu.Append(wx.ID_PREFERENCES, '&Preferences...', 'Change program configuration.'))
  self.Bind(wx.EVT_MENU, lambda event: functions.quit(), self.file_menu.Append(wx.ID_EXIT, '&Quit', 'Quit the program.'))
  mb.Append(self.file_menu, '&File')
  self.connect_menu = wx.Menu()
  self.Bind(wx.EVT_MENU, lambda event: do_connect(), self.connect_menu.Append(wx.ID_ANY, '&Connect...', 'Create a new connection.'))
  self.Bind(wx.EVT_MENU, lambda event: functions.disconnect(), self.connect_menu.Append(wx.ID_ANY, '&Disconnect', 'Disconnect from the MUD.'))
  mb.Append(self.connect_menu, '&Connect')
  self.SetMenuBar(mb)
  self.Bind(wx.EVT_CLOSE, self.on_close)
Exemple #15
0
def loginUser(username=""):
    '''
    Handles login for online database
    '''
    isCommandLine = username

    username = username if username else getUserInput("Please enter your username")

    if not checkConnection("test"):
        handleOfflineLogin(username)

    pw  = getUserInput("Please enter your password", True)
    inc = 0
    while not checkUserCredentials(pw, username) and inc < 2:
        print("Sorry, that doesn't match our records")
        pw   = getUserInput("Please enter your password", True)
        inc += 1

    if inc >= 2: # three strikes; you're out
        quit()

    setDBUsername(pw, username)
    pullDatabase()
    return True
Exemple #16
0
def start():

  clear()

  #tells the code we are in room 1
  data['Room'] = 1
  
  # Room title
  print(f.GREEN +'DARK ROOM'+ s.RESET_ALL)

  #prints this if you have been here before
  if data['fe1'] == 0:
    print("\nyou're back in the dark room")
  
  #checks if this is your first entry
  if data['fe1'] == 1:

    data['fe1'] = 0

    with open('save.json', 'w') as save:
      json.dump(data, save)

    t.sleep(1)
    #Room outline
    print('\n Suddenly you wake into a dark cave. its pitch black but you begin to feel your way around the room ')
    t.sleep(3)
    print(' \nyou find two doors one to the left one to the right')

  t.sleep(1)
  #suggested commands
  print('\n l for left r for right or look to explore some more')

  #Room 1 game loop
  while True:

    # recives and converts answer to lower case
    answer = input("\n>").lower()

    # sends the player left
    if 'l' == answer:
      clear()
      print('you go left')
      t.sleep(3)
      lake_room()
    
    # sends the player right
    elif 'r' == answer:
      clear()
      print('you go right')
      t.sleep(3)
      abandoned_forge()

    # the player explore the area
    elif 'look' == answer:
      # if they have a torch they find something
      if data['torch'] == 1:
        print('\n you look around and find what appears to be another door in the wall')
        data['door_found'] = 1

    #check for the open door command
    elif 'open door' ==  answer:
      #check if the playere has found the door and has the key
      if  data['has_key'] == 1 and data['door_found'] == 1:
        print('The door flies open and you are blinded by the light of the outside world')

        t.sleep(2)

        print("You've finished 0.0.2 of The Wills of Men. Thank you for playing!! ")

        with open('save.json', 'w') as save:
          json.dump(data, save)
        break

    #saves the game
    elif 'save' in answer:
      with open('save.json', 'w') as save:
        json.dump(data, save)
        print('Saved!')

    #sends player to quit function
    elif 'quit' in answer:
      quit()

# player death condition
  else:
    game_over('you died of boredom') # so did I
Exemple #17
0
def abandoned_forge():

  data['Room'] = 3

  # clears page for neew room
  clear()

  # rooms title
  print(f.GREEN +'ABANDONED FORGE'+ s.RESET_ALL)
  if data['fe3'] == 0:
    print('you feel calm as you enter the forge')

    if data['coal_bucket'] == 0:
      print('\nin the corner there is a barrel of coal')
  if data['fe3'] == 1:

    data['fe3'] = 0
    t.sleep(1)

    # room outline for player
    print('\nYou walk into a new room. It appears to be an old forge with old will forging equipment and an anvil. there is a thin been of light coming into the room from a man made hole in the ceiling. in the corner there is a barrel of coal')

  #Room 3 game loop
  while True:
    answer = input('\n>')

    #sends the player to the previous room
    if 'go back' == answer:
      go_back()

    #saves the game
    elif 'save' == answer:
      with open('save.json', 'w') as save:
        json.dump(data, save)
        print('Saved!')

    #checks if the player wants to get the coal bucket
    elif 'get coal bucket' == answer:
      if data['coal_bucket'] == 0:
        data['coal_bucket'] = 1
        print('you grab the bucket of coal')

    #checks the player wants to light the forge
    elif 'light' or 'light forge' or 'light fire' == answer:
      if data['torch'] == 1 and data['coal_bucket'] == 1:
        t.sleep(2)
        print ('\nAs you place the coal in the forge and light the fire you feel a great increase in your power ' + f.YELLOW +'Somewhere a door to the outside can be found'+ s.RESET_ALL, )

        t.sleep(1)

        print('\na key materialises on the anvil')

        t.sleep(1)

        print ('\n do you want to pick it up y/n')

        answer = input('\n>')

        #check the player want the key
        if 'y' in answer:
          data['has_key'] = 1
          print('you get the key from the anvil.')
          print('\n on it there is an inscription .' + f.RED +'"The way to light is found in the darkest places"' +s.RESET_ALL)

        #the player says no (why would you)
        elif 'n' in answer:
          print('ok')
        
    #quits the game
    elif 'quit' in answer:
      quit()
Exemple #18
0
             VERSION: 1.0

GITHUB: "https://github.com/RajGhosh289"
Type !help to print all available commands

    """)

while True:
    getI = input("PyCon ==> ")

    if getI.__contains__("!help"):
        print(
            "!help - Print all available commands\n!quit - To terminate the program\n!newfile - To create a new file\n!editfile - To edit predefined file\n!wc - To open weight converter app\n"
        )
    elif getI.__contains__("!newfile"):
        functions.creatNewFile(input("Enter a name for your file: "))
        print()
    elif getI.__contains__("!editfile"):
        functions.editFile(input("File name "), input("Edit: "))
        print()
    elif getI.__contains__("!wc"):
        weight_converter.calculator()
        print()
    elif getI.__contains__("!quit"):
        functions.quit()
    else:
        print(
            "[Command >> " + getI + " <<]" +
            " is not recognised by our <system> -- type !help to print all available commands\n"
        )