mirror of
https://github.com/barronwaffles/dwc_network_server_emulator.git
synced 2026-04-20 15:47:32 -05:00
create_gamespy_message refactored
This commit is contained in:
parent
89495cabc1
commit
f77afa38eb
|
|
@ -123,26 +123,21 @@ def create_gamespy_message_from_list(messages):
|
|||
|
||||
def create_gamespy_message(messages, id=None):
|
||||
"""Create a message based on a dictionary (or list) of parameters."""
|
||||
query = ""
|
||||
|
||||
if isinstance(messages, dict):
|
||||
messages = create_gamespy_message_from_dict(messages)
|
||||
|
||||
# Check for an id if the id needs to be updated.
|
||||
# If it already exists in the list then update it, else add it
|
||||
if id is not None:
|
||||
for message in messages:
|
||||
for i, message in enumerate(messages):
|
||||
# If it already exists in the list then update it
|
||||
if message[0] == "id":
|
||||
messages.pop(messages.index(message))
|
||||
messages.append(("id", str(id)))
|
||||
id = None # Updated id, so don't add it to the query later
|
||||
break # Found id, stop searching list
|
||||
messages[i] = ("id", str(id))
|
||||
break
|
||||
else:
|
||||
# Otherwise, add it in the list
|
||||
messages.append(("id", str(id)))
|
||||
|
||||
query = create_gamespy_message_from_list(messages)
|
||||
|
||||
if id is not None:
|
||||
query += create_gamespy_message_from_list([("id", id)])
|
||||
|
||||
query += "\\final\\"
|
||||
|
||||
return query
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user