mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 09:43:37 +02:00
Implemented memberlist
command
This commit is contained in:
parent
411e15d53d
commit
87eb1f02e7
@ -291,6 +291,26 @@ public class DChannel
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of all the members
|
||||||
|
*/
|
||||||
|
public DConnection[] getMembers()
|
||||||
|
{
|
||||||
|
/* Members list */
|
||||||
|
DConnection[] memberList;
|
||||||
|
|
||||||
|
/* Lock the members list */
|
||||||
|
memberLock.lock();
|
||||||
|
|
||||||
|
memberList = members;
|
||||||
|
|
||||||
|
/* Unlock the members list */
|
||||||
|
memberLock.unlock();
|
||||||
|
|
||||||
|
return memberList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override string toString()
|
public override string toString()
|
||||||
{
|
{
|
||||||
string toStr;
|
string toStr;
|
||||||
|
@ -41,6 +41,7 @@ public class DConnection : Thread
|
|||||||
LIST,
|
LIST,
|
||||||
MSG,
|
MSG,
|
||||||
MEMBER_COUNT,
|
MEMBER_COUNT,
|
||||||
|
MEMBER_LIST,
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,6 +485,59 @@ public class DConnection : Thread
|
|||||||
/* Append the length */
|
/* Append the length */
|
||||||
reply ~= numberBytes;
|
reply ~= numberBytes;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
/* If `memberlist` command (requires: authed, client) */
|
||||||
|
else if(command == Command.MEMBER_LIST && hasAuthed && connType == ConnectionType.CLIENT)
|
||||||
|
{
|
||||||
|
/* Status */
|
||||||
|
bool status = true;
|
||||||
|
|
||||||
|
/* Get the channel name */
|
||||||
|
string channelName = cast(string)message.data[1..message.data.length];
|
||||||
|
|
||||||
|
/* Get the channel */
|
||||||
|
DChannel channel = server.getChannelByName(channelName);
|
||||||
|
|
||||||
|
/* Encode the status */
|
||||||
|
reply ~= [channel !is null];
|
||||||
|
|
||||||
|
/* If the channel exists */
|
||||||
|
if(channel)
|
||||||
|
{
|
||||||
|
/* Get the list of members in the channel */
|
||||||
|
DConnection[] members = channel.getMembers();
|
||||||
|
|
||||||
|
/* Construct a CSV string of the members */
|
||||||
|
string memberString;
|
||||||
|
|
||||||
|
for(ulong i = 0; i < members.length; i++)
|
||||||
|
{
|
||||||
|
if(i == members.length-1)
|
||||||
|
{
|
||||||
|
memberString ~= members[i].getUsername();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memberString ~= members[i].getUsername()~",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode the string into the reply */
|
||||||
|
reply ~= cast(byte[])memberString;
|
||||||
|
}
|
||||||
|
/* If the channel does not exist */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/* If no matching built-in command was found */
|
/* If no matching built-in command was found */
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user