Browse Source

Don't allow more than 7 servers from one IP

pull/4/head
a1batross 9 years ago
parent
commit
6eb0a2ae83
  1. 18
      pymaster.py

18
pymaster.py

@ -103,23 +103,31 @@ class PyMaster: @@ -103,23 +103,31 @@ class PyMaster:
if( gamedir != None ):
if( gamedir != i.gamedir):
continue
# Use pregenerated address string
packet += i.queryAddr
packet += b'\0\0\0\0\0\0' # Fill last IP:Port with \0
self.sock.sendto(packet, addr)
def removeServerFromList(self, data, addr):
logPrint("Remove Server: from {0}:{1}".format(addr[0], addr[1]))
for i in self.serverList:
if (i.addr == addr):
logPrint("Remove Server: from {0}:{1}".format(addr[0], addr[1]))
self.serverList.remove(i)
def sendChallengeToServer(self, data, addr):
logPrint("Challenge Request: from {0}:{1}".format(addr[0], addr[1]))
# At first, remove old server- data from list
self.removeServerFromList(None, addr)
#self.removeServerFromList(None, addr)
count = 0
for i in self.serverList:
if ( i.addr[0] == addr[0] ):
if( i.addr[1] == addr[1] ):
self.serverList.remove(i)
else:
count += 1
if( count > 7 ):
return
# Generate a 32 bit challenge number
challenge = random.randint(0, 2**32-1)
@ -150,7 +158,7 @@ class PyMaster: @@ -150,7 +158,7 @@ class PyMaster:
packet = b'Server\t\t\tGame\tMap\t\tPlayers\tVersion\tChallenge\tCheck\n'
for i in self.serverList:
line = '{0}:{1}\t{2}\t{3}\t\t{4}/{5}\t{6}\t{7}\t{8}n'.format(i.addr[0], i.addr[1],
line = '{0}:{1}\t{2}\t{3}\t{4}/{5}\t{6}\t{7}\t{8}\n'.format(i.addr[0], i.addr[1],
i.gamedir, i.gamemap, i.players,
i.maxplayers, i.version, i.challenge, i.check)
packet += line.encode('latin_1')

Loading…
Cancel
Save