public void Send(GenericMessage MSG)
        {
            //We send Messages always from the "Addr" string variable.

            //check for broadcast receiver
            if (MSG.Receiver.StartsWith("[") && MSG.Receiver.EndsWith("]"))
            {
                Broadcast(MSG);
            }
            else
            {
                BA.sendMessage(MSG.Receiver, Addr, JsonConverter.B64enc(MSG.Command), JsonConverter.B64enc(MSG.RawContent));
                GenericServerLog(this, GenericLogType.Info, false, string.Format("Sending Message from {0} to {1}", Addr, MSG.Receiver));
            }
        }
        public void Start()
        {
            if (T != null)
            {
                Stop();
            }

            GenericServerLog(this, GenericLogType.Info, false, "Starting Bitmessage server");

            //Check if API has been set
            if (!QuickSettings.Has("API-ADDR") || !QuickSettings.Has("API-NAME") || !QuickSettings.Has("API-PASS") || !QuickSettings.Has("BM-ADDR"))
            {
                if (!AskAPI())
                {
                    GenericServerLog(this, GenericLogType.Fatal, true, "API Settings for Bitmessage have not been made. Please configure Bitmessage Plugin");
                    throw new Exception("API Settings for Bitmessage have not been made. Please configure Bitmessage Plugin");
                }
            }

            Addr   = QuickSettings.Get("BM-ADDR");
            BA     = (BitAPI)XmlRpcProxyGen.Create(typeof(BitAPI));
            BA.Url = string.Format("http://{0}/", QuickSettings.Get("API-ADDR"));
            BA.Headers.Add("Authorization", "Basic " + JsonConverter.B64enc(string.Format("{0}:{1}", QuickSettings.Get("API-NAME"), QuickSettings.Get("API-PASS"))));

            try
            {
                if (BA.helloWorld("A", "B") != "A-B")
                {
                    GenericServerLog(this, GenericLogType.Error, true, "API Settings for Bitmessage are wrong. The API seems to answer, but the answer is incorrect. Please check settings");
                    throw new Exception("API Settings for Bitmessage are wrong. The API seems to answer, but the answer is incorrect. Please check settings");
                }
            }
            catch
            {
                GenericServerLog(this, GenericLogType.Error, true, "Cannot contact Bitmessage API. Verify the client is running, has the API enabled and the settings are correct");
                throw new Exception("Cannot contact Bitmessage API. Verify the client is running, has the API enabled and the settings are correct");
            }
            T = new Thread(run);
            T.IsBackground = true;
            T.Start();
        }
Beispiel #3
0
        private static void save(NameValueCollection nvc)
        {
            string content = string.Empty;

            foreach (string k in nvc.AllKeys)
            {
                content += string.Format("{0}|{1}#", k, JsonConverter.B64enc(nvc[k]));
            }
            if (!Directory.Exists("Config"))
            {
                Directory.CreateDirectory("Config");
            }
            if (File.Exists(FILE))
            {
                File.Delete(FILE);
            }
            if (nvc.HasKeys())
            {
                File.WriteAllBytes(FILE, Crypt.Encrypt(Encoding.UTF8.GetBytes(content.Trim(new char[] { '#' })), PWD));
            }
        }
 public void Broadcast(GenericMessage MSG)
 {
     BA.sendBroadcast(Addr, JsonConverter.B64enc(MSG.Command), JsonConverter.B64enc(MSG.RawContent));
     GenericServerLog(this, GenericLogType.Info, false, string.Format("Sending Broadcast from {0}", Addr));
 }