示例#1
0
文件: sajoin.py 项目: ekimekim/txircd
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "SAJOIN", ":You have not registered")
         return {}
     if "o" not in user.mode:
         user.sendMessage(irc.ERR_NOPRIVILEGES, ":Permission denied - You do not have the correct operator privileges")
         return {}
     if not params or len(params) < 2:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "SAJOIN", ":Not enough parameters")
         return {}
     if params[0] not in self.ircd.users:
         user.sendMessage(irc.ERR_NOSUCHNICK, params[0], ":No such nick/channel")
         return {}
     if params[1][0] != "#":
         user.sendMessage(irc.ERR_BADCHANMASK, chan["channel"], ":Bad Channel Mask")
         return {}
     if params[1] in self.ircd.channels:
         cdata = self.ircd.channels[params[1]]
     else:
         cdata = IRCChannel(self.ircd, params[1])
     return {
         "user": user,
         "targetuser": self.ircd.users[params[0]],
         "targetchan": cdata
     }
示例#2
0
 def parseParams(self, user, params, prefix, tags):
     if not params or not params[0]:
         user.sendSingleError("JoinCmd", irc.ERR_NEEDMOREPARAMS, "JOIN",
                              "Not enough parameters")
         return None
     joiningChannels = params[0].split(",")
     chanKeys = params[1].split(",") if len(params) > 1 else []
     while len(chanKeys) < len(joiningChannels):
         chanKeys.append("")
     user.startErrorBatch("JoinCmd")
     removeIndices = []
     for index, chanName in enumerate(joiningChannels):
         if chanName[0] != "#":
             user.sendBatchedError("JoinCmd", irc.ERR_BADCHANMASK, chanName,
                                   "Bad channel mask")
             removeIndices.append(index)
     removeIndices.sort()
     removeIndices.reverse(
     )  # Put the indices to remove in reverse order so we don't have to finagle with them on removal
     for index in removeIndices:
         del joiningChannels[index]
         del chanKeys[index]
     if not joiningChannels:
         return None
     channels = []
     for chan in joiningChannels:
         try:
             channels.append(self.ircd.channels[chan] if chan in self.ircd.
                             channels else IRCChannel(self.ircd, chan))
         except InvalidChannelNameError:
             user.sendBatchedError("JoinCmd", irc.ERR_BADCHANMASK, chanName,
                                   "Bad channel mask")
     return {"channels": channels, "keys": chanKeys}
示例#3
0
 def autoJoinChannels(self, user):
     for chanName in self.ircd.config.get("client_join_on_connect", []):
         if chanName[0] != "#":
             chanName = "#{}".format(chanName)
         if chanName in self.ircd.channels:
             channel = self.ircd.channels[chanName]
         else:
             channel = IRCChannel(self.ircd, chanName)
         user.joinChannel(channel)
示例#4
0
 def parseParams(self, server, params, prefix, tags):
     if len(params) < 4:
         return None
     try:
         time = datetime.utcfromtimestamp(int(params[1]))
     except ValueError:
         return None
     modes = {}
     currParam = 3
     for mode in params[2]:
         if mode == "+":
             continue
         if mode not in self.ircd.channelModeTypes or self.ircd.channelModeTypes[
                 mode] == ModeType.Status:
             return None
         modeType = self.ircd.channelModeTypes[mode]
         if modeType in (ModeType.ParamOnUnset, ModeType.Param):
             try:
                 modes[mode] = params[currParam]
             except IndexError:
                 return None
             currParam += 1
         else:
             modes[mode] = None
     try:
         usersInChannel = params[currParam].split()
     except IndexError:
         return None
     if currParam + 1 < len(params):
         return None
     users = {}
     try:
         for userData in usersInChannel:
             ranks, uuid = userData.split(",")
             if uuid not in self.ircd.users:
                 return None
             for rank in ranks:
                 if rank not in self.ircd.channelModeTypes or self.ircd.channelModeTypes[
                         rank] != ModeType.Status:
                     return None
             users[self.ircd.users[uuid]] = ranks
     except ValueError:
         return None
     if params[0] in self.ircd.channels:
         channel = self.ircd.channels[params[0]]
     else:
         channel = IRCChannel(self.ircd, params[0])
     return {
         "channel": channel,
         "time": time,
         "modes": modes,
         "users": users
     }
示例#5
0
 def execute(self, server, data):
     if "lostuser" in data:
         return True
     user = data["user"]
     chanName = data["channel"]
     if user.uuid[:3] == self.ircd.serverID:
         channel = self.ircd.channels[
             chanName] if chanName in self.ircd.channels else IRCChannel(
                 self.ircd, chanName)
         user.joinChannel(channel, True)
     else:
         self.ircd.servers[user.uuid[:3]].sendMessage("RJOIN",
                                                      user.uuid,
                                                      chanName,
                                                      prefix=data["prefix"])
     return True
示例#6
0
 def parseParams(self, server, params, prefix, tags):
     if len(params) != 1:
         return None
     if prefix not in self.ircd.users:
         if prefix in self.ircd.recentlyQuitUsers:
             return {"lostuser": True}
         return None
     try:
         return {
             "user":
             self.ircd.users[prefix],
             "channel":
             self.ircd.channels[params[0]] if params[0]
             in self.ircd.channels else IRCChannel(self.ircd, params[0])
         }
     except ValueError:
         return None
示例#7
0
 def processParams(self, user, params):
     if user.registered > 0:
         user.sendMessage(irc.ERR_NOTREGISTERED, "JOIN", ":You have not registered")
         return {}
     if not params:
         user.sendMessage(irc.ERR_NEEDMOREPARAMS, "JOIN", ":Not enough parameters")
         return {}
     channels = params[0].split(",")
     keys = params[1].split(",") if len(params) > 1 else []
     joining = []
     for i in range(0, len(channels)):
         channame = channels[i][:64]
         if not channame:
             user.sendMessage(irc.ERR_BADCHANMASK, "*", ":Bad Channel Mask")
             continue
         if channame[0] != "#":
             user.sendMessage(irc.ERR_BADCHANMASK, channame, ":Bad Channel Mask")
             continue
         if channame in self.ircd.channels:
             cdata = self.ircd.channels[channame]
         else:
             cdata = IRCChannel(self.ircd, channame)
         joining.append({"channel": cdata, "key": keys[i] if i < len(keys) else None})
     remove = []
     for chan in joining:
         if user in chan["channel"].users:
             remove.append(chan)
     for chan in remove:
         joining.remove(chan)
     channels = []
     keys = []
     for chan in joining:
         channels.append(chan["channel"])
         keys.append(chan["key"])
     return {
         "user": user,
         "targetchan": channels,
         "keys": keys,
         "moreparams": params[2:]
     }
示例#8
0
	def parseParams(self, user, params, prefix, tags):
		if len(params) < 2:
			user.sendSingleError("SajoinCmd", irc.ERR_NEEDMOREPARAMS, "SAJOIN", "Not enough parameters")
			return None
		if params[0] not in self.ircd.userNicks:
			user.sendSingleError("SajoinCmd", irc.ERR_NOSUCHNICK, params[0], "No such nick")
			return None
		channame = params[1]
		if channame[0] != "#":
			channame = "#{}".format(channame)
		if channame in self.ircd.channels:
			channel = self.ircd.channels[channame]
		else:
			try:
				channel = IRCChannel(self.ircd, channame)
			except InvalidChannelNameError:
				user.sendSingleError("SajoinCmd", irc.ERR_BADCHANMASK, channame, "Bad channel mask")
				return None
		return {
			"user": self.ircd.users[self.ircd.userNicks[params[0]]],
			"channel": channel
		}