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