Valhalla Legends Forums Archive | Battle.net Bot Development | chat flood timings

AuthorMessageTime
aton
g'mornin

does anyone know the _exact_ time values that a bot(or a normal starcraft user) has to stick to that he does not flood.
if i send 1 line every 2,5 seconds, it seems okay, but thats really slow.

are there any rules like max 5 lines every 7 seconds or smth like that?
November 16, 2005, 9:41 PM
Ringo
I dont think you can get away with more than 150 messages every 10mins (600 seconds) in the long run
November 16, 2005, 10:18 PM
Yegg
Some flood protection code written by Adron in C:

[code]/* If this returns non-zero, delay that many milliseconds
  before trying again. If this returns zero, send your
  data.
*/
unsigned long RequiredDelay(unsigned long bytes)
{
    static unsigned long lasttick = 0;    // time (ms) of last call to function
    static unsigned long sentbytes = 0;  // number of outstanding bytes
    const unsigned long perpacket = 200;  // extra bytes per packet
    const unsigned long msperbyte = 10;  // milliseconds per byte
    const unsigned long maxbytes = 600;  // max bytes outstanding
    unsigned long tick = GetTickCount();
    if(lasttick - tick > sentbytes * msperbyte)
        sentbytes = 0;
    else
        sentbytes -= (lasttick-tick) / msperbyte;
    lasttick = tick;
    if(sentbytes + perpacket + bytes > maxbytes)
        return (sentbytes + perpacket + bytes - maxbytes) * msperbyte;
    sentbytes += perpacket + bytes;
    return 0;
}[/code]
November 17, 2005, 1:14 AM
Myndfyr
That code seems like it would not be thread-safe or safe for multiple connection instances.
November 17, 2005, 2:22 AM
iago
This works in Java pretty well, although it'll take a little debugging.  It's based on Adron's idea of costs and credits and stuff:

[code]    /** Note on implementation: This will assume that all previous packets have already been sent.  Don't call this multiple
    * time in a row and hope to get a good result! */
    public long getDelay(String text, Object data)
    {
        if(out.getLocalSettingDefault(getName(), "prevent flooding", "true").equals("false"))
            return 0;
       
        boolean debug              = true;
        int packetCost              = 250;
        int byteCost                = 15;
        int byteOverThresholdCost  = 20;
        int thresholdBytes          = 65;
        int maxCredits              = 800;
        int creditRate              = 10;
       
        // Add the credits for the elapsed time
        if(credits < maxCredits)
        {
            credits += (System.currentTimeMillis() - lastSent) / creditRate;
           
            if(credits > maxCredits)
            {
                if(debug)
                    out.systemMessage(DEBUG, "Maximum anti-flood credits reached (" + maxCredits + ")");
                credits = maxCredits;
            }
        }
       
        lastSent = System.currentTimeMillis();

        // Get the packet's "cost"
        int thisByteDelay = byteCost;
       
        if(text.length() > thresholdBytes)
            byteCost = byteOverThresholdCost;

        int thisPacketCost = packetCost + (thisByteDelay * text.length());

        if(debug)
            out.systemMessage(DEBUG, "Cost for this packet = " + thisPacketCost);

        // Check how long this packet will have to wait
        int requiredDelay = 0;
        // If we can't "afford" the packet, figure out how much time we'll have to wait
        if(credits < 0)
            requiredDelay = -credits * creditRate;
       
//        if(thisPacketCost > credits)
//            requiredDelay = -((credits - thisPacketCost) * thisByteDelay);
       
        // Deduct this packet from the credits
        credits -= thisPacketCost;
       
        if(debug)
            out.systemMessage(DEBUG, "Remaining credits: " + credits + "; Delay: " + requiredDelay);
       
        //System.out.println(requiredDelay);

        return requiredDelay;
    }

[/code]
November 17, 2005, 2:25 AM

Search