public async Task <bool> Delete(PresenceProfileLookup lookup)
        {
            var to_profile = (await this.profileRepository.Lookup(lookup.profileLookup)).FirstOrDefault();

            if (to_profile == null)
            {
                return(false);
            }
            var redis_hash_key        = "status_" + to_profile.Id;
            var db                    = presenceStatusDatabase.GetDatabase();
            ConnectionFactory factory = connectionFactory.Get();

            using (IConnection connection = factory.CreateConnection())
            {
                using (IModel channel = connection.CreateModel())
                {
                    String message          = String.Format("\\type\\status_update\\profileid\\{0}", to_profile.Id);
                    byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(message);

                    IBasicProperties props = channel.CreateBasicProperties();
                    props.ContentType = "text/plain";
                    channel.BasicPublish(GP_EXCHANGE, GP_BUDDY_ROUTING_KEY, props, messageBodyBytes);
                }
            }
            db.KeyDelete(redis_hash_key);
            return(true);
        }
예제 #2
0
        private void SendBansUpdate(IEnumerable <UsermodeRecord> usermodes, bool add)
        {
            var                     db     = peerChatCacheDb.GetDatabase();
            IScanningCursor         cursor = null;
            IEnumerable <HashEntry> entries;

            foreach (var usermode in usermodes)
            {
                if (usermode.hostmask != null && usermode.hostmask.Length > 0 && (usermode.modeflags & (int)EUserChannelFlag.EUserChannelFlag_Banned) != 0)
                {
                    do
                    {
                        entries = db.HashScan("channels", usermode.channelmask, 10, cursor?.Cursor ?? 0);
                        foreach (var entry in entries)
                        {
                            ConnectionFactory factory = connectionFactory.Get();
                            using (IConnection connection = factory.CreateConnection())
                            {
                                using (IModel channel = connection.CreateModel())
                                {
                                    var modeString = (add ? "+" : "-") + "b *@" + usermode.hostmask;
                                    SendModeString(entry.Value, modeString);
                                }
                            }
                        }
                        cursor = (IScanningCursor)entries;
                    } while ((cursor?.Cursor ?? 0) != 0);
                }
            }
        }
예제 #3
0
        public async Task <bool> AppendSnapshotUpdate(string _id, SnapshotUpdate snapshotUpdate)
        {
            var data = new BsonDocument();

            foreach (var kvEntry in snapshotUpdate.data)
            {
                var element = new BsonElement(kvEntry.Key, new BsonString(kvEntry.Value));
                data.Add(element);
            }
            var entry = new BsonDocument
            {
                { "created", new BsonDateTime(DateTime.UtcNow) },
                { "data", data },
                { "completed", new BsonBoolean(snapshotUpdate.completed) }
            };
            var filter = Builders <BsonDocument> .Filter.Eq("_id", new ObjectId(_id));

            var update = Builders <BsonDocument> .Update.Push("updates", entry);

            var result = await collection.UpdateOneAsync(filter, update);

            var success = result.IsAcknowledged && result.IsModifiedCountAvailable && result.ModifiedCount > 0;

            if (success && snapshotUpdate.completed)
            {
                ConnectionFactory factory = connectionFactory.Get();
                using (IConnection connection = factory.CreateConnection())
                {
                    using (IModel channel = connection.CreateModel())
                    {
                        var lookup = new SnapshotLookup();
                        lookup._id = _id;
                        var    fullSnapshot     = (await Lookup(lookup)).First();
                        var    jsonString       = Newtonsoft.Json.JsonConvert.SerializeObject(fullSnapshot);
                        byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(jsonString);

                        IBasicProperties props = channel.CreateBasicProperties();
                        props.ContentType = "application/json";
                        props.Headers     = new Dictionary <string, object>();
                        props.Headers["X-OpenSpy-GameId"] = snapshotUpdate.gameid;
                        channel.BasicPublish(GSTATS_EXCHANGE, GSTATS_ROUTING_KEY, props, messageBodyBytes);
                        return(true);
                    }
                }
            }
            return(success);
        }
        private void SendUpdatePassword(int channel_id, string current_password, string password)
        {
            if (string.IsNullOrEmpty(current_password))
            {
                current_password = null;
            }

            if (string.IsNullOrEmpty(password))
            {
                password = null;
            }

            ConnectionFactory factory = connectionFactory.Get();

            using (IConnection connection = factory.CreateConnection())
            {
                using (IModel channel = connection.CreateModel())
                {
                    string modeString = "";

                    if (password == null && current_password != null)
                    {
                        modeString = "-k";
                    }
                    else if (password != null && !password.Equals(current_password))
                    {
                        modeString = "+k " + password;
                    }

                    var    modeStringBytes  = System.Text.Encoding.UTF8.GetBytes(modeString);
                    String message          = String.Format("\\type\\MODE\\toChannelId\\{0}\\message\\{1}\\fromUserId\\-1\\includeSelf\\1", channel_id, Convert.ToBase64String(modeStringBytes));
                    byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(message);

                    IBasicProperties props = channel.CreateBasicProperties();
                    props.ContentType = "text/plain";
                    channel.BasicPublish(PEERCHAT_EXCHANGE, PEERCAHT_CLIENT_MESSAGE_KEY, props, messageBodyBytes);
                }
            }
        }
예제 #5
0
        public async Task <bool> AuthorizeAdd(Profile from_profile, Profile to_profile)
        {
            if (DeleteBuddyRequest(to_profile, from_profile))
            {
                ConnectionFactory factory = connectionFactory.Get();
                Buddy             buddy   = new Buddy();
                buddy.ToProfileid   = from_profile.Id;
                buddy.FromProfileid = to_profile.Id;
                await Create(buddy);

                using (IConnection connection = factory.CreateConnection())
                {
                    using (IModel channel = connection.CreateModel())
                    {
                        String message          = String.Format("\\type\\authorize_add\\to_profileid\\{0}\\from_profileid\\{1}", to_profile.Id, from_profile.Id);
                        byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(message);

                        IBasicProperties props = channel.CreateBasicProperties();
                        props.ContentType = "text/plain";
                        channel.BasicPublish(GP_EXCHANGE, GP_BUDDY_ROUTING_KEY, props, messageBodyBytes);
                        return(true);
                    }
                }
            }/* else if(await IsOnBuddyList(to_profile, from_profile))
              * {
              * Buddy buddy = new Buddy();
              * buddy.ToProfileid = to_profile.Id;
              * buddy.FromProfileid = from_profile.Id;
              * await Create(buddy);
              * return true;
              * }
              * else
              * {
              * throw new ArgumentException();
              * }*/
            return(false);
        }
예제 #6
0
        private void SendBlockEvent(String type, Profile from, Profile to)
        {
            ConnectionFactory factory = connectionFactory.Get();

            using (IConnection connection = factory.CreateConnection())
            {
                using (IModel channel = connection.CreateModel())
                {
                    String message          = String.Format("\\type\\{0}\\from_profileid\\{1}\\to_profileid\\{2}", type, from.Id, to.Id);
                    byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(message);

                    IBasicProperties props = channel.CreateBasicProperties();
                    props.ContentType = "text/plain";
                    channel.BasicPublish(GP_EXCHANGE, GP_BLOCK_ROUTING_KEY, props, messageBodyBytes);
                }
            }
        }
예제 #7
0
        private void SendLoginEvent(Session model)
        {
            ConnectionFactory factory = mqConnectionFactory.Get();

            //post MQ message with peer app name/addr
            using (IConnection connection = factory.CreateConnection())
            {
                using (IModel channel = connection.CreateModel())
                {
                    String message          = String.Format("\\type\\auth_event\\app_name\\{0}\\session_key\\{1}\\profileid\\{2}\\userid\\{3}", model.appName, model.sessionKey, model.profile.Id, model.profile.Userid);
                    byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(message);

                    IBasicProperties props = channel.CreateBasicProperties();
                    props.ContentType = "text/plain";
                    channel.BasicPublish(AUTHSESSION_EXCHANGE, AUTHSESSION_ROUTING_KEY, props, messageBodyBytes);
                }
            }
        }