void _server_ClientMessageReceivedEvent(SocketMessageServer server, SocketCommunicatorEx client, object message) { ServerAccessControl accessControl = AccessControl; // Check security first. if (accessControl != null && message is AccessMessage == false) { if (accessControl.IsAllowed(ObtainClientAccessControl(client.Id)) == false) { #if Matrix_Diagnostics InstanceMonitor.Info("Message [" + message.ToString() +"] from client [" + client.ToString() + "] not allowed due to access control.", TracerItem.PriorityEnum.Medium); #endif return; } } if (message is EnvelopeMessage) {// Envelope user message. EnvelopeMessage envelopeMessage = (EnvelopeMessage)message; // Remove the remote message bus index association. envelopeMessage.Sender.LocalMessageBusIndex = ClientId.InvalidMessageBusClientIndex; foreach (ClientId id in envelopeMessage.Receivers) { // Assign the id as local id, if it is, otherwise skip it. id.LocalMessageBusIndex = base.GetClientIndexByGuid(id.Guid); if (id.IsMessageBusIndexValid) { id.MessageBus = this; if (DoSendToClient(envelopeMessage.Sender, id, envelopeMessage.Envelope, null) != SendToClientResultEnum.Success) { #if Matrix_Diagnostics InstanceMonitor.OperationError(string.Format("Failed to accept envelope message [{0}].", envelopeMessage.ToString())); #endif } } else { #if Matrix_Diagnostics InstanceMonitor.OperationError(string.Format("Failed to accept envelope message [{0}] due unrecognized receiver id.", envelopeMessage.ToString())); #endif } } } else if (message is ClientsListMessage) {// Message bus system message. ClientsListMessage updateMessage = (ClientsListMessage)message; for (int i = 0; i < updateMessage.Ids.Count; i++) { RegisterClientId(client.Id, updateMessage.Ids[i], updateMessage.Types[i], updateMessage.SourcesTypes[i]); } } else if (message is RequestClientListUpdateMessage) { SendClientsUpdate(client.Id); } else if (message is ClientUpdateMessage) { ClientUpdateMessage updateMessage = (ClientUpdateMessage)message; bool validClient; lock (_syncRoot) { validClient = _remoteClientNetId.ContainsKey(updateMessage.ClientId); } if (validClient) { RaiseClientAddedEvent(updateMessage.ClientId); } else { #if Matrix_Diagnostics InstanceMonitor.OperationError(string.Format("Failed to raise update event for client [{0}], since client not found.", updateMessage.ClientId.ToString())); #endif } } else if (message is AccessMessage) { ClientAccessControl control = ObtainClientAccessControl(client.Id); if (control != null) { control.Update(message as AccessMessage); } } else if (message is StateUpdateMessage) { RaiseCounterPartyUpdateEvent("Client:" + client.Id.ToString(), ((StateUpdateMessage)message).State.ToString()); } else { #if Matrix_Diagnostics InstanceMonitor.Warning(string.Format("Message [{0}] not recognized.", message.GetType().Name)); #endif } }
void _server_ClientConnectedEvent(SocketMessageServer server, SocketCommunicatorEx client) { // The client expects is, so activate keep alive. client.KeepAlive = true; // Send local bus clients info to connected element. // Important - this will also be sent even to clients that do not have verified access control. if (SendClientsUpdate(client.Id) == false) { #if Matrix_Diagnostics InstanceMonitor.OperationError("Failed to send clients update to client [" + client.ToString() + ", " + client.Id + "]."); #endif } }