forked from lesderid/salty-ircd
Refactor channel management and give +o on creation
This commit is contained in:
parent
0bd65fd449
commit
3c43cfa64b
|
@ -10,24 +10,32 @@ import ircd.message;
|
|||
class Channel
|
||||
{
|
||||
string name;
|
||||
|
||||
Connection[] members;
|
||||
Connection owner;
|
||||
|
||||
string topic = "";
|
||||
|
||||
Connection[] members;
|
||||
char[] modes;
|
||||
char[][Connection] memberModes;
|
||||
|
||||
private Server _server;
|
||||
|
||||
this(string name, Connection owner, Server server)
|
||||
this(string name, Server server)
|
||||
{
|
||||
this.name = name;
|
||||
this.owner = owner;
|
||||
this.members = [owner];
|
||||
this.members = [];
|
||||
this._server = server;
|
||||
}
|
||||
|
||||
void join(Connection connection)
|
||||
{
|
||||
members ~= connection;
|
||||
memberModes[connection] = null;
|
||||
|
||||
if(members.length == 1)
|
||||
{
|
||||
memberModes[connection] ~= 'o';
|
||||
}
|
||||
}
|
||||
|
||||
void sendNames(Connection connection, bool sendRplEndOfNames = true)
|
||||
{
|
||||
string channelType;
|
||||
|
@ -47,7 +55,7 @@ class Channel
|
|||
|
||||
auto onChannel = members.canFind(connection);
|
||||
|
||||
connection.send(Message(_server.name, "353", [connection.nick, channelType, name, members.filter!(m => onChannel || !m.modes.canFind('i')).map!(m => m.nick).join(' ')], true));
|
||||
connection.send(Message(_server.name, "353", [connection.nick, channelType, name, members.filter!(m => onChannel || !m.modes.canFind('i')).map!(m => prefixedNick(m)).join(' ')], true));
|
||||
|
||||
if(sendRplEndOfNames)
|
||||
{
|
||||
|
@ -55,6 +63,16 @@ class Channel
|
|||
}
|
||||
}
|
||||
|
||||
string prefixedNick(Connection member)
|
||||
{
|
||||
if(memberModes[member].canFind('o'))
|
||||
{
|
||||
return '@' ~ member.nick;
|
||||
}
|
||||
|
||||
return member.nick;
|
||||
}
|
||||
|
||||
void sendPrivMsg(Connection sender, string text)
|
||||
{
|
||||
foreach(member; members.filter!(m => m.nick != sender.nick))
|
||||
|
|
|
@ -60,6 +60,21 @@ class Connection
|
|||
return 0;
|
||||
}
|
||||
|
||||
override bool opEquals(Object o)
|
||||
{
|
||||
Connection other;
|
||||
if((other = cast(Connection)o) !is null)
|
||||
{
|
||||
return nick == other.nick;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
override ulong toHash()
|
||||
{
|
||||
return typeid(nick).getHash(&nick);
|
||||
}
|
||||
|
||||
bool visibleTo(Connection other)
|
||||
{
|
||||
return !modes.canFind('i') || channels.any!(c => c.members.canFind(other));
|
||||
|
|
|
@ -130,14 +130,14 @@ class Server
|
|||
Channel channel;
|
||||
if(channelRange.empty)
|
||||
{
|
||||
channel = new Channel(channelName, connection, this);
|
||||
channel = new Channel(channelName, this);
|
||||
channels ~= channel;
|
||||
}
|
||||
else
|
||||
{
|
||||
channel = channelRange[0];
|
||||
channel.members ~= connection;
|
||||
}
|
||||
channel.join(connection);
|
||||
|
||||
foreach(member; channel.members)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue