Esempio n. 1
0
        public void SendMessage(Socket handler, string rec, Header type, RSAParameters key)
        {
            switch (type)
            {
            case Header.Login:
                JMessage jmess = JMessage.Deserialize(rec);
                KeyValuePair <string, string> kv = jmess.ToValue <KeyValuePair <string, string> >();

                string answ = ResolveLogin(kv.Key, kv.Value);

                Send(handler, answ, key);

                break;

            case Header.Message:
                jmess = JMessage.Deserialize(rec);
                //Console.WriteLine(Convert.FromBase64String(rec));
                Message message = jmess.ToValue <Message>();
                ServerApp.Messages.AddMessage(message);
                Send(handler, JMessage.Serialize(JMessage.FromValue <IList <CommonApp.Model.Message> >(ServerApp.Messages.GetMessagesOfUser(message.UserNameFrom), Header.Message)), key);
                break;

            case Header.Messages:
                string user = JMessage.Deserialize(rec).ToValue <string>();
                Send(handler, JMessage.Serialize(JMessage.FromValue <IList <CommonApp.Model.Message> >(ServerApp.Messages.GetMessagesOfUser(user), Header.Messages)), key);
                break;

            case Header.Users:
                jmess = JMessage.FromValue <Dictionary <string, string> >(ServerApp.Users.UsersDict, Header.Users);
                Send(handler, JMessage.Serialize(jmess), key);
                break;
            }
        }
Esempio n. 2
0
        public void UnpackAndSend(Socket handler, string message, Header type)
        {
            JMessage jmess = JMessage.Deserialize(message);
            KeyValuePair <string, string> keyValuePair = jmess.ToValue <KeyValuePair <string, string> >();
            RSAParameters param = (RSAParameters)ServerApp.Users.GetUserKeys()[keyValuePair.Key];

            SendMessage(handler, keyValuePair.Value, type, param);
        }
Esempio n. 3
0
        public void SendUnencrypted(Socket handler, string rec)
        {
            JMessage des = JMessage.Deserialize(rec);
            KeyValuePair <string, RSAParameters> kv2 = des.ToValue <KeyValuePair <string, RSAParameters> >();

            ServerApp.Users.SetUserKey(kv2.Key, kv2.Value);
            JMessage jmess;

            jmess = JMessage.FromValue <RSAParameters>(_RSA.ExportParameters(false), Header.ExchangePKs);
            handler.Send(Encoding.ASCII.GetBytes(JMessage.Serialize(jmess)));
        }
Esempio n. 4
0
        public T GetMessage <T>(string message)
        {
            JMessage mess = JMessage.Deserialize(message);

            return(mess.ToValue <T>());
        }