diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-10-21 18:05:06 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2008-10-21 18:05:06 +0000 |
| commit | 9acb3e5e713d1ab6b2312aa4cdc7946f85f875d0 (patch) | |
| tree | 93189cbe6fc70c2ca1b5e374a2114156d55e371a /src/engine/e_network_server.c | |
| parent | 142b5ad5143ddcfc9d7fee2563bee753a968f011 (diff) | |
| download | zcatch-9acb3e5e713d1ab6b2312aa4cdc7946f85f875d0.tar.gz zcatch-9acb3e5e713d1ab6b2312aa4cdc7946f85f875d0.zip | |
continued on ban support. cleaned up settings a bit. reworked the datadir autodetection. introduced engine_openfile, engine_getpath and engine_listdir. never use fs_listdir or io_open directly
Diffstat (limited to 'src/engine/e_network_server.c')
| -rw-r--r-- | src/engine/e_network_server.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/src/engine/e_network_server.c b/src/engine/e_network_server.c index a22bcbf8..7e60a9ce 100644 --- a/src/engine/e_network_server.c +++ b/src/engine/e_network_server.c @@ -162,8 +162,11 @@ int netserver_ban_add(NETSERVER *s, NETADDR addr, int type, int seconds) s->banpool_firstfree->prev = 0; ban->next = 0; ban->prev = 0; - ban->info.expires = stamp; + ban->info.expires = 0; + if(seconds) + ban->info.expires = stamp; ban->info.type = type; + ban->info.addr = addr; /* add it to the ban hash */ if(s->bans[iphash]) @@ -174,7 +177,7 @@ int netserver_ban_add(NETSERVER *s, NETADDR addr, int type, int seconds) /* insert it into the used list */ insert_after = s->banpool_firstused; - while(1) + while(insert_after) { if(!insert_after->next) break; @@ -186,7 +189,6 @@ int netserver_ban_add(NETSERVER *s, NETADDR addr, int type, int seconds) if(!insert_after || insert_after->info.expires > stamp) { /* insert first */ - insert_after->prev = ban; s->banpool_firstused = ban; ban->next = insert_after; ban->prev = 0; @@ -200,6 +202,27 @@ int netserver_ban_add(NETSERVER *s, NETADDR addr, int type, int seconds) ban->next->prev = ban; insert_after->next = ban; } + + /* drop banned clients */ + { + char buf[128]; + int i; + NETADDR banaddr; + + if(seconds) + str_format(buf, sizeof(buf), "you have been banned for %d seconds", seconds); + else + str_format(buf, sizeof(buf), "you have been banned"); + + for(i = 0; i < s->max_clients; i++) + { + banaddr = s->slots[i].conn.peeraddr; + banaddr.port = 0; + + if(net_addr_comp(&addr, &banaddr) == 0) + netserver_drop(s, i, buf); + } + } return 0; } @@ -242,18 +265,20 @@ int netserver_recv(NETSERVER *s, NETCHUNK *chunk) if(unpack_packet(s->recv.buffer, bytes, &s->recv.data) == 0) { NETBAN *ban = 0; + NETADDR banaddr = addr; int iphash = (addr.ip[0]+addr.ip[1]+addr.ip[2]+addr.ip[3])&0xff; found = 0; + banaddr.port = 0; /* search a ban */ for(ban = s->bans[iphash]; ban; ban = ban->hashnext) { - if(net_addr_comp(&ban->info.addr, &addr) == 0) + if(net_addr_comp(&ban->info.addr, &banaddr) == 0) break; } /* check if we just should drop the packet */ - if(ban && ban->info.type == NETBANTYPE_DROP && ban->info.expires > now) + if(ban && ban->info.type == NETBANTYPE_DROP && (!ban->info.expires || ban->info.expires > now)) continue; if(s->recv.data.flags&NET_PACKETFLAG_CONNLESS) |