public void SendToAllExcept(List <string> addressesToExclude, DetourMessage message) { if (addressesToExclude.Count == 1) { foreach (var item in RoomClients) { if (item.Key != addressesToExclude[0]) { Server.MessagesToSend.Enqueue(new SendableMessage { Address = item.Key, Message = message }); } } } else { foreach (var item in RoomClients) { if (!addressesToExclude.Contains(item.Key)) { Server.MessagesToSend.Enqueue(new SendableMessage { Address = item.Key, Message = message }); } } } }
/// <summary> /// Enqueues a Message to send to Address as JSON. /// </summary> public static void SendMessage(string Address, DetourMessage Message) { MessagesToSend.Enqueue(new SendableMessage { Address = Address, Message = Message }); }
public void SendToAll(DetourMessage message) { foreach (var item in RoomClients.Values) { Server.MessagesToSend.Enqueue(new SendableMessage { Address = item.Id, Message = message }); } }
/// <summary> /// Called by the ClientContainer when message is received, runs it through the appropriate handler. /// </summary> public static void ReceivedMessage(string Address, DetourMessage v) { if (MessageTypeToMessageDefinition.ContainsKey(v.MessageType)) { MessageTypeToMessageDefinition[v.MessageType].EventHandler(Address, v); } if (ServerReceivedMessage != null) { ServerReceivedMessage.Invoke(Address, v); } }
public static void RoomRequestReceived(string Address, DetourMessage RoomMessage) { Console.WriteLine("room request received"); var _RoomMessageFromClient = RoomMessage as RoomRequestMessage; var _SelectedClient = AllClients[Address]; if (RoomTypes.ContainsKey(_RoomMessageFromClient.RequestedRoomType)) { var successfulMatch = MatchToRoom(_RoomMessageFromClient.RequestedRoomType, _SelectedClient); if (successfulMatch != null) { RoomTypes[_RoomMessageFromClient.RequestedRoomType].OnRoomJoined.Invoke(Address, successfulMatch, RoomMessage); } } }
public static void SendToRoomExcept(string RoomId, List <string> AddressesToExclude, DetourMessage Message) { Console.WriteLine("Sending to all except " + AddressesToExclude.Count); Rooms[RoomId].SendToAllExcept(AddressesToExclude, Message); }
public static void SendToRoom(string RoomId, DetourMessage Message) { Rooms[RoomId].SendToAll(Message); }