예제 #1
0
def server_loop(port, args=(), line_callback=None, quit_on_disconnect=True):
    if osutil.is_android:
        serverpath = os.path.join(os.path.dirname(client.freeciv.freecivclient.__file__), 'freecivserver')
    else:
        serverpath = 'server/freeciv-server'
    args = ('--Ppm', '-p', str(port), '-s', get_save_dir(), ) + args
    print 'starting server - executable at', serverpath
    stat = os.stat(serverpath)
    os.chmod(serverpath, 0o744) # octal!!!!
    piddir = get_save_dir()
    cmd = (serverpath, ) + args
    if osutil.is_desktop:
        os.environ['LD_PRELOAD'] = ''
    if quit_on_disconnect:
        os.environ['FREECIV_QUIT_ON_DISCONNECT'] = 'true'
    else:
        del os.environ['FREECIV_QUIT_ON_DISCONNECT']
    print cmd
    serv_in, stream = os.popen4(cmd, bufsize=1) # line buffering
    
    p = subprocess.Popen(cmd, bufsize=1,
          stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
    stream = p.stdout
    
    while True:
        line = stream.readline()
        if not line:
            break
        if line_callback:
            line_callback(line)
        monitor.log('server', line.rstrip())
예제 #2
0
def server_loop(port, args=(), line_callback=None, quit_on_disconnect=True):
    assert quit_on_disconnect
    args = (
        '--Ppm',
        '-p',
        str(port),
        '-s',
        get_save_dir(),
    ) + args

    piddir = get_save_dir()
    print 'server args', args

    if features.get('app.fork'):
        stream = zygote_start_server(args)
    else:
        stream = subprocess_start_server(args)

    while True:
        line = stream.readline()
        if not line:
            break
        if line_callback:
            line_callback(line)
        print 'server:', line.rstrip()
예제 #3
0
def server_loop(port, args='', line_callback=None, quit_on_disconnect=True):
    if osutil.is_android:
        serverpath = os.path.join(os.path.dirname(client.freeciv.freecivclient.__file__), 'freecivserver')
    else:
        serverpath = 'server/freeciv-server'
    args = "--Ppm -p %d -s '%s' %s" % (port, get_save_dir(), args)
    print 'starting server - executable at', serverpath
    stat = os.stat(serverpath)
    os.chmod(serverpath, 0o744) # octal!!!!
    piddir = get_save_dir()
    cmd = '%s %s 2>&1 & echo $!>%s/serverpid' % (serverpath, args, piddir)
    if osutil.is_desktop:
        os.environ['LD_PRELOAD'] = ''
    if quit_on_disconnect:
        os.environ['FREECIV_QUIT_ON_DISCONNECT'] = 'true'
    else:
        del os.environ['FREECIV_QUIT_ON_DISCONNECT']
    print cmd
    stream = os.popen(cmd, 'r', 1) # line buffering
    
    while True:
        line = stream.readline()
        if not line:
            break
        if line_callback:
            line_callback(line)
        print '[server]', line.rstrip()
예제 #4
0
파일: save.py 프로젝트: Swarmers/Bunnies01
def server_loop(port, args=(), line_callback=None, quit_on_disconnect=True):
    if osutil.is_android:
        serverpath = os.path.join(os.path.dirname(client.freeciv.freecivclient.__file__), 'freecivserver')
    else:
        serverpath = 'server/freeciv-server'
    args = ('--Ppm', '-p', str(port), '-s', get_save_dir(), ) + args
    print 'starting server - executable at', serverpath
    stat = os.stat(serverpath)
    try:
        os.chmod(serverpath, 0o744) # octal!!!!
    except OSError as err:
        print 'chmodding server failed', err
    piddir = get_save_dir()
    cmd = (serverpath, ) + args
    if osutil.is_desktop:
        os.environ['LD_PRELOAD'] = ''
    if quit_on_disconnect:
        os.environ['FREECIV_QUIT_ON_DISCONNECT'] = 'true'
    else:
        del os.environ['FREECIV_QUIT_ON_DISCONNECT']
    print cmd
    serv_in, stream = os.popen4(cmd, bufsize=1) # line buffering

    p = subprocess.Popen(cmd, bufsize=1,
          stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
    stream = p.stdout

    while True:
        line = stream.readline()
        if not line:
            break
        if line_callback:
            line_callback(line)
        monitor.log('server', line.rstrip())
예제 #5
0
def start_server(port, args=(), line_callback=None, quit_on_disconnect=True):
    assert quit_on_disconnect
    args = ('-p', str(port), '-s', get_save_dir(), ) + args

    piddir = get_save_dir()
    print 'server args', args

    if features.get('app.fork'):
        stream = zygote_start_server(args)
    else:
        stream = subprocess_start_server(args)
    thread.start_new_thread(server_loop, (stream, line_callback))
    time.sleep(0.3)
예제 #6
0
def server_loop(port, args=(), line_callback=None, quit_on_disconnect=True):
    assert quit_on_disconnect
    args = ('--Ppm', '-p', str(port), '-s', get_save_dir(), ) + args

    piddir = get_save_dir()
    print 'server args', args

    stream = zygote_start_server(args)

    while True:
        line = stream.readline()
        if not line:
            break
        if line_callback:
            line_callback(line)
        print 'server:', line.rstrip()
예제 #7
0
def get_saves():
    def sort_key(name):
        return os.path.getmtime(os.path.join(path, name))

    path = get_save_dir()
    names = os.listdir(path)
    names.sort(key=sort_key, reverse=True)
    for name in names:
        if '.sav' in name:
            yield (name, os.path.join(path, name))