Пример #1
0
        public static void sendNickname(byte[] recipient, byte[] contact_address)
        {
            if (contact_address != null && contact_address.Length > 1)
            {
                if (!Node.users.hasUser(contact_address))
                {
                    return;
                }
                byte[] nickData = Node.users.getUser(contact_address).nickData;
                if (nickData != null)
                {
                    sendMessage(recipient, new StreamMessage(nickData));
                }

                return;
            }

            SpixiMessage reply_spixi_message = new SpixiMessage(SpixiMessageCode.nick, Encoding.UTF8.GetBytes(Config.botName));

            byte[] sender = IxianHandler.getWalletStorage().getPrimaryAddress();

            // Send the nickname message to friend
            StreamMessage reply_message = new StreamMessage();

            reply_message.type           = StreamMessageCode.info;
            reply_message.recipient      = recipient;
            reply_message.sender         = sender;
            reply_message.data           = reply_spixi_message.getBytes();
            reply_message.encryptionType = StreamMessageEncryptionCode.none;
            reply_message.id             = new byte[] { 5 };

            reply_message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey());

            sendMessage(recipient, reply_message);
        }
Пример #2
0
        public static void sendAcceptAdd(byte[] recipient, byte[] pub_key)
        {
            Node.users.setPubKey(recipient, pub_key, false);
            var user = Node.users.getUser(recipient);

            if (user != null && user.status != BotContactStatus.banned)
            {
                user.status = BotContactStatus.normal;
            }

            SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.acceptAddBot, null);

            StreamMessage message = new StreamMessage();

            message.type           = StreamMessageCode.info;
            message.recipient      = recipient;
            message.sender         = IxianHandler.getWalletStorage().getPrimaryAddress();
            message.data           = spixi_message.getBytes();
            message.encryptionType = StreamMessageEncryptionCode.none;
            message.id             = new byte[] { 1 };

            message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey());

            sendMessage(recipient, message);
        }
Пример #3
0
        public static void onMsgDelete(byte[] msg_id, int channel, RemoteEndpoint endpoint)
        {
            StreamMessage msg = Messages.getMessage(msg_id, channel);

            if (msg == null)
            {
                return;
            }

            if (isAdmin(endpoint.presence.wallet) || msg.sender.SequenceEqual(endpoint.presence.wallet))
            {
                Messages.removeMessage(msg_id, channel);

                SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.msgDelete, msg_id, channel);

                StreamMessage message = new StreamMessage();
                message.type           = StreamMessageCode.info;
                message.sender         = IxianHandler.getWalletStorage().getPrimaryAddress();
                message.recipient      = message.sender;
                message.data           = spixi_message.getBytes();
                message.encryptionType = StreamMessageEncryptionCode.none;

                message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey());

                Messages.addMessage(message, channel, false);

                NetworkServer.forwardMessage(ProtocolMessageCode.s2data, message.getBytes());
            }
        }
Пример #4
0
        public static void sendAvatar(byte[] recipient, byte[] contact_address)
        {
            if (contact_address != null && contact_address.Length > 1)
            {
                if (!Node.users.hasUser(contact_address))
                {
                    return;
                }

                string path = Node.users.getAvatarPath(contact_address);
                if (path == null)
                {
                    return;
                }

                byte[] avatar_data = File.ReadAllBytes(path);
                if (avatar_data != null)
                {
                    sendMessage(recipient, new StreamMessage(avatar_data));
                }

                return;
            }

            byte[] avatar_bytes = Node.getAvatarBytes();

            if (avatar_bytes == null)
            {
                return;
            }

            SpixiMessage reply_spixi_message = new SpixiMessage(SpixiMessageCode.avatar, avatar_bytes);

            byte[] sender = IxianHandler.getWalletStorage().getPrimaryAddress();

            // Send the nickname message to friend
            StreamMessage reply_message = new StreamMessage();

            reply_message.type           = StreamMessageCode.info;
            reply_message.recipient      = recipient;
            reply_message.sender         = sender;
            reply_message.data           = reply_spixi_message.getBytes();
            reply_message.encryptionType = StreamMessageEncryptionCode.none;
            reply_message.id             = new byte[] { 6 };

            reply_message.sign(IxianHandler.getWalletStorage().getPrimaryPrivateKey());

            sendMessage(recipient, reply_message);
        }
Пример #5
0
        // Requests the avatar of the sender
        public static void requestAvatar(byte[] recipient)
        {
            // Prepare the message and send to the S2 nodes
            SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.getAvatar, new byte[1]);

            StreamMessage message = new StreamMessage();

            message.type           = StreamMessageCode.info;
            message.recipient      = recipient;
            message.sender         = IxianHandler.getWalletStorage().getPrimaryAddress();
            message.data           = spixi_message.getBytes();
            message.encryptionType = StreamMessageEncryptionCode.none;
            message.id             = new byte[] { 4 };

            sendMessage(recipient, message);
        }
Пример #6
0
        public static void sendBotAction(byte[] recipient, SpixiBotActionCode action, byte[] data, int channel = 0)
        {
            SpixiBotAction sba = new SpixiBotAction(action, data);

            // Prepare the message and send to the S2 nodes
            SpixiMessage spixi_message = new SpixiMessage(SpixiMessageCode.botAction, sba.getBytes(), channel);

            StreamMessage message = new StreamMessage();

            message.type           = StreamMessageCode.info;
            message.recipient      = recipient;
            message.sender         = IxianHandler.getWalletStorage().getPrimaryAddress();
            message.data           = spixi_message.getBytes();
            message.encryptionType = StreamMessageEncryptionCode.none;

            sendMessage(recipient, message);
        }