pep.py/constants/serverPackets.py

266 lines
8.8 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-05-18 17:12:46 +00:00
from helpers import packetHelper
from constants import dataTypes
from helpers import userHelper
from objects import glob
from constants import userRanks
from constants import packetIDs
from constants import privileges
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]])
packets += notification("You are banned. You can ask to get unbanned after 1 month since your ban by contacting support@ripple.moe")
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):
result = 1
2016-09-02 15:45:10 +00:00
if supporter:
2016-04-19 17:40:59 +00:00
result += 4
2016-09-02 15:45:10 +00:00
if GMT:
2016-04-19 17:40:59 +00:00
result += 2
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):
friends = userHelper.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)
2016-09-02 15:45:10 +00:00
if userToken is None:
return bytes()
if userToken.restricted == True and force == False:
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
if username == "FokaBot":
userRank = userRanks.MOD
2016-09-02 15:45:10 +00:00
elif userHelper.isInPrivilegeGroup(userID, "community manager"):
userRank = userRanks.MOD
2016-09-02 15:45:10 +00:00
elif userHelper.isInPrivilegeGroup(userID, "developer"):
userRank = userRanks.ADMIN
elif (userToken.privileges & privileges.USER_DONOR) > 0:
2016-04-19 17:40:59 +00:00
userRank = userRanks.SUPPORTER
else:
userRank = userRanks.NORMAL
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)
2016-09-02 15:45:10 +00:00
if userToken is None:
return bytes()
if (userToken.restricted == True or userToken.irc == True) and force == False:
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],
[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]
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],
[userHelper.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 None
# Get match binary data and build packet
match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_newMatch, match.getMatchData())
def updateMatch(matchID):
# Make sure the match exists
if matchID not in glob.matches.matches:
return None
# 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 None
# 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 None
# 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]])