From 9c8824ff0cd9ba4acd97188523562a161dd82e51 Mon Sep 17 00:00:00 2001 From: polaris Date: Fri, 18 Apr 2014 09:19:57 -0400 Subject: [PATCH] Modified NAS slightly I was having trouble with the base64 encoded data, so I replaced it with something that should definitely work. I also reduced the size of the auth token so there won't be any possible overflows. Since it's random data it can easily be adjusted in the future if for some reason it's too small. --- gamespy/gs_database.py | 10 +++++++--- nintendo_nas_server.py | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gamespy/gs_database.py b/gamespy/gs_database.py index 1d67df1..efe60b7 100644 --- a/gamespy/gs_database.py +++ b/gamespy/gs_database.py @@ -1,10 +1,12 @@ import sqlite3 import hashlib import itertools -import other.utils as utils import time import logging +import other.utils as utils +import gamespy.gs_utility as gs_utils + # Logger settings logger_output_to_console = True logger_output_to_file = True @@ -382,7 +384,9 @@ class GamespyDatabase(object): return r["data"] def generate_authtoken(self, userid, data): - size = 128 + # Since the auth token passed back to the game will be random, we can make it small enough that there + # should never be a crash due to the size of the token. + size = 16 authtoken = "NDS" + utils.generate_random_str(size) q = "SELECT authtoken FROM nas_logins WHERE authtoken = ?" @@ -412,7 +416,7 @@ class GamespyDatabase(object): c.execute(q, [authtoken, data, userid]) c.close() - self.conn.commit(); + self.conn.commit() return authtoken diff --git a/nintendo_nas_server.py b/nintendo_nas_server.py index 65ce707..76b52e0 100644 --- a/nintendo_nas_server.py +++ b/nintendo_nas_server.py @@ -75,9 +75,9 @@ class NintendoNasHTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler): logger.log(logging.DEBUG, ret) for k, v in ret.iteritems(): - ret[k] = self.base64_enc(v) + ret[k] = gs_utils.base64_encode(v) - self.wfile.write(urllib.urlencode(ret).replace("%2A", "*")) + self.wfile.write(urllib.urlencode(ret)) #elif self.path == "/pr": # TODO