2016-04-19 17:40:59 +00:00
|
|
|
"""
|
|
|
|
Event called when someone joins a channel
|
|
|
|
"""
|
|
|
|
|
2016-05-18 17:12:46 +00:00
|
|
|
from constants import clientPackets
|
2016-05-17 21:40:34 +00:00
|
|
|
from helpers import consoleHelper
|
|
|
|
from constants import bcolors
|
2016-05-18 17:12:46 +00:00
|
|
|
from constants import serverPackets
|
|
|
|
from objects import glob
|
|
|
|
from constants import exceptions
|
2016-06-04 10:44:54 +00:00
|
|
|
from helpers import logHelper as log
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
def handle(userToken, packetData):
|
|
|
|
# Channel join packet
|
|
|
|
packetData = clientPackets.channelJoin(packetData)
|
|
|
|
joinChannel(userToken, packetData["channel"])
|
|
|
|
|
|
|
|
def joinChannel(userToken, channelName):
|
|
|
|
'''
|
|
|
|
Join a channel
|
|
|
|
|
|
|
|
userToken -- user token object of user that joins the chanlle
|
|
|
|
channelName -- name of channel
|
|
|
|
'''
|
|
|
|
try:
|
|
|
|
# Get usertoken data
|
|
|
|
username = userToken.username
|
|
|
|
userID = userToken.userID
|
|
|
|
userRank = userToken.rank
|
|
|
|
|
|
|
|
# Check spectator channel
|
|
|
|
# If it's spectator channel, skip checks and list stuff
|
|
|
|
if channelName != "#spectator" and channelName != "#multiplayer":
|
|
|
|
# Normal channel, do check stuff
|
|
|
|
# Make sure the channel exists
|
|
|
|
if channelName not in glob.channels.channels:
|
|
|
|
raise exceptions.channelUnknownException
|
|
|
|
|
|
|
|
# Check channel permissions
|
|
|
|
if glob.channels.channels[channelName].publicRead == False and userRank <= 2:
|
|
|
|
raise exceptions.channelNoPermissionsException
|
|
|
|
|
|
|
|
# Add our userID to users in that channel
|
|
|
|
glob.channels.channels[channelName].userJoin(userID)
|
|
|
|
|
|
|
|
# Add the channel to our joined channel
|
|
|
|
userToken.joinChannel(channelName)
|
|
|
|
|
|
|
|
# Send channel joined
|
|
|
|
userToken.enqueue(serverPackets.channelJoinSuccess(userID, channelName))
|
|
|
|
|
|
|
|
# Console output
|
2016-06-04 10:44:54 +00:00
|
|
|
log.info("{} joined channel {}".format(username, channelName))
|
2016-04-19 17:40:59 +00:00
|
|
|
except exceptions.channelNoPermissionsException:
|
2016-06-04 10:44:54 +00:00
|
|
|
log.warning("{} attempted to join channel {}, but they have no read permissions".format(username, channelName))
|
2016-04-19 17:40:59 +00:00
|
|
|
except exceptions.channelUnknownException:
|
2016-06-04 10:44:54 +00:00
|
|
|
log.warning("{} attempted to join an unknown channel ({})".format(username, channelName))
|