mirror of
https://github.com/de2tla2f/pymaster.git
synced 2024-11-25 12:21:28 +00:00
Don't allow more than 7 servers from one IP
This commit is contained in:
parent
def879f91c
commit
6eb0a2ae83
18
pymaster.py
18
pymaster.py
|
@ -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:
|
|||
|
||||
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…
Reference in a new issue