pep.py/constants/clientPackets.py

146 lines
4.1 KiB
Python
Raw Normal View History

2016-04-19 17:40:59 +00:00
""" Contains functions used to read specific client packets from byte stream """
2016-05-18 17:12:46 +00:00
from constants import dataTypes
from helpers import packetHelper
from constants import slotStatuses
2016-04-19 17:40:59 +00:00
""" Users listing packets """
2016-04-19 17:40:59 +00:00
def userActionChange(stream):
return packetHelper.readPacketData(stream,
[
2016-09-02 15:16:22 +00:00
["actionID", dataTypes.BYTE],
["actionText", dataTypes.STRING],
["actionMd5", dataTypes.STRING],
["actionMods", dataTypes.UINT32],
["gameMode", dataTypes.BYTE],
["beatmapID", dataTypes.SINT32]
2016-04-19 17:40:59 +00:00
])
def userStatsRequest(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["users", dataTypes.INT_LIST]])
2016-06-17 15:43:49 +00:00
def userPanelRequest(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["users", dataTypes.INT_LIST]])
2016-04-19 17:40:59 +00:00
""" Client chat packets """
def sendPublicMessage(stream):
return packetHelper.readPacketData(stream,
[
2016-09-02 15:16:22 +00:00
["unknown", dataTypes.STRING],
["message", dataTypes.STRING],
["to", dataTypes.STRING]
2016-04-19 17:40:59 +00:00
])
def sendPrivateMessage(stream):
return packetHelper.readPacketData(stream,
[
2016-09-02 15:16:22 +00:00
["unknown", dataTypes.STRING],
["message", dataTypes.STRING],
["to", dataTypes.STRING],
["unknown2", dataTypes.UINT32]
2016-04-19 17:40:59 +00:00
])
def setAwayMessage(stream):
return packetHelper.readPacketData(stream,
[
2016-09-02 15:16:22 +00:00
["unknown", dataTypes.STRING],
["awayMessage", dataTypes.STRING]
2016-04-19 17:40:59 +00:00
])
def channelJoin(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["channel", dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def channelPart(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["channel", dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def addRemoveFriend(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["friendID", dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
""" Spectator packets """
2016-04-19 17:40:59 +00:00
def startSpectating(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["userID", dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
""" Multiplayer packets """
2016-04-19 17:40:59 +00:00
def matchSettings(stream):
# Data to return, will be merged later
data = []
# Some settings
struct = [
2016-09-02 15:16:22 +00:00
["matchID", dataTypes.UINT16],
["inProgress", dataTypes.BYTE],
["unknown", dataTypes.BYTE],
["mods", dataTypes.UINT32],
["matchName", dataTypes.STRING],
["matchPassword", dataTypes.STRING],
["beatmapName", dataTypes.STRING],
["beatmapID", dataTypes.UINT32],
["beatmapMD5", dataTypes.STRING]
2016-04-19 17:40:59 +00:00
]
# Slot statuses (not used)
for i in range(0,16):
2016-09-02 15:16:22 +00:00
struct.append(["slot{}Status".format(str(i)), dataTypes.BYTE])
2016-04-19 17:40:59 +00:00
# Slot statuses (not used)
for i in range(0,16):
2016-09-02 15:16:22 +00:00
struct.append(["slot{}Team".format(str(i)), dataTypes.BYTE])
2016-04-19 17:40:59 +00:00
# Read first part
data.append(packetHelper.readPacketData(stream, struct))
# Skip userIDs because fuck
start = 7+2+1+1+4+4+16+16+len(data[0]["matchName"])+len(data[0]["matchPassword"])+len(data[0]["beatmapMD5"])+len(data[0]["beatmapName"])
start += 1 if (data[0]["matchName"] == "") else 2
start += 1 if (data[0]["matchPassword"] == "") else 2
start += 2 # If beatmap name and MD5 don't change, the client sends \x0b\x00 istead of \x00 only, so always add 2. ...WHY!
start += 2
for i in range(0,16):
s = data[0]["slot{}Status".format(str(i))]
if s != slotStatuses.free and s != slotStatuses.locked:
start += 4
# Other settings
struct = [
2016-09-02 15:16:22 +00:00
["hostUserID", dataTypes.SINT32],
["gameMode", dataTypes.BYTE],
["scoringType", dataTypes.BYTE],
["teamType", dataTypes.BYTE],
["freeMods", dataTypes.BYTE],
2016-04-19 17:40:59 +00:00
]
# Read last part
data.append(packetHelper.readPacketData(stream[start:], struct, False))
result = {}
for i in data:
result.update(i)
return result
def createMatch(stream):
return matchSettings(stream)
def changeMatchSettings(stream):
return matchSettings(stream)
def changeSlot(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def joinMatch(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["matchID", dataTypes.UINT32], ["password", dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def changeMods(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["mods", dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def lockSlot(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def transferHost(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def matchInvite(stream):
2016-09-02 15:16:22 +00:00
return packetHelper.readPacketData(stream, [["userID", dataTypes.UINT32]])