def rebroadcast(collection, testing_mode=False):
    """
    Rebroadcast the collection to the Main Channel
    :param collection: the collection object
    :return:
    """

    #Connect to bitmessage and create a temporary address
    bitmessage = Bitmessage()
    from_address = bitmessage.create_address("Rebroadcast", random=True)
    collection.address = from_address

    #Connect to controller and rebroadcast
    controller = Controller()
    print("Rebroadcasting collection: " + collection.title)

    if testing_mode:
        success = controller.publish_collection(collection, from_address,
                                                from_address)
    else:
        success = controller.publish_collection(collection,
                                                MAIN_CHANNEL_ADDRESS,
                                                from_address)

    if not success:
        return False

    return True
Exemple #2
0
def main():
    controller = Controller(Program, Movie, Serie, Premiere, View)
    while True:
        try:
            choice = controller.menu()
        except ValueError:
            print("Invalid choice!")
        else:
            if choice == 1:
                controller.register_movie()
            elif choice == 2:
                controller.register_serie()
            elif choice == 3:
                controller.show_movies()
            elif choice == 4:
                controller.show_series()
            elif choice == 5:
                controller.show_premieres()
            elif choice == 6:
                controller.show_spinoffs()
            elif choice == 7:
                controller.like_item()
            elif choice == 8:
                controller.set_premiere()
            elif choice == 9:
                controller.add_spinoff()
            elif choice == 0:
                exit(0)
            else:
                print("Invalid choice!")
Exemple #3
0
def main():
    """main.
    """

    ctrlr = Controller(None, None, CYSMenu("chess yo self"), None)
    ctrlr.start()
    return 0
Exemple #4
0
    def Zone(self, controller, request, callback):
        # service
        entity_service = EntityService_Stub(channels.entity_channel)
        event_service = EventService_Stub(channels.event_channel)

        # model
        entity = Entity()
        entity.id = request.entity_id
        entity = entity_service.GetEntity(controller, entity)
        world = self.worlds.get(entity.world_id, None)

        # event
        event_controller = Controller()
        entity_group_changed_event = EntityGroupChangedEvent()

        # pre
        entity_group_changed_event.entity_id = entity.id
        entity_group_changed_event.pre_group_id = entity.group_id

        #
        has_changed_groups = self.handle_entity_group_membership(world, entity)
        entity_service.UpdateEntity(controller, entity)
        if has_changed_groups:
            # post
            entity_group_changed_event.group_id = entity.group_id

            # broadcast event
            event_service.EntityGroupChanged(event_controller, entity_group_changed_event)

        response = ZoneResponse()
        return response
Exemple #5
0
    def Teleport(self, controller, request, callback):
        # service
        entity_service = EntityService_Stub(channels.entity_channel)
        event_service = EventService_Stub(channels.event_channel)

        # model
        entity = Entity()
        entity.id = request.entity_id
        entity = entity_service.GetEntity(controller, entity)
        world = self.worlds[entity.world_id]

        # event
        event_controller = Controller()
        entity_group_changed_event = EntityGroupChangedEvent()

        # pre
        entity_group_changed_event.entity_id = entity.id
        entity_group_changed_event.pre_group_id = entity.group_id

        #
        entity.x = request.x
        entity.y = request.y
        self.handle_entity_group_membership(world, entity)
        entity_service.UpdateEntity(controller, entity)

        # post
        entity_group_changed_event.group_id = entity.group_id

        # broadcast event
        event_service.EntityGroupChanged(event_controller, entity_group_changed_event)

        response = TeleportResponse()
        return response
Exemple #6
0
    def Move(self, controller, request, callback):
        # service
        entity_service = EntityService_Stub(channels.entity_channel)
        event_service = EventService_Stub(channels.event_channel)

        # model
        entity = Entity()
        entity.id = request.entity_id
        entity = entity_service.GetEntity(controller, entity)

        # event
        entity_move_event = EntityMoveEvent()

        # pre
        event_controller = Controller()
        entity_move_event.entity_id = entity.id
        entity_move_event.pre_x = entity.x
        entity_move_event.pre_y = entity.y

        #
        entity.x = request.x
        entity.y = request.y
        entity_service.UpdateEntity(controller, entity)

        # post
        entity_move_event.x = entity.x
        entity_move_event.y = entity.y

        # broadcast event
        event_service.EntityMove(event_controller, entity_move_event)

        response = MoveResponse()
        return response
Exemple #7
0
def get_collections():
    """Get collections from the main channel"""

    collection_handler = Controller()
    wait_for_interrupt(exit_func,
                       do_import(collection_handler),
                       args=[collection_handler])
def main():
    parser = ArgumentParser(
        description=
        'Jezyki obietkowe - zadanie 2. Celem zadania bylo stworzenie '
        'symulacji automatu komorkowego "Game of Life". W kontrolerze '
        'zdefiniowano parametry NUM_ROWS, NUM_COLS, SIZE_OF_CELL '
        'oznaczajace kolejno liczbe wierszy, liczbe kolumn oraz wielkosc komorki '
        'uzywanej w grze. Zaleca sie modyfikowac te wartosci aby uzyskac '
        'mniejsza/wieksza plansze z uwzglednieniem warunku, '
        'ze okno gry ma wielkosc 500x500 px. Domyslnie ustawiono 50|50|10.')
    parser.add_argument(
        '--entry_point',
        dest='entry_point',
        type=str,
        choices=['glider', 'random'],
        default='random',
        help=
        'Ustaw glider jesli chcesz sprawdzic dzialanie typowego glidera z gry w zycie.'
        ' Domyslnie random.')

    args = parser.parse_args()
    entry_point = args.entry_point  # glider | random

    cnt = Controller()
    cnt.app(entry_point)
    def __init__(self):

        #deklarasi variable
        self.mapel = Mapel()
        self.sekolah = Sekolah()
        self.menu = Menu()
        self.view = View(self)
        self.controller = Controller(self)
Exemple #10
0
 def setUp(self):
     '''Create the model, controller & GUI'''
     self.current_version = '4.4.1'
     self.model = Model()
     self.controller = Controller(self.model)
     self.controller.scanner_thread.close(
     )  # getting PermissionError when left open while testing - Mock it instead
     self.view = View(self.model, self.controller)
Exemple #11
0
    def PlayerJoin(self, controller, request, callback):
        # service list
        entity_service = EntityService_Stub(channels.entity_channel)
        event_service = EventService_Stub(channels.event_channel)

        # model
        player = Player()
        player.id = request.player_id
        player = entity_service.GetPlayer(controller, player)
        player.kind = 1 # Wariior
        checkpoint = self.world_map.checkpoints.get(player.last_check_point, None)
        world = self.get_random_world()
        entity_service.UpdateEntity(controller, player)

        # event list
        event_controller = Controller()
        entity_join_world_event = EntityJoinWorldEvent()
        population_update_event = PopulationUpdateEvent()
        entity_group_changed_event = EntityGroupChangedEvent()

        # pre
        entity_join_world_event.entity_id = player.id
        entity_group_changed_event.entity_id = player.id
        entity_group_changed_event.pre_group_id = player.group_id
        population_update_event.world_id = world.id
        population_update_event.pre_population = len(world.player_ids)

        #
        if not checkpoint:
            random_start = randint(0, len(self.world_map.starting_areas) - 1)
            checkpoint_id = self.world_map.starting_areas[random_start]
            checkpoint = self.world_map.checkpoints[checkpoint_id]
        player.world_id = world.id
        player.x = checkpoint.x
        player.y = checkpoint.y
        player.hitpoints = 100
        world.player_ids.append(player.id)

        self.handle_entity_group_membership(world, player)
        entity_service.UpdateEntity(controller, player)

        # post
        entity_join_world_event.world_id = player.world_id
        entity_group_changed_event.group_id = player.group_id
        population_update_event.population = len(world.player_ids)

        # broadcast event
        event_service.EntityJoinWorld(event_controller, entity_join_world_event)
        event_service.PopulationUpdate(event_controller, population_update_event)
        event_service.EntityGroupChanged(event_controller, entity_group_changed_event)

        response = PlayerJoinResponse()
        response.player_id = player.id
        response.x = player.x
        response.y = player.y
        response.hitpoints = player.hitpoints
        return response
Exemple #12
0
    def __init__(self, sys_argv):
        super(App, self).__init__(sys_argv)
        self.model = Model()
        self.controller = Controller(self.model)
        self.view = View(self.model, self.controller)

        self.view.show()
        # self.view.showFullScreen()
        self.view.setWindowTitle("App")
class Menu:
    controller = Controller()

    def start(self):
        name = input('Hello!\nMovie name:\n>>> ')
        rating = input('\nMovie rating:\n>>> ')

        self.controller.create_movie(name, rating)
        self.controller.show_movies()
Exemple #14
0
def start():
    controller = Controller()
    controller.view.print_instructions()
    choice = ''
    while choice != "Q":
        try:
            choice = input().upper()
        except KeyboardInterrupt:
            sys.exit()
        controller.handle_input(choice, list(item_table.items)[0].id)
    def connect_button_handler(
            self, event):  # wxGlade: ControllerConnectDialog.<event_handler>
        controller = wx.App.Get()

        c = Controller(self.ports[self.port_listbox.GetSelection()].device,
                       controller, self.c_num)
        c.start()

        print(controller.controller_list)
        self.Close(event)
Exemple #16
0
def publish_collection(address_password, collection_address):
    bitmessage_connection = Bitmessage()
    address = bitmessage_connection.create_address(address_password)
    collection = cache.get_collection_with_address(collection_address)
    if collection is not None:
        collection_handler = Controller()
        collection_handler.publish_collection(collection, config.MAIN_CHANNEL_ADDRESS, address)
        print ("Collection published successfully!")
    else:
        print ("Collection not found in local cache.")
Exemple #17
0
    def hit_points_update(self):
        browserquest_stub = BrowserQuest_Stub(channels.browserquest_channel)
        entity_service = BrowserQuest_Stub(channels.entity_channel)

        request = GetPlayerIDListRequest()
        controller = Controller()
        id_list = entity_service.GetPlayerIDList(controller, request)
        for id in id_list.ids:
            player = Player()
            player.id = id
            player = entity_service.GetPlayer(controller, player)
            if player.hit_points >= 100:
                continue
            player.hit_points += 5
            if player.hit_points >= 100:
                player.hit_points = 100
            health_request = HealthRequest()
            health_request.hit_points = player.hit_points
            controller = Controller()
            controller.player_ids = [player.id]
            browserquest_stub.hitpoints(controller, health_request)
 def setUp(self):
     self.controller = Controller()
     self.cache = self.controller.cache
     self.address = 'ffafaf'
     coll_address = str(uuid.uuid1())
     doc_hash_1 = str(uuid.uuid1())
     doc_hash_2 = str(uuid.uuid1())
     doc_hash_3 = str(uuid.uuid1())
     self.test_collection_evil = Collection(
         title="Test multiple33333",
         description="This is a collection! with multiple docs222",
         address=self.address,
         btc="123456789",
         keywords=[
             Keyword(name="Keyword A", id=1199),
             Keyword(name="Keyword c", id=1214),
         ],
         documents=[
             Document(
                 description="Test document Z",
                 hash="zzzzzzzz",
                 title="Test Z",
                 accesses=0,
                 filename="joe.txt",
                 collection_address="BM-2cSrapXpgDTFD8AyDmU1BGifNkB2Z6X9k8"
             ),
             Document(
                 description="Test document B",
                 hash='gdssgsdg',
                 title="Test B",
                 accesses=3,
                 filename="gile.txt",
                 collection_address="BM-2cSrapXpgDTFD8AyDmU1BGifNkB2Z6X9k8"
             ),
             Document(
                 description="Test document Bddd",
                 hash='afff',
                 title="Test B",
                 accesses=3,
                 filename="gile.txt",
                 collection_address="BM-2cSrapXpgDTFD8AyDmU1BGifNkB2Z6X9k8"
             ),
         ],
         creation_date=datetime.datetime.now(),
         oldest_date=datetime.datetime.now(),
         latest_broadcast_date=datetime.datetime.now(),
         latest_btc_tx="btctx1",
         oldest_btc_tx="btctx12",
         accesses=2,
         votes=3,
         votes_last_checked=datetime.datetime.now())
 def start_game(self, deck=None):
     if len(self.players_info) >= 2:
         for user_id, user_info in enumerate(self.players_info):
             nickname = user_info[0].get()
             if user_info[1].get():
                 controller = AIController(user_id)
                 nickname += ' (AI)'
             else:
                 controller = Controller(user_id)
             self.game.add_player(nickname, controller)
         if client_id is not None:
             self.start_pooling()
         self.game.tkraise()
         self.game.start_game(deck)
Exemple #20
0
 def __init__(self):
     #self.name = name
     self.controller = Controller()
     self.__user_is_active = False
     self.user = False
     self.commands = {
         "show_movies": self.show_movies,
         "show_projections": self.show_projections,
         "make_reservations": self.make_reservations,
         "give_up": self.give_up,
         "register": self.register,
         "login": self.login,
         "finalize": self.finalize,
         "help": self.help,
         "exit": self.exit
     }
    def setUp(self):
        self.controller = Controller()
        self.address = self.controller.connection.create_address('Controller Test address', True)

        coll_address = str(uuid.uuid1())
        doc_hash_1 = str(uuid.uuid1())
        doc_hash_2 = str(uuid.uuid1())
        doc_hash_3 = str(uuid.uuid1())

        self.test_collection = Collection(
            title="Test",
            description="This is a collection!",
            address=self.address,
            btc="123456789",
            keywords=[
                Keyword(name="Keyword A"),
                Keyword(name="Keyword B"),
            ],
            documents=[
                Document(
                    description="Test document A",
                    hash=doc_hash_1,
                    title="Test A",
                    accesses=0,
                    filename="joe.txt",
                    collection_address="afgagahhsgh"
                    ),
                Document(
                    description="Test document B",
                    hash=doc_hash_2,
                    title="Test B",
                    accesses=3,
                    filename="gile.txt",
                    collection_address="afgagasghhhss"
                    ),
            ],
            creation_date=datetime.datetime.now(),
            oldest_date=datetime.datetime.now(),
            latest_broadcast_date=datetime.datetime.now(),
            latest_btc_tx="btctx1",
            oldest_btc_tx="btctx12",
            accesses=2,
            votes=3,
            votes_last_checked=datetime.datetime.now()
        )
        self.test_signature = Signature(pubkey='itsakey',address=self.address)
class Menu:
    controller = Controller()
    def start(self):
        user_name = input('Hello!\nProvide your user_name:\n>>> ')
        # user = get_user_by_user_name(user_name)
        user = None
        if user:
            pass
        else:
            print('Unknown user!\n Would you like to create new user?')
            create_new = input('>>> ')
            if create_new.lower() in ['y', 'yes']:
                user_type = input('Are you a Client or Mechanic?\n>>> ')
                if len(user_type) == 0:
                    print('Invalid user type!')
                    sys.exit()
                new_user_name = input('Provide user_name:\n>>> ')
                if len(new_user_name) == 0:
                    print('Invalid user name!')
                    sys.exit()
                new_phone_number = input("Provide phone_number:\n>>>")
                if len(new_phone_number) == 0:
                    print('Invalid phone number!')
                    sys.exit()
                new_email = input("Provide email:\n>>>")
                if len(new_email) == 0:
                    print('Invalid email!')
                    sys.exit()
                new_address = input("Provide address:\n>>>")
                if len(new_address) == 0:
                    print('Invalid address!')
                    sys.exit()

                def on_click():


                    self.controller.create_user(
                        new_user_name,
                        new_phone_number,
                        new_email,
                        new_address,
                        user_type
                    )
            else:
                sys.exit()
Exemple #23
0
    def __init__(self):
        super(Interface, self).__init__()

        self.setWindowTitle("Parser Juniper")
        self.ui = uic.loadUi("views/principal.ui")
        self.setCentralWidget(self.ui)

        inputText = self.ui.findChildren(QTextEdit, "inputText")[0]
        outputText = self.ui.findChildren(QTextBrowser, "outputText")[0]
        parseButton = self.ui.findChildren(QPushButton, "parse")[0]
        quitButton = self.ui.findChildren(QPushButton, "quit")[0]

        self.controller = Controller(inputText, outputText)

        parseButton.clicked.connect(self.controller.click)
        quitButton.clicked.connect(quit)

        self.show()
Exemple #24
0
    def Damage(self, controller, request, callback):
        entity_service = EntityService_Stub(channels.entity_channel)
        event_service = EventService_Stub(channels.event_channel)

        attack = Entity()
        attack.id = request.attack_id
        target = Entity()
        target.id = request.target_id
        attack = entity_service.GetEntity(controller, attack)
        target = entity_service.GetEntity(controller, target)

        event_controller = Controller()
        damage_event = DamageEvent()
        kill_event = KillEvent()
        damage_event.attack_id = attack.id
        damage_event.attack_weapon = attack.weapon
        damage_event.target_armor = target.armor
        damage_event.pre_target_hitpoints = target.hitpoints
        kill_event.killer_id = attack.id
        kill_event.killed_id = target.id

        damage = randint(0, 3)
        dealt = attack.weapon * randint(5, 10)
        absorbed = target.armor * randint(1, 3)
        if dealt - absorbed > 0:
            damage = dealt - absorbed

        target.hitpoints -= damage
        if target.hitpoints <= 0:
            target.is_dead = True
        entity_service.UpdateEntity(controller, target)

        damage_event.target_hitpoints = target.hitpoints

        event_service.Damage(event_controller, damage_event)
        if target.hitpoints <= 0:
            event_service.Kill(event_controller, kill_event)

        response = DamageResponse()
        response.attack_id = request.attack_id
        response.target_id = request.target_id
        response.damage = damage
        return response
Exemple #25
0
 def spawn_mobs(self, world, mob_area):
     entity_service = EntityService_Stub(channels.entity_channel)
     controller = Controller()
     mob_property = self.mob_properties[mob_area.type]
     for i in xrange(mob_area.nb):
         position = self.get_random_position_inside_area(mob_area)
         mob = Mob()
         mob.x = position['x']
         mob.y = position['y']
         mob.kind = self.get_entity_number_by_name(mob_area.type)
         mob.area_id = mob_area.id
         mob.world_id = mob_area.world_id
         mob.hitpoints = mob_property['hp']
         mob.weapon = mob_property['weapon']
         mob.armor = mob_property['armor']
         mob_area.entity_ids.append(mob.id)
         mob = entity_service.CreateMob(controller, mob)
         world.entity_ids.append(mob.id)
         self.handle_entity_group_membership(world, mob)
Exemple #26
0
    def on_message(self, message):
        if message is None:
            return
        print "data:", message
        request_data = json.loads(message)
        method_descriptor = self.browserquest.DESCRIPTOR.methods[request_data[0]]
        request_class = self.browserquest.GetRequestClass(method_descriptor)
        request = request_class()
        for index in xrange(1, len(request_data)):
            field_descriptor = request_class.DESCRIPTOR.fields_by_number[index]
            if field_descriptor.label == 3: # repeated TODO: only WHO enter this
                field = getattr(request, field_descriptor.name)
                field.extend(request_data[index:])
                break
            else:
                setattr(request, field_descriptor.name, request_data[index])

        controller = Controller()
        controller.connection = self.connection
        controller.environ = self.environ
        self.browserquest.CallMethod(method_descriptor, controller, request, None)
Exemple #27
0
    def Attack(self, controller, request, callback):
        entity_service = EntityService_Stub(channels.entity_channel)
        event_service = EventService_Stub(channels.event_channel)

        attack = Entity()
        attack.id = request.attack_id
        target = Entity()
        target.id = request.target_id
        attack = entity_service.GetEntity(controller, attack)
        target = entity_service.GetEntity(controller, target)

        event_controller = Controller()
        attack_event = AttackEvent()
        attack_event.attack_id = request.attack_id
        attack_event.target_id = request.target_id
        event_service.Attack(event_controller, attack_event)

        response = AttackResponse()
        response.attack_id = request.attack_id
        response.target_id = request.target_id
        return response
Exemple #28
0
    def hello(self, controller, request, callback):
        world_service = WorldService_Stub(channels.world_channel)
        event_service = EventService_Stub(channels.event_channel)
        browserquest_stub = BrowserQuest_Stub(channels.browserquest_channel)
        entity_service = EntityService_Stub(channels.entity_channel)

        _player = Player()
        _player.name = request.name
        player = entity_service.GetPlayer(controller, _player)
        if not player:
            player = entity_service.CreatePlayer(controller, _player)
            player.armor = 1
            player.weapon = 1
            entity_service.UpdateEntity(controller, player)

        # regist connection
        connections = channels.browserquest_channel.connections
        connections[player.id] = controller.connection
        controller.environ['player_id'] = player.id

        event_controller = Controller()
        player_logined_event = PlayerLoginedEvent()
        player_logined_event.player_id = player.id
        event_service.PlayerLogined(event_controller, player_logined_event)

        player_join_request = world_service_pb2.PlayerJoinRequest()
        player_join_request.player_id = player.id
        player_join_response = world_service.PlayerJoin(
            controller, player_join_request)

        welcome = WelcomeRequest()
        welcome.player_id = player.id
        welcome.name = request.name
        welcome.x = player_join_response.x
        welcome.y = player_join_response.y
        welcome.hitpoints = player_join_response.hitpoints
        controller.player_ids = [player_join_response.player_id]
        browserquest_stub.welcome(controller, welcome)
Exemple #29
0
    def test_db(self):
        # CREATE
        c = Controller(TournamentCarrier(), PlayerCarrier(), CYSMenu("Test"))

        # insert one tournament details version
        c.insert_tournament("Le petit jeu", "9 rue de la 1ere D.F.L",
                            "24/12/2021", my_rounds, my_players,
                            TimeControl.RAPID,
                            "C'est le plus petit tournoi d'echecs du monde !")
        # insert one tournament Obj version
        c.insert_tournament_obj(my_tournament)
        # insert multiple tournaments
        c.insert_tournament_objs(my_tournaments)

        # insert one player details version
        c.insert_player("test", "bob", "23/12/1992", Gender.MALE, 500)
        # insert one player Obj version
        c.insert_player_obj(my_player)
        # insert multiple players
        c.insert_player_objs(my_players)

        # READ
        c.log_all_items()
Exemple #30
0
 def mob_active(self):
     for mob_id in Entity.objects.mobs:
         if randint(0, 1):
             continue
         mob = Entity.objects.entities.get(mob_id, None)
         if not mob or mob.is_dead:
             continue
         mob_area = World.objects.mob_areas.get(mob.area_id, None)
         if not mob_area:
             continue
         world = World.objects.worlds.get(mob_area.world_id, None)
         if not world:
             continue
         position = World.objects.get_random_position_inside_area(mob_area)
         mob.x = position['x']
         mob.y = position['y']
         move_request = MoveRequest()
         move_request.entity_id = mob.id
         move_request.entity_x = mob.x
         move_request.entity_y = mob.y
         controller = Controller()
         controller.player_ids = World.objects.get_adjacent_player_ids(
             world, mob)
         Service.objects.browserquest_stub.move(controller, move_request)