pep.py/events/channelJoinEvent.py

58 lines
1.8 KiB
Python
Raw Normal View History

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
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
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
log.info("{} joined channel {}".format(username, channelName))
2016-04-19 17:40:59 +00:00
except exceptions.channelNoPermissionsException:
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:
log.warning("{} attempted to join an unknown channel ({})".format(username, channelName))