mirror of
https://github.com/barronwaffles/dwc_network_server_emulator.git
synced 2026-04-26 17:16:52 -05:00
Added some exception catching for debugging
This commit is contained in:
parent
7ff0467d2a
commit
5a2bca3a57
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from twisted.internet.protocol import Factory
|
||||
from twisted.internet.endpoints import serverFromString
|
||||
|
|
@ -75,6 +76,7 @@ class Gamestats(LineReceiver):
|
|||
logger.log(level, "[%s:%d | %s | %s] %s", self.address.host, self.address.port, self.session, self.gameid, message)
|
||||
|
||||
def connectionMade(self):
|
||||
try:
|
||||
self.log(logging.INFO, "Received connection from %s:%d" % (self.address.host, self.address.port))
|
||||
|
||||
# Generate a random challenge string
|
||||
|
|
@ -92,11 +94,14 @@ class Gamestats(LineReceiver):
|
|||
|
||||
msg = self.crypt(msg)
|
||||
self.transport.write(bytes(msg))
|
||||
except:
|
||||
self.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def connectionLost(self, reason):
|
||||
return
|
||||
|
||||
def rawDataReceived(self, data):
|
||||
try:
|
||||
# Decrypt packet
|
||||
msg = self.remaining_message + str(self.crypt(data))
|
||||
self.data = msg
|
||||
|
|
@ -121,6 +126,8 @@ class Gamestats(LineReceiver):
|
|||
print(data_parsed)
|
||||
|
||||
cmds.get(data_parsed['__cmd__'], cmd_err)(data_parsed)
|
||||
except:
|
||||
self.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def perform_auth(self, data_parsed):
|
||||
self.log(logging.DEBUG, "Parsing 'auth'...")
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import time
|
|||
import Queue
|
||||
import gamespy.gs_utility as gs_utils
|
||||
import other.utils as utils
|
||||
import traceback
|
||||
|
||||
from multiprocessing.managers import BaseManager
|
||||
|
||||
|
|
@ -43,6 +44,7 @@ class GameSpyNatNegServer(object):
|
|||
self.server_manager.connect()
|
||||
|
||||
def start(self):
|
||||
try:
|
||||
# Start natneg server
|
||||
address = ('0.0.0.0', 27901) # accessible to outside connections (use this if you don't know what you're doing)
|
||||
|
||||
|
|
@ -58,6 +60,8 @@ class GameSpyNatNegServer(object):
|
|||
recv_data, addr = self.socket.recvfrom(2048)
|
||||
|
||||
self.handle_packet(recv_data, addr)
|
||||
except:
|
||||
logger.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def write_queue_send(self, data, address):
|
||||
time.sleep(0.05)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
import traceback
|
||||
|
||||
from twisted.internet.protocol import Factory
|
||||
from twisted.internet.endpoints import serverFromString
|
||||
|
|
@ -57,6 +58,7 @@ class PlayerSearch(LineReceiver):
|
|||
pass
|
||||
|
||||
def rawDataReceived(self, data):
|
||||
try:
|
||||
logger.log(logging.DEBUG, "SEARCH RESPONSE: %s" % data)
|
||||
|
||||
data = self.leftover + data
|
||||
|
|
@ -69,6 +71,8 @@ class PlayerSearch(LineReceiver):
|
|||
self.perform_otherslist(data_parsed)
|
||||
else:
|
||||
logger.log(logging.DEBUG, "Found unknown search command, don't know how to handle '%s'." % data_parsed['__cmd__'])
|
||||
except:
|
||||
logger.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def perform_otherslist(self, data_parsed):
|
||||
# Reference: http://wiki.tockdom.com/wiki/MKWii_Network_Protocol/Server/gpsp.gs.nintendowifi.net
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from twisted.internet.protocol import Factory
|
||||
from twisted.internet.endpoints import serverFromString
|
||||
|
|
@ -89,6 +90,7 @@ class PlayerSession(LineReceiver):
|
|||
return ipaddress
|
||||
|
||||
def connectionMade(self):
|
||||
try:
|
||||
self.transport.setTcpKeepAlive(1)
|
||||
|
||||
self.log(logging.INFO, "Received connection from %s:%d" % (self.address.host, self.address.port))
|
||||
|
|
@ -109,8 +111,11 @@ class PlayerSession(LineReceiver):
|
|||
|
||||
self.log(logging.DEBUG, "SENDING: '%s'..." % msg)
|
||||
self.transport.write(bytes(msg))
|
||||
except:
|
||||
self.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def connectionLost(self, reason):
|
||||
try:
|
||||
self.log(logging.INFO, "Client disconnected")
|
||||
|
||||
self.status = "0"
|
||||
|
|
@ -123,8 +128,11 @@ class PlayerSession(LineReceiver):
|
|||
|
||||
self.db.delete_session(self.session)
|
||||
self.log(logging.INFO, "Deleted session " + self.session)
|
||||
except:
|
||||
self.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def rawDataReceived(self, data):
|
||||
try:
|
||||
self.log(logging.DEBUG, "RESPONSE: '%s'..." % data)
|
||||
|
||||
# In the case where command string is too big to fit into one read, any parts that could not be successfully
|
||||
|
|
@ -162,6 +170,8 @@ class PlayerSession(LineReceiver):
|
|||
#self.log(-1, data_parsed)
|
||||
self.log(logging.DEBUG, data_parsed)
|
||||
cmds.get(data_parsed['__cmd__'], cmd_err)(data_parsed)
|
||||
except:
|
||||
self.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def perform_login(self, data_parsed):
|
||||
authtoken_parsed = gs_utils.parse_authtoken(data_parsed['authtoken'], self.db)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import threading
|
|||
import time
|
||||
import ctypes
|
||||
import Queue
|
||||
import traceback
|
||||
|
||||
from multiprocessing.managers import BaseManager
|
||||
|
||||
|
|
@ -60,6 +61,7 @@ class GameSpyQRServer(object):
|
|||
logger.log(level, "[%s:%d] %s", address[0], address[1], message)
|
||||
|
||||
def start(self):
|
||||
try:
|
||||
manager_address = ("127.0.0.1", 27500)
|
||||
manager_password = ""
|
||||
|
||||
|
|
@ -80,7 +82,7 @@ class GameSpyQRServer(object):
|
|||
server_browser_server_thread = threading.Thread(target=server_browser_server.start)
|
||||
server_browser_server_thread.start()
|
||||
|
||||
self.write_queue = Queue.Queue();
|
||||
self.write_queue = Queue.Queue()
|
||||
self.db = gs_database.GamespyDatabase()
|
||||
threading.Thread(target=self.write_queue_worker).start()
|
||||
|
||||
|
|
@ -92,6 +94,8 @@ class GameSpyQRServer(object):
|
|||
self.handle_packet(self.socket, recv_data, address)
|
||||
|
||||
self.keepalive_check()
|
||||
except:
|
||||
logger.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def write_queue_send(self, data, address):
|
||||
time.sleep(0.05)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
import logging
|
||||
import socket
|
||||
import ctypes
|
||||
import traceback
|
||||
|
||||
from twisted.internet.protocol import Factory
|
||||
from twisted.internet.endpoints import serverFromString
|
||||
|
|
@ -97,6 +98,7 @@ class Session(LineReceiver):
|
|||
logger.log(level, "[%s:%d] %s", self.address.host, self.address.port,message)
|
||||
|
||||
def rawDataReceived(self, data):
|
||||
try:
|
||||
# First 2 bytes are the packet size.
|
||||
#
|
||||
# Third byte is the command byte.
|
||||
|
|
@ -234,6 +236,8 @@ class Session(LineReceiver):
|
|||
self.log(logging.DEBUG, "Received unknown command (%02x) from %s:%s..." % (ord(data[2]), self.address.host, self.address.port))
|
||||
self.log(logging.DEBUG, utils.pretty_print_hex(bytearray(data)))
|
||||
self.log(logging.DEBUG, utils.pretty_print_hex(data))
|
||||
except:
|
||||
self.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def get_game_id(self, data):
|
||||
game_id = data[5: -1]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import urlparse
|
|||
import BaseHTTPServer
|
||||
import os
|
||||
import random
|
||||
import traceback
|
||||
|
||||
import gamespy.gs_database as gs_database
|
||||
import gamespy.gs_utility as gs_utils
|
||||
|
|
@ -40,6 +41,7 @@ class NasHTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
return "Nintendo Wii (http)"
|
||||
|
||||
def do_GET(self):
|
||||
try:
|
||||
# conntest server
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/html")
|
||||
|
|
@ -47,8 +49,11 @@ class NasHTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_header("Server", "BigIP")
|
||||
self.end_headers()
|
||||
self.wfile.write("ok")
|
||||
except:
|
||||
logger.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def do_POST(self):
|
||||
try:
|
||||
length = int(self.headers['content-length'])
|
||||
post = self.str_to_dict(self.rfile.read(length))
|
||||
ret = ''
|
||||
|
|
@ -242,6 +247,8 @@ class NasHTTPServerHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_header("Content-Length", str(len(ret)))
|
||||
self.end_headers()
|
||||
self.wfile.write(ret)
|
||||
except:
|
||||
logger.log(logging.ERROR, "Unknown exception: %s" % traceback.format_exc())
|
||||
|
||||
def str_to_dict(self, str):
|
||||
ret = urlparse.parse_qs(str)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user