IRC Support for username with spaces

BATs with Donor have bright yellow username in chat
General performance improvements
Code cleaning
Multiplayer improvements and fixes
Fixed some spectator bugs
This commit is contained in:
Nyo
2016-09-02 12:41:19 +02:00
parent e16e4d7493
commit 653303831b
47 changed files with 450 additions and 622 deletions

View File

@@ -57,13 +57,12 @@ def addRemoveFriend(stream):
return packetHelper.readPacketData(stream, [["friendID", dataTypes.sInt32]])
""" SPECTATOR PACKETS """
""" Spectator packets """
def startSpectating(stream):
return packetHelper.readPacketData(stream,[["userID", dataTypes.sInt32]])
""" MULTIPLAYER PACKETS """
""" Multiplayer packets """
def matchSettings(stream):
# Data to return, will be merged later
data = []
@@ -115,9 +114,6 @@ def matchSettings(stream):
# Read last part
data.append(packetHelper.readPacketData(stream[start:], struct, False))
# Mods if freemod (not used)
#if data[1]["freeMods"] == 1:
result = {}
for i in data:
result.update(i)

View File

@@ -25,8 +25,8 @@ message -- list containing arguments passed from the message
. . .
return the message or **False** if there's no response by the bot
TODO: Change False to None, because False doesn't make any sense
"""
def instantRestart(fro, chan, message):
glob.tokens.enqueueAll(serverPackets.notification("We are restarting Bancho. Be right back!"))
systemHelper.scheduleShutdown(0, True, delay=1)

View File

@@ -1,4 +1,3 @@
"""Contains readable gamemodes with their codes"""
std = 0
taiko = 1
ctb = 2
@@ -9,10 +8,8 @@ def getGameModeForDB(gameMode):
Convert a gamemode number to string for database table/column
gameMode -- gameMode int or variable (ex: gameMode.std)
return -- game mode readable string for db
"""
if gameMode == std:
return "std"
elif gameMode == taiko:
@@ -27,10 +24,8 @@ def getGameModeForPrinting(gameMode):
Convert a gamemode number to string for showing to a user (e.g. !last)
gameMode -- gameMode int or variable (ex: gameMode.std)
return -- game mode readable string for a human
"""
if gameMode == std:
return "osu!"
elif gameMode == taiko:

View File

@@ -5,9 +5,9 @@ from helpers import userHelper
from objects import glob
from constants import userRanks
from constants import packetIDs
from constants import privileges
""" Login errors packets
(userID packets derivates) """
""" Login errors packets """
def loginFailed():
return packetHelper.buildPacket(packetIDs.server_userID, [[-1, dataTypes.sInt32]])
@@ -18,7 +18,6 @@ def loginBanned():
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
#return packetHelper.buildPacket(packetIDs.server_userID, [[-3, dataTypes.sInt32]])
def loginError():
return packetHelper.buildPacket(packetIDs.server_userID, [[-5, dataTypes.sInt32]])
@@ -29,6 +28,7 @@ def needSupporter():
def needVerification():
return packetHelper.buildPacket(packetIDs.server_userID, [[-8, dataTypes.sInt32]])
""" Login packets """
def userID(uid):
return packetHelper.buildPacket(packetIDs.server_userID, [[uid, dataTypes.sInt32]])
@@ -51,19 +51,8 @@ def userSupporterGMT(supporter, GMT):
return packetHelper.buildPacket(packetIDs.server_supporterGMT, [[result, dataTypes.uInt32]])
def friendList(userID):
friendsData = []
# Get friend IDs from db
friends = userHelper.getFriendList(userID)
# Friends number
friendsData.append([len(friends), dataTypes.uInt16])
# Add all friend user IDs to friendsData
for i in friends:
friendsData.append([i, dataTypes.sInt32])
return packetHelper.buildPacket(packetIDs.server_friendsList, friendsData)
return packetHelper.buildPacket(packetIDs.server_friendsList, [[friends, dataTypes.intList]])
def onlineUsers():
userIDs = []
@@ -91,7 +80,7 @@ def userPanel(userID, force = False):
# Get user data
username = userToken.username
timezone = 24+userToken.timeOffset # TODO: Timezone
timezone = 24+userToken.timeOffset
country = userToken.country
gameRank = userToken.gameRank
latitude = userToken.getLatitude()
@@ -105,7 +94,7 @@ def userPanel(userID, force = False):
userRank = userRanks.MOD
elif userHelper.isInPrivilegeGroup(userID, "developer") == True:
userRank = userRanks.ADMIN
elif userHelper.isInPrivilegeGroup(userID, "donor") == True:
elif (userToken.privileges & privileges.USER_DONOR) > 0:
userRank = userRanks.SUPPORTER
else:
userRank = userRanks.NORMAL
@@ -126,10 +115,12 @@ def userPanel(userID, force = False):
def userStats(userID, force = False):
# Get userID's token from tokens list
userToken = glob.tokens.getTokenFromUserID(userID)
if userToken == None:
return bytes()
if (userToken.restricted == True or userToken.irc == True) and force == False:
return bytes()
return packetHelper.buildPacket(packetIDs.server_userStats,
[
[userID, dataTypes.uInt32],
@@ -150,14 +141,23 @@ def userStats(userID, force = False):
""" 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]])
return packetHelper.buildPacket(packetIDs.server_sendMessage, [
[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]])
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]])
return packetHelper.buildPacket(packetIDs.server_channelInfo, [
[chan, dataTypes.string],
[channel.description, dataTypes.string],
[channel.getConnectedUsersCount(), dataTypes.uInt16]
])
def channelInfoEnd():
return packetHelper.buildPacket(packetIDs.server_channelInfoEnd, [[0, dataTypes.uInt32]])
@@ -199,7 +199,6 @@ def createMatch(matchID):
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:
@@ -209,7 +208,6 @@ def updateMatch(matchID):
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:
@@ -219,9 +217,8 @@ def matchStart(matchID):
match = glob.matches.matches[matchID]
return packetHelper.buildPacket(packetIDs.server_matchStart, match.getMatchData())
def disposeMatch(matchID):
return packetHelper.buildPacket(packetIDs.server_disposeMatch, [[matchID, dataTypes.uInt16]])
return packetHelper.buildPacket(packetIDs.server_disposeMatch, [[matchID, dataTypes.uInt32]])
def matchJoinSuccess(matchID):
# Make sure the match exists
@@ -260,9 +257,10 @@ def playerFailed(slotID):
def matchTransferHost():
return packetHelper.buildPacket(packetIDs.server_matchTransferHost)
""" Other packets """
def notification(message):
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]])