Exemplo n.º 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 => { }));
            }
        }
Exemplo n.º 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, true, false);

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

            //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.ToBuilder();

            if (this.Attributes.Count > 0)
            {
                channelState.AddRangeAttribute(this.Attributes.Values);
            }
            if (this.Invitations.Count > 0)
            {
                channelState.AddRangeInvitation(this.Invitations.Values);
            }
            // added member should recieve a NotifyAdd.
            var addNotification = bnet.protocol.channel.AddNotification.CreateBuilder()
                                  .SetChannelState(channelState.Build())
                                  .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 => { }));

            //send bnet,2,7 target = addedmember.gameaccount
            //this always follows channel.AddNotification
            var fieldKey = FieldKeyHelper.Create(FieldKeyHelper.Program.D3, FieldKeyHelper.OriginatingClass.GameAccount, 7, 0);
            var field    = bnet.protocol.presence.Field.CreateBuilder().SetKey(fieldKey);

            field.SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetStringValue(client.Account.BnetEntityId.Low.ToString() + "#1").Build());
            var operation            = bnet.protocol.presence.FieldOperation.CreateBuilder().SetField(field.Build()).Build();
            var state                = bnet.protocol.presence.ChannelState.CreateBuilder().SetEntityId(client.Account.CurrentGameAccount.BnetEntityId).AddFieldOperation(operation).Build();
            var channelStatePresense = bnet.protocol.channel.ChannelState.CreateBuilder().SetExtension(bnet.protocol.presence.ChannelState.Presence, state);
            var notification         = bnet.protocol.channel.UpdateChannelStateNotification.CreateBuilder().SetStateChange(channelStatePresense).Build();

            client.MakeTargetedRPC(client.Account.CurrentGameAccount, () =>
                                   bnet.protocol.channel.ChannelSubscriber.CreateStub(client).NotifyUpdateChannelState(null, notification, callback => { }));


            if (this.IsGameChannel)
            {
                if (client.GameChannel != null)
                {
                    Logger.Warn("Client {0} in game channel {1}, but joining game channel {2}.", client, client.GameChannel, this);
                }
                client.GameChannel = this;
            }
            else
            {
                if (client.PartyChannel != null)
                {
                    Logger.Warn("Client {0} in party channel {1}, but joining party channel {2}.", client, client.PartyChannel, this);
                }
                client.PartyChannel = this;
            }

            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 => { }));
            }
        }