def publish(ctx: Context, message: str, topic: str, subtopic: str):
    client = ctx.obj[CLIENT]
    deviceId = ctx.obj[DEVICE_ID]

    if topic == EVENTS_TOPIC and subtopic:
        topic = '{}/{}'.format(topic, subtopic)

    publishPayload(client, deviceId, topic, message)

    time.sleep(2)

    disconnect(client)
示例#2
0
def endGamePlayerLost():
    global buttons
    for i in range(10):
        for j in range(10):
            buttons[i][j].grid_forget()
            buttons[i][j].destroy()
    frame = Frame(root)
    frame.grid(row=0, column=0)
    label = Label(frame,
                  text="You Lost!!!",
                  font=("Helvetica", 20, "bold"),
                  width=30,
                  height=10)
    label.grid(row=0, column=0)
    root.update()
    time.sleep(7)
    client.disconnect()
    sys.exit()
示例#3
0
def endTurn():
    statusLabel.config(text="Opponent's Turn")
    global isPlayerTurn
    global isExitGame
    isPlayerTurn = False
    jsonOppMove = client.recvCommand()

    #keep checking server for input (nonblocking socket)
    while jsonOppMove == "":
        #exit game was triggered by this client
        if isExitGame:
            client.disconnect()
            sys.exit()
        #exit game was triggered by other client
        if not client.isOpponentConnected():
            messagebox.showerror("Player Left",
                                 "The Player Left the Game. You Win.")
            client.disconnect()
            sys.exit()
        root.update()
        jsonOppMove = client.recvCommand()

    #convert opponent action received to object
    oppMove = Action(jsonOppMove)
    #translate tiles from player side to opponent side
    fromRow = translateRow(oppMove.fromRow)
    fromCol = translateColumn(oppMove.fromCol)
    toRow = translateRow(oppMove.toRow)
    toCol = translateColumn(oppMove.toCol)

    #check if player action type
    if (oppMove.action == "move"):
        moveOpponent(fromRow, fromCol, toRow, toCol)
    elif (oppMove.action == "attack"):
        opponentAttack(fromRow, fromCol, toRow, toCol)
    roomSelect.isFirst = True
    isPlayerTurn = True
    statusLabel.config(text="Your Turn")
    helpLabel.config(text="")
示例#4
0
        client.connect(server_ip, client_ip, tcp_port, udp_port)
        connected = True
    elif option == 2:
        user = str(input('Ingrese su usuario: '))
        if "invalid" in client.authenticate(user):
            user = None  
    elif option == 3:
        msg = client.req_msg()
        msg_decoded = base64.b64decode(msg)
        user_msg = msg_decoded.decode('utf-8')
        print('El mensaje recibido es:', user_msg)
    elif option == 4:
        client.req_msg_length()
    elif option == 5:
        if msg_decoded:
            client.validate_msg(msg_decoded)
        else:
            print('Primero debe solicitar el mensaje al servidor')
    elif option == 6:
        client.logout()
        client.disconnect()
        connected = False
        user = None
        msg_decoded = None

    print('')
    menu()
    print('')
    option = int(input('Marque la opción que desee: '))

print('¡Hasta luego!')
示例#5
0
def disconnect(button):
    client.disconnect()
    return False
示例#6
0
    time.sleep(t)
    # stop before sending data
    ser.write(bytearray(stop))
    # call function to send distance and angle data (by Chico)
    sendDistance(server, "{0:6.1f".format(dist[i]))
    print(dist[i])
    # drive straight after rotating for 90 degree
    cmd = [137] + velocity + ADJUSTED_STRAIGHT
    ser.write(bytearray(cmd))
    # initialise starting time
    stTime = time.time()
    # icriment lists index
    i += 1
    j += 1
    if (ti[j] <= TIME_ROBOT_WIDTH):
        done = True

ser.write(bytearray(stop))

print("before finish")
# call function to send "finish" signal to indicate mapping is done (by Chico)
sendDistance(server, "finish")

print("after finish")

# Disconnect from port so another program (e.g., RealTerm)
# can connect.
ser.close()
# disconnect from server
client.disconnect(server)
def disconnect(button):
    client.disconnect()
    return False
 def readInput(value):
     if (value == EXIT_VALUE):
         disconnect(client)
         non_blocking_input.stop()
示例#9
0
def main():
    """ This is the main function of the module, from here all the other modules and functions are called.
        First the client module is called and the tool will attempt to establish a connection with the
        target MongoDB instance. When connected the user is given the option to attempt data recovery or
        terminate the connection(if further functionality is added to the tool, other options can be added
        to this area). If the user attempts data recovery, the user input modules are called. The user input
        details is then passed to the getIDs module, which returns ObjectIds. These ObjectIds are passed to
        the getDocs module which writes its findings to the log file.
        If the user chooses to terminate the connection, the client module is called again.
        """

    # get connection details from user
    print("-----------------------------------------------------------")
    server_address, server_port = input(
        "\nEnter MongoDB Client Address and Port: ").split(':')

    connection = client.connect(server_address, server_port)

    serverVersion = client.check_version(connection)

    print("\n-----------------------------------------------------------")

    while (1):

        # connection established
        print("\nCONNECTED TO: " + server_address + ":" + server_port)

        # connect to the oplog.rs collection within the local database
        db = connection.local.oplog.rs

        # option selection
        selection = input(
            "\n1 - Attempt data recovery \n2 - Close connection \n\nSelect: ")

        # option 1, attempt data recovery
        if selection == '1':

            while (1):

                print(
                    "\n-----------------------------------------------------------"
                )

                output, oplog_operation, oplog_database, oplog_collection = search_criteria(
                )

                if oplog_operation == "i":
                    op = ("INSERTED")
                if oplog_operation == "u":
                    op = ("UPDATED")
                if oplog_operation == "d":
                    op = ("DELETED")

                datetime_start = datetime_range("Start")
                datetime_end = datetime_range("End")

                file_name, log_file = create_log()

                log_file.write("Conncted to Server: " + server_address + ":" +
                               server_port + "\nMongoDB Version: " +
                               str(serverVersion) + "\n\nSearching for " + op +
                               " documents in, \nDatabase: " + oplog_database +
                               "\nCollection: " + oplog_collection +
                               "\n\nBetween Times,\nStart: " +
                               str(datetime_start) + "\nEnd: " +
                               str(datetime_end) +
                               "\n\n-----------------------\n")

                print("\nRetreiving IDs...")

                object_id, cursor_count = getIDs.id(
                    log_file, db, datetime_start, datetime_end,
                    oplog_operation, oplog_database, oplog_collection)

                print(("\nIdentified " + str(cursor_count) + " " + op +
                       " document(s)"))

                if object_id:
                    contains = True
                else:
                    print("\nNo matching entries recovered")
                    print(
                        "\n-----------------------------------------------------------"
                    )
                    break

                recovery_message = ("\nAttempting to recover " + op +
                                    " entries...")

                start = time.time()

                # initiate get_inserted to retreive inserted entries
                if oplog_operation == 'i':
                    print(recovery_message)
                    getDocs.insert(log_file, db, object_id)

                # initiate get_updated to retreive updated entries
                if oplog_operation == 'u':
                    print(recovery_message)
                    getDocs.update(log_file, db, object_id)

                # initiate get_deleted to retreive deleted entries
                if oplog_operation == 'd' and contains is True:
                    print(recovery_message)
                    getDocs.delete(log_file, db, object_id)

                log_file.close()

                end = time.time()

                print("\n-----------------------\n")

                if output in ('y', 'yes'):
                    read_log(file_name)

                print("Results in Log: " + file_name)

                print("\nTotal Recovery Time: " + str(end - start))

                # Give user the option to return to main menu?
                print(
                    "\n-----------------------------------------------------------"
                )
                flag = input('\nContinue with data recovery? ')
                if (flag[0].upper() == 'N'):
                    print(
                        "\n-----------------------------------------------------------"
                    )
                    break

        # terminate the connection
        if selection == '2':
            client.disconnect(connection)
示例#10
0
def cleanUp():

    GPIO.cleanup()  # cleanup all GPIO
    client.disconnect()

    print("cleaned up")
示例#11
0
def exitGame():
    global isExitGame
    isExitGame = True
    client.disconnect()
    sys.exit()
示例#12
0
def disconnect(button):
    client.disconnect()
    button.gump.close()
    return True
示例#13
0
def quitGame():
    client.disconnect()