mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 20:09:41 +01:00
Disable channel modes and remove some client modes.
This commit is contained in:
parent
c99bc6b453
commit
dbaa73a319
@ -6,11 +6,7 @@ type Channel struct {
|
|||||||
key string
|
key string
|
||||||
topic string
|
topic string
|
||||||
members ClientSet
|
members ClientSet
|
||||||
invites map[string]bool
|
|
||||||
// modes
|
|
||||||
inviteOnly bool
|
|
||||||
noOutside bool
|
noOutside bool
|
||||||
// modes with args
|
|
||||||
password string
|
password string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +18,6 @@ func NewChannel(s *Server, name string) *Channel {
|
|||||||
return &Channel{
|
return &Channel{
|
||||||
name: name,
|
name: name,
|
||||||
members: make(ClientSet),
|
members: make(ClientSet),
|
||||||
invites: make(map[string]bool),
|
|
||||||
server: s,
|
server: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,11 +52,6 @@ func (ch *Channel) IsEmpty() bool {
|
|||||||
|
|
||||||
func (ch *Channel) Join(cl *Client, key string) {
|
func (ch *Channel) Join(cl *Client, key string) {
|
||||||
if ch.key != key {
|
if ch.key != key {
|
||||||
cl.send <- ErrInviteOnlyChannel(ch)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if ch.inviteOnly && !ch.invites[cl.nick] {
|
|
||||||
cl.send <- ErrBadChannelKey(ch)
|
cl.send <- ErrBadChannelKey(ch)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -122,20 +112,3 @@ func (ch *Channel) ChangeTopic(cl *Client, newTopic string) {
|
|||||||
ch.Send(RplNoTopic(ch), nil)
|
ch.Send(RplNoTopic(ch), nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *Channel) Invite(inviter *Client, invitee *Client) {
|
|
||||||
if !ch.members[inviter] {
|
|
||||||
inviter.send <- ErrNotOnChannel(ch)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if ch.members[invitee] {
|
|
||||||
inviter.send <- ErrUserOnChannel(ch, invitee)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
ch.invites[invitee.nick] = true
|
|
||||||
|
|
||||||
invitee.send <- RplInviteMsg(ch, inviter)
|
|
||||||
inviter.send <- RplInvitingMsg(ch, invitee)
|
|
||||||
}
|
|
||||||
|
@ -7,25 +7,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
// communication
|
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
send chan<- Reply
|
send chan<- Reply
|
||||||
recv <-chan string
|
recv <-chan string
|
||||||
// basic info
|
|
||||||
username string
|
username string
|
||||||
realname string
|
realname string
|
||||||
hostname string
|
hostname string
|
||||||
nick string
|
nick string
|
||||||
serverPass bool
|
serverPass bool
|
||||||
registered bool
|
registered bool
|
||||||
// modes
|
|
||||||
away bool
|
away bool
|
||||||
invisible bool
|
|
||||||
wallOps bool
|
wallOps bool
|
||||||
restricted bool
|
|
||||||
operator bool
|
|
||||||
localOperator bool
|
|
||||||
// relations
|
|
||||||
server *Server
|
server *Server
|
||||||
channels ChannelSet
|
channels ChannelSet
|
||||||
}
|
}
|
||||||
@ -77,14 +69,10 @@ func (c *Client) Nick() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UModeString() string {
|
func (c *Client) UModeString() string {
|
||||||
mode := "+"
|
|
||||||
if c.invisible {
|
|
||||||
mode += "i"
|
|
||||||
}
|
|
||||||
if c.wallOps {
|
if c.wallOps {
|
||||||
mode += "w"
|
return "+w"
|
||||||
}
|
}
|
||||||
return mode
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) HasNick() bool {
|
func (c *Client) HasNick() bool {
|
||||||
|
@ -226,6 +226,15 @@ func (m *ModeMessage) Handle(s *Server, c *Client) {
|
|||||||
s.ChangeUserMode(c, m.modes)
|
s.ChangeUserMode(c, m.modes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ChannelModeMessage) Handle(s *Server, c *Client) {
|
||||||
|
channel := s.channels[m.channel]
|
||||||
|
if channel != nil {
|
||||||
|
c.send <- ErrNoChanModes(channel)
|
||||||
|
} else {
|
||||||
|
c.send <- ErrNoSuchChannel(s, m.channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// JOIN ( <channel> *( "," <channel> ) [ <key> *( "," <key> ) ] ) / "0"
|
// JOIN ( <channel> *( "," <channel> ) [ <key> *( "," <key> ) ] ) / "0"
|
||||||
|
|
||||||
type JoinMessage struct {
|
type JoinMessage struct {
|
||||||
@ -372,39 +381,6 @@ func (m *TopicMessage) Handle(s *Server, c *Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// INVITE <nickname> <channel>
|
|
||||||
|
|
||||||
type InviteMessage struct {
|
|
||||||
nickname string
|
|
||||||
channel string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewInviteMessage(args []string) (Message, error) {
|
|
||||||
if len(args) < 2 {
|
|
||||||
return nil, NotEnoughArgsError
|
|
||||||
}
|
|
||||||
return &InviteMessage{
|
|
||||||
nickname: args[0],
|
|
||||||
channel: args[1],
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *InviteMessage) Handle(s *Server, c *Client) {
|
|
||||||
channel := s.channels[m.channel]
|
|
||||||
if channel == nil {
|
|
||||||
c.send <- ErrNoSuchNick(s, m.channel)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
invitee := s.nicks[m.nickname]
|
|
||||||
if invitee == nil {
|
|
||||||
c.send <- ErrNoSuchNick(s, m.nickname)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.Invite(c, invitee)
|
|
||||||
}
|
|
||||||
|
|
||||||
// OPER <name> <password>
|
// OPER <name> <password>
|
||||||
|
|
||||||
type OperMessage struct {
|
type OperMessage struct {
|
||||||
|
@ -10,7 +10,6 @@ type ParseFunc func([]string) (Message, error)
|
|||||||
var (
|
var (
|
||||||
ErrParseMessage = errors.New("failed to parse message")
|
ErrParseMessage = errors.New("failed to parse message")
|
||||||
parseCommandFuncs = map[string]ParseFunc{
|
parseCommandFuncs = map[string]ParseFunc{
|
||||||
"INVITE": NewInviteMessage,
|
|
||||||
"JOIN": NewJoinMessage,
|
"JOIN": NewJoinMessage,
|
||||||
"MODE": NewModeMessage,
|
"MODE": NewModeMessage,
|
||||||
"NICK": NewNickMessage,
|
"NICK": NewNickMessage,
|
||||||
|
@ -77,7 +77,7 @@ func RplCreated(server *Server) Reply {
|
|||||||
|
|
||||||
func RplMyInfo(server *Server) Reply {
|
func RplMyInfo(server *Server) Reply {
|
||||||
return NewReply(server, RPL_MYINFO,
|
return NewReply(server, RPL_MYINFO,
|
||||||
fmt.Sprintf("%s %s w ikn", server.name, VERSION))
|
fmt.Sprintf("%s %s w kn", server.name, VERSION))
|
||||||
}
|
}
|
||||||
|
|
||||||
func RplUModeIs(server *Server, client *Client) Reply {
|
func RplUModeIs(server *Server, client *Client) Reply {
|
||||||
@ -187,3 +187,8 @@ func ErrNoSuchNick(source Identifier, nick string) Reply {
|
|||||||
func ErrPasswdMismatch(server *Server) Reply {
|
func ErrPasswdMismatch(server *Server) Reply {
|
||||||
return NewReply(server, ERR_PASSWDMISMATCH, ":Password incorrect")
|
return NewReply(server, ERR_PASSWDMISMATCH, ":Password incorrect")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ErrNoChanModes(channel *Channel) Reply {
|
||||||
|
return NewReply(channel.server, ERR_NOCHANMODES,
|
||||||
|
channel.name+" :Channel doesn't support modes")
|
||||||
|
}
|
||||||
|
@ -142,16 +142,6 @@ func (s *Server) Quit(c *Client, message string) {
|
|||||||
func (s *Server) ChangeUserMode(c *Client, modes []string) {
|
func (s *Server) ChangeUserMode(c *Client, modes []string) {
|
||||||
for _, mode := range modes {
|
for _, mode := range modes {
|
||||||
switch mode {
|
switch mode {
|
||||||
case "+i":
|
|
||||||
c.invisible = true
|
|
||||||
case "-i":
|
|
||||||
c.invisible = false
|
|
||||||
case "-o":
|
|
||||||
c.operator = false
|
|
||||||
case "-O":
|
|
||||||
c.localOperator = false
|
|
||||||
case "+r":
|
|
||||||
c.restricted = true
|
|
||||||
case "+w":
|
case "+w":
|
||||||
c.wallOps = true
|
c.wallOps = true
|
||||||
case "-w":
|
case "-w":
|
||||||
|
Loading…
Reference in New Issue
Block a user