Documentation ¶
Overview ¶
Package chat implements a chat server It aims to handle connections, manage users and channels and allow execution of chat commands
Index ¶
- Variables
- type Channel
- func (c *Channel) AddUser(nickName string)
- func (c *Channel) Broadcast(chatServer *Server, message string)
- func (c *Channel) GetName() string
- func (c *Channel) GetUserCount() int
- func (c *Channel) GetUsers() map[string]bool
- func (c *Channel) RemoveUser(nickName string)
- func (c *Channel) SetName(channelName string)
- type Server
- func (s *Server) AddChannel(channelName string)
- func (s *Server) AddUser(user *User)
- func (s *Server) Broadcast(message string)
- func (s *Server) BroadcastInChannel(channelName string, message string) error
- func (s *Server) ConnectedUsersCount() int
- func (s *Server) GetChannel(channelName string) (*Channel, error)
- func (s *Server) GetChannelCount() int
- func (s *Server) GetChannelUsers(channelName string) (map[string]bool, error)
- func (s *Server) GetUser(nickName string) (*User, error)
- func (s *Server) InterviewUser(conn drivers.Connection)
- func (s *Server) IsUserConnected(nickName string) bool
- func (s *Server) Listen()
- func (s *Server) ReceiveConnection(conn drivers.Connection)
- func (s *Server) RemoveUser(nickName string) error
- func (s *Server) RemoveUserFromChannel(nickName, channelName string) error
- type User
- func (u *User) Disconnect() error
- func (u *User) GetChannel() string
- func (u *User) GetCommandParams(chatServer *Server, userInput string, executable command.Executable) (*command.Params, error)
- func (u *User) GetIncoming() (string, error)
- func (u *User) GetNickName() string
- func (u *User) GetOutgoing() string
- func (u *User) HandleNewInput(chatServer *Server, userInput string) (bool, error)
- func (u *User) HasIgnored(nickName string) bool
- func (u *User) Ignore(nickName string)
- func (u *User) Listen(chatServer *Server)
- func (u *User) ReadFrom(chatServer *Server)
- func (u *User) SetChannel(name string)
- func (u *User) SetIncoming(message string)
- func (u *User) SetNickName(nickName string)
- func (u *User) SetOutgoing(messageType int, message string)
- func (u *User) SetOutgoingf(messageType int, format string, a ...interface{})
- func (u *User) WriteTo()
Constants ¶
This section is empty.
Variables ¶
var ReadConnectionLimitBytes = 100000 // 100KB
ReadConnectionLimitBytes is the maximum size of input we accept from user This is important to defend against DOS attacks
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel users can be in a channel and chat with each other
func (*Channel) GetUserCount ¶
GetUserCount returns the number of connected users to this channel
func (*Channel) RemoveUser ¶
RemoveUser removes a user from this server
type Server ¶
type Server struct { Incoming chan string Outgoing chan string // contains filtered or unexported fields }
Server keeps listening for connections, it contains users and channels
func (*Server) AddChannel ¶
AddChannel adds a channel to this server
func (*Server) BroadcastInChannel ¶
BroadcastInChannel broadcasts a message to all the users in a channel
func (*Server) ConnectedUsersCount ¶
ConnectedUsersCount returns the number of connected users
func (*Server) GetChannel ¶
GetChannel gets a channel from the given channelName
func (*Server) GetChannelCount ¶
GetChannelCount returns the number of channels on this server
func (*Server) GetChannelUsers ¶
GetChannelUsers returns list of nicknames of the users connected to this server
func (*Server) InterviewUser ¶
func (s *Server) InterviewUser(conn drivers.Connection)
InterviewUser interviews user and allows him to connect after identification
func (*Server) IsUserConnected ¶
IsUserConnected checks to see if a user with the given nickname is connected to this server or not
func (*Server) Listen ¶
func (s *Server) Listen()
Listen Makes this server start listening to connections, when a user is connected he or she is welcomed
func (*Server) ReceiveConnection ¶
func (s *Server) ReceiveConnection(conn drivers.Connection)
ReceiveConnection is used when there's a new connection
func (*Server) RemoveUser ¶
RemoveUser from this server
func (*Server) RemoveUserFromChannel ¶
RemoveUserFromChannel removes a user from a channel
type User ¶
type User struct {
// contains filtered or unexported fields
}
User is temporarily in connected to a chat server, and can be in certain channels
func NewConnectedUser ¶
func NewConnectedUser(connection drivers.Connection) *User
NewConnectedUser returns a new User with a connection
func (*User) GetChannel ¶
GetChannel gets the current channel name for the user
func (*User) GetCommandParams ¶
func (u *User) GetCommandParams(chatServer *Server, userInput string, executable command.Executable) (*command.Params, error)
GetCommandParams looks at command parameters in userInput and populates the parameters for command execution
func (*User) GetIncoming ¶
GetIncoming gets the incoming message from the user
func (*User) GetNickName ¶
GetNickName returns the nickname of this user
func (*User) GetOutgoing ¶
GetOutgoing gets the outgoing message for a user
func (*User) HandleNewInput ¶
HandleNewInput interprets user input and lets chatServer handle it
func (*User) HasIgnored ¶
HasIgnored checks to see if a user has ignored another user or not
func (*User) SetChannel ¶
SetChannel sets the current channel name for the user
func (*User) SetIncoming ¶
SetIncoming sets an incoming message from the user
func (*User) SetNickName ¶
SetNickName sets the nickname for this user
func (*User) SetOutgoing ¶
SetOutgoing sets an outgoing message to the user
func (*User) SetOutgoingf ¶
SetOutgoingf sets an outgoing message to the user