예제 #1
0
        private static void ReconnectAllSockets()
        {
            foreach (KeyValuePair <string, TcpClientEntry> kvPair in DllEntry.tcpClients)
            {
                string         hash  = kvPair.Key;
                TcpClientEntry entry = kvPair.Value;

                if (!DllEntry.IsConnected(entry.TcpClient))
                {
                    try
                    {
                        entry.TcpClient.Close();
                    }
                    catch (ObjectDisposedException) { }

                    try
                    {
                        entry.TcpClient = DllEntry.Connect(entry.Uri);
                        Log("Reconnected");
                    }
                    catch (SocketException e)
                    {
                        Log($"Reconnect - Socket exception {e.Message}");
                    }
                }
            }
        }
예제 #2
0
        public static string Connect(string address)
        {
            string hash = "";

            using (SHA1Managed sha1 = new SHA1Managed())
            {
                hash = string.Join("", sha1.ComputeHash(Encoding.Default.GetBytes(address)).Select(b => b.ToString("x2"))).Substring(0, 7);
            }
            Log(hash);

            if (DllEntry.tcpClients.ContainsKey(hash))
            {
                return(hash);
            }

            if (!Uri.TryCreate(address, UriKind.Absolute, out Uri uri))
            {
                Log("Malformed address: " + address);
                return("error");
            }

            Log("Connecting to: " + uri.Host + ":" + uri.Port);
            TcpClient tcpClient = DllEntry.Connect(uri);

            DllEntry.tcpClients.Add(hash, new TcpClientEntry()
            {
                Uri = uri, TcpClient = tcpClient
            });

            return(hash);
        }
예제 #3
0
        public static void RVExtension(StringBuilder output, int outputSize, [MarshalAs(UnmanagedType.LPStr)] string input)
        {
            if (input != "version")
            {
                return;
            }

            output.Append(DllEntry.GetVersion());
        }
예제 #4
0
        public static string IsConnected(string hash)
        {
            if (!DllEntry.tcpClients.ContainsKey(hash))
            {
                return("error");
            }

            return(DllEntry.IsConnected(DllEntry.tcpClients[hash].TcpClient) ? "success" : "false");
        }
예제 #5
0
        private static void OnTick(object state)
        {
            DllEntry.ReconnectAllSockets();

            List <int> ports = DllEntry.GetArmaServerPorts();

            if (!ports.SequenceEqual(DllEntry.serverPorts))
            {
                DllEntry.serverPorts = ports;
                foreach (TcpClientEntry tcpClientEntry in DllEntry.tcpClients.Values)
                {
                    DllEntry.Send(tcpClientEntry.TcpClient, $"PORTS:{string.Join(":", DllEntry.serverPorts)}");
                }
            }
        }
예제 #6
0
        public static string Send(string data)
        {
            string[] dataParts = data.Split(new char[] { ':' }, 2);
            string   hash      = dataParts[0];

            data = dataParts[1];

            if (!DllEntry.tcpClients.ContainsKey(hash))
            {
                return("Socket for address not connected");
            }

            DllEntry.Send(DllEntry.tcpClients[hash].TcpClient, data);

            return("success");
        }
예제 #7
0
 public static void RVExtensionVersion(StringBuilder output, int outputSize)
 {
     output.Append(DllEntry.GetVersion());
 }