Exemplo n.º 1
0
def recvReplyMsgs(d):
    # process all messages in socket recv buffer
    startTime = time.perf_counter()
    msgQ = []
    more = True
    while more:
        try:
            msgQ.append(d.srvSocket.recvMessage())
        except nbipc.NetBotSocketException as e:
            more = False
        except Exception as e:
            log(str(type(e)) + " " + str(e), "ERROR")
            more = False

    botMsgCount = {}
    for msg, ip, port in msgQ:

        src = nbipc.formatIpPort(ip, port)

        # Track src counter and drop msg if we have already proccessed the max msgs for this src this step
        if src in botMsgCount:
            botMsgCount[src] += 1
        else:
            botMsgCount[src] = 1
        if botMsgCount[src] > d.conf['botMsgsPerStep']:
            continue
        
        if dropMessage(d):
            continue

        reply = processMsg(d, msg, src)
        if reply:
            if dropMessage(d):
                continue
            try:
                d.srvSocket.sendMessage(reply, ip, port)
            except Exception as e:
                log(str(e), "ERROR")

    if d.state['gameNumber'] > 0: # Don't count missed steps while waiting for bots to join.
        for src in d.bots:
            if src not in botMsgCount:
                d.bots[src]['missedSteps'] += 1

    d.state['msgTime'] += time.perf_counter() - startTime
Exemplo n.º 2
0
def recvReplyMsgs(d):
    # process all messages in socket recv buffer
    startTime = time.perf_counter()
    msgQ = []
    more = True
    while more:
        try:
            msgQ.append(d.srvSocket.recvMessage())
        except nbipc.NetBotSocketException as e:
            more = False
        except Exception as e:
            log(str(type(e)) + " " + str(e), "ERROR")
            more = False

    botMsgCount = {}
    for msg, ip, port in msgQ:
        if dropMessage(d):
            continue

        src = nbipc.formatIpPort(ip, port)

        # Track src counter and drop msg if we have already proccessed the max msgs for this src this step
        if src in botMsgCount:
            botMsgCount[src] += 1
        else:
            botMsgCount[src] = 1
        if botMsgCount[src] > d.conf['botMsgsPerStep']:
            continue

        reply = processMsg(d, msg, src)
        if reply:
            if dropMessage(d):
                continue
            try:
                d.srvSocket.sendMessage(reply, ip, port)
            except Exception as e:
                log(str(e), "ERROR")

    d.state['msgTime'] += time.perf_counter() - startTime
    log("Msgs Processed per Bot this step: " + str(botMsgCount), "DEBUG")