Exemple #1
0
        public void AddMember(MooNetClient client)
        {
            if (HasUser(client))
            {
                Logger.Warn("Attempted to add client {0} to channel when it was already a member of the channel", client.Connection.RemoteEndPoint.ToString());
                return;
            }

            var identity = client.GetIdentity(false, false, true);

            bool isOwner     = client == this.Owner;
            var  addedMember = new Member(identity, (isOwner) ? Member.Privilege.UnkCreator : Member.Privilege.UnkMember);

            if (this.Members.Count > 0)
            {
                addedMember.AddRoles((isOwner) ? Member.Role.PartyLeader : Member.Role.PartyMember, Member.Role.ChannelMember);
            }
            else
            {
                addedMember.AddRole((isOwner) ? Member.Role.ChannelCreator : Member.Role.ChannelMember);
            }

            // This needs to be here so that the foreach below will also send to the client that was just added
            this.Members.Add(client, addedMember);

            // Cache the built state and member
            var channelState = this.State;

            // added member should recieve a NotifyAdd.
            var addNotification = bnet.protocol.channel.AddNotification.CreateBuilder()
                                  .SetChannelState(channelState)
                                  .SetSelf(addedMember.BnetMember)
                                  .AddRangeMember(this.Members.Values.ToList().Select(member => member.BnetMember).ToList()).Build();

            client.MakeTargetedRPC(this, () =>
                                   bnet.protocol.channel.ChannelSubscriber.CreateStub(client).NotifyAdd(null, addNotification, callback => { }));

            client.CurrentChannel = this; // set clients current channel to one he just joined.

            if (this.Members.Count < 2)
            {
                return;
            }

            // other members should recieve a NotifyJoin.
            var joinNotification = bnet.protocol.channel.JoinNotification.CreateBuilder()
                                   .SetMember(addedMember.BnetMember).Build();

            foreach (var pair in this.Members.Where(pair => pair.Value != addedMember)) // only send this to previous members of the channel.
            {
                pair.Key.MakeTargetedRPC(this, () =>
                                         bnet.protocol.channel.ChannelSubscriber.CreateStub(pair.Key).NotifyJoin(null, joinNotification, callback => { }));
            }
        }
Exemple #2
0
        public void AddMember(MooNetClient client)
        {
            if (HasUser(client))
            {
                Logger.Warn("Attempted to add client {0} to channel when it was already a member of the channel", client.Connection.RemoteEndPoint.ToString());
                return;
            }

            var identity = client.GetIdentity(false, false, true);

            bool isOwner = client == this.Owner;
            var addedMember = new Member(identity,
                (isOwner) ? Member.Privilege.UnkCreator : Member.Privilege.UnkMember);

            if (this.Members.Count > 0)
            {
                addedMember.AddRoles(
                    (isOwner) ? Member.Role.PartyLeader : Member.Role.PartyMember,
                    Member.Role.ChannelMember);
            }
            else
            {
                addedMember.AddRole((isOwner) ? Member.Role.ChannelCreator : Member.Role.ChannelMember);
            }

            // This needs to be here so that the foreach below will also send to the client that was just added
            this.Members.Add(client, addedMember);

            // Cache the built state and member
            var channelState = this.State;
            var bnetMember = addedMember.BnetMember;

            var method = bnet.protocol.channel.ChannelSubscriber.Descriptor.FindMethodByName("NotifyAdd");
            foreach (var pair in this.Members)
            {
                var message = bnet.protocol.channel.AddNotification.CreateBuilder()
                    .SetChannelState(channelState)
                    // Set the Self property for each call on each client
                    // TODO: This may not be necessary here (this field is optional); check the caps
                    .SetSelf(pair.Value.BnetMember)
                    .AddMember(bnetMember)
                    .Build();
                //Logger.Warn("NotifyAdd:\n{0}", message.ToString());
                pair.Key.CallMethod(method, message, this.DynamicId);
            }
            client.CurrentChannel = this;
        }
Exemple #3
0
        public void AddMember(MooNetClient client)
        {
            if (HasUser(client))
            {
                Logger.Warn("Attempted to add client {0} to channel when it was already a member of the channel", client.Connection.RemoteEndPoint.ToString());
                return;
            }

            var identity = client.GetIdentity(false, false, true);

            bool isOwner = client == this.Owner;
            var addedMember = new Member(identity, (isOwner) ? Member.Privilege.UnkCreator : Member.Privilege.UnkMember);

            if (this.Members.Count > 0)
            {
                addedMember.AddRoles((isOwner) ? Member.Role.PartyLeader : Member.Role.PartyMember, Member.Role.ChannelMember);
            }
            else
            {
                addedMember.AddRole((isOwner) ? Member.Role.ChannelCreator : Member.Role.ChannelMember);
            }

            // This needs to be here so that the foreach below will also send to the client that was just added
            this.Members.Add(client, addedMember);

            // Cache the built state and member
            var channelState = this.State;

            // added member should recieve a NotifyAdd.
            var addNotification = bnet.protocol.channel.AddNotification.CreateBuilder()
                .SetChannelState(channelState)
                .SetSelf(addedMember.BnetMember)
                .AddRangeMember(this.Members.Values.ToList().Select(member => member.BnetMember).ToList()).Build();

            client.MakeTargetedRPC(this, () =>
                bnet.protocol.channel.ChannelSubscriber.CreateStub(client).NotifyAdd(null, addNotification, callback => { }));

            client.CurrentChannel = this; // set clients current channel to one he just joined.

            if (this.Members.Count < 2) return;

            // other members should recieve a NotifyJoin.
            var joinNotification = bnet.protocol.channel.JoinNotification.CreateBuilder()
                .SetMember(addedMember.BnetMember).Build();

            foreach (var pair in this.Members.Where(pair => pair.Value != addedMember)) // only send this to previous members of the channel.
            {
                pair.Key.MakeTargetedRPC(this, () =>
                    bnet.protocol.channel.ChannelSubscriber.CreateStub(pair.Key).NotifyJoin(null, joinNotification, callback => { }));
            }
        }