mirror of
https://github.com/barronwaffles/dwc_network_server_emulator.git
synced 2026-07-19 16:51:29 -05:00
More list literals (listerals?)
This commit is contained in:
parent
c95bebb911
commit
2c631489e5
|
|
@ -100,12 +100,12 @@ class PlayerSession(LineReceiver):
|
|||
self.challenge = utils.generate_random_str(10, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
|
||||
# The first command sent to the client is always a login challenge containing the server challenge key.
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "lc"))
|
||||
msg_d.append(('__cmd_val__', "1"))
|
||||
msg_d.append(('challenge', self.challenge))
|
||||
msg_d.append(('id', "1"))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "lc"),
|
||||
('__cmd_val__', "1"),
|
||||
('challenge', self.challenge),
|
||||
('id', "1"),
|
||||
])
|
||||
|
||||
self.log(logging.DEBUG, "SENDING: '%s'..." % msg)
|
||||
self.transport.write(bytes(msg))
|
||||
|
|
@ -142,33 +142,26 @@ class PlayerSession(LineReceiver):
|
|||
|
||||
commands, self.remaining_message = gs_query.parse_gamespy_message(data)
|
||||
|
||||
cmds = {
|
||||
"login": self.perform_login,
|
||||
"logout": self.perform_logout,
|
||||
"getprofile": self.perform_getprofile,
|
||||
"updatepro": self.perform_updatepro,
|
||||
"ka": self.perform_ka,
|
||||
"status": self.perform_status,
|
||||
"bm": self.perform_bm,
|
||||
"addbuddy": self.perform_addbuddy,
|
||||
"delbuddy": self.perform_delbuddy,
|
||||
"authadd": self.perform_authadd,
|
||||
}
|
||||
def cmd_err(data_parsed):
|
||||
# Maybe write unknown commands to a separate file later so new data can be collected more easily?
|
||||
self.log(logging.ERROR, "Found unknown command, don't know how to handle '%s'." % data_parsed['__cmd__'])
|
||||
|
||||
for data_parsed in commands:
|
||||
#self.log(-1, data_parsed)
|
||||
self.log(logging.DEBUG, data_parsed)
|
||||
|
||||
if data_parsed['__cmd__'] == "login":
|
||||
self.perform_login(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "logout":
|
||||
self.perform_logout(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "getprofile":
|
||||
self.perform_getprofile(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "updatepro":
|
||||
self.perform_updatepro(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "ka":
|
||||
self.perform_ka(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "status":
|
||||
self.perform_status(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "bm":
|
||||
self.perform_bm(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "addbuddy":
|
||||
self.perform_addbuddy(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "delbuddy":
|
||||
self.perform_delbuddy(data_parsed)
|
||||
elif data_parsed['__cmd__'] == "authadd":
|
||||
self.perform_authadd(data_parsed)
|
||||
else:
|
||||
# Maybe write unknown commands to a separate file later so new data can be collected more easily?
|
||||
self.log(logging.ERROR, "Found unknown command, don't know how to handle '%s'." % data_parsed['__cmd__'])
|
||||
cmds.get(data_parsed['__cmd__'], cmd_err)(data_parsed)
|
||||
|
||||
def perform_login(self, data_parsed):
|
||||
authtoken_parsed = gs_utils.parse_authtoken(data_parsed['authtoken'], self.db)
|
||||
|
|
@ -249,17 +242,18 @@ class PlayerSession(LineReceiver):
|
|||
|
||||
self.sessions[profileid] = self
|
||||
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "lc"))
|
||||
msg_d.append(('__cmd_val__', "2"))
|
||||
msg_d.append(('sesskey', self.sesskey))
|
||||
msg_d.append(('proof', proof))
|
||||
msg_d.append(('userid', userid))
|
||||
msg_d.append(('profileid', profileid))
|
||||
msg_d.append(('uniquenick', uniquenick))
|
||||
msg_d.append(('lt', loginticket)) # Some kind of token... don't know it gets used or generated, but it doesn't seem to have any negative effects if it's not properly generated.
|
||||
msg_d.append(('id', data_parsed['id']))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "lc"),
|
||||
('__cmd_val__', "2"),
|
||||
('sesskey', self.sesskey),
|
||||
('proof', proof),
|
||||
('userid', userid),
|
||||
('profileid', profileid),
|
||||
('uniquenick', uniquenick),
|
||||
# Some kind of token... don't know it gets used or generated, but it doesn't seem to have any negative effects if it's not properly generated.
|
||||
('lt', loginticket),
|
||||
('id', data_parsed['id']),
|
||||
])
|
||||
|
||||
# Take the first 4 letters of gsbrcd instead of gamecd because they should be consistent across game
|
||||
# regions. For example, the US version of Metroid Prime Hunters has the gamecd "AMHE" and the first 4 letters
|
||||
|
|
@ -268,7 +262,7 @@ class PlayerSession(LineReceiver):
|
|||
# Japanese version (ATRJ) while the gamecd is region specific (ATRE for US and ATRJ for JP).
|
||||
# gameid is used to send all people on the player's friends list a status updates, so don't make it region
|
||||
# specific.
|
||||
self.gameid = gsbrcd[0:4]
|
||||
self.gameid = gsbrcd[:4]
|
||||
self.profileid = int(profileid)
|
||||
|
||||
self.log(logging.DEBUG, "SENDING: %s" % msg)
|
||||
|
|
@ -306,16 +300,17 @@ class PlayerSession(LineReceiver):
|
|||
# Wii example: \pi\\profileid\474888031\nick\5pde5vhn1WR9E2g1t533\userid\442778352\email\5pde5vhn1WR9E2g1t533@nds\sig\b126556e5ee62d4da9629dfad0f6b2a8\uniquenick\5pde5vhn1WR9E2g1t533\pid\11\lon\0.000000\lat\0.000000\loc\\id\2\final\
|
||||
sig = utils.generate_random_hex_str(32)
|
||||
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "pi"))
|
||||
msg_d.append(('__cmd_val__', ""))
|
||||
msg_d.append(('profileid', profile['profileid']))
|
||||
msg_d.append(('nick', profile['uniquenick']))
|
||||
msg_d.append(('userid', profile['userid']))
|
||||
msg_d.append(('email', profile['email']))
|
||||
msg_d.append(('sig', sig))
|
||||
msg_d.append(('uniquenick', profile['uniquenick']))
|
||||
msg_d.append(('pid', profile['pid']))
|
||||
msg_d = [
|
||||
('__cmd__', "pi"),
|
||||
('__cmd_val__', ""),
|
||||
('profileid', profile['profileid']),
|
||||
('nick', profile['uniquenick']),
|
||||
('userid', profile['userid']),
|
||||
('email', profile['email']),
|
||||
('sig', sig),
|
||||
('uniquenick', profile['uniquenick']),
|
||||
('pid', profile['pid']),
|
||||
]
|
||||
|
||||
if profile['firstname'] != "":
|
||||
msg_d.append(('firstname', profile['firstname'])) # Wii gets a firstname
|
||||
|
|
@ -323,10 +318,12 @@ class PlayerSession(LineReceiver):
|
|||
if profile['lastname'] != "":
|
||||
msg_d.append(('lastname', profile['lastname']))
|
||||
|
||||
msg_d.append(('lon', profile['lon']))
|
||||
msg_d.append(('lat', profile['lat']))
|
||||
msg_d.append(('loc', profile['loc']))
|
||||
msg_d.append(('id', data_parsed['id']))
|
||||
msg_d.extend([
|
||||
('lon', profile['lon']),
|
||||
('lat', profile['lat']),
|
||||
('loc', profile['loc']),
|
||||
('id', data_parsed['id']),
|
||||
])
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
|
||||
self.log(logging.DEBUG, "SENDING: %s" % msg)
|
||||
|
|
@ -356,10 +353,10 @@ class PlayerSession(LineReceiver):
|
|||
def perform_ka(self, data_parsed):
|
||||
self.keepalive = int(time.time())
|
||||
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "ka"))
|
||||
msg_d.append(('__cmd_val__', ""))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "ka"),
|
||||
('__cmd_val__', ""),
|
||||
])
|
||||
self.transport.write(msg)
|
||||
|
||||
|
||||
|
|
@ -371,10 +368,11 @@ class PlayerSession(LineReceiver):
|
|||
self.statstring = data_parsed['statstring']
|
||||
self.locstring = data_parsed['locstring']
|
||||
|
||||
# fields = []
|
||||
# #fields.append(("status", self.status))
|
||||
# fields.append(("stat", self.statstring))
|
||||
# fields.append(("loc", self.locstring))
|
||||
# fields = [
|
||||
# #("status", self.status),
|
||||
# ("stat", self.statstring),
|
||||
# ("loc", self.locstring),
|
||||
# ]
|
||||
#
|
||||
# for f in fields:
|
||||
# self.db.update_profile(self.sesskey, f)
|
||||
|
|
@ -389,7 +387,7 @@ class PlayerSession(LineReceiver):
|
|||
|
||||
|
||||
def perform_bm(self, data_parsed):
|
||||
if data_parsed['__cmd_val__'] == "1" or data_parsed['__cmd_val__'] == "5" or data_parsed['__cmd_val__'] == "102" or data_parsed['__cmd_val__'] == "103": # Message to/from clients?
|
||||
if data_parsed['__cmd_val__'] in ("1", "5", "102", "103"): # Message to/from clients?
|
||||
if "t" in data_parsed:
|
||||
# Send message to the profile id in "t"
|
||||
dest_profileid = int(data_parsed['t'])
|
||||
|
|
@ -413,23 +411,23 @@ class PlayerSession(LineReceiver):
|
|||
|
||||
# Send error to user if they tried to send a message to someone who isn't a buddy.
|
||||
if not_buddies:
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "error"))
|
||||
msg_d.append(('__cmd_val__', ""))
|
||||
msg_d.append(('err', 2305))
|
||||
msg_d.append(('errmsg', "The profile the message was to be sent to is not a buddy."))
|
||||
msg_d.append(('id', 1))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "error"),
|
||||
('__cmd_val__', ""),
|
||||
('err', 2305),
|
||||
('errmsg', "The profile the message was to be sent to is not a buddy."),
|
||||
('id', 1),
|
||||
])
|
||||
logger.log(logging.DEBUG, "Trying to send message to someone who isn't a buddy: %s" % msg)
|
||||
self.transport.write(msg)
|
||||
return
|
||||
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "bm"))
|
||||
msg_d.append(('__cmd_val__', "1"))
|
||||
msg_d.append(('f', self.profileid))
|
||||
msg_d.append(('msg', dest_msg))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "bm"),
|
||||
('__cmd_val__', "1"),
|
||||
('f', self.profileid),
|
||||
('msg', dest_msg),
|
||||
])
|
||||
|
||||
if dest_profileid in self.sessions:
|
||||
self.log(logging.DEBUG, "SENDING TO %s:%s: %s" % (self.sessions[dest_profileid].address.host, self.sessions[dest_profileid].address.port, msg))
|
||||
|
|
@ -439,13 +437,13 @@ class PlayerSession(LineReceiver):
|
|||
self.log(logging.DEBUG, "Saving message to %d: %s" % (dest_profileid, msg))
|
||||
self.db.save_pending_message(self.profileid, dest_profileid, msg)
|
||||
else:
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "error"))
|
||||
msg_d.append(('__cmd_val__', ""))
|
||||
msg_d.append(('err', 2307))
|
||||
msg_d.append(('errmsg', "The buddy to send a message to is offline."))
|
||||
msg_d.append(('id', 1))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "error"),
|
||||
('__cmd_val__', ""),
|
||||
('err', 2307),
|
||||
('errmsg', "The buddy to send a message to is offline."),
|
||||
('id', 1),
|
||||
])
|
||||
logger.log(logging.DEBUG, "Trying to send message to someone who isn't online: %s" % msg)
|
||||
self.transport.write(msg)
|
||||
|
||||
|
|
@ -494,12 +492,12 @@ class PlayerSession(LineReceiver):
|
|||
else:
|
||||
status_msg = "|s|%s|ss|%s|ls|%s|ip|%d|p|0|qm|0" % (self.status, self.statstring, self.locstring, self.get_ip_as_int(self.address.host))
|
||||
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "bm"))
|
||||
msg_d.append(('__cmd_val__', "100"))
|
||||
msg_d.append(('f', self.profileid))
|
||||
msg_d.append(('msg', status_msg))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "bm"),
|
||||
('__cmd_val__', "100"),
|
||||
('f', self.profileid),
|
||||
('msg', status_msg),
|
||||
])
|
||||
|
||||
for buddy in self.buddies:
|
||||
if buddy['buddyProfileId'] in self.sessions:
|
||||
|
|
@ -519,12 +517,12 @@ class PlayerSession(LineReceiver):
|
|||
else:
|
||||
status_msg = "|s|0|ss|Offline"
|
||||
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "bm"))
|
||||
msg_d.append(('__cmd_val__', "100"))
|
||||
msg_d.append(('f', buddy['buddyProfileId']))
|
||||
msg_d.append(('msg', status_msg))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "bm"),
|
||||
('__cmd_val__', "100"),
|
||||
('f', buddy['buddyProfileId']),
|
||||
('msg', status_msg),
|
||||
])
|
||||
|
||||
self.transport.write(bytes(msg))
|
||||
|
||||
|
|
@ -532,12 +530,12 @@ class PlayerSession(LineReceiver):
|
|||
buddies = self.db.buddy_need_auth_message(self.profileid)
|
||||
|
||||
for buddy in buddies:
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "bm"))
|
||||
msg_d.append(('__cmd_val__', "1"))
|
||||
msg_d.append(('f', buddy['userProfileId']))
|
||||
msg_d.append(('msg', "I have authorized your request to add me to your list"))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "bm"),
|
||||
('__cmd_val__', "1"),
|
||||
('f', buddy['userProfileId']),
|
||||
('msg', "I have authorized your request to add me to your list"),
|
||||
])
|
||||
|
||||
self.transport.write(bytes(msg))
|
||||
self.db.buddy_sent_auth_message(buddy['userProfileId'], buddy['buddyProfileId'])
|
||||
|
|
@ -557,13 +555,13 @@ class PlayerSession(LineReceiver):
|
|||
if senttime == None:
|
||||
senttime = int(time.time())
|
||||
|
||||
msg_d = []
|
||||
msg_d.append(('__cmd__', "bm"))
|
||||
msg_d.append(('__cmd_val__', "2"))
|
||||
msg_d.append(('f', profileid))
|
||||
msg_d.append(('date', senttime))
|
||||
msg_d.append(('msg', msg))
|
||||
msg = gs_query.create_gamespy_message(msg_d)
|
||||
msg = gs_query.create_gamespy_message([
|
||||
('__cmd__', "bm"),
|
||||
('__cmd_val__', "2"),
|
||||
('f', profileid),
|
||||
('date', senttime),
|
||||
('msg', msg),
|
||||
])
|
||||
|
||||
session.transport.write(bytes(msg))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user