Skip to content
Snippets Groups Projects
Commit f8f82ab7 authored by Denis Maurin's avatar Denis Maurin
Browse files

feature(comm): broadcast

parent b97ad260
No related branches found
No related tags found
1 merge request!46comm broadcast
......@@ -17,7 +17,6 @@ namespace Client.comm
this.send = send;
}
void IDataToComm.announceUser(User user)
{
AnnounceUserMessage msg = new AnnounceUserMessage(user);
......
......@@ -53,13 +53,27 @@ namespace Server.comm
private void OnReceiveFrom(MessageToServer msg, string id)
{
msg.Handle(id, this.CommToDataServer, this.SendTo);
msg.Handle(
id,
this.CommToDataServer,
this.SendTo,
this.BroadcastExceptTo
);
}
public void SendTo(MessageToClient msg, string id)
{
this.tcpClientHandlers[id].Send(msg);
}
public void BroadcastExceptTo(MessageToClient msg, string exceptId)
{
foreach(KeyValuePair<string, TcpClientHandler<MessageToClient, MessageToServer>> client in this.tcpClientHandlers)
{
if(client.Key == exceptId) break;
client.Value.Send(msg);
}
}
// TODO : clean stop or destroy
}
......
......@@ -44,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="comm\messages\NotifyUserChangeMessage.cs" />
<Compile Include="comm\TcpClientHandler.cs" />
<Compile Include="data\Game.cs" />
<Compile Include="data\LightGame.cs" />
......@@ -59,7 +60,7 @@
<Compile Include="interfaces\ICommToData.cs" />
<Compile Include="interfaces\ICommToDataServer.cs" />
<Compile Include="comm\messages\AnnounceUserMessage.cs" />
<Compile Include="comm\messages\UserAnnouncedMessage.cs" />
<Compile Include="comm\messages\RegisterUserReturnMessage.cs" />
<Compile Include="comm\MessageToClient.cs" />
<Compile Include="comm\MessageToServer.cs" />
<Compile Include="interfaces\IDataToComm.cs" />
......
......@@ -11,7 +11,8 @@ namespace Shared.comm
public abstract void Handle(
string id,
ICommToDataServer commToDataServer,
Action<MessageToClient, string> sendTo
Action<MessageToClient, string> sendTo,
Action<MessageToClient, string> broadcastExceptTo
);
}
}
using Shared.comm.messages;
using Shared.data;
using Shared.interfaces;
using System;
......@@ -21,12 +22,14 @@ namespace Shared.comm
public override void Handle(
string id,
ICommToDataServer commToDataServer,
Action<MessageToClient, string> sendTo
Action<MessageToClient, string> sendTo,
Action<MessageToClient, string> broadcastExceptTo
)
{
Console.WriteLine(this.user.firstname);
// commToDataServer.$
sendTo(new UserAnnouncedMessage(), id);
sendTo(new RegisterUserReturnMessage(), id);
broadcastExceptTo(new NotifyUserChangeMessage(), id);
}
}
}
......
using Shared.interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.comm.messages
{
public class NotifyUserChangeMessage : MessageToClient
{
/// <summary>
/// Operates the process of the message.
/// </summary>
public override void Handle(ICommToData commToData)
{
//commToData.$
}
}
}
......@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Shared.comm
{
public class UserAnnouncedMessage : MessageToClient
public class RegisterUserReturnMessage : MessageToClient
{
/// <summary>
/// Operates the process of the message.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment