Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Add BSSID bans for NDS
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle95wm committed Feb 26, 2018
1 parent a74366c commit ebd3cb5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions gamespy/gs_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def initialize_database(self):
tx.nonquery("CREATE TABLE IF NOT EXISTS gamestat_profile (profileid INT, dindex TEXT, ptype TEXT, data TEXT)")
tx.nonquery("CREATE TABLE IF NOT EXISTS gameinfo (profileid INT, dindex TEXT, ptype TEXT, data TEXT)")
tx.nonquery("CREATE TABLE IF NOT EXISTS nas_logins (userid TEXT, authtoken TEXT, data TEXT)")
tx.nonquery("CREATE TABLE IF NOT EXISTS ap_banned (bssid TEXT, timestamp INT(11), reason TEXT, ubtime INT(11))")
tx.nonquery("CREATE TABLE IF NOT EXISTS ip_banned (ipaddr TEXT, timestamp INT(11), reason TEXT, ubtime INT(11))")
tx.nonquery("CREATE TABLE IF NOT EXISTS console_macadr_banned (macadr TEXT, timestamp INT(11), reason TEXT, ubtime INT(11))")
tx.nonquery("CREATE TABLE IF NOT EXISTS console_csnum_banned (csnum TEXT)")
Expand Down Expand Up @@ -406,6 +407,12 @@ def get_nas_login_from_userid(self, userid):
else:
return json.loads(r["data"])

def is_ap_banned(self,postdata):
if 'bssid' in postdata:
with Transaction(self.conn) as tx:
row = tx.queryone("SELECT COUNT(*) FROM ap_banned WHERE bssid = ? AND ubtime > ?",(postdata['bssid'],time.time(),))
return int(row[0]) > 0

def is_ip_banned(self,postdata):
with Transaction(self.conn) as tx:
row = tx.queryone("SELECT COUNT(*) FROM ip_banned WHERE ipaddr = ? AND ubtime > ?",(postdata['ipaddr'],time.time(),))
Expand Down
13 changes: 11 additions & 2 deletions nas_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ def do_POST(self):
ret = self.dict_to_str(ret)

elif action == "login":
if self.server.db.is_ip_banned(post):
logger.log(logging.DEBUG, "login denied for banned user "+str(post))
if self.server.db.is_ap_banned(post):
logger.log(logging.DEBUG, "login denied for banned user (AP is banned) "+str(post))
ret = {
"datetime": time.strftime("%Y%m%d%H%M%S"),
"returncd": "3917",
"locator": "gamespy.com",
"retry": "1",
"reason": "User banned."
}
elif self.server.db.is_ip_banned(post):
logger.log(logging.DEBUG, "login denied for banned user (IP is banned) "+str(post))
ret = {
"datetime": time.strftime("%Y%m%d%H%M%S"),
"returncd": "3917",
Expand Down

0 comments on commit ebd3cb5

Please sign in to comment.