private object SendMessage(NetCoreMessage _message, bool synced = false, bool external = false) { if (!external && _message.Type.Contains('|')) { string[] splitType = _message.Type.Split('|'); string target = splitType[0]; _message.Type = splitType[1]; if (LocalNetCoreRouter.hasEndpoint(target)) { if (synced) { if (((NetCoreAdvancedMessage)_message).requestGuid == null) { ((NetCoreAdvancedMessage)_message).requestGuid = Guid.NewGuid(); } } return(LocalNetCoreRouter.Route(target, new NetCoreEventArgs() { message = _message })); } } return(hub?.SendMessage(_message, synced)); }
public void setReturnValue(object _objectValue) { var message = new NetCoreAdvancedMessage("{RETURNVALUE}") { objectValue = _objectValue }; if (returnMessage != null) { RTCV.Common.Logging.GlobalLogger.Warn($"NetCoreEventArgs: ReturnValue was already set but was overriden with another value"); } _returnMessage = message; }
public void setReturnValue(object _objectValue) { var message = new NetCoreAdvancedMessage("{RETURNVALUE}") { objectValue = _objectValue }; if (returnMessage != null) { ConsoleEx.WriteLine($"ReturnValue was already set but was overriden with another value"); } _returnMessage = message; }
internal void QueueMessage(NetCoreMessage message, bool priority = false) { lock (MessagePoolLock) { if (message.Type.Length > 0 && message.Type[0] == '{' && MessagePool.FirstOrDefault(it => it.Type == message.Type) != null) //Prevents doubling of internal messages { return; } if (priority) //This makes sure a prioritized message is the very next to be treated { MessagePool.AddFirst(message); } else { MessagePool.AddLast(message); } } }
internal object SendMessage(NetCoreMessage message, bool synced = false) { if (message is NetCoreSimpleMessage) { spec.Connector.udp.SendMessage((NetCoreSimpleMessage)message); } else //message is NetCoreAdvancedMessage { if (synced) { return(spec.Connector.tcp.SendSyncedMessage((NetCoreAdvancedMessage)message)); //This will block the sender's thread until a response is received } else { spec.Connector.tcp.SendMessage((NetCoreAdvancedMessage)message); //This sends the message async } } return(null); }
private object SendMessage(NetCoreMessage _message, bool synced = false) { if (_message.Type.Contains('|') && LocalNetCoreRouter.HasEndpoints) { string[] splitType = _message.Type.Split('|'); string target = splitType[0]; _message.Type = splitType[1]; if (synced) { (_message as NetCoreAdvancedMessage).requestGuid = Guid.NewGuid(); } return(LocalNetCoreRouter.Route(target, null, new NetCoreEventArgs() { message = _message })); } return(hub?.SendMessage(_message, synced)); }
internal bool ProcessAdvancedMessage(NetCoreMessage _message) { NetCoreAdvancedMessage message; if (_message is NetCoreAdvancedMessage) { message = (_message as NetCoreAdvancedMessage); } else { message = new NetCoreAdvancedMessage(_message.Type); // promote message to Advanced if simple ({BOOP} command goes through UDP Link) } if (!message.Type.StartsWith("{EVENT_") || ConsoleEx.ShowDebug) { ConsoleEx.WriteLine(spec.Side.ToString() + ":Process advanced message -> " + message.Type.ToString()); } switch (message.Type) { // NetCore Internal Commands // Some of these commands go through the UDP Link but are upgraded to an Advanced Message // As they are parsed by the Message Hub case "{HI}": //Greetings to confirm that communication is established expectingSomeone = true; status = NetworkStatus.CONNECTED; if (spec.Side == NetworkSide.SERVER) { //Server receives {HI} after client has established connection ConsoleEx.WriteLine($"TCP Server Connected"); //spec.OnServerConnected(null); spec.Connector.hub.QueueMessage(new NetCoreAdvancedMessage("{EVENT_SERVERCONNECTED}")); SendMessage(new NetCoreAdvancedMessage("{HI}")); } else //(side == NetworkSide.CLIENT) { //Client always sends the first {HI} but will wait for the Server to reply with one ConsoleEx.WriteLine($"TCP Client Connected to {IP}:{Port}"); //spec.OnClientConnected(null); spec.Connector.hub.QueueMessage(new NetCoreAdvancedMessage("{EVENT_CLIENTCONNECTED}")); } break; case "{BYE}": // End of disconnect Kill(); break; case "{BOOP}": // Ping system to confirm is TCP link is still in order // Boops are redirected through the UDP pipe so if the TCP Link is busy transfering a lot of data // or is jammed waiting for a return, these will still go through BoopMonitoringCounter = DefaultBoopMonitoringCounter; break; //THREADSAFE EVENT FIRING case "{EVENT_CLIENTCONNECTING}": spec.OnClientConnecting(null); break; case "{EVENT_CLIENTCONNECTINGFAILED}": spec.OnClientConnectingFailed(null); break; case "{EVENT_CLIENTCONNECTED}": spec.OnClientConnected(null); break; case "{EVENT_CLIENTDISCONNECTED}": spec.OnClientDisconnected(null); break; case "{EVENT_CLIENTCONNECTIONLOST}": spec.OnClientConnectionLost(null); break; case "{EVENT_SERVERLISTENING}": spec.OnServerListening(null); break; case "{EVENT_SERVERCONNECTED}": spec.OnServerConnected(null); break; case "{EVENT_SERVERDISCONNECTED}": spec.OnServerDisconnected(null); break; case "{EVENT_SERVERCONNECTIONLOST}": spec.OnServerConnectionLost(null); break; case "{EVENT_SYNCEDMESSAGESTART}": spec.OnSyncedMessageStart(null); break; case "{EVENT_SYNCEDMESSAGEEND}": spec.OnSyncedMessageEnd(null); break; default: //If message wasn't procesed, just return false //Message may be handled on an upper level return(false); } return(true); }