示例#1
0
def app(net_addr, net_port):
    engine = Engine(mtu=1492)
    orb = engine.init_orb(i_nearcast=I_NEARCAST)
    orb.init_cog(CogUdpListener)
    #
    bridge = orb.init_autobridge()
    bridge.nc_init(net_addr=net_addr, net_port=net_port)
    #
    engine.event_loop()
示例#2
0
def app():
    engine = Engine(mtu=MTU)
    orb = engine.init_orb(i_nearcast=I_NEARCAST)
    orb.init_cog(CogCounter)
    orb.init_cog(CogWatcher)
    #
    bridge = orb.init_autobridge()
    bridge.nc_init()
    #
    engine.event_loop()
示例#3
0
文件: weeds.py 项目: mchi/solent
def game(console_type):
    engine = None
    try:
        engine = Engine(
            mtu=MTU)
        engine.set_default_timeout(0.04)
        #engine.debug_eloop_on()
        #
        orb = engine.init_orb(
            i_nearcast=I_CONTAINMENT_NEARCAST_SCHEMA)
        #orb.add_log_snoop()
        orb.init_cog(CogInterpreter)
        orb.init_cog(CogToTerm)
        orb.init_cog(CogToMenu)
        orb.init_cog(CogToRoguebox)
        #
        bridge = orb.init_autobridge()
        bridge.nearcast.prime_console(
            console_type=console_type,
            console_height=CONSOLE_HEIGHT,
            console_width=CONSOLE_WIDTH)
        bridge.nearcast.init()
        #
        engine.event_loop()
    except SolentQuitException:
        pass
    except:
        traceback.print_exc()
    finally:
        if engine != None:
            engine.close()
示例#4
0
def app(net_addr, net_port):
    engine = Engine(
        mtu=1492)
    orb = engine.init_orb(
        i_nearcast=I_NEARCAST_SCHEMA)
    orb.init_cog(CogUdpSender)
    #
    bridge = orb.init_cog(CogBridge)
    bridge.nc_init(
        addr=net_addr,
        port=net_port)
    #
    engine.event_loop()
示例#5
0
def should_start_and_stop_without_crashing():
    receiver = Receiver()
    #
    engine = Engine(mtu=MTU)
    rail_line_console = RailLineConsole()
    rail_h = 'test/line_console'
    rail_line_console.zero(
        rail_h=rail_h,
        cb_line_console_connect=receiver.on_line_console_connect,
        cb_line_console_condrop=receiver.on_line_console_condrop,
        cb_line_console_command=receiver.on_line_console_command,
        engine=engine)
    engine.cycle()
    #
    # Stage: Start it
    rail_line_console.start(ip='localhost', port=5000)
    #
    # Verify
    engine.cycle()
    assert rail_line_console.is_server_listening() == True
    assert rail_line_console.is_accept_connected() == False
    #
    # Stage: Stop it
    rail_line_console.stop()
    #
    # Verify
    engine.cycle()
    assert rail_line_console.is_server_listening() == False
    assert rail_line_console.is_accept_connected() == False
    #
    return True
示例#6
0
def main():
    console_type = 'curses'
    if '--pygame' in sys.argv:
        console_type = 'pygame'
    if PLATFORM_SYSTEM == 'Windows':
        console_type = 'pygame'
    #
    # Snake is a good go-to program for testing. Hence, I like to leave this
    # in, commented out.
    '''
    init_network_logging(
        mtu=MTU,
        addr='127.255.255.255',
        port=7789,
        label='snake')
    '''
    #
    engine = Engine(mtu=MTU)
    try:
        engine.default_timeout = 0.01
        init_nearcast(engine=engine, console_type=console_type)
        #
        engine.event_loop()
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#7
0
def main():
    console_type = 'curses'
    if '--pygame' in sys.argv:
        console_type = 'pygame'
    elif sys.platform in ('msys', 'win32', 'win64'):
        b_ok = True
        try:
            import pygame
            console_type = 'pygame'
        except:
            print("[!] On Windows, snake needs pygame. (But, try winsnake!).")
            sys.exit(1)
    #
    engine = Engine(
        mtu=MTU)
    try:
        engine.default_timeout = 0.01
        init_nearcast(
            engine=engine,
            console_type=console_type)
        #
        engine.event_loop()
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#8
0
def main():
    init_logging()
    #
    engine = None
    try:
        engine = Engine(mtu=MTU)
        #
        orb = engine.init_orb(i_nearcast=I_NEARCAST_SCHEMA)
        orb.init_cog(CogLineConsole)
        orb.init_cog(CogInterpreter)
        orb.init_cog(CogRedisClient)
        #
        bridge = orb.init_autobridge()
        bridge.nc_init()
        #
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    except:
        traceback.print_exc()
    finally:
        if engine != None:
            engine.close()
示例#9
0
def main():
    print("This is stub code to allow us to create a native-Windows console")
    print("At the time of writing, that console is unfinished.")
    print("(Hence, this will crash shortly.)")
    #
    console_type = 'windows'
    #
    engine = Engine(
        mtu=MTU)
    try:
        engine.default_timeout = 0.01
        launch(
            engine=engine,
            console_type=console_type)
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#10
0
def main():
    engine = Engine(mtu=MTU)
    engine.set_default_timeout(0.0)
    try:
        orb = engine.init_orb(i_nearcast=I_NEARCAST)
        orb.init_cog(CogSdlWorld)
        #
        bridge = orb.init_autobridge()
        bridge.nc_init(title='Game', width=1000, height=600)
        #
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#11
0
def launch(console_type):
    engine = Engine(mtu=MTU)
    try:
        engine.default_timeout = 0.01
        init_nearcast(engine=engine, console_type=console_type)
        #
        engine.event_loop()
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#12
0
def should_accept_client_and_boot_client_on_stop():
    ip = 'localhost'
    port = 5000
    #
    engine = Engine(mtu=MTU)
    receiver = Receiver()
    #
    # step: start
    rail_line_console = RailLineConsole()
    rail_h = 'test/line_console'
    rail_line_console.zero(
        rail_h=rail_h,
        cb_line_console_connect=receiver.on_line_console_connect,
        cb_line_console_condrop=receiver.on_line_console_condrop,
        cb_line_console_command=receiver.on_line_console_command,
        engine=engine)
    rail_line_console.start(ip=ip, port=port)
    #
    # verify
    engine.cycle()
    assert rail_line_console.is_server_listening() == True
    assert rail_line_console.is_accept_connected() == False
    #
    # step: client connects
    client = engine.init_spin(construct=SpinBasicTcpClient)
    client.start(addr=ip, port=port)
    #
    # verify
    engine.cycle()
    assert rail_line_console.is_server_listening() == False
    assert rail_line_console.is_accept_connected() == True
    assert client.is_connected() == True
    #
    # step: server is stopped with client attached
    rail_line_console.stop()
    #
    # confirm effects
    engine.cycle()
    assert rail_line_console.is_server_listening() == False
    assert rail_line_console.is_accept_connected() == False
    assert client.is_connected() == False
    #
    return True
示例#13
0
def main():
    engine = Engine(mtu=MTU)
    engine.set_default_timeout(0.08)
    #
    try:
        init_nearcast(engine=engine,
                      lc_addr=LC_ADDR,
                      lc_port=LC_PORT,
                      console_width=CONSOLE_WIDTH,
                      console_height=CONSOLE_HEIGHT)
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    finally:
        engine.close()
        log("after engine close")
示例#14
0
def main():
    console_type = 'curses'
    init_network_logging(
        mtu=1490,
        addr=get_broadcast(),
        port=4999,
        label=__name__)
    log("Log opened.")

    engine = None
    try:
        engine = Engine(
            mtu=MTU)
        engine.set_default_timeout(0.04)
        #engine.debug_eloop_on()
        #
        orb = engine.init_orb(
            i_nearcast=I_CONTAINMENT_NEARCAST_SCHEMA)
        orb.add_log_snoop()
        orb.init_cog(CogInterpreter)
        orb.init_cog(CogToTerm)
        orb.init_cog(CogToMenu)
        orb.init_cog(CogToRoguebox)
        #
        bridge = orb.init_autobridge()
        bridge.nearcast.prime_console(
            console_type=console_type,
            console_height=CONSOLE_HEIGHT,
            console_width=CONSOLE_WIDTH)
        bridge.nearcast.init()
        #
        engine.event_loop()
    except SolentQuitException:
        pass
    except:
        traceback.print_exc()
    finally:
        if engine != None:
            engine.close()
示例#15
0
def main():
    engine = Engine(mtu=MTU)
    try:
        init(engine=engine)
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    finally:
        engine.close()
def main():
    engine = Engine(mtu=MTU)
    try:
        orb = engine.init_orb(i_nearcast=I_NEARCAST)
        orb.add_log_snoop()
        orb.init_cog(CogInterpret)
        orb.init_cog(CogToLineConsole)
        bridge = orb.init_cog(CogBridge)
        bridge.nc_init()
        engine.event_loop()
    except SolentQuitException:
        pass
    except KeyboardInterrupt:
        pass
    finally:
        engine.close()
示例#17
0
def main():
    engine = Engine(mtu=MTU)
    try:
        init(engine=engine,
             console_addr=CONSOLE_ADDR,
             console_port=CONSOLE_PORT)
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#18
0
文件: mud.py 项目: solent-eng/solent
def main():
    engine = Engine(mtu=MTU)
    try:
        init_nearcast(engine=engine,
                      linetalk_addr=LINETALK_ADDR,
                      linetalk_port=LINETALK_PORT)
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#19
0
def main():
    init_logging()
    #
    engine = None
    try:
        engine = Engine(
            mtu=MTU)
        engine.default_timeout = 0.04
        #
        orb = engine.init_orb(
            i_nearcast=I_NEARCAST_SCHEMA)
        orb.init_cog(CogInterpreter)
        orb.init_cog(CogTerm)
        engine.event_loop()
    except SolentQuitException:
        pass
    except:
        traceback.print_exc()
    finally:
        if engine != None:
            engine.close()
示例#20
0
def main():
    print('''test this with
        echo "Hello" | socat - UDP-DATAGRAM:%s:%s,broadcast
    Or
        python3 -m solent.tools.qd_poll 127.255.255.255 50000
    ''' % (NET_ADDR, NET_PORT))
    #
    engine = Engine(mtu=MTU)
    try:
        init(engine=engine, net_addr=NET_ADDR, net_port=NET_PORT)
        #
        # You can use this to print more info about the event loop. This would be
        # useful if you had a flailing event loop and could not work out what was
        # causing the activity.
        engine.debug_eloop_on()
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#21
0
def main():
    (_cmd, bulk_addr, bulk_port) = sys.argv
    bulk_port = int(bulk_port)

    engine = Engine(mtu=MTU)
    try:
        bridge = init_nearcast(engine=engine,
                               cons_addr=CONS_ADDR,
                               cons_port=CONS_PORT,
                               bulk_addr=bulk_addr,
                               bulk_port=bulk_port)

        engine.event_loop()
    finally:
        engine.close()
示例#22
0
def main():
    engine = Engine(
        mtu=MTU)
    try:
        orb = engine.init_orb(
            i_nearcast=I_NEARCAST)
        orb.add_log_snoop()
        orb.init_cog(CogInterpret)
        orb.init_cog(CogToLinetalk)
        bridge = orb.init_autobridge()
        bridge.nc_prime(
            username='******',
            password='******')
        bridge.nc_init()
        engine.event_loop()
    except SolentQuitException:
        pass
    except KeyboardInterrupt:
        pass
    finally:
        engine.close()
示例#23
0
def main():
    if '--help' in sys.argv:
        usage()
    if 3 != len(sys.argv):
        usage()
    (_, addr, port) = sys.argv
    port = int(port)
    #
    engine = Engine(mtu=MTU)
    try:
        init_nearcast(engine=engine, addr=addr, port=port)
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#24
0
def main():
    (_cmd, dir_save, bulk_addr, bulk_port) = sys.argv
    bulk_port = int(bulk_port)

    if not os.path.exists(dir_save):
        raise Exception("No dir at %s" % (dir_save))
    if not os.path.isdir(dir_save):
        raise Exception("Path at %s is not a directory." % (dir_save))

    engine = Engine(mtu=MTU)
    try:
        bridge = init_nearcast(engine=engine,
                               bulk_addr=bulk_addr,
                               bulk_port=bulk_port,
                               dir_save=dir_save)
        engine.event_loop()
    finally:
        engine.close()
示例#25
0
def main():
    p = sys.platform
    #
    if p not in ('msys', 'win32', 'win64'):
        m = ' '.join([
            "ERROR: winsnake only works on windows.",
            "Try solent.demo.snake for other platforms.",
            "(sys.platform: |%s|)" % (p)
        ])
        print(m)
        sys.exit(1)
    #
    engine = Engine(mtu=MTU)
    engine.default_timeout = 0.01
    #
    try:
        init_nearcast(engine=engine, game_name=GAME_NAME)
        engine.event_loop()
    except SolentQuitException:
        pass
    finally:
        engine.close()
示例#26
0
def main():
    if 3 != len(sys.argv):
        usage()
    #
    engine = Engine(mtu=MTU)
    try:
        net_addr = sys.argv[1]
        net_port = int(sys.argv[2])
        #
        init_nearcast(engine=engine, net_addr=net_addr, net_port=net_port)
        engine.event_loop()
    except KeyboardInterrupt:
        pass
    except SolentQuitException:
        pass
    except:
        traceback.print_exc()
    finally:
        engine.close()
示例#27
0
def should_transfer_of_text():
    ip = 'localhost'
    port = 5000
    #
    engine = Engine(mtu=MTU)
    receiver = Receiver()
    #
    # step: start it
    rail_line_console = RailLineConsole()
    rail_h = 'test/line_console'
    rail_line_console.zero(
        rail_h=rail_h,
        cb_line_console_connect=receiver.on_line_console_connect,
        cb_line_console_condrop=receiver.on_line_console_condrop,
        cb_line_console_command=receiver.on_line_console_command,
        engine=engine)
    rail_line_console.start(ip=ip, port=port)
    #
    # verify
    engine.cycle()
    assert rail_line_console.is_server_listening() == True
    assert rail_line_console.is_accept_connected() == False
    #
    # step: client connects
    client = engine.init_spin(construct=SpinBasicTcpClient)
    client.start(addr=ip, port=port)
    #
    # verify
    engine.cycle()
    assert rail_line_console.is_server_listening() == False
    assert rail_line_console.is_accept_connected() == True
    assert client.is_connected() == True
    #
    # step: client sends text that does not have a newline
    client.send(msg="abc def")  # emphasis: no newline
    #
    # verify: we should not have received a line
    engine.cycle()
    assert 0 == len(receiver.sb)
    #
    # step: now send a new line and some overflow
    client.send(msg="\noverflow")
    client.send(msg="/second half")
    #
    # verify: we should have seen our first line
    engine.cycle()
    assert 1 == len(receiver.sb)
    assert receiver.sb[0] == ['abc', 'def']
    #
    # step: another line ending
    client.send(msg='\n')
    #
    # verify
    engine.cycle()
    assert 2 == len(receiver.sb)
    assert receiver.sb[-1] == ['overflow/second', 'half']
    #
    # step: multiple lines in one pass
    client.send(msg="three\nfour\n")
    #
    # verify
    engine.cycle()
    assert 4 == len(receiver.sb)
    assert receiver.sb[-2] == [
        'three',
    ]
    assert receiver.sb[-1] == [
        'four',
    ]
    #
    # step: we write to client
    s = "here is some text\n"
    rail_line_console.send(msg=s)
    #
    # verify
    engine.cycle()
    assert 1 == len(client.sb)
    assert client.sb[-1] == s
    #
    return True