mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 09:43:37 +02:00
Broadcast leave message to channel the client left
This commit is contained in:
parent
89f9b7cc41
commit
ea34d7b4a2
@ -149,12 +149,43 @@ public class DChannel
|
|||||||
/* Set it as the new list */
|
/* Set it as the new list */
|
||||||
members = newMembers;
|
members = newMembers;
|
||||||
|
|
||||||
/* TODO: Send left message here */
|
/* Unlock the members list */
|
||||||
|
memberLock.unlock();
|
||||||
|
|
||||||
|
/* Send broadcast leave message */
|
||||||
|
broadcastLeave(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void broadcastLeave(DConnection left)
|
||||||
|
{
|
||||||
|
/* Lock the members list */
|
||||||
|
memberLock.lock();
|
||||||
|
|
||||||
|
/* Send left message here */
|
||||||
|
foreach(DConnection currentMember; members)
|
||||||
|
{
|
||||||
|
sendLeaveMessage(currentMember, left);
|
||||||
|
}
|
||||||
|
|
||||||
/* Unlock the members list */
|
/* Unlock the members list */
|
||||||
memberLock.unlock();
|
memberLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendLeaveMessage(DConnection member, DConnection left)
|
||||||
|
{
|
||||||
|
/* The protocol data to send */
|
||||||
|
byte[] protocolData;
|
||||||
|
|
||||||
|
/* Set the notificaiton type to `channel status` */
|
||||||
|
protocolData ~= [1];
|
||||||
|
|
||||||
|
/* Set the channel notificaiton type to `member leave` */
|
||||||
|
protocolData ~= cast(byte[])left.getUsername();
|
||||||
|
|
||||||
|
/* Write the notification */
|
||||||
|
member.writeSocket(0, protocolData);
|
||||||
|
}
|
||||||
|
|
||||||
public bool sendMessage(DConnection sender, string message)
|
public bool sendMessage(DConnection sender, string message)
|
||||||
{
|
{
|
||||||
bool status;
|
bool status;
|
||||||
@ -162,7 +193,7 @@ public class DChannel
|
|||||||
/* The protocol data to send */
|
/* The protocol data to send */
|
||||||
byte[] msg;
|
byte[] msg;
|
||||||
|
|
||||||
/* Set the notificaiton type */
|
/* Set the notificaiton type to `message notification` */
|
||||||
msg ~= [0];
|
msg ~= [0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,14 +214,21 @@ public class DChannel
|
|||||||
/* Send the message */
|
/* Send the message */
|
||||||
writeln("Delivering message '"~message~"' for channel '"~name~"' to user '"~member.getUsername()~"'...");
|
writeln("Delivering message '"~message~"' for channel '"~name~"' to user '"~member.getUsername()~"'...");
|
||||||
status = member.writeSocket(0, msg);
|
status = member.writeSocket(0, msg);
|
||||||
|
|
||||||
|
if(status)
|
||||||
|
{
|
||||||
writeln("Delivered message '"~message~"' for channel '"~name~"' to user '"~member.getUsername()~"'!");
|
writeln("Delivered message '"~message~"' for channel '"~name~"' to user '"~member.getUsername()~"'!");
|
||||||
|
}
|
||||||
/* TODO: Errors from status */
|
else
|
||||||
|
{
|
||||||
|
writeln("Failed to deliver message '"~message~"' for channel '"~name~"' to user '"~member.getUsername()~"'!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return status;
|
/* TODO: Don't, retur true */
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string toString()
|
public override string toString()
|
||||||
|
@ -155,6 +155,8 @@ public class DConnection : Thread
|
|||||||
|
|
||||||
/* Remove this user from the connection queue */
|
/* Remove this user from the connection queue */
|
||||||
server.removeConnection(this);
|
server.removeConnection(this);
|
||||||
|
|
||||||
|
writeln(to!(string)(this)~" Connection cleaned up");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: add mutex for writing with message and funciton for doing so */
|
/* TODO: add mutex for writing with message and funciton for doing so */
|
||||||
|
Loading…
Reference in New Issue
Block a user