Class: Net::IRC::Server::Session

Inherits:
Object
  • Object
show all
Includes:
Net::IRC, Constants
Defined in:
lib/net/irc/server.rb

Constant Summary

Constants included from Constants

Constants::ADMIN, Constants::AWAY, Constants::CONNECT, Constants::DIE, Constants::ERROR, Constants::ERR_ALREADYREGISTRED, Constants::ERR_BADCHANMASK, Constants::ERR_BADCHANNELKEY, Constants::ERR_BADMASK, Constants::ERR_BANLISTFULL, Constants::ERR_BANNEDFROMCHAN, Constants::ERR_CANNOTSENDTOCHAN, Constants::ERR_CANTKILLSERVER, Constants::ERR_CHANNELISFULL, Constants::ERR_CHANOPRIVSNEEDED, Constants::ERR_ERRONEUSNICKNAME, Constants::ERR_FILEERROR, Constants::ERR_INVITEONLYCHAN, Constants::ERR_KEYSET, Constants::ERR_NEEDMOREPARAMS, Constants::ERR_NICKCOLLISION, Constants::ERR_NICKNAMEINUSE, Constants::ERR_NOADMININFO, Constants::ERR_NOCHANMODES, Constants::ERR_NOLOGIN, Constants::ERR_NOMOTD, Constants::ERR_NONICKNAMEGIVEN, Constants::ERR_NOOPERHOST, Constants::ERR_NOORIGIN, Constants::ERR_NOPERMFORHOST, Constants::ERR_NOPRIVILEGES, Constants::ERR_NORECIPIENT, Constants::ERR_NOSERVICEHOST, Constants::ERR_NOSUCHCHANNEL, Constants::ERR_NOSUCHNICK, Constants::ERR_NOSUCHSERVER, Constants::ERR_NOSUCHSERVICE, Constants::ERR_NOTEXTTOSEND, Constants::ERR_NOTONCHANNEL, Constants::ERR_NOTOPLEVEL, Constants::ERR_NOTREGISTERED, Constants::ERR_PASSWDMISMATCH, Constants::ERR_RESTRICTED, Constants::ERR_SUMMONDISABLED, Constants::ERR_TOOMANYCHANNELS, Constants::ERR_TOOMANYTARGETS, Constants::ERR_UMODEUNKNOWNFLAG, Constants::ERR_UNAVAILRESOURCE, Constants::ERR_UNIQOPPRIVSNEEDED, Constants::ERR_UNKNOWNCOMMAND, Constants::ERR_UNKNOWNMODE, Constants::ERR_USERNOTINCHANNEL, Constants::ERR_USERONCHANNEL, Constants::ERR_USERSDISABLED, Constants::ERR_USERSDONTMATCH, Constants::ERR_WASNOSUCHNICK, Constants::ERR_WILDTOPLEVEL, Constants::ERR_YOUREBANNEDCREEP, Constants::ERR_YOUWILLBEBANNED, Constants::INFO, Constants::INVITE, Constants::ISON, Constants::JOIN, Constants::KICK, Constants::KILL, Constants::LINKS, Constants::LIST, Constants::LUSERS, Constants::MODE, Constants::MOTD, Constants::NAMES, Constants::NICK, Constants::NOTICE, Constants::OPER, Constants::PART, Constants::PASS, Constants::PING, Constants::PONG, Constants::PRIVMSG, Constants::QUIT, Constants::REHASH, Constants::RESTART, Constants::RPL_ADMINEMAIL, Constants::RPL_ADMINLOC1, Constants::RPL_ADMINLOC2, Constants::RPL_ADMINME, Constants::RPL_AWAY, Constants::RPL_BANLIST, Constants::RPL_CHANNELMODEIS, Constants::RPL_CLOSEEND, Constants::RPL_CLOSING, Constants::RPL_CREATED, Constants::RPL_ENDOFBANLIST, Constants::RPL_ENDOFEXCEPTLIST, Constants::RPL_ENDOFINFO, Constants::RPL_ENDOFINVITELIST, Constants::RPL_ENDOFLINKS, Constants::RPL_ENDOFMOTD, Constants::RPL_ENDOFNAMES, Constants::RPL_ENDOFSERVICES, Constants::RPL_ENDOFSTATS, Constants::RPL_ENDOFUSERS, Constants::RPL_ENDOFWHO, Constants::RPL_ENDOFWHOIS, Constants::RPL_ENDOFWHOWAS, Constants::RPL_EXCEPTLIST, Constants::RPL_INFO, Constants::RPL_INFOSTART, Constants::RPL_INVITELIST, Constants::RPL_INVITING, Constants::RPL_ISON, Constants::RPL_ISUPPORT, Constants::RPL_KILLDONE, Constants::RPL_LINKS, Constants::RPL_LIST, Constants::RPL_LISTEND, Constants::RPL_LISTSTART, Constants::RPL_LUSERCHANNELS, Constants::RPL_LUSERCLIENT, Constants::RPL_LUSERME, Constants::RPL_LUSEROP, Constants::RPL_LUSERUNKNOWN, Constants::RPL_MOTD, Constants::RPL_MOTDSTART, Constants::RPL_MYINFO, Constants::RPL_MYPORTIS, Constants::RPL_NAMREPLY, Constants::RPL_NONE, Constants::RPL_NOTOPIC, Constants::RPL_NOUSERS, Constants::RPL_NOWAWAY, Constants::RPL_REHASHING, Constants::RPL_SERVICE, Constants::RPL_SERVICEINFO, Constants::RPL_SERVLIST, Constants::RPL_SERVLISTEND, Constants::RPL_STATSBLINE, Constants::RPL_STATSCLINE, Constants::RPL_STATSCOMMANDS, Constants::RPL_STATSDLINE, Constants::RPL_STATSHLINE, Constants::RPL_STATSILINE, Constants::RPL_STATSKLINE, Constants::RPL_STATSLINKINFO, Constants::RPL_STATSLLINE, Constants::RPL_STATSNLINE, Constants::RPL_STATSOLINE, Constants::RPL_STATSPING, Constants::RPL_STATSQLINE, Constants::RPL_STATSSLINE, Constants::RPL_STATSUPTIME, Constants::RPL_STATSVLINE, Constants::RPL_STATSYLINE, Constants::RPL_SUMMONING, Constants::RPL_TIME, Constants::RPL_TOPIC, Constants::RPL_TRACECLASS, Constants::RPL_TRACECONNECTING, Constants::RPL_TRACEEND, Constants::RPL_TRACEHANDSHAKE, Constants::RPL_TRACELINK, Constants::RPL_TRACELOG, Constants::RPL_TRACENEWTYPE, Constants::RPL_TRACEOPERATOR, Constants::RPL_TRACERECONNECT, Constants::RPL_TRACESERVER, Constants::RPL_TRACESERVICE, Constants::RPL_TRACEUNKNOWN, Constants::RPL_TRACEUSER, Constants::RPL_TRYAGAIN, Constants::RPL_UMODEIS, Constants::RPL_UNAWAY, Constants::RPL_UNIQOPIS, Constants::RPL_USERHOST, Constants::RPL_USERS, Constants::RPL_USERSSTART, Constants::RPL_VERSION, Constants::RPL_WELCOME, Constants::RPL_WHOISCHANNELS, Constants::RPL_WHOISCHANOP, Constants::RPL_WHOISIDLE, Constants::RPL_WHOISOPERATOR, Constants::RPL_WHOISSERVER, Constants::RPL_WHOISUSER, Constants::RPL_WHOREPLY, Constants::RPL_WHOWASUSER, Constants::RPL_YOUREOPER, Constants::RPL_YOURESERVICE, Constants::RPL_YOURHOST, Constants::SERVICE, Constants::SERVLIST, Constants::SQUERY, Constants::SQUIT, Constants::STATS, Constants::SUMMON, Constants::TIME, Constants::TOPIC, Constants::TRACE, Constants::USER, Constants::USERHOST, Constants::USERS, Constants::VERSION, Constants::WALLOPS, Constants::WHO, Constants::WHOIS, Constants::WHOWAS

Constants included from Net::IRC

COMMANDS, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Net::IRC

ctcp_decoding, ctcp_encoding

Constructor Details

#initialize(server, socket, logger, opts = {}) ⇒ Session

Returns a new instance of Session.



80
81
82
# File 'lib/net/irc/server.rb', line 80

def initialize(server, socket, logger, opts={})
	@server, @socket, @log, @opts = server, socket, logger, opts
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Do nothing. This is for avoiding error on calling super. So you can always call super at subclass.



161
162
# File 'lib/net/irc/server.rb', line 161

def method_missing(name, *args)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



58
59
60
# File 'lib/net/irc/server.rb', line 58

def host
  @host
end

#nickObject (readonly)

Returns the value of attribute nick.



58
59
60
# File 'lib/net/irc/server.rb', line 58

def nick
  @nick
end

#prefixObject (readonly)

Returns the value of attribute prefix.



58
59
60
# File 'lib/net/irc/server.rb', line 58

def prefix
  @prefix
end

#realObject (readonly)

Returns the value of attribute real.



58
59
60
# File 'lib/net/irc/server.rb', line 58

def real
  @real
end

Class Method Details

.start(*args) ⇒ Object



84
85
86
# File 'lib/net/irc/server.rb', line 84

def self.start(*args)
	new(*args).start
end

Instance Method Details

#avaiable_channel_modesObject

Override subclass.



76
77
78
# File 'lib/net/irc/server.rb', line 76

def avaiable_channel_modes
	"spknm"
end

#avaiable_user_modesObject

Override subclass.



71
72
73
# File 'lib/net/irc/server.rb', line 71

def avaiable_user_modes
	"eixwy"
end

#finishObject

Close this session.



111
112
113
114
115
116
117
# File 'lib/net/irc/server.rb', line 111

def finish
	begin
		@socket.close
	rescue
	end
	on_disconnected
end

#on_connectedObject

Call when socket connected.



141
142
# File 'lib/net/irc/server.rb', line 141

def on_connected
end

#on_disconnectedObject

Call when socket closed.



145
146
# File 'lib/net/irc/server.rb', line 145

def on_disconnected
end

#on_message(m) ⇒ Object

Catch all messages. If this method return true, aother callback will not be called.



150
151
# File 'lib/net/irc/server.rb', line 150

def on_message(m)
end

#on_nick(m) ⇒ Object

Default NICK callback. Set @nick.



127
128
129
# File 'lib/net/irc/server.rb', line 127

def on_nick(m)
	@nick = m.params[0]
end

#on_pass(m) ⇒ Object

Default PASS callback. Set @pass.



121
122
123
# File 'lib/net/irc/server.rb', line 121

def on_pass(m)
	@pass = m.params[0]
end

#on_ping(m) ⇒ Object

Default PING callback. Response PONG.



154
155
156
# File 'lib/net/irc/server.rb', line 154

def on_ping(m)
	post server_name, PONG, m.params[0]
end

#on_user(m) ⇒ Object

Default USER callback. Set @user, @real, @host and call initial_message.



133
134
135
136
137
138
# File 'lib/net/irc/server.rb', line 133

def on_user(m)
	@user, @real = m.params[0], m.params[3]
	@host = @socket.peeraddr[2]
	@prefix = Prefix.new("#{@nick}!#{@user}@#{@host}")
	initial_message
end

#server_nameObject

Override subclass.



61
62
63
# File 'lib/net/irc/server.rb', line 61

def server_name
	"net-irc"
end

#server_versionObject

Override subclass.



66
67
68
# File 'lib/net/irc/server.rb', line 66

def server_version
	"0.0.0"
end

#startObject

Start session loop.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/net/irc/server.rb', line 89

def start
	on_connected
	while l = @socket.gets
		begin
			@log.debug "RECEIVE: #{l.chomp}"
			m = Message.parse(l)
			next if on_message(m) === true

			name = "on_#{(COMMANDS[m.command.upcase] || m.command).downcase}"
			send(name, m) if respond_to?(name)

			break if m.command == QUIT
		rescue Message::InvalidMessage
			@log.error "MessageParse: " + l.inspect
		end
	end
rescue IOError
ensure
	finish
end