private void BridgeMain() { var input = string.Empty; OnServerConnect.Invoke(this, new EventArgs()); try { while ((input = reader.ReadLine()) != null) { //IrcLog(input); var tokens = input.Split(' '); if (tokens[0].ToUpper() == "PING") { Write("PONG " + tokens[1]); } else { switch (tokens[1].ToUpper()) { case "PRIVMSG": ChannelMessageReceived(input); break; default: break; } } } } catch (Exception err) { } IrcLog($"BridgeMain() Terminated. Connection to {Config.UplinkHost} has been lost. "); }
public FizzySteamyMirror() { // dispatch the events from the server server.OnConnected += (id) => OnServerConnect?.Invoke(id); server.OnDisconnected += (id) => OnServerDisconnect?.Invoke(id); server.OnReceivedData += (id, data) => OnServerData?.Invoke(id, data); server.OnReceivedError += (id, exception) => OnServerError?.Invoke(id, exception); // dispatch events from the client client.OnConnected += () => OnClientConnect?.Invoke(); client.OnDisconnected += () => OnClientDisconnect?.Invoke(); client.OnReceivedData += (data) => OnClientData?.Invoke(data); client.OnReceivedError += (exception) => OnClientError?.Invoke(exception); Debug.Log("FizzySteamyMirror initialized!"); }
public void ConnectOrDisconnect() { if (TCPClient.Connected) { TCPClient.Client.Disconnect(true); UDPListen = false; TCPListen = false; Clients.Clear(); if (UPnPEnabled) { ClearUpUPnP(); } if (OnServerDisconnect != null) { OnServerDisconnect.Invoke(this, new EventArgs()); } if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Disconnected."); } } else { try { InternetAccessAdapter = GetAdapterWithInternetAccess(); if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Adapter with Internet Access: " + InternetAccessAdapter); } TCPClient = new TcpClient(); TCPClient.Client.Connect(ServerEndpoint); UDPListen = true; TCPListen = true; SendMessageUDP(LocalClientInfo.Simplified(), ServerEndpoint); LocalClientInfo.InternalEndpoint = (IPEndPoint)UDPClient.Client.LocalEndPoint; if (UPnPEnabled) { UPnPMappings = UPnPNAT.StaticPortMappingCollection; ClearUpUPnP(); if (LocalClientInfo.InternalEndpoint != null) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "UDP Listening on Port " + LocalClientInfo.InternalEndpoint.Port); } if (AttemptUPnP(LocalClientInfo.InternalEndpoint.Port)) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "UPnP Map Added"); } LocalClientInfo.UPnPEnabled = true; } else { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "UPnP Mapping Not Possible"); } } } } Thread.Sleep(500); SendMessageTCP(LocalClientInfo); Thread KeepAlive = new Thread(new ThreadStart(delegate { while (TCPClient.Connected) { Thread.Sleep(5000); SendMessageTCP(new KeepAlive()); } })); KeepAlive.IsBackground = true; KeepAlive.Start(); if (OnServerConnect != null) { OnServerConnect.Invoke(this, new EventArgs()); } } catch (Exception ex) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Error when connecting " + ex.Message); } } } }