pep.py/constants/serverPackets.py

270 lines
9.4 KiB
Python
Raw Normal View History

2016-04-19 17:40:59 +00:00
""" Contains functions used to write specific server packets to byte streams """
2016-10-02 20:48:14 +00:00
from common.constants import privileges
from common.ripple import userUtils
2016-05-18 17:12:46 +00:00
from constants import dataTypes
from constants import packetIDs
2016-10-02 20:48:14 +00:00
from constants import userRanks
from helpers import packetHelper
from objects import glob
2016-04-19 17:40:59 +00:00
""" Login errors packets """
2016-04-19 17:40:59 +00:00
def loginFailed():
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
def forceUpdate():
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userID, [[-2, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
def loginBanned():
2016-09-02 15:16:22 +00:00
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
2016-10-06 15:41:40 +00:00
packets += notification("You are banned. You can appeal after one month since your ban by sending an email to support@ripple.moe from the email address you've used to sign up.")
return packets
def loginLocked():
packets = packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.SINT32]])
packets += notification("Your account is locked. You can't log in, but your profile and scores are still visible from the website. If you want to unlock your account, send an email to support@ripple.moe from the email address you've used to sign up.")
return packets
2016-04-19 17:40:59 +00:00
def loginError():
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
def needSupporter():
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userID, [[-6, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
2016-06-11 16:43:27 +00:00
def needVerification():
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userID, [[-8, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
2016-04-19 17:40:59 +00:00
""" Login packets """
def userID(uid):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userID, [[uid, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
def silenceEndTime(seconds):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_silenceEnd, [[seconds, dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def protocolVersion(version = 19):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_protocolVersion, [[version, dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def mainMenuIcon(icon):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_mainMenuIcon, [[icon, dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def userSupporterGMT(supporter, GMT, tournamentStaff):
2016-04-19 17:40:59 +00:00
result = 1
2016-09-02 15:45:10 +00:00
if supporter:
result |= userRanks.SUPPORTER
2016-09-02 15:45:10 +00:00
if GMT:
result |= userRanks.BAT
if tournamentStaff:
result |= userRanks.TOURNAMENT_STAFF
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_supporterGMT, [[result, dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def friendList(userID):
2016-10-02 20:48:14 +00:00
friends = userUtils.getFriendList(userID)
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_friendsList, [[friends, dataTypes.INT_LIST]])
2016-04-19 17:40:59 +00:00
def onlineUsers():
userIDs = []
2016-04-19 17:40:59 +00:00
users = glob.tokens.tokens
# Create list with all connected (and not restricted) users
for _, value in users.items():
2016-09-02 15:45:10 +00:00
if not value.restricted:
userIDs.append(value.userID)
2016-04-19 17:40:59 +00:00
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userPresenceBundle, [[userIDs, dataTypes.INT_LIST]])
2016-04-19 17:40:59 +00:00
""" Users packets """
def userLogout(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userLogout, [[userID, dataTypes.SINT32], [0, dataTypes.BYTE]])
2016-04-19 17:40:59 +00:00
def userPanel(userID, force = False):
# Connected and restricted check
2016-04-19 17:40:59 +00:00
userToken = glob.tokens.getTokenFromUserID(userID)
if userToken is None or ((userToken.restricted) and not force):
return bytes()
# Get user data
username = userToken.username
timezone = 24+userToken.timeOffset
country = userToken.country
gameRank = userToken.gameRank
2016-04-19 17:40:59 +00:00
latitude = userToken.getLatitude()
longitude = userToken.getLongitude()
# Get username color according to rank
# Only admins and normal users are currently supported
userRank = 0
2016-04-19 17:40:59 +00:00
if username == "FokaBot":
userRank |= userRanks.MOD
2016-10-02 20:48:14 +00:00
elif userUtils.isInPrivilegeGroup(userID, "community manager"):
userRank |= userRanks.MOD
2016-10-02 20:48:14 +00:00
elif userUtils.isInPrivilegeGroup(userID, "developer"):
userRank |= userRanks.ADMIN
elif (userToken.privileges & privileges.USER_DONOR) > 0:
userRank |= userRanks.SUPPORTER
2016-04-19 17:40:59 +00:00
else:
userRank |= userRanks.NORMAL
2016-04-19 17:40:59 +00:00
return packetHelper.buildPacket(packetIDs.server_userPanel,
[
2016-09-02 15:16:22 +00:00
[userID, dataTypes.SINT32],
[username, dataTypes.STRING],
[timezone, dataTypes.BYTE],
[country, dataTypes.BYTE],
[userRank, dataTypes.BYTE],
[longitude, dataTypes.FFLOAT],
[latitude, dataTypes.FFLOAT],
[gameRank, dataTypes.UINT32]
2016-04-19 17:40:59 +00:00
])
def userStats(userID, force = False):
2016-04-19 17:40:59 +00:00
# Get userID's token from tokens list
userToken = glob.tokens.getTokenFromUserID(userID)
if userToken is None or ((userToken.restricted or userToken.irc or userToken.tournament) and not force):
return bytes()
2016-04-19 17:40:59 +00:00
return packetHelper.buildPacket(packetIDs.server_userStats,
[
2016-09-02 15:16:22 +00:00
[userID, dataTypes.UINT32],
[userToken.actionID, dataTypes.BYTE],
[userToken.actionText, dataTypes.STRING],
[userToken.actionMd5, dataTypes.STRING],
[userToken.actionMods, dataTypes.SINT32],
[userToken.gameMode, dataTypes.BYTE],
[userToken.beatmapID, dataTypes.SINT32],
2016-09-02 15:16:22 +00:00
[userToken.rankedScore, dataTypes.UINT64],
[userToken.accuracy, dataTypes.FFLOAT],
[userToken.playcount, dataTypes.UINT32],
[userToken.totalScore, dataTypes.UINT64],
[userToken.gameRank, dataTypes.UINT32],
[userToken.pp if 65535 >= userToken.pp > 0 else 0, dataTypes.UINT16]
2016-04-19 17:40:59 +00:00
])
""" Chat packets """
def sendMessage(fro, to, message):
return packetHelper.buildPacket(packetIDs.server_sendMessage, [
2016-09-02 15:16:22 +00:00
[fro, dataTypes.STRING],
[message, dataTypes.STRING],
[to, dataTypes.STRING],
2016-10-02 20:48:14 +00:00
[userUtils.getID(fro), dataTypes.SINT32]
])
2016-04-19 17:40:59 +00:00
def channelJoinSuccess(userID, chan):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_channelJoinSuccess, [[chan, dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def channelInfo(chan):
channel = glob.channels.channels[chan]
return packetHelper.buildPacket(packetIDs.server_channelInfo, [
2016-09-02 15:16:22 +00:00
[chan, dataTypes.STRING],
[channel.description, dataTypes.STRING],
[channel.getConnectedUsersCount(), dataTypes.UINT16]
])
2016-04-19 17:40:59 +00:00
def channelInfoEnd():
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_channelInfoEnd, [[0, dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def channelKicked(chan):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_channelKicked, [[chan, dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def userSilenced(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_userSilenced, [[userID, dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
""" Spectator packets """
def addSpectator(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_spectatorJoined, [[userID, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
def removeSpectator(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_spectatorLeft, [[userID, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
def spectatorFrames(data):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_spectateFrames, [[data, dataTypes.BBYTES]])
2016-04-19 17:40:59 +00:00
def noSongSpectator(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_spectatorCantSpectate, [[userID, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
2016-06-08 15:26:31 +00:00
def fellowSpectatorJoined(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorJoined, [[userID, dataTypes.SINT32]])
2016-06-08 15:26:31 +00:00
def fellowSpectatorLeft(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_fellowSpectatorLeft, [[userID, dataTypes.SINT32]])
2016-06-08 15:26:31 +00:00
2016-04-19 17:40:59 +00:00
""" Multiplayer Packets """
def createMatch(matchID):
# Make sure the match exists
if matchID not in glob.matches.matches:
return bytes()
2016-04-19 17:40:59 +00:00
# Get match binary data and build packet
match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_newMatch, match.getMatchData())
# TODO: Add match object argument to save some CPU
2016-04-19 17:40:59 +00:00
def updateMatch(matchID):
# Make sure the match exists
if matchID not in glob.matches.matches:
return bytes()
2016-04-19 17:40:59 +00:00
# Get match binary data and build packet
match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_updateMatch, match.getMatchData())
def matchStart(matchID):
# Make sure the match exists
if matchID not in glob.matches.matches:
return bytes()
2016-04-19 17:40:59 +00:00
# Get match binary data and build packet
match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_matchStart, match.getMatchData())
def disposeMatch(matchID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_disposeMatch, [[matchID, dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def matchJoinSuccess(matchID):
# Make sure the match exists
if matchID not in glob.matches.matches:
return bytes()
2016-04-19 17:40:59 +00:00
# Get match binary data and build packet
match = glob.matches.matches[matchID]
data = packetHelper.buildPacket(packetIDs.server_matchJoinSuccess, match.getMatchData())
return data
def matchJoinFail():
return packetHelper.buildPacket(packetIDs.server_matchJoinFail)
def changeMatchPassword(newPassword):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_matchChangePassword, [[newPassword, dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def allPlayersLoaded():
return packetHelper.buildPacket(packetIDs.server_matchAllPlayersLoaded)
def playerSkipped(userID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_matchPlayerSkipped, [[userID, dataTypes.SINT32]])
2016-04-19 17:40:59 +00:00
def allPlayersSkipped():
return packetHelper.buildPacket(packetIDs.server_matchSkip)
def matchFrames(slotID, data):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_matchScoreUpdate, [[data[7:11], dataTypes.BBYTES], [slotID, dataTypes.BYTE], [data[12:], dataTypes.BBYTES]])
2016-04-19 17:40:59 +00:00
def matchComplete():
return packetHelper.buildPacket(packetIDs.server_matchComplete)
def playerFailed(slotID):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_matchPlayerFailed, [[slotID, dataTypes.UINT32]])
2016-04-19 17:40:59 +00:00
def matchTransferHost():
return packetHelper.buildPacket(packetIDs.server_matchTransferHost)
2016-04-19 17:40:59 +00:00
""" Other packets """
def notification(message):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_notification, [[message, dataTypes.STRING]])
2016-04-19 17:40:59 +00:00
def banchoRestart(msUntilReconnection):
2016-09-02 15:16:22 +00:00
return packetHelper.buildPacket(packetIDs.server_restart, [[msUntilReconnection, dataTypes.UINT32]])