chat

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package chat implements a chat server It aims to handle connections, manage users and channels and allow execution of chat commands

Index

Constants

This section is empty.

Variables

View Source
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 NewChannel

func NewChannel() *Channel

NewChannel returns a channel

func (*Channel) AddUser

func (c *Channel) AddUser(nickName string)

AddUser adds a user to this channel

func (*Channel) Broadcast

func (c *Channel) Broadcast(chatServer *Server, message string)

Broadcast sends a message to every user in a channel

func (*Channel) GetName

func (c *Channel) GetName() string

GetName gets a channel's name

func (*Channel) GetUserCount

func (c *Channel) GetUserCount() int

GetUserCount returns the number of connected users to this channel

func (*Channel) GetUsers

func (c *Channel) GetUsers() map[string]bool

GetUsers returns nicknames of connected users

func (*Channel) RemoveUser

func (c *Channel) RemoveUser(nickName string)

RemoveUser removes a user from this server

func (*Channel) SetName

func (c *Channel) SetName(channelName string)

SetName sets a channel's name

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 NewServer

func NewServer() *Server

NewServer returns a new instance of the chat server

func (*Server) AddChannel

func (s *Server) AddChannel(channelName string)

AddChannel adds a channel to this server

func (*Server) AddUser

func (s *Server) AddUser(user *User)

AddUser to this server

func (*Server) Broadcast

func (s *Server) Broadcast(message string)

Broadcast sends a message to every user connected to the server

func (*Server) BroadcastInChannel

func (s *Server) BroadcastInChannel(channelName string, message string) error

BroadcastInChannel broadcasts a message to all the users in a channel

func (*Server) ConnectedUsersCount

func (s *Server) ConnectedUsersCount() int

ConnectedUsersCount returns the number of connected users

func (*Server) GetChannel

func (s *Server) GetChannel(channelName string) (*Channel, error)

GetChannel gets a channel from the given channelName

func (*Server) GetChannelCount

func (s *Server) GetChannelCount() int

GetChannelCount returns the number of channels on this server

func (*Server) GetChannelUsers

func (s *Server) GetChannelUsers(channelName string) (map[string]bool, error)

GetChannelUsers returns list of nicknames of the users connected to this server

func (*Server) GetUser

func (s *Server) GetUser(nickName string) (*User, error)

GetUser gets a connected user

func (*Server) InterviewUser

func (s *Server) InterviewUser(conn drivers.Connection)

InterviewUser interviews user and allows him to connect after identification

func (*Server) IsUserConnected

func (s *Server) IsUserConnected(nickName string) bool

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

func (s *Server) RemoveUser(nickName string) error

RemoveUser from this server

func (*Server) RemoveUserFromChannel

func (s *Server) RemoveUserFromChannel(nickName, channelName string) error

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 NewUser

func NewUser(nickName string) *User

NewUser returns a new new User

func (*User) Disconnect

func (u *User) Disconnect() error

Disconnect a user from this server

func (*User) GetChannel

func (u *User) GetChannel() string

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

func (u *User) GetIncoming() (string, error)

GetIncoming gets the incoming message from the user

func (*User) GetNickName

func (u *User) GetNickName() string

GetNickName returns the nickname of this user

func (*User) GetOutgoing

func (u *User) GetOutgoing() string

GetOutgoing gets the outgoing message for a user

func (*User) HandleNewInput

func (u *User) HandleNewInput(chatServer *Server, userInput string) (bool, error)

HandleNewInput interprets user input and lets chatServer handle it

func (*User) HasIgnored

func (u *User) HasIgnored(nickName string) bool

HasIgnored checks to see if a user has ignored another user or not

func (*User) Ignore

func (u *User) Ignore(nickName string)

Ignore a user

func (*User) Listen

func (u *User) Listen(chatServer *Server)

Listen starts reading from and writing to a user

func (*User) ReadFrom

func (u *User) ReadFrom(chatServer *Server)

ReadFrom reads data from users and lets chat server interpret it

func (*User) SetChannel

func (u *User) SetChannel(name string)

SetChannel sets the current channel name for the user

func (*User) SetIncoming

func (u *User) SetIncoming(message string)

SetIncoming sets an incoming message from the user

func (*User) SetNickName

func (u *User) SetNickName(nickName string)

SetNickName sets the nickname for this user

func (*User) SetOutgoing

func (u *User) SetOutgoing(messageType int, message string)

SetOutgoing sets an outgoing message to the user

func (*User) SetOutgoingf

func (u *User) SetOutgoingf(messageType int, format string, a ...interface{})

SetOutgoingf sets an outgoing message to the user

func (*User) WriteTo

func (u *User) WriteTo()

WriteTo to the user's connection and remembers the last message that was sent out

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL