Beispiel #1
0
def request_pick_up():
    """Tell server to pick up an item at the player's feet."""
    items = []
    for item in CS.map.grid[CS.u.x][CS.u.y].items:
        items.append(item.oid)

    Network.request(',', (tuple(items),))
Beispiel #2
0
def request_pick_up():
    """Tell server to pick up an item at the player's feet."""
    items = []
    for item in CS.map.grid[CS.u.x][CS.u.y].items:
        items.append(item.oid)

    Network.request(',', (tuple(items), ))
 def _readConfig(self, configFile):
     configParser = ConfigParser.ConfigParser()
     configParser.read(configFile,encoding='utf-8')
     httpserver_config = HttpServer_Config()
     httpserver_config.local_ip=configParser.get('baseInfo','local_ip').strip()
     if not httpserver_config.local_ip:
         httpserver_config.local_ip=Network.get_local_ip()
     httpserver_config.httpserver_port=configParser.get('baseInfo','httpserver_port').strip()
     if not httpserver_config.httpserver_port:
         httpserver_config.httpserver_port=str(8000)
     return httpserver_config
         get_allure_process_id = get_allure_process_id.decode(
             'utf-8')
         get_allure_process_id = StrTool.getStringWithLBRB(
             get_allure_process_id, 'LISTENING', '\r\n').strip()
         kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
         try:
             subprocess.check_call(kill_allure_process_command,
                                   shell=True)
         except:
             print('关闭allure进程,进程id:' + get_allure_process_id +
                   ',该进程监听已监听端口:' + ieport)
     except:
         print('allure未查找到监听端口%s的服务' % ieport)
     print('生成ie报告,使用端口' + ieport)
     print('ie报告地址:http://%s:%s/' %
           (Network.get_local_ip(), ieport))
     p = p_pool.apply_async(generate_windows_reports,
                            ('output/web_ui/ie', ieport))
 if chromeport:
     # 获得当前监听chrome端口的进程id
     get_chromeport_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % chromeport
     try:
         get_allure_process_id = subprocess.check_output(
             get_chromeport_process_id_command, shell=True)
         get_allure_process_id = get_allure_process_id.decode(
             'utf-8')
         get_allure_process_id = StrTool.getStringWithLBRB(
             get_allure_process_id, 'LISTENING', '\r\n').strip()
         kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
         try:
             subprocess.check_call(kill_allure_process_command,
Beispiel #5
0
 def move(self, dx, dy=None):
     """Move by (dx, dy) cells."""
     dx, dy = flatten_args(dx, dy)
     Network.request('m', (dx, dy))
Beispiel #6
0
 def attack(self, target):
     """Attack a target oid."""
     Network.request('F', (target.oid,))
Beispiel #7
0
def handle_responses():
    """Read in server responses from the network and process."""

    res = Network.get_response()
    while res:
        # Load level map
        if 'map' in res:
            CS.map = ClientMap.unserialize(res['map'])
            new_dlevel = True
        else:
            new_dlevel = False

        # Update log messages
        if 'log' in res:
            for msg in res['log']:
                CS.msgs.append(msg)

            CS.log_updated = True

        # Update monsters
        if 'm' in res:
            for oid, m_str in res['m'].iteritems():
                if oid in ClientObject.obj_dict:
                    ClientObject.obj_dict[oid].update_from_string(m_str)
                else:
                    mon = ClientMonster.unserialize(m_str)
                    mon.place_on_map()

        # Delete monsters
        if 'm_del' in res:
            for oid, flags in res['m_del']:
                ClientObject.obj_dict[oid].delete(flags)

        # Update items
        if 'i' in res:
            for oid, i_str in res['i'].iteritems():
                if oid in ClientObject.obj_dict:
                    ClientObject.obj_dict[oid].update_from_string(i_str)
                else:
                    item = ClientItem.unserialize(i_str)
                    item.place_on_map()

        # Delete items
        if 'i_del' in res:
            for oid, flags in res['i_del']:
                ClientObject.obj_dict[oid].delete(flags)

        # Update the player object
        if 'u' in res:
            if CS.u is not None:
                CS.u.update_from_string(res['u'])
            else:
                CS.u = ClientPlayer.unserialize(res['u'])

            # If we're changing dungeon levels, the player needs a new FOV map
            if new_dlevel:
                CS.u.set_fov_map(CS.map.grid)

            CS.u.fov_map.do_fov(CS.u.x, CS.u.y, CS.u.fov_radius)
            gui.center_map()

        res = Network.get_response()
Beispiel #8
0
def handle_events():
    """Handle input events."""
    for event in pygame.event.get():
        if event.type == pgl.QUIT:
            quit_game()
        elif event.type == pgl.KEYDOWN:
            CS.key = event
        elif event.type == pgl.KEYUP:
            CS.key = None
        elif event.type == pgl.MOUSEBUTTONDOWN:
            CS.button = event.button
        elif event.type == pgl.MOUSEBUTTONUP:
            CS.button = None
        elif event.type == pgl.MOUSEMOTION:
            pass
        elif event.type == pgl.VIDEORESIZE:
            gui.handle_resize(event.w, event.h)

        # Handle scrolling
        CS.x_scrollbar.handle_event(event)
        CS.y_scrollbar.handle_event(event)
        CS.log_scrollbar.handle_event(event)

    if CS.key:
        key_code, char, mod = CS.key.key, CS.key.unicode, CS.key.mod
        CS.key = None
    else:
        key_code, char, mod = None, None, None

    if CS.mode == cfg.ST_PLAYING:
        # Handle all keypresses
        if key_code:
            handled = False
            key_combo = ''

            if mod & pgl.KMOD_SHIFT:
                if char not in CS.pkeys[pgl.KMOD_NONE]:
                    key_combo = 'Shift + '

                if (key_code in CS.pkeys[pgl.KMOD_SHIFT] and
                    CS.pkeys[pgl.KMOD_SHIFT][key_code].action):
                    CS.pkeys[pgl.KMOD_SHIFT][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_CTRL:
                key_combo = 'Ctrl + '

                if (key_code in CS.pkeys[pgl.KMOD_CTRL] and
                    CS.pkeys[pgl.KMOD_CTRL][key_code].action):
                    CS.pkeys[pgl.KMOD_CTRL][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_ALT:
                key_combo = 'Alt + '

                if (key_code in CS.pkeys[pgl.KMOD_ALT] and
                    CS.pkeys[pgl.KMOD_ALT][key_code].action):
                    CS.pkeys[pgl.KMOD_ALT][key_code].perform_action()
                    handled = True

            if not handled:
                # First, look up by char.  If it's not found, then look up by
                # key_code.
                if (char in CS.pkeys[pgl.KMOD_NONE] and
                    CS.pkeys[pgl.KMOD_NONE][char].action):
                    CS.pkeys[pgl.KMOD_NONE][char].perform_action()
                    handled = True
                elif (key_code in CS.pkeys[pgl.KMOD_NONE] and
                      CS.pkeys[pgl.KMOD_NONE][key_code].action):
                    CS.pkeys[pgl.KMOD_NONE][key_code].perform_action()
                    handled = True

            if key_code not in CS.ignore_keys and handled is False:
                if char in CS.pkeys[pgl.KMOD_NONE]:
                    key_to_print = char
                else:
                    key_to_print = pygame.key.name(key_code)
                    client_message("Unknown command '{0}{1}'.".format(
                            key_combo, key_to_print))

    elif CS.mode == cfg.ST_MENU:
        if key_code:
            if len(char) == 1:
                index = ord(char) - ord('a')
                if index >= 0 and index < len(CS.menu_options):
                    if CS.menu == 'use':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('a', (item.oid,))

                    elif CS.menu == 'drop':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('d', (item.oid,))
                else:
                    CS.mode = cfg.ST_PLAYING  # Exit menu
            else:
                CS.mode = cfg.ST_PLAYING  # Exit menu

    elif CS.mode == cfg.ST_TARGETING:
        if CS.button:
            x, y = pygame.mouse.get_pos()
            x, y = gui.mouse2cell(x, y)

            # Accept the target if the player clicked in FOV, and in
            # case a range is specified, if it's in that range
            if CS.button == cfg.BUTTON_L and CS.u.fov_map.in_fov(x, y):
                targeting_function = CS.targeting_function.pop(0)
                success = targeting_function(CS.targeting_item, x, y)

                # If this targeting is the result of an item use,
                # destroy the item
                if CS.targeting_item and success:
                    CS.u.inventory.remove(CS.targeting_item)
                    del ClientObject.obj_dict[CS.targeting_item.oid]
                    CS.targeting_item = None

            CS.mode = cfg.ST_PLAYING
        elif key_code:
            client_message('Cancelled')
            CS.mode = cfg.ST_PLAYING
    elif CS.mode == cfg.ST_PLAYBACK:
        pass
    elif CS.mode == cfg.ST_QUIT:
        # Do nothing; let the main loop exit on its own.
        pass
    else:
        impossible('Unknown state: ' + CS.mode)
Beispiel #9
0
def server_tick():
    """
    Called from the main game loop to handle server functionality.
    Handle client requests, monster turns, and send responses to client.
    """
    handle_requests()

    if SS.u_took_turn:
        SS.u.fov_map.do_fov(SS.u.x, SS.u.y, SS.u.fov_radius)
        monsters_take_turn()
        SS.u_took_turn = False

    # Send responses to the client.
    res = {}

    # Tell the client to update the whole map, if necessary
    if SS.map.dirty:
        res['map'] = SS.map.client_serialize()
        SS.map.dirty = False
    else:
        # If there are individual Cells to update, tell the client.
        pass

    # Tell the client which monsters to update.
    # FIXME: We currently send the whole monster object, but this needs to be
    # modified to only send the attributes which have changed since the last
    # update.
    for mon in SS.map.monsters:
        if mon.dirty:
            if 'm' not in res:
                res['m'] = {}
            res['m'][mon.oid] = mon.client_serialize()
            mon.dirty = False

    for mon in SS.monsters_to_delete:
        if 'm_del' not in res:
            res['m_del'] = []
        res['m_del'].append(mon)
    del SS.monsters_to_delete[:]

    # Tell the client which items to update.
    for item in SS.map.items:
        if item.dirty:
            if 'i' not in res:
                res['i'] = {}
            res['i'][item.oid] = item.client_serialize()
            item.dirty = False

    for item in SS.items_to_delete:
        if 'i_del' not in res:
            res['i_del'] = []
        res['i_del'].append(item)
    del SS.items_to_delete[:]

    # Send the updated player to the client.
    if SS.u.dirty:
        res['u'] = SS.u.client_serialize()
        SS.u.dirty = False

    if len(SS.msgs):
        res['log'] = []
        for msg in SS.msgs:
            res['log'].append(msg)
        SS.msgs.clear()

    if res:
        Network.send_response(res)
Beispiel #10
0
def handle_responses():
    """Read in server responses from the network and process."""

    res = Network.get_response()
    while res:
        # Load level map
        if 'map' in res:
            CS.map = ClientMap.unserialize(res['map'])
            new_dlevel = True
        else:
            new_dlevel = False

        # Update log messages
        if 'log' in res:
            for msg in res['log']:
                CS.msgs.append(msg)

            CS.log_updated = True

        # Update monsters
        if 'm' in res:
            for oid, m_str in res['m'].iteritems():
                if oid in ClientObject.obj_dict:
                    ClientObject.obj_dict[oid].update_from_string(m_str)
                else:
                    mon = ClientMonster.unserialize(m_str)
                    mon.place_on_map()

        # Delete monsters
        if 'm_del' in res:
            for oid, flags in res['m_del']:
                ClientObject.obj_dict[oid].delete(flags)

        # Update items
        if 'i' in res:
            for oid, i_str in res['i'].iteritems():
                if oid in ClientObject.obj_dict:
                    ClientObject.obj_dict[oid].update_from_string(i_str)
                else:
                    item = ClientItem.unserialize(i_str)
                    item.place_on_map()

        # Delete items
        if 'i_del' in res:
            for oid, flags in res['i_del']:
                ClientObject.obj_dict[oid].delete(flags)

        # Update the player object
        if 'u' in res:
            if CS.u is not None:
                CS.u.update_from_string(res['u'])
            else:
                CS.u = ClientPlayer.unserialize(res['u'])

            # If we're changing dungeon levels, the player needs a new FOV map
            if new_dlevel:
                CS.u.set_fov_map(CS.map.grid)

            CS.u.fov_map.do_fov(CS.u.x, CS.u.y, CS.u.fov_radius)
            gui.center_map()

        res = Network.get_response()
Beispiel #11
0
def handle_events():
    """Handle input events."""
    for event in pygame.event.get():
        if event.type == pgl.QUIT:
            quit_game()
        elif event.type == pgl.KEYDOWN:
            CS.key = event
        elif event.type == pgl.KEYUP:
            CS.key = None
        elif event.type == pgl.MOUSEBUTTONDOWN:
            CS.button = event.button
        elif event.type == pgl.MOUSEBUTTONUP:
            CS.button = None
        elif event.type == pgl.MOUSEMOTION:
            pass
        elif event.type == pgl.VIDEORESIZE:
            gui.handle_resize(event.w, event.h)

        # Handle scrolling
        CS.x_scrollbar.handle_event(event)
        CS.y_scrollbar.handle_event(event)
        CS.log_scrollbar.handle_event(event)

    if CS.key:
        key_code, char, mod = CS.key.key, CS.key.unicode, CS.key.mod
        CS.key = None
    else:
        key_code, char, mod = None, None, None

    if CS.mode == cfg.ST_PLAYING:
        # Handle all keypresses
        if key_code:
            handled = False
            key_combo = ''

            if mod & pgl.KMOD_SHIFT:
                if char not in CS.pkeys[pgl.KMOD_NONE]:
                    key_combo = 'Shift + '

                if (key_code in CS.pkeys[pgl.KMOD_SHIFT]
                        and CS.pkeys[pgl.KMOD_SHIFT][key_code].action):
                    CS.pkeys[pgl.KMOD_SHIFT][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_CTRL:
                key_combo = 'Ctrl + '

                if (key_code in CS.pkeys[pgl.KMOD_CTRL]
                        and CS.pkeys[pgl.KMOD_CTRL][key_code].action):
                    CS.pkeys[pgl.KMOD_CTRL][key_code].perform_action()
                    handled = True

            elif mod & pgl.KMOD_ALT:
                key_combo = 'Alt + '

                if (key_code in CS.pkeys[pgl.KMOD_ALT]
                        and CS.pkeys[pgl.KMOD_ALT][key_code].action):
                    CS.pkeys[pgl.KMOD_ALT][key_code].perform_action()
                    handled = True

            if not handled:
                # First, look up by char.  If it's not found, then look up by
                # key_code.
                if (char in CS.pkeys[pgl.KMOD_NONE]
                        and CS.pkeys[pgl.KMOD_NONE][char].action):
                    CS.pkeys[pgl.KMOD_NONE][char].perform_action()
                    handled = True
                elif (key_code in CS.pkeys[pgl.KMOD_NONE]
                      and CS.pkeys[pgl.KMOD_NONE][key_code].action):
                    CS.pkeys[pgl.KMOD_NONE][key_code].perform_action()
                    handled = True

            if key_code not in CS.ignore_keys and handled is False:
                if char in CS.pkeys[pgl.KMOD_NONE]:
                    key_to_print = char
                else:
                    key_to_print = pygame.key.name(key_code)
                    client_message("Unknown command '{0}{1}'.".format(
                        key_combo, key_to_print))

    elif CS.mode == cfg.ST_MENU:
        if key_code:
            if len(char) == 1:
                index = ord(char) - ord('a')
                if index >= 0 and index < len(CS.menu_options):
                    if CS.menu == 'use':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('a', (item.oid, ))

                    elif CS.menu == 'drop':
                        CS.mode = cfg.ST_PLAYING  # Exit menu
                        if len(CS.u.inventory) > 0:
                            item = CS.u.inventory[index]
                            if item is not None:
                                Network.request('d', (item.oid, ))
                else:
                    CS.mode = cfg.ST_PLAYING  # Exit menu
            else:
                CS.mode = cfg.ST_PLAYING  # Exit menu

    elif CS.mode == cfg.ST_TARGETING:
        if CS.button:
            x, y = pygame.mouse.get_pos()
            x, y = gui.mouse2cell(x, y)

            # Accept the target if the player clicked in FOV, and in
            # case a range is specified, if it's in that range
            if CS.button == cfg.BUTTON_L and CS.u.fov_map.in_fov(x, y):
                targeting_function = CS.targeting_function.pop(0)
                success = targeting_function(CS.targeting_item, x, y)

                # If this targeting is the result of an item use,
                # destroy the item
                if CS.targeting_item and success:
                    CS.u.inventory.remove(CS.targeting_item)
                    del ClientObject.obj_dict[CS.targeting_item.oid]
                    CS.targeting_item = None

            CS.mode = cfg.ST_PLAYING
        elif key_code:
            client_message('Cancelled')
            CS.mode = cfg.ST_PLAYING
    elif CS.mode == cfg.ST_PLAYBACK:
        pass
    elif CS.mode == cfg.ST_QUIT:
        # Do nothing; let the main loop exit on its own.
        pass
    else:
        impossible('Unknown state: ' + CS.mode)
Beispiel #12
0
 def move(self, dx, dy=None):
     """Move by (dx, dy) cells."""
     dx, dy = flatten_args(dx, dy)
     Network.request('m', (dx, dy))
Beispiel #13
0
 def attack(self, target):
     """Attack a target oid."""
     Network.request('F', (target.oid, ))
Beispiel #14
0
                    get_allure_process_id, 'LISTENING', '\r\n').strip()
                kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
                try:
                    subprocess.check_call(kill_allure_process_command,
                                          shell=True)
                except:
                    print('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s' %
                          (DateTimeTool.getNowTime(), get_allure_process_id,
                           port))
            except:
                print('%sallure未查找到监听端口%s的服务' %
                      (DateTimeTool.getNowTime(), port))
            print('%s生成报告%s/report/app_ui_report_%s,使用端口%s' %
                  (DateTimeTool.getNowTime(), report_dirs[i], test_time, port))
            print('%s报告地址:http://%s:%s/' %
                  (DateTimeTool.getNowTime(), Network.get_local_ip(), port))
            p = p_pool.apply_async(generate_windows_reports,
                                   (report_dirs[i], test_time, port))
        p_pool.close()
        p_pool.join()
    else:
        # 获得当前allure所有进程id
        get_allure_process_ids_command = "ps -ef|grep -i allure\\.CommandLine|grep -v grep|awk '{print $2}'"
        allure_process_ids = subprocess.check_output(
            get_allure_process_ids_command, shell=True)
        allure_process_ids = allure_process_ids.decode('utf-8')
        allure_process_ids = allure_process_ids.split('\n')

        for i in range(len(report_dirs)):
            port = str(int(start_port) + i)
            # 获得当前监听port端口的进程id
Beispiel #15
0
    notice_markdown_text = '* API生成时间:%s \n' % test_time
    if 'Windows' == platform.system():
        get_allure_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % port
        try:
            get_allure_process_id = subprocess.check_output(get_allure_process_id_command, shell=True)
            get_allure_process_id = get_allure_process_id.decode('utf-8')
            get_allure_process_id = StrTool.getStringWithLBRB(get_allure_process_id, 'LISTENING', '\r\n').strip()
            kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
            try:
                subprocess.check_call(kill_allure_process_command, shell=True)
            except:
                print('%s关闭allure进程,进程id:%s,该进程监听已监听端口:%s'%(DateTimeTool.getNowTime(),get_allure_process_id,port))
        except:
            print('%sallure未查找到监听端口%s的服务' % (DateTimeTool.getNowTime(),port))
        print('%s生成报告,使用端口%s'%(DateTimeTool.getNowTime(),port))
        print('%s报告地址:http://%s:%s/' % (DateTimeTool.getNowTime(),Network.get_local_ip(), port))
        process = multiprocessing.Process(target=generate_windows_reports, args=(test_time, port))
        process.start()
        process.join()
    else:
        # 获得当前allure所有进程id
        get_allure_process_ids_command = "ps -ef|grep -i allure\\.CommandLine|grep -v grep|awk '{print $2}'"
        allure_process_ids = subprocess.check_output(get_allure_process_ids_command, shell=True)
        allure_process_ids = allure_process_ids.decode('utf-8')
        allure_process_ids = allure_process_ids.split('\n')

        # 获得当前监听port端口的进程id
        get_port_process_ids_command = "netstat -anp|grep -i " + port + "|grep -v grep|awk '{print $7}'|awk -F '/' '{print $1}'"
        port_process_ids = subprocess.check_output(get_port_process_ids_command, shell=True)
        port_process_ids = port_process_ids.decode('utf-8')
        port_process_ids = port_process_ids.split('\n')
                        get_allure_process_id_command, shell=True)
                    get_allure_process_id = get_allure_process_id.decode(
                        'utf-8')
                    get_allure_process_id = StrTool.getStringWithLBRB(
                        get_allure_process_id, 'LISTENING', '\r\n').strip()
                    kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
                    try:
                        subprocess.check_call(kill_allure_process_command,
                                              shell=True)
                    except:
                        print('关闭allure进程,进程id:' + get_allure_process_id +
                              ',该进程监听已监听端口:' + port)
                except:
                    print('allure未查找到监听端口%s的服务' % port)
                print('生成报告' + report_dirs[i] + ',使用端口' + port)
                print('报告地址:http://%s:%s/' % (Network.get_local_ip(), port))
                p = p_pool.apply_async(generate_windows_reports,
                                       (report_dirs[i], port))
            p_pool.close()
            p_pool.join()
        else:
            # 获得当前allure所有进程id
            get_allure_process_ids_command = "ps -ef|grep -i allure\\.CommandLine|grep -v grep|awk '{print $2}'"
            allure_process_ids = subprocess.check_output(
                get_allure_process_ids_command, shell=True)
            allure_process_ids = allure_process_ids.decode('utf-8')
            allure_process_ids = allure_process_ids.split('\n')

            for i in range(len(report_dirs)):
                port = str(int(start_port) + i)
                # 获得当前监听port端口的进程id
         get_allure_process_id = subprocess.check_output(
             get_ieport_process_id_command, shell=True)
         get_allure_process_id = get_allure_process_id.decode('utf-8')
         get_allure_process_id = StrTool.getStringWithLBRB(
             get_allure_process_id, 'LISTENING', '\r\n').strip()
         kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
         try:
             subprocess.check_call(kill_allure_process_command,
                                   shell=True)
         except:
             print('关闭allure进程,进程id:' + get_allure_process_id +
                   ',该进程监听已监听端口:' + ieport)
     except:
         print('allure未查找到监听端口%s的服务' % ieport)
     print('生成ie报告,使用端口' + ieport)
     print('ie报告地址:http://%s:%s/' % (Network.get_local_ip(), ieport))
     p = p_pool.apply_async(generate_windows_reports,
                            ('output/web_ui/ie', ieport))
 if chromeport:
     # 获得当前监听chrome端口的进程id
     get_chromeport_process_id_command = 'netstat -ano|findstr "0.0.0.0:%s"' % chromeport
     try:
         get_allure_process_id = subprocess.check_output(
             get_chromeport_process_id_command, shell=True)
         get_allure_process_id = get_allure_process_id.decode('utf-8')
         get_allure_process_id = StrTool.getStringWithLBRB(
             get_allure_process_id, 'LISTENING', '\r\n').strip()
         kill_allure_process_command = 'taskkill /F /pid %s' % get_allure_process_id
         try:
             subprocess.check_call(kill_allure_process_command,
                                   shell=True)
Beispiel #18
0
def server_tick():
    """
    Called from the main game loop to handle server functionality.
    Handle client requests, monster turns, and send responses to client.
    """
    handle_requests()

    if SS.u_took_turn:
        SS.u.fov_map.do_fov(SS.u.x, SS.u.y, SS.u.fov_radius)
        monsters_take_turn()
        SS.u_took_turn = False

    # Send responses to the client.
    res = {}

    # Tell the client to update the whole map, if necessary
    if SS.map.dirty:
        res['map'] = SS.map.client_serialize()
        SS.map.dirty = False
    else:
        # If there are individual Cells to update, tell the client.
        pass

    # Tell the client which monsters to update.
    # FIXME: We currently send the whole monster object, but this needs to be
    # modified to only send the attributes which have changed since the last
    # update.
    for mon in SS.map.monsters:
        if mon.dirty:
            if 'm' not in res:
                res['m'] = {}
            res['m'][mon.oid] = mon.client_serialize()
            mon.dirty = False

    for mon in SS.monsters_to_delete:
        if 'm_del' not in res:
            res['m_del'] = []
        res['m_del'].append(mon)
    del SS.monsters_to_delete[:]

    # Tell the client which items to update.
    for item in SS.map.items:
        if item.dirty:
            if 'i' not in res:
                res['i'] = {}
            res['i'][item.oid] = item.client_serialize()
            item.dirty = False

    for item in SS.items_to_delete:
        if 'i_del' not in res:
            res['i_del'] = []
        res['i_del'].append(item)
    del SS.items_to_delete[:]

    # Send the updated player to the client.
    if SS.u.dirty:
        res['u'] = SS.u.client_serialize()
        SS.u.dirty = False

    if len(SS.msgs):
        res['log'] = []
        for msg in SS.msgs:
            res['log'].append(msg)
        SS.msgs.clear()

    if res:
        Network.send_response(res)