.BANCHO. Some code refactoring
This commit is contained in:
parent
653303831b
commit
3703618112
|
@ -1,17 +1,16 @@
|
||||||
"""Contains user actions"""
|
"""Contains user actions"""
|
||||||
#TODO: Uppercase
|
IDLE = 0
|
||||||
idle = 0
|
AFK = 1
|
||||||
afk = 1
|
PLAYING = 2
|
||||||
playing = 2
|
EDITING = 3
|
||||||
editing = 3
|
MODDING = 4
|
||||||
modding = 4
|
MULTIPLAYER = 5
|
||||||
multiplayer = 5
|
WATCHING = 6
|
||||||
watching = 6
|
UNKNOWN = 7
|
||||||
unknown = 7
|
TESTING = 8
|
||||||
testing = 8
|
SUBMITTING = 9
|
||||||
submitting = 9
|
PAUSED = 10
|
||||||
paused = 10
|
LOBBY = 11
|
||||||
lobby = 11
|
MULTIPLAYING= 12
|
||||||
multiplaying= 12
|
OSU_DIRECT = 13
|
||||||
osuDirect = 13
|
NONE = 14
|
||||||
none = 14
|
|
||||||
|
|
|
@ -8,58 +8,58 @@ from constants import slotStatuses
|
||||||
def userActionChange(stream):
|
def userActionChange(stream):
|
||||||
return packetHelper.readPacketData(stream,
|
return packetHelper.readPacketData(stream,
|
||||||
[
|
[
|
||||||
["actionID", dataTypes.byte],
|
["actionID", dataTypes.BYTE],
|
||||||
["actionText", dataTypes.string],
|
["actionText", dataTypes.STRING],
|
||||||
["actionMd5", dataTypes.string],
|
["actionMd5", dataTypes.STRING],
|
||||||
["actionMods", dataTypes.uInt32],
|
["actionMods", dataTypes.UINT32],
|
||||||
["gameMode", dataTypes.byte]
|
["gameMode", dataTypes.BYTE]
|
||||||
])
|
])
|
||||||
|
|
||||||
def userStatsRequest(stream):
|
def userStatsRequest(stream):
|
||||||
return packetHelper.readPacketData(stream, [["users", dataTypes.intList]])
|
return packetHelper.readPacketData(stream, [["users", dataTypes.INT_LIST]])
|
||||||
|
|
||||||
def userPanelRequest(stream):
|
def userPanelRequest(stream):
|
||||||
return packetHelper.readPacketData(stream, [["users", dataTypes.intList]])
|
return packetHelper.readPacketData(stream, [["users", dataTypes.INT_LIST]])
|
||||||
|
|
||||||
|
|
||||||
""" Client chat packets """
|
""" Client chat packets """
|
||||||
def sendPublicMessage(stream):
|
def sendPublicMessage(stream):
|
||||||
return packetHelper.readPacketData(stream,
|
return packetHelper.readPacketData(stream,
|
||||||
[
|
[
|
||||||
["unknown", dataTypes.string],
|
["unknown", dataTypes.STRING],
|
||||||
["message", dataTypes.string],
|
["message", dataTypes.STRING],
|
||||||
["to", dataTypes.string]
|
["to", dataTypes.STRING]
|
||||||
])
|
])
|
||||||
|
|
||||||
def sendPrivateMessage(stream):
|
def sendPrivateMessage(stream):
|
||||||
return packetHelper.readPacketData(stream,
|
return packetHelper.readPacketData(stream,
|
||||||
[
|
[
|
||||||
["unknown", dataTypes.string],
|
["unknown", dataTypes.STRING],
|
||||||
["message", dataTypes.string],
|
["message", dataTypes.STRING],
|
||||||
["to", dataTypes.string],
|
["to", dataTypes.STRING],
|
||||||
["unknown2", dataTypes.uInt32]
|
["unknown2", dataTypes.UINT32]
|
||||||
])
|
])
|
||||||
|
|
||||||
def setAwayMessage(stream):
|
def setAwayMessage(stream):
|
||||||
return packetHelper.readPacketData(stream,
|
return packetHelper.readPacketData(stream,
|
||||||
[
|
[
|
||||||
["unknown", dataTypes.string],
|
["unknown", dataTypes.STRING],
|
||||||
["awayMessage", dataTypes.string]
|
["awayMessage", dataTypes.STRING]
|
||||||
])
|
])
|
||||||
|
|
||||||
def channelJoin(stream):
|
def channelJoin(stream):
|
||||||
return packetHelper.readPacketData(stream,[["channel", dataTypes.string]])
|
return packetHelper.readPacketData(stream, [["channel", dataTypes.STRING]])
|
||||||
|
|
||||||
def channelPart(stream):
|
def channelPart(stream):
|
||||||
return packetHelper.readPacketData(stream,[["channel", dataTypes.string]])
|
return packetHelper.readPacketData(stream, [["channel", dataTypes.STRING]])
|
||||||
|
|
||||||
def addRemoveFriend(stream):
|
def addRemoveFriend(stream):
|
||||||
return packetHelper.readPacketData(stream, [["friendID", dataTypes.sInt32]])
|
return packetHelper.readPacketData(stream, [["friendID", dataTypes.SINT32]])
|
||||||
|
|
||||||
|
|
||||||
""" Spectator packets """
|
""" Spectator packets """
|
||||||
def startSpectating(stream):
|
def startSpectating(stream):
|
||||||
return packetHelper.readPacketData(stream,[["userID", dataTypes.sInt32]])
|
return packetHelper.readPacketData(stream, [["userID", dataTypes.SINT32]])
|
||||||
|
|
||||||
|
|
||||||
""" Multiplayer packets """
|
""" Multiplayer packets """
|
||||||
|
@ -69,24 +69,24 @@ def matchSettings(stream):
|
||||||
|
|
||||||
# Some settings
|
# Some settings
|
||||||
struct = [
|
struct = [
|
||||||
["matchID", dataTypes.uInt16],
|
["matchID", dataTypes.UINT16],
|
||||||
["inProgress", dataTypes.byte],
|
["inProgress", dataTypes.BYTE],
|
||||||
["unknown", dataTypes.byte],
|
["unknown", dataTypes.BYTE],
|
||||||
["mods", dataTypes.uInt32],
|
["mods", dataTypes.UINT32],
|
||||||
["matchName", dataTypes.string],
|
["matchName", dataTypes.STRING],
|
||||||
["matchPassword", dataTypes.string],
|
["matchPassword", dataTypes.STRING],
|
||||||
["beatmapName", dataTypes.string],
|
["beatmapName", dataTypes.STRING],
|
||||||
["beatmapID", dataTypes.uInt32],
|
["beatmapID", dataTypes.UINT32],
|
||||||
["beatmapMD5", dataTypes.string]
|
["beatmapMD5", dataTypes.STRING]
|
||||||
]
|
]
|
||||||
|
|
||||||
# Slot statuses (not used)
|
# Slot statuses (not used)
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
struct.append(["slot{}Status".format(str(i)), dataTypes.byte])
|
struct.append(["slot{}Status".format(str(i)), dataTypes.BYTE])
|
||||||
|
|
||||||
# Slot statuses (not used)
|
# Slot statuses (not used)
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
struct.append(["slot{}Team".format(str(i)), dataTypes.byte])
|
struct.append(["slot{}Team".format(str(i)), dataTypes.BYTE])
|
||||||
|
|
||||||
# Read first part
|
# Read first part
|
||||||
data.append(packetHelper.readPacketData(stream, struct))
|
data.append(packetHelper.readPacketData(stream, struct))
|
||||||
|
@ -104,11 +104,11 @@ def matchSettings(stream):
|
||||||
|
|
||||||
# Other settings
|
# Other settings
|
||||||
struct = [
|
struct = [
|
||||||
["hostUserID", dataTypes.sInt32],
|
["hostUserID", dataTypes.SINT32],
|
||||||
["gameMode", dataTypes.byte],
|
["gameMode", dataTypes.BYTE],
|
||||||
["scoringType", dataTypes.byte],
|
["scoringType", dataTypes.BYTE],
|
||||||
["teamType", dataTypes.byte],
|
["teamType", dataTypes.BYTE],
|
||||||
["freeMods", dataTypes.byte],
|
["freeMods", dataTypes.BYTE],
|
||||||
]
|
]
|
||||||
|
|
||||||
# Read last part
|
# Read last part
|
||||||
|
@ -126,19 +126,19 @@ def changeMatchSettings(stream):
|
||||||
return matchSettings(stream)
|
return matchSettings(stream)
|
||||||
|
|
||||||
def changeSlot(stream):
|
def changeSlot(stream):
|
||||||
return packetHelper.readPacketData(stream, [["slotID", dataTypes.uInt32]])
|
return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
|
||||||
|
|
||||||
def joinMatch(stream):
|
def joinMatch(stream):
|
||||||
return packetHelper.readPacketData(stream, [["matchID", dataTypes.uInt32], ["password", dataTypes.string]])
|
return packetHelper.readPacketData(stream, [["matchID", dataTypes.UINT32], ["password", dataTypes.STRING]])
|
||||||
|
|
||||||
def changeMods(stream):
|
def changeMods(stream):
|
||||||
return packetHelper.readPacketData(stream, [["mods", dataTypes.uInt32]])
|
return packetHelper.readPacketData(stream, [["mods", dataTypes.UINT32]])
|
||||||
|
|
||||||
def lockSlot(stream):
|
def lockSlot(stream):
|
||||||
return packetHelper.readPacketData(stream, [["slotID", dataTypes.uInt32]])
|
return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
|
||||||
|
|
||||||
def transferHost(stream):
|
def transferHost(stream):
|
||||||
return packetHelper.readPacketData(stream, [["slotID", dataTypes.uInt32]])
|
return packetHelper.readPacketData(stream, [["slotID", dataTypes.UINT32]])
|
||||||
|
|
||||||
def matchInvite(stream):
|
def matchInvite(stream):
|
||||||
return packetHelper.readPacketData(stream, [["userID", dataTypes.uInt32]])
|
return packetHelper.readPacketData(stream, [["userID", dataTypes.UINT32]])
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
"""Bancho packets data types"""
|
"""Bancho packets data types"""
|
||||||
#TODO: Uppercase, maybe?
|
BYTE = 0
|
||||||
byte = 0
|
UINT16 = 1
|
||||||
uInt16 = 1
|
SINT16 = 2
|
||||||
sInt16 = 2
|
UINT32 = 3
|
||||||
uInt32 = 3
|
SINT32 = 4
|
||||||
sInt32 = 4
|
UINT64 = 5
|
||||||
uInt64 = 5
|
SINT64 = 6
|
||||||
sInt64 = 6
|
STRING = 7
|
||||||
string = 7
|
FFLOAT = 8 # because float is a keyword
|
||||||
ffloat = 8 # because float is a keyword
|
BBYTES = 9
|
||||||
bbytes = 9
|
INT_LIST = 10 # TODO: Maybe there are some packets that still use uInt16 + uInt32 thing somewhere.
|
||||||
intList = 10 # TODO: Maybe there are some packets that still use uInt16 + uInt32 thing somewhere.
|
|
||||||
|
|
|
@ -9,38 +9,38 @@ from constants import privileges
|
||||||
|
|
||||||
""" Login errors packets """
|
""" Login errors packets """
|
||||||
def loginFailed():
|
def loginFailed():
|
||||||
return packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
|
||||||
|
|
||||||
def forceUpdate():
|
def forceUpdate():
|
||||||
return packetHelper.buildPacket(packetIDs.server_userID, [[-2, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_userID, [[-2, dataTypes.SINT32]])
|
||||||
|
|
||||||
def loginBanned():
|
def loginBanned():
|
||||||
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.sInt32]])
|
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
|
||||||
packets += notification("You are banned. You can ask to get unbanned after 1 month since your ban by contacting support@ripple.moe")
|
packets += notification("You are banned. You can ask to get unbanned after 1 month since your ban by contacting support@ripple.moe")
|
||||||
return packets
|
return packets
|
||||||
|
|
||||||
def loginError():
|
def loginError():
|
||||||
return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.SINT32]])
|
||||||
|
|
||||||
def needSupporter():
|
def needSupporter():
|
||||||
return packetHelper.buildPacket(packetIDs.server_userID, [[-6, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_userID, [[-6, dataTypes.SINT32]])
|
||||||
|
|
||||||
def needVerification():
|
def needVerification():
|
||||||
return packetHelper.buildPacket(packetIDs.server_userID, [[-8, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_userID, [[-8, dataTypes.SINT32]])
|
||||||
|
|
||||||
|
|
||||||
""" Login packets """
|
""" Login packets """
|
||||||
def userID(uid):
|
def userID(uid):
|
||||||
return packetHelper.buildPacket(packetIDs.server_userID, [[uid, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_userID, [[uid, dataTypes.SINT32]])
|
||||||
|
|
||||||
def silenceEndTime(seconds):
|
def silenceEndTime(seconds):
|
||||||
return packetHelper.buildPacket(packetIDs.server_silenceEnd, [[seconds, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_silenceEnd, [[seconds, dataTypes.UINT32]])
|
||||||
|
|
||||||
def protocolVersion(version = 19):
|
def protocolVersion(version = 19):
|
||||||
return packetHelper.buildPacket(packetIDs.server_protocolVersion, [[version, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_protocolVersion, [[version, dataTypes.UINT32]])
|
||||||
|
|
||||||
def mainMenuIcon(icon):
|
def mainMenuIcon(icon):
|
||||||
return packetHelper.buildPacket(packetIDs.server_mainMenuIcon, [[icon, dataTypes.string]])
|
return packetHelper.buildPacket(packetIDs.server_mainMenuIcon, [[icon, dataTypes.STRING]])
|
||||||
|
|
||||||
def userSupporterGMT(supporter, GMT):
|
def userSupporterGMT(supporter, GMT):
|
||||||
result = 1
|
result = 1
|
||||||
|
@ -48,11 +48,11 @@ def userSupporterGMT(supporter, GMT):
|
||||||
result += 4
|
result += 4
|
||||||
if GMT == True:
|
if GMT == True:
|
||||||
result += 2
|
result += 2
|
||||||
return packetHelper.buildPacket(packetIDs.server_supporterGMT, [[result, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_supporterGMT, [[result, dataTypes.UINT32]])
|
||||||
|
|
||||||
def friendList(userID):
|
def friendList(userID):
|
||||||
friends = userHelper.getFriendList(userID)
|
friends = userHelper.getFriendList(userID)
|
||||||
return packetHelper.buildPacket(packetIDs.server_friendsList, [[friends, dataTypes.intList]])
|
return packetHelper.buildPacket(packetIDs.server_friendsList, [[friends, dataTypes.INT_LIST]])
|
||||||
|
|
||||||
def onlineUsers():
|
def onlineUsers():
|
||||||
userIDs = []
|
userIDs = []
|
||||||
|
@ -63,12 +63,12 @@ def onlineUsers():
|
||||||
if value.restricted == False:
|
if value.restricted == False:
|
||||||
userIDs.append(value.userID)
|
userIDs.append(value.userID)
|
||||||
|
|
||||||
return packetHelper.buildPacket(packetIDs.server_userPresenceBundle, [[userIDs, dataTypes.intList]])
|
return packetHelper.buildPacket(packetIDs.server_userPresenceBundle, [[userIDs, dataTypes.INT_LIST]])
|
||||||
|
|
||||||
|
|
||||||
""" Users packets """
|
""" Users packets """
|
||||||
def userLogout(userID):
|
def userLogout(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_userLogout, [[userID, dataTypes.sInt32], [0, dataTypes.byte]])
|
return packetHelper.buildPacket(packetIDs.server_userLogout, [[userID, dataTypes.SINT32], [0, dataTypes.BYTE]])
|
||||||
|
|
||||||
def userPanel(userID, force = False):
|
def userPanel(userID, force = False):
|
||||||
# Connected and restricted check
|
# Connected and restricted check
|
||||||
|
@ -101,14 +101,14 @@ def userPanel(userID, force = False):
|
||||||
|
|
||||||
return packetHelper.buildPacket(packetIDs.server_userPanel,
|
return packetHelper.buildPacket(packetIDs.server_userPanel,
|
||||||
[
|
[
|
||||||
[userID, dataTypes.sInt32],
|
[userID, dataTypes.SINT32],
|
||||||
[username, dataTypes.string],
|
[username, dataTypes.STRING],
|
||||||
[timezone, dataTypes.byte],
|
[timezone, dataTypes.BYTE],
|
||||||
[country, dataTypes.byte],
|
[country, dataTypes.BYTE],
|
||||||
[userRank, dataTypes.byte],
|
[userRank, dataTypes.BYTE],
|
||||||
[longitude, dataTypes.ffloat],
|
[longitude, dataTypes.FFLOAT],
|
||||||
[latitude, dataTypes.ffloat],
|
[latitude, dataTypes.FFLOAT],
|
||||||
[gameRank, dataTypes.uInt32]
|
[gameRank, dataTypes.UINT32]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,70 +123,70 @@ def userStats(userID, force = False):
|
||||||
|
|
||||||
return packetHelper.buildPacket(packetIDs.server_userStats,
|
return packetHelper.buildPacket(packetIDs.server_userStats,
|
||||||
[
|
[
|
||||||
[userID, dataTypes.uInt32],
|
[userID, dataTypes.UINT32],
|
||||||
[userToken.actionID, dataTypes.byte],
|
[userToken.actionID, dataTypes.BYTE],
|
||||||
[userToken.actionText, dataTypes.string],
|
[userToken.actionText, dataTypes.STRING],
|
||||||
[userToken.actionMd5, dataTypes.string],
|
[userToken.actionMd5, dataTypes.STRING],
|
||||||
[userToken.actionMods, dataTypes.sInt32],
|
[userToken.actionMods, dataTypes.SINT32],
|
||||||
[userToken.gameMode, dataTypes.byte],
|
[userToken.gameMode, dataTypes.BYTE],
|
||||||
[0, dataTypes.sInt32],
|
[0, dataTypes.SINT32],
|
||||||
[userToken.rankedScore, dataTypes.uInt64],
|
[userToken.rankedScore, dataTypes.UINT64],
|
||||||
[userToken.accuracy, dataTypes.ffloat],
|
[userToken.accuracy, dataTypes.FFLOAT],
|
||||||
[userToken.playcount, dataTypes.uInt32],
|
[userToken.playcount, dataTypes.UINT32],
|
||||||
[userToken.totalScore, dataTypes.uInt64],
|
[userToken.totalScore, dataTypes.UINT64],
|
||||||
[userToken.gameRank, dataTypes.uInt32],
|
[userToken.gameRank, dataTypes.UINT32],
|
||||||
[userToken.pp, dataTypes.uInt16]
|
[userToken.pp, dataTypes.UINT16]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
""" Chat packets """
|
""" Chat packets """
|
||||||
def sendMessage(fro, to, message):
|
def sendMessage(fro, to, message):
|
||||||
return packetHelper.buildPacket(packetIDs.server_sendMessage, [
|
return packetHelper.buildPacket(packetIDs.server_sendMessage, [
|
||||||
[fro, dataTypes.string],
|
[fro, dataTypes.STRING],
|
||||||
[message, dataTypes.string],
|
[message, dataTypes.STRING],
|
||||||
[to, dataTypes.string],
|
[to, dataTypes.STRING],
|
||||||
[userHelper.getID(fro), dataTypes.sInt32]
|
[userHelper.getID(fro), dataTypes.SINT32]
|
||||||
])
|
])
|
||||||
|
|
||||||
def channelJoinSuccess(userID, chan):
|
def channelJoinSuccess(userID, chan):
|
||||||
return packetHelper.buildPacket(packetIDs.server_channelJoinSuccess, [[chan, dataTypes.string]])
|
return packetHelper.buildPacket(packetIDs.server_channelJoinSuccess, [[chan, dataTypes.STRING]])
|
||||||
|
|
||||||
def channelInfo(chan):
|
def channelInfo(chan):
|
||||||
channel = glob.channels.channels[chan]
|
channel = glob.channels.channels[chan]
|
||||||
return packetHelper.buildPacket(packetIDs.server_channelInfo, [
|
return packetHelper.buildPacket(packetIDs.server_channelInfo, [
|
||||||
[chan, dataTypes.string],
|
[chan, dataTypes.STRING],
|
||||||
[channel.description, dataTypes.string],
|
[channel.description, dataTypes.STRING],
|
||||||
[channel.getConnectedUsersCount(), dataTypes.uInt16]
|
[channel.getConnectedUsersCount(), dataTypes.UINT16]
|
||||||
])
|
])
|
||||||
|
|
||||||
def channelInfoEnd():
|
def channelInfoEnd():
|
||||||
return packetHelper.buildPacket(packetIDs.server_channelInfoEnd, [[0, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_channelInfoEnd, [[0, dataTypes.UINT32]])
|
||||||
|
|
||||||
def channelKicked(chan):
|
def channelKicked(chan):
|
||||||
return packetHelper.buildPacket(packetIDs.server_channelKicked, [[chan, dataTypes.string]])
|
return packetHelper.buildPacket(packetIDs.server_channelKicked, [[chan, dataTypes.STRING]])
|
||||||
|
|
||||||
def userSilenced(userID):
|
def userSilenced(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_userSilenced, [[userID, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_userSilenced, [[userID, dataTypes.UINT32]])
|
||||||
|
|
||||||
|
|
||||||
""" Spectator packets """
|
""" Spectator packets """
|
||||||
def addSpectator(userID):
|
def addSpectator(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_spectatorJoined, [[userID, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_spectatorJoined, [[userID, dataTypes.SINT32]])
|
||||||
|
|
||||||
def removeSpectator(userID):
|
def removeSpectator(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_spectatorLeft, [[userID, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_spectatorLeft, [[userID, dataTypes.SINT32]])
|
||||||
|
|
||||||
def spectatorFrames(data):
|
def spectatorFrames(data):
|
||||||
return packetHelper.buildPacket(packetIDs.server_spectateFrames, [[data, dataTypes.bbytes]])
|
return packetHelper.buildPacket(packetIDs.server_spectateFrames, [[data, dataTypes.BBYTES]])
|
||||||
|
|
||||||
def noSongSpectator(userID):
|
def noSongSpectator(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_spectatorCantSpectate, [[userID, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_spectatorCantSpectate, [[userID, dataTypes.SINT32]])
|
||||||
|
|
||||||
def fellowSpectatorJoined(userID):
|
def fellowSpectatorJoined(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorJoined, [[userID, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorJoined, [[userID, dataTypes.SINT32]])
|
||||||
|
|
||||||
def fellowSpectatorLeft(userID):
|
def fellowSpectatorLeft(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorLeft, [[userID, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorLeft, [[userID, dataTypes.SINT32]])
|
||||||
|
|
||||||
|
|
||||||
""" Multiplayer Packets """
|
""" Multiplayer Packets """
|
||||||
|
@ -218,7 +218,7 @@ def matchStart(matchID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchStart, match.getMatchData())
|
return packetHelper.buildPacket(packetIDs.server_matchStart, match.getMatchData())
|
||||||
|
|
||||||
def disposeMatch(matchID):
|
def disposeMatch(matchID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_disposeMatch, [[matchID, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_disposeMatch, [[matchID, dataTypes.UINT32]])
|
||||||
|
|
||||||
def matchJoinSuccess(matchID):
|
def matchJoinSuccess(matchID):
|
||||||
# Make sure the match exists
|
# Make sure the match exists
|
||||||
|
@ -234,25 +234,25 @@ def matchJoinFail():
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchJoinFail)
|
return packetHelper.buildPacket(packetIDs.server_matchJoinFail)
|
||||||
|
|
||||||
def changeMatchPassword(newPassword):
|
def changeMatchPassword(newPassword):
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchChangePassword, [[newPassword, dataTypes.string]])
|
return packetHelper.buildPacket(packetIDs.server_matchChangePassword, [[newPassword, dataTypes.STRING]])
|
||||||
|
|
||||||
def allPlayersLoaded():
|
def allPlayersLoaded():
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchAllPlayersLoaded)
|
return packetHelper.buildPacket(packetIDs.server_matchAllPlayersLoaded)
|
||||||
|
|
||||||
def playerSkipped(userID):
|
def playerSkipped(userID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchPlayerSkipped, [[userID, dataTypes.sInt32]])
|
return packetHelper.buildPacket(packetIDs.server_matchPlayerSkipped, [[userID, dataTypes.SINT32]])
|
||||||
|
|
||||||
def allPlayersSkipped():
|
def allPlayersSkipped():
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchSkip)
|
return packetHelper.buildPacket(packetIDs.server_matchSkip)
|
||||||
|
|
||||||
def matchFrames(slotID, data):
|
def matchFrames(slotID, data):
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchScoreUpdate, [[data[7:11], dataTypes.bbytes], [slotID, dataTypes.byte], [data[12:], dataTypes.bbytes]])
|
return packetHelper.buildPacket(packetIDs.server_matchScoreUpdate, [[data[7:11], dataTypes.BBYTES], [slotID, dataTypes.BYTE], [data[12:], dataTypes.BBYTES]])
|
||||||
|
|
||||||
def matchComplete():
|
def matchComplete():
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchComplete)
|
return packetHelper.buildPacket(packetIDs.server_matchComplete)
|
||||||
|
|
||||||
def playerFailed(slotID):
|
def playerFailed(slotID):
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchPlayerFailed, [[slotID, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_matchPlayerFailed, [[slotID, dataTypes.UINT32]])
|
||||||
|
|
||||||
def matchTransferHost():
|
def matchTransferHost():
|
||||||
return packetHelper.buildPacket(packetIDs.server_matchTransferHost)
|
return packetHelper.buildPacket(packetIDs.server_matchTransferHost)
|
||||||
|
@ -260,7 +260,7 @@ def matchTransferHost():
|
||||||
|
|
||||||
""" Other packets """
|
""" Other packets """
|
||||||
def notification(message):
|
def notification(message):
|
||||||
return packetHelper.buildPacket(packetIDs.server_notification, [[message, dataTypes.string]])
|
return packetHelper.buildPacket(packetIDs.server_notification, [[message, dataTypes.STRING]])
|
||||||
|
|
||||||
def banchoRestart(msUntilReconnection):
|
def banchoRestart(msUntilReconnection):
|
||||||
return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.uInt32]])
|
return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.UINT32]])
|
|
@ -32,7 +32,7 @@ def handle(userToken, packetData):
|
||||||
# userToken.partMatch()
|
# userToken.partMatch()
|
||||||
|
|
||||||
# Update cached stats if our pp changedm if we've just submitted a score or we've changed gameMode
|
# Update cached stats if our pp changedm if we've just submitted a score or we've changed gameMode
|
||||||
if (userToken.actionID == actions.playing or userToken.actionID == actions.multiplaying) or (userToken.pp != userHelper.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):
|
if (userToken.actionID == actions.PLAYING or userToken.actionID == actions.MULTIPLAYING) or (userToken.pp != userHelper.getPP(userID, userToken.gameMode)) or (userToken.gameMode != packetData["gameMode"]):
|
||||||
# Always update game mode, or we'll cache stats from the wrong game mode if we've changed it
|
# Always update game mode, or we'll cache stats from the wrong game mode if we've changed it
|
||||||
userToken.gameMode = packetData["gameMode"]
|
userToken.gameMode = packetData["gameMode"]
|
||||||
userToken.updateCachedStats()
|
userToken.updateCachedStats()
|
||||||
|
|
|
@ -54,21 +54,21 @@ def unpackData(data, dataType):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get right pack Type
|
# Get right pack Type
|
||||||
if dataType == dataTypes.uInt16:
|
if dataType == dataTypes.UINT16:
|
||||||
unpackType = "<H"
|
unpackType = "<H"
|
||||||
elif dataType == dataTypes.sInt16:
|
elif dataType == dataTypes.SINT16:
|
||||||
unpackType = "<h"
|
unpackType = "<h"
|
||||||
elif dataType == dataTypes.uInt32:
|
elif dataType == dataTypes.UINT32:
|
||||||
unpackType = "<L"
|
unpackType = "<L"
|
||||||
elif dataType == dataTypes.sInt32:
|
elif dataType == dataTypes.SINT32:
|
||||||
unpackType = "<l"
|
unpackType = "<l"
|
||||||
elif dataType == dataTypes.uInt64:
|
elif dataType == dataTypes.UINT64:
|
||||||
unpackType = "<Q"
|
unpackType = "<Q"
|
||||||
elif dataType == dataTypes.sInt64:
|
elif dataType == dataTypes.SINT64:
|
||||||
unpackType = "<q"
|
unpackType = "<q"
|
||||||
elif dataType == dataTypes.string:
|
elif dataType == dataTypes.STRING:
|
||||||
unpackType = "<s"
|
unpackType = "<s"
|
||||||
elif dataType == dataTypes.ffloat:
|
elif dataType == dataTypes.FFLOAT:
|
||||||
unpackType = "<f"
|
unpackType = "<f"
|
||||||
else:
|
else:
|
||||||
unpackType = "<B"
|
unpackType = "<B"
|
||||||
|
@ -90,19 +90,19 @@ def packData(__data, dataType):
|
||||||
pack = True # if True, use pack. False only with strings
|
pack = True # if True, use pack. False only with strings
|
||||||
|
|
||||||
# Get right pack Type
|
# Get right pack Type
|
||||||
if dataType == dataTypes.bbytes:
|
if dataType == dataTypes.BBYTES:
|
||||||
# Bytes, do not use pack, do manually
|
# Bytes, do not use pack, do manually
|
||||||
pack = False
|
pack = False
|
||||||
data = __data
|
data = __data
|
||||||
elif dataType == dataTypes.intList:
|
elif dataType == dataTypes.INT_LIST:
|
||||||
# Pack manually
|
# Pack manually
|
||||||
pack = False
|
pack = False
|
||||||
# Add length
|
# Add length
|
||||||
data = packData(len(__data), dataTypes.uInt16)
|
data = packData(len(__data), dataTypes.UINT16)
|
||||||
# Add all elements
|
# Add all elements
|
||||||
for i in __data:
|
for i in __data:
|
||||||
data += packData(i, dataTypes.sInt32)
|
data += packData(i, dataTypes.SINT32)
|
||||||
elif dataType == dataTypes.string:
|
elif dataType == dataTypes.STRING:
|
||||||
# String, do not use pack, do manually
|
# String, do not use pack, do manually
|
||||||
pack = False
|
pack = False
|
||||||
if len(__data) == 0:
|
if len(__data) == 0:
|
||||||
|
@ -113,21 +113,21 @@ def packData(__data, dataType):
|
||||||
data += b"\x0B"
|
data += b"\x0B"
|
||||||
data += uleb128Encode(len(__data))
|
data += uleb128Encode(len(__data))
|
||||||
data += str.encode(__data, "latin_1", "ignore")
|
data += str.encode(__data, "latin_1", "ignore")
|
||||||
elif dataType == dataTypes.uInt16:
|
elif dataType == dataTypes.UINT16:
|
||||||
packType = "<H"
|
packType = "<H"
|
||||||
elif dataType == dataTypes.sInt16:
|
elif dataType == dataTypes.SINT16:
|
||||||
packType = "<h"
|
packType = "<h"
|
||||||
elif dataType == dataTypes.uInt32:
|
elif dataType == dataTypes.UINT32:
|
||||||
packType = "<L"
|
packType = "<L"
|
||||||
elif dataType == dataTypes.sInt32:
|
elif dataType == dataTypes.SINT32:
|
||||||
packType = "<l"
|
packType = "<l"
|
||||||
elif dataType == dataTypes.uInt64:
|
elif dataType == dataTypes.UINT64:
|
||||||
packType = "<Q"
|
packType = "<Q"
|
||||||
elif dataType == dataTypes.sInt64:
|
elif dataType == dataTypes.SINT64:
|
||||||
packType = "<q"
|
packType = "<q"
|
||||||
elif dataType == dataTypes.string:
|
elif dataType == dataTypes.STRING:
|
||||||
packType = "<s"
|
packType = "<s"
|
||||||
elif dataType == dataTypes.ffloat:
|
elif dataType == dataTypes.FFLOAT:
|
||||||
packType = "<f"
|
packType = "<f"
|
||||||
else:
|
else:
|
||||||
packType = "<B"
|
packType = "<B"
|
||||||
|
@ -173,7 +173,7 @@ def readPacketID(stream):
|
||||||
stream -- data stream
|
stream -- data stream
|
||||||
return -- packet ID (int)
|
return -- packet ID (int)
|
||||||
"""
|
"""
|
||||||
return unpackData(stream[0:2], dataTypes.uInt16)
|
return unpackData(stream[0:2], dataTypes.UINT16)
|
||||||
|
|
||||||
def readPacketLength(stream):
|
def readPacketLength(stream):
|
||||||
"""
|
"""
|
||||||
|
@ -182,7 +182,7 @@ def readPacketLength(stream):
|
||||||
stream -- data stream
|
stream -- data stream
|
||||||
return -- packet length (int)
|
return -- packet length (int)
|
||||||
"""
|
"""
|
||||||
return unpackData(stream[3:7], dataTypes.uInt32)
|
return unpackData(stream[3:7], dataTypes.UINT32)
|
||||||
|
|
||||||
|
|
||||||
def readPacketData(stream, structure = [], hasFirstBytes = True):
|
def readPacketData(stream, structure = [], hasFirstBytes = True):
|
||||||
|
@ -211,22 +211,22 @@ def readPacketData(stream, structure = [], hasFirstBytes = True):
|
||||||
for i in structure:
|
for i in structure:
|
||||||
start = end
|
start = end
|
||||||
unpack = True
|
unpack = True
|
||||||
if i[1] == dataTypes.intList:
|
if i[1] == dataTypes.INT_LIST:
|
||||||
# sInt32 list.
|
# sInt32 list.
|
||||||
# Unpack manually with for loop
|
# Unpack manually with for loop
|
||||||
unpack = False
|
unpack = False
|
||||||
|
|
||||||
# Read length (uInt16)
|
# Read length (uInt16)
|
||||||
length = unpackData(stream[start:start+2], dataTypes.uInt16)
|
length = unpackData(stream[start:start+2], dataTypes.UINT16)
|
||||||
|
|
||||||
# Read all int inside list
|
# Read all int inside list
|
||||||
data[i[0]] = []
|
data[i[0]] = []
|
||||||
for j in range(0,length):
|
for j in range(0,length):
|
||||||
data[i[0]].append(unpackData(stream[start+2+(4*j):start+2+(4*(j+1))], dataTypes.sInt32))
|
data[i[0]].append(unpackData(stream[start+2+(4*j):start+2+(4*(j+1))], dataTypes.SINT32))
|
||||||
|
|
||||||
# Update end
|
# Update end
|
||||||
end = start+2+(4*length)
|
end = start+2+(4*length)
|
||||||
elif i[1] == dataTypes.string:
|
elif i[1] == dataTypes.STRING:
|
||||||
# String, don't unpack
|
# String, don't unpack
|
||||||
unpack = False
|
unpack = False
|
||||||
|
|
||||||
|
@ -243,13 +243,13 @@ def readPacketData(stream, structure = [], hasFirstBytes = True):
|
||||||
|
|
||||||
# Read bytes
|
# Read bytes
|
||||||
data[i[0]] = ''.join(chr(j) for j in stream[start+1+length[1]:end])
|
data[i[0]] = ''.join(chr(j) for j in stream[start+1+length[1]:end])
|
||||||
elif i[1] == dataTypes.byte:
|
elif i[1] == dataTypes.BYTE:
|
||||||
end = start+1
|
end = start+1
|
||||||
elif i[1] == dataTypes.uInt16 or i[1] == dataTypes.sInt16:
|
elif i[1] == dataTypes.UINT16 or i[1] == dataTypes.SINT16:
|
||||||
end = start+2
|
end = start+2
|
||||||
elif i[1] == dataTypes.uInt32 or i[1] == dataTypes.sInt32:
|
elif i[1] == dataTypes.UINT32 or i[1] == dataTypes.SINT32:
|
||||||
end = start+4
|
end = start+4
|
||||||
elif i[1] == dataTypes.uInt64 or i[1] == dataTypes.sInt64:
|
elif i[1] == dataTypes.UINT64 or i[1] == dataTypes.SINT64:
|
||||||
end = start+8
|
end = start+8
|
||||||
|
|
||||||
# Unpack if needed
|
# Unpack if needed
|
||||||
|
|
|
@ -619,3 +619,9 @@ def hasVerifiedHardware(userID):
|
||||||
if data != None:
|
if data != None:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cacheUserIDs():
|
||||||
|
"""Cache userIDs in glob.userIDCache, used later with getID()."""
|
||||||
|
data = glob.db.fetchAll("SELECT id, username FROM users WHERE privileges & {} > 0".format(privileges.USER_NORMAL))
|
||||||
|
for i in data:
|
||||||
|
glob.userIDCache[i["username"]] = i["id"]
|
|
@ -13,7 +13,7 @@ npRegex = re.compile("^https?:\\/\\/osu\\.ppy\\.sh\\/b\\/(\\d*)")
|
||||||
def connect():
|
def connect():
|
||||||
"""Add FokaBot to connected users and send userpanel/stats packet to everyone"""
|
"""Add FokaBot to connected users and send userpanel/stats packet to everyone"""
|
||||||
token = glob.tokens.addToken(999)
|
token = glob.tokens.addToken(999)
|
||||||
token.actionID = actions.idle
|
token.actionID = actions.IDLE
|
||||||
glob.tokens.enqueueAll(serverPackets.userPanel(999))
|
glob.tokens.enqueueAll(serverPackets.userPanel(999))
|
||||||
glob.tokens.enqueueAll(serverPackets.userStats(999))
|
glob.tokens.enqueueAll(serverPackets.userStats(999))
|
||||||
|
|
||||||
|
|
|
@ -86,47 +86,47 @@ class match():
|
||||||
"""
|
"""
|
||||||
# General match info
|
# General match info
|
||||||
struct = [
|
struct = [
|
||||||
[self.matchID, dataTypes.uInt16],
|
[self.matchID, dataTypes.UINT16],
|
||||||
[int(self.inProgress), dataTypes.byte],
|
[int(self.inProgress), dataTypes.BYTE],
|
||||||
[0, dataTypes.byte],
|
[0, dataTypes.BYTE],
|
||||||
[self.mods, dataTypes.uInt32],
|
[self.mods, dataTypes.UINT32],
|
||||||
[self.matchName, dataTypes.string],
|
[self.matchName, dataTypes.STRING],
|
||||||
[self.matchPassword, dataTypes.string],
|
[self.matchPassword, dataTypes.STRING],
|
||||||
[self.beatmapName, dataTypes.string],
|
[self.beatmapName, dataTypes.STRING],
|
||||||
[self.beatmapID, dataTypes.uInt32],
|
[self.beatmapID, dataTypes.UINT32],
|
||||||
[self.beatmapMD5, dataTypes.string],
|
[self.beatmapMD5, dataTypes.STRING],
|
||||||
]
|
]
|
||||||
|
|
||||||
# Slots status IDs, always 16 elements
|
# Slots status IDs, always 16 elements
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
struct.append([self.slots[i].status, dataTypes.byte])
|
struct.append([self.slots[i].status, dataTypes.BYTE])
|
||||||
|
|
||||||
# Slot teams, always 16 elements
|
# Slot teams, always 16 elements
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
struct.append([self.slots[i].team, dataTypes.byte])
|
struct.append([self.slots[i].team, dataTypes.BYTE])
|
||||||
|
|
||||||
# Slot user ID. Write only if slot is occupied
|
# Slot user ID. Write only if slot is occupied
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
uid = self.slots[i].userID
|
uid = self.slots[i].userID
|
||||||
if uid > -1:
|
if uid > -1:
|
||||||
struct.append([uid, dataTypes.uInt32])
|
struct.append([uid, dataTypes.UINT32])
|
||||||
|
|
||||||
# Other match data
|
# Other match data
|
||||||
struct.extend([
|
struct.extend([
|
||||||
[self.hostUserID, dataTypes.sInt32],
|
[self.hostUserID, dataTypes.SINT32],
|
||||||
[self.gameMode, dataTypes.byte],
|
[self.gameMode, dataTypes.BYTE],
|
||||||
[self.matchScoringType, dataTypes.byte],
|
[self.matchScoringType, dataTypes.BYTE],
|
||||||
[self.matchTeamType, dataTypes.byte],
|
[self.matchTeamType, dataTypes.BYTE],
|
||||||
[self.matchModMode, dataTypes.byte],
|
[self.matchModMode, dataTypes.BYTE],
|
||||||
])
|
])
|
||||||
|
|
||||||
# Slot mods if free mod is enabled
|
# Slot mods if free mod is enabled
|
||||||
if self.matchModMode == matchModModes.freeMod:
|
if self.matchModMode == matchModModes.freeMod:
|
||||||
for i in range(0,16):
|
for i in range(0,16):
|
||||||
struct.append([self.slots[i].mods, dataTypes.uInt32])
|
struct.append([self.slots[i].mods, dataTypes.UINT32])
|
||||||
|
|
||||||
# Seed idk
|
# Seed idk
|
||||||
struct.append([self.seed, dataTypes.uInt32])
|
struct.append([self.seed, dataTypes.UINT32])
|
||||||
|
|
||||||
return struct
|
return struct
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class token():
|
||||||
self.spamRate = 0
|
self.spamRate = 0
|
||||||
|
|
||||||
# Stats cache
|
# Stats cache
|
||||||
self.actionID = actions.idle
|
self.actionID = actions.IDLE
|
||||||
self.actionText = ""
|
self.actionText = ""
|
||||||
self.actionMd5 = ""
|
self.actionMd5 = ""
|
||||||
self.actionMods = 0
|
self.actionMods = 0
|
||||||
|
|
5
pep.py
5
pep.py
|
@ -135,6 +135,11 @@ if __name__ == "__main__":
|
||||||
glob.tokens.spamProtectionResetLoop()
|
glob.tokens.spamProtectionResetLoop()
|
||||||
consoleHelper.printDone()
|
consoleHelper.printDone()
|
||||||
|
|
||||||
|
# Cache user ids
|
||||||
|
consoleHelper.printNoNl("> Caching user IDs... ")
|
||||||
|
userHelper.cacheUserIDs()
|
||||||
|
consoleHelper.printDone()
|
||||||
|
|
||||||
# Localize warning
|
# Localize warning
|
||||||
glob.localize = generalFunctions.stringToBool(glob.conf.config["localize"]["enable"])
|
glob.localize = generalFunctions.stringToBool(glob.conf.config["localize"]["enable"])
|
||||||
if glob.localize == False:
|
if glob.localize == False:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user