File: floodprot

package info (click to toggle)
epic5 3.0.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 5,328 kB
  • sloc: ansic: 75,810; makefile: 648; ruby: 227; python: 215; sh: 78; perl: 13
file content (67 lines) | stat: -rw-r--r-- 1,426 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
if (word(2 $loadinfo()) != [pf]) { load -pf $word(1 $loadinfo()); return; };

addset floodprot_burst int {
  if ([$0] < 1) {
    set floodprot_burst 4;
    return;
  };
  # new input can't be sent before queued one
  fe ($myservers(0)) sv {
    @ floodprot[$sv] = [$0] + 1;
  };
  ^assign -sv;
};

set floodprot_burst 4;

on ?send_to_server "*" {
  if ([$2] == [PONG] || [$2] == [PING]) {
    return 0;
  };
  if (floodprot[$0] == []) {
    @ floodprot[$0] = 1;
    return 0;
  };
  if (floodprot[$0] <= getset(floodprot_burst)) {
    @ floodprot[$0]++;
    return 0;
  };
  @ setitem(queue-$0 $numitems(queue-$0) $2-);
  return 1;
};

on #-server_lost 1023 "*" {
  @ delarray(queue-$0);
  ^assign -floodprot[$0];
};

timer -general -update -refnum _floodprot -repeat -1 3 {
  fe ($myservers(0)) sv {
    if (floodprot[$sv] == []) {
      @ floodprot[$sv] = 0;
    };
    if (numitems(queue-$sv) > 0) {
      @ floodprot[$sv] = -1;
      @ line = getitem(queue-$sv 0);
      @ delitem(queue-$sv 0);
      //xquote -s $sv $chop(1 $line);
      ^assign -line;
      @ floodprot[$sv] = getset(floodprot_burst) + 1;
    } elif (floodprot[$sv] > 0) {
        @ floodprot[$sv] -= 1;
    };
  };
  ^assign -sv;
};

alias qflush {
  fe ($myservers(0)) sv {
    if (numitems(queue-$sv)) {
      xecho -b Flushed queue for server $sv;
      @ delarray(queue-$sv);
      ^assign -floodprot[$0];
    };
  };
  ^assign -sv;
};
#weirdo'2k6