Exemplo n.º 1
0
        public virtual string Handle(string parameters, MooNetClient invokerClient = null)
        {
            // check if the user has enough privileges to access command group.
            // check if the user has enough privileges to invoke the command.
            if (invokerClient != null && this.Attributes.MinUserLevel > invokerClient.Account.UserLevel)
            {
                return("You don't have enough privileges to invoke that command.");
            }

            string[]         @params = null;
            CommandAttribute target  = null;

            if (parameters == string.Empty)
            {
                target = this.GetDefaultSubcommand();
            }
            else
            {
                @params = parameters.Split(' ');
                target  = this.GetSubcommand(@params[0]) ?? this.GetDefaultSubcommand();

                if (target != this.GetDefaultSubcommand())
                {
                    @params = @params.Skip(1).ToArray();
                }
            }

            // check if the user has enough privileges to invoke the command.
            if (invokerClient != null && target.MinUserLevel > invokerClient.Account.UserLevel)
            {
                return("You don't have enough privileges to invoke that command.");
            }

            return((string)this._commands[target].Invoke(this, new object[] { @params, invokerClient }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a client subscriber to object, which will eventually be notified whenever the object changes state.
        /// </summary>
        /// <param name="client">The client to add as a subscriber.</param>
        /// <param name="remoteObjectId">The client's dynamic ID.</param>
        public void AddSubscriber(MooNetClient client, ulong remoteObjectId)
        {
            // [D3Inferno]
            // Remove Subscribers that have been disconnected.
            // Apparently the RPCObject is not being cleaned up properly.
            // See the comment at the top for more info.
            // Conver to an Array so we can remove as we iterate.
            foreach (var subscriber in this.Subscribers.ToArray())
            {
                if (!subscriber.Connection.IsConnected)
                {
                    Logger.Warn("Removing disconnected subscriber {0}", subscriber);
                    this.Subscribers.Remove(subscriber);
                }
            }

            // Map the subscriber's dynamic ID to to our dynamic ID so we know how to translate later on when the object makes a notify call
            client.MapLocalObjectID(this.DynamicId, remoteObjectId);
            this.Subscribers.Add(client);
            // Since the client wasn't previously subscribed, it should not be aware of the object's state -- let's notify it
            foreach (var subscriber in this.Subscribers)
            {
                this.NotifySubscriptionAdded(subscriber);
            }
            //this.NotifySubscriptionAdded(client);
        }
Exemplo n.º 3
0
        public string Position(string[] @params, MooNetClient invokerClient)
        {
            Player player;

            if (invokerClient != null && invokerClient.InGameClient != null)
            {
                player = invokerClient.InGameClient.Player;
            }
            else
            {
                if (@params.Count() < 1)
                {
                    return("Invalid arguments. Type 'help debug position' to get help.");
                }

                var account = AccountManager.GetAccountByEmail(@params[0]);
                if (account == null)
                {
                    return(string.Format("No account with email: {0} exists.", @params[0]));
                }

                if (account.LoggedInClient == null || account.LoggedInClient.InGameClient == null)
                {
                    return(string.Format("Account {0} is not in-game.", @params[0]));
                }

                player = account.LoggedInClient.InGameClient.Player;
            }

            return(string.Format("Player position: {0}", player.Position));
        }
Exemplo n.º 4
0
        public static void HandleRemove(MooNetClient client, bnet.protocol.friends.GenericFriendRequest request)
        {
            var removee = AccountManager.GetAccountByPersistentID(request.TargetId.Low);
            var remover = client.Account;

            var removeeAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(removee.BnetAccountID).Build();
            var removerAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(remover.BnetAccountID).Build();

            var removed = Friends.Remove(remover.BnetAccountID.Low, removeeAsFriend);

            if (!removed)
            {
                Logger.Warn("No friendship mapping between {0} and {1}", remover.BnetAccountID.Low, removeeAsFriend);
            }
            removed = Friends.Remove(removee.BnetAccountID.Low, removerAsFriend);
            if (!removed)
            {
                Logger.Warn("No friendship mapping between {0} and {1}", removee.BnetAccountID.Low, removerAsFriend);
            }
            RemoveFriendshipFromDB(remover, removee);

            var notifyRemover = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(removeeAsFriend).Build();

            client.MakeTargetedRPC(FriendManager.Instance, () =>
                                   bnet.protocol.friends.FriendsNotify.CreateStub(client).NotifyFriendRemoved(null, notifyRemover, callback => { }));

            if (removee.IsOnline)
            {
                var notifyRemovee = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(removerAsFriend).Build();
                removee.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                       bnet.protocol.friends.FriendsNotify.CreateStub(removee.LoggedInClient).NotifyFriendRemoved(null, notifyRemovee, callback => { }));
            }
        }
Exemplo n.º 5
0
        public void HandleDecline(MooNetClient client, bnet.protocol.invitation.GenericRequest request)
        {
            if (!this._onGoingInvitations.ContainsKey(request.InvitationId))
            {
                return;
            }
            var invitation = this._onGoingInvitations[request.InvitationId];

            var inviter = ToonManager.GetToonByLowID(invitation.InviterIdentity.ToonId.Low);

            if (inviter == null || inviter.Owner.LoggedInClient == null)
            {
                return;
            }

            var notification =
                bnet.protocol.channel.UpdateChannelStateNotification.CreateBuilder()
                .SetAgentId(bnet.protocol.EntityId.CreateBuilder().SetHigh(0).SetLow(0)) // caps have this set to high: 0 low: 0 /raist.
                .SetStateChange(bnet.protocol.channel.ChannelState.CreateBuilder().AddInvitation(invitation)
                                .SetReason((uint)InvitationRemoveReason.Declined));

            this._onGoingInvitations.Remove(invitation.Id);

            // notify invoker about the decline.
            inviter.Owner.LoggedInClient.MakeTargetedRPC(inviter.Owner.LoggedInClient.CurrentChannel, () =>
                                                         bnet.protocol.channel.ChannelSubscriber.CreateStub(inviter.Owner.LoggedInClient).NotifyUpdateChannelState(null, notification.Build(), callback => { }));
        }
Exemplo n.º 6
0
        public void Revoke(MooNetClient client, bnet.protocol.channel_invitation.RevokeInvitationRequest request)
        {
            if (!this._onGoingInvitations.ContainsKey(request.InvitationId))
            {
                return;
            }
            var invitation = this._onGoingInvitations[request.InvitationId];

            //notify inviter about revoke
            var updateChannelNotification =
                bnet.protocol.channel.UpdateChannelStateNotification.CreateBuilder()
                .SetAgentId(bnet.protocol.EntityId.CreateBuilder().SetHigh(0).SetLow(0)) // caps have this set to high: 0 low: 0 /dustin
                .SetStateChange(bnet.protocol.channel.ChannelState.CreateBuilder()
                                .AddInvitation(invitation)
                                .SetReason((uint)InvitationRemoveReason.Revoked));

            this._onGoingInvitations.Remove(request.InvitationId);

            client.MakeTargetedRPC(client.CurrentChannel, () =>
                                   bnet.protocol.channel.ChannelSubscriber.CreateStub(client).NotifyUpdateChannelState(null, updateChannelNotification.Build(), callback => { }));

            //notify invitee about revoke
            var invitationRemoved =
                bnet.protocol.channel_invitation.InvitationRemovedNotification.CreateBuilder()
                .SetInvitation(invitation)
                .SetReason((uint)InvitationRemoveReason.Revoked);

            var invitee = ToonManager.GetToonByLowID(invitation.InviteeIdentity.ToonId.Low);

            invitee.Owner.LoggedInClient.MakeTargetedRPC(this, () =>
                                                         bnet.protocol.channel_invitation.ChannelInvitationNotify.CreateStub(invitee.Owner.LoggedInClient).NotifyReceivedInvitationRemoved(null, invitationRemoved.Build(), callback => { }));
        }
Exemplo n.º 7
0
        public static void HandleRemove(MooNetClient client, bnet.protocol.friends.GenericFriendRequest request)
        {
            var removee = AccountManager.GetAccountByPersistentID(request.TargetId.Low);
            var remover = client.Account;

            var removeeAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(removee.BnetEntityId).Build();
            var removerAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(remover.BnetEntityId).Build();

            RemoveFriendshipFromDB(remover, removee);

            var notifyRemover = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(removeeAsFriend).Build();

            client.MakeTargetedRPC(FriendManager.Instance, () =>
                                   bnet.protocol.friends.FriendsNotify.CreateStub(client).NotifyFriendRemoved(null, notifyRemover, callback => { }));


            var removeeGameAccounts = GameAccountManager.GetGameAccountsForAccount(removee);

            foreach (var removeeGameAccount in removeeGameAccounts)
            {
                if (!removeeGameAccount.IsOnline)
                {
                    continue;
                }
                var notifyRemovee = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(removerAsFriend).Build();
                removeeGameAccount.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                                  bnet.protocol.friends.FriendsNotify.CreateStub(removeeGameAccount.LoggedInClient).NotifyFriendRemoved(null, notifyRemovee, callback => { }));
            }
        }
Exemplo n.º 8
0
        public Channel HandleAccept(MooNetClient client, bnet.protocol.channel_invitation.AcceptInvitationRequest request)
        {
            if (!this._onGoingInvitations.ContainsKey(request.InvitationId))
            {
                return(null);
            }

            var invitation = this._onGoingInvitations[request.InvitationId];
            var channel    = ChannelManager.GetChannelByEntityId(invitation.GetExtension(bnet.protocol.channel_invitation.ChannelInvitation.ChannelInvitationProp).ChannelDescription.ChannelId);

            var notification = bnet.protocol.channel_invitation.InvitationRemovedNotification.CreateBuilder().SetInvitation(invitation.ToBuilder()).SetReason((uint)InvitationRemoveReason.Accepted);

            this._onGoingInvitations.Remove(invitation.Id);

            // notify invitee and let him remove the handled invitation.
            client.MakeTargetedRPC(this, () =>
                                   bnet.protocol.channel_invitation.ChannelInvitationNotify.CreateStub(client).NotifyReceivedInvitationRemoved(null, notification.Build(), callback => { }));

            channel.Join(client, request.ObjectId); // add invitee to channel -- so inviter and other members will also be notified too.

            var inviter = GameAccountManager.GetAccountByPersistentID(invitation.InviterIdentity.AccountId.Low);

            var stateNotification = bnet.protocol.channel.UpdateChannelStateNotification.CreateBuilder()
                                    .SetAgentId(bnet.protocol.EntityId.CreateBuilder().SetHigh(0).SetLow(0).Build())
                                    .SetStateChange(bnet.protocol.channel.ChannelState.CreateBuilder().AddRangeInvitation(channel.Invitations.Values).SetReason(0).Build())
                                    .Build();

            foreach (var member in channel.Members.Keys)
            {
                member.MakeTargetedRPC(channel, () =>
                                       bnet.protocol.channel.ChannelSubscriber.CreateStub(member).NotifyUpdateChannelState(null, stateNotification, callback => { }));
            }

            return(channel);
        }
Exemplo n.º 9
0
        public string DropAll(string[] @params, MooNetClient invokerClient)
        {
            if (invokerClient == null)
            {
                return("You can not invoke this command from console.");
            }

            if (invokerClient.InGameClient == null)
            {
                return("You can only invoke this command while ingame.");
            }

            var player = invokerClient.InGameClient.Player;

            var bpItems = new List <Item>(player.Inventory.GetBackPackItems());


            foreach (var item in bpItems)
            {
                var msg = new InventoryDropItemMessage {
                    ItemID = item.DynamicID
                };
                player.Inventory.Consume(invokerClient.InGameClient, msg);
            }
            return(string.Format("Dropped {0} Items for you", bpItems.Count));
        }
Exemplo n.º 10
0
        public string LevelUp(string[] @params, MooNetClient invokerClient)
        {
            if (invokerClient == null)
            {
                return("You can not invoke this command from console.");
            }

            if (invokerClient.InGameClient == null)
            {
                return("You can only invoke this command while ingame.");
            }

            var player = invokerClient.InGameClient.Player;
            var amount = 1;

            if (@params != null)
            {
                if (!Int32.TryParse(@params[0], out amount))
                {
                    amount = 1;
                }
            }

            for (int i = 0; i < amount; i++)
            {
                player.UpdateExp(player.Attributes[Net.GS.Message.GameAttribute.Experience_Next]);
            }

            player.Toon.GameAccount.NotifyUpdate();
            return(string.Format("New level: {0}", player.Toon.Level));
        }
Exemplo n.º 11
0
            public string AddGold(string[] @params, MooNetClient invokerClient)
            {
                if (invokerClient == null)
                {
                    return("You can not invoke this command from console.");
                }

                if (invokerClient.InGameClient == null)
                {
                    return("You can only invoke this command while ingame.");
                }

                if (@params == null)
                {
                    return("Enter a amount to get gold.");
                }

                foreach (char ch in @params[0])
                {
                    if (!Char.IsNumber(ch) && ch != 32)
                    {
                        return("Only integer values");
                    }
                }

                Player player = invokerClient.InGameClient.Player;

                Int32 goldAdded = Int32.Parse(@params[0]);

                player.Inventory.AddGoldAmount(goldAdded);

                return(string.Format("Added {0} gold.", goldAdded));
            }
Exemplo n.º 12
0
        public static Channel CreateNewChannel(MooNetClient client, ulong remoteObjectId)
        {
            var channel = new Channel(client, false, remoteObjectId);

            Channels.Add(channel.DynamicId, channel);
            return(channel);
        }
Exemplo n.º 13
0
        public PacketIn(MooNetClient client, CodedInputStream stream)
        {
            this.Client = client;
            this.Stream = stream;

            this.Read();
        }
Exemplo n.º 14
0
        protected void MakeRPC(MooNetClient client, List <bnet.protocol.presence.FieldOperation> operations)
        {
            // Create a presence.ChannelState
            var state = bnet.protocol.presence.ChannelState.CreateBuilder().SetEntityId(this.BnetEntityId).AddRangeFieldOperation(operations).Build();

            // Embed in channel.ChannelState
            var channelState = bnet.protocol.channel.ChannelState.CreateBuilder().SetExtension(bnet.protocol.presence.ChannelState.Presence, state);

            // Put in AddNotification message
            var builder = bnet.protocol.channel.AddNotification.CreateBuilder().SetChannelState(channelState);

            // Make the RPC call to all online game accounts
            //TODO: Split notifications per game type
            client.MakeTargetedRPC(this, () =>
                                   bnet.protocol.channel.ChannelSubscriber.CreateStub(client).NotifyAdd(null, builder.Build(), callback => { }));

            //foreach (var gameClient in client.Account.GameAccounts)
            //{
            //    if (gameClient.Value.IsOnline)
            //    {
            //        gameClient.Value.LoggedInClient.MakeTargetedRPC(this, () =>
            //            bnet.protocol.channel.ChannelSubscriber.CreateStub(gameClient.Value.LoggedInClient).NotifyAdd(null, builder.Build(), callback => { }));
            //    }
            //}
        }
Exemplo n.º 15
0
        private static void InitAuthentication(MooNetClient client, bnet.protocol.authentication.LogonRequest request)
        {
            client.LoginEmail = request.Email;
            var account = AccountManager.GetAccountByEmail(request.Email.ToLower()); // check if account exists.

            if (account == null)                                                     // we should be returning an error to client /raist.
            {
                client.AuthenticationErrorCode = AuthenticationErrorCodes.NoGameAccount;
                client.AuthenticationComplete();
                return;
            }

            var thumbprintData = "f9513183031b3836103ac3a3bb606c0e06fd3b94ae4a6b6e405844085b794e901b0ebb1db650b85bac4b489a38a1ca9dcef2bbd13445d0cd85accfc62d84bc3a8d960b1a7a65cd8d3f72a172f41dca98459015ffbd25d766b02824a42dacb7c4cd64f4b3b9e316de23ec1dbb0153b73a4fa58ffb39c3f484b4b478a660dc8979e16e52f978a0ca2fc4184fa0f69844d73ef99f47e3ccb02cf6a636b4ae9513404eee7e0ad536dcef50cd1699e38195e6afdd3655a3a3529b4e52b33ac5d04f5fa2b15536a2c782c89c0acf133e14eac15af035abf5e44e9e1124a3397dac8f90a4ccb1717540698869fc1ba9037e099d68698ecf17ffdd36f07013176be24269fda1e5d221708181d95474fc1d74bb901062a9f6a3e24aef79e9d583d9126796d63c153a0f75f02da27ecc0971f39a46ec29087c3ae474e08fdf8f65d1445b293399bc495ff651b7d2d7a36216ba5e4400ea7bbc884dc4cf3ed27f14501b8bb7fc0f86b5089880e6889bcd851153e299a337d6c945f710559595e351995341cbef44abac379cf0f845b362d294eec390d50f1a50089d250eae1b1205cea1aff514de076516f467cd077a1fbb759b415dc6c0ea1617f31f7d764a0d60d5b67aa82b4202b2a9455eb9ca3683955ec45aaf56aba42a2f3ae9be5f3eed093a6601816d00e0569bfcb91fb7843945336c99757812d373d510d25744f9480b6cc87e8a".ToByteArray();

            var srp6a = new SRP6a(account); // create srp6 handler to process the authentication.

            OngoingAuthentications.Add(client, srp6a);

            // request client to load thumbprint.dll for authentication.
            var moduleLoadRequest = bnet.protocol.authentication.ModuleLoadRequest.CreateBuilder()
                                    .SetModuleHandle(bnet.protocol.ContentHandle.CreateBuilder()
                                                     .SetRegion(0x00005858) // XX
                                                     .SetUsage(0x61757468)  // auth - thumbprint.dll
                                                     .SetHash(ByteString.CopyFrom(VersionInfo.MooNet.ThumbprintHashMap[client.Platform])))
                                    .SetMessage(ByteString.CopyFrom(thumbprintData))
                                    .Build();

            client.ThumbprintReq = true;
            client.MakeRPC(() => bnet.protocol.authentication.AuthenticationClient.CreateStub(client).ModuleLoad(null, moduleLoadRequest, callback => { }));
        }
Exemplo n.º 16
0
        public GameFactory(MooNetClient owner, bnet.protocol.game_master.FindGameRequest request, ulong requestId)
            : base(owner, true)
        {
            this.Started      = false;
            this.Owner        = owner; //Game is really the owner Channel.Owner should maybe be EntityId instead of MooNetClient -Egris
            this.RequestId    = requestId;
            this.FactoryID    = request.FactoryId;
            this.BnetEntityId = bnet.protocol.EntityId.CreateBuilder().SetHigh((ulong)EntityIdHelper.HighIdType.GameId).SetLow(this.DynamicId).Build();
            this.GameHandle   = bnet.protocol.game_master.GameHandle.CreateBuilder().SetFactoryId(this.FactoryID).SetGameId(this.BnetEntityId).Build();

            foreach (bnet.protocol.attribute.Attribute attribute in request.Properties.CreationAttributesList)
            {
                if (attribute.Name != "GameCreateParams")
                {
                    Logger.Warn("FindGame(): Unknown CreationAttribute: {0}", attribute.Name);
                }
                else
                {
                    this.GameCreateParams = D3.OnlineService.GameCreateParams.ParseFrom(attribute.Value.MessageValue);
                }
            }

            foreach (bnet.protocol.attribute.Attribute attribute in request.Properties.Filter.AttributeList)
            {
                if (attribute.Name != "version")
                {
                    Logger.Warn("FindGame(): Unknown Attribute: {0}", attribute.Name);
                }
                else
                {
                    this.Version = attribute.Value.StringValue;
                }
            }
        }
Exemplo n.º 17
0
        public PacketIn(MooNetClient client, CodedInputStream stream)
        {
            this.Client = client;
            this.Stream = stream;

            this.Read();
        }
Exemplo n.º 18
0
        public string Item(string[] @params, MooNetClient invokerClient)
        {
            var matches = new List <ItemTable>();

            if (@params.Count() < 1)
            {
                return("Invalid arguments. Type 'help lookup item' to get help.");
            }

            var pattern = @params[0].ToLower();

            foreach (var asset in MPQStorage.Data.Assets[SNOGroup.GameBalance].Values)
            {
                var data = asset.Data as GameBalance;
                if (data == null || data.Type != BalanceType.Items)
                {
                    continue;
                }

                foreach (var itemDefinition in data.Item)
                {
                    if (itemDefinition.Name.ToLower().Contains(pattern))
                    {
                        matches.Add(itemDefinition);
                    }
                }
            }
            return(matches.Aggregate(matches.Count >= 1 ? "Item Matches:\n" : "No match found.",
                                     (current, match) => current + string.Format("[{0}] {1}\n", match.SNOActor.ToString("D6"), match.Name)));
        }
Exemplo n.º 19
0
        public string Portal(string[] @params, MooNetClient invokerClient)
        {
            if (invokerClient == null)
            {
                return("You can not invoke this command from console.");
            }

            if (invokerClient.InGameClient == null)
            {
                return("You can only invoke this command while ingame.");
            }

            var world = invokerClient.InGameClient.Game.GetWorld(71150);

            if (world != invokerClient.InGameClient.Player.World)
            {
                invokerClient.InGameClient.Player.ChangeWorld(world, world.StartingPoints.First().Position);
            }
            else
            {
                invokerClient.InGameClient.Player.Teleport(world.StartingPoints.First().Position);
            }

            return(string.Format("Teleported back to town."));
        }
Exemplo n.º 20
0
        public string Conversation(string[] @params, MooNetClient invokerClient)
        {
            if (invokerClient == null)
            {
                return("You can not invoke this command from console.");
            }

            if (invokerClient.InGameClient == null)
            {
                return("You can only invoke this command while ingame.");
            }

            if (@params.Count() != 1)
            {
                return("Invalid arguments. Type 'help conversation' to get help.");
            }

            try
            {
                var conversation = MPQStorage.Data.Assets[SNOGroup.Conversation][Int32.Parse(@params[0])];
                invokerClient.InGameClient.Player.Conversations.StartConversation(Int32.Parse(@params[0]));
                return(String.Format("Started conversation {0}", conversation.FileName));
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemplo n.º 21
0
        public string Delete(string[] @params, MooNetClient invokerClient)
        {
            if (@params.Count() == 0)
            {
                return("Invalid arguments. Type 'help account delete' to get help.");
            }

            var account = AccountManager.GetAccountByEmail(@params[0]);

            if (account == null)
            {
                return(string.Format("No account with email '{0}' exists.", @params));
            }

            //Delete game accounts for account
            //which in turn will delete toons for each game account
            foreach (var gameAccount in GameAccountManager.GetGameAccountsForAccount(account))
            {
                GameAccountManager.DeleteGameAccount(gameAccount);
            }

            AccountManager.DeleteAccount(account);

            return(string.Format("Deleted account {0}.", @params));
        }
Exemplo n.º 22
0
        public string SetPassword(string[] @params, MooNetClient invokerClient)
        {
            if (@params.Count() < 2)
            {
                return("Invalid arguments. Type 'help account setpassword' to get help.");
            }

            var email    = @params[0];
            var password = @params[1];

            var account = AccountManager.GetAccountByEmail(email);

            if (account == null)
            {
                return(string.Format("No account with email '{0}' exists.", email));
            }

            if (password.Length < 8 || password.Length > 16)
            {
                return("Password should be a minimum of 8 and a maximum of 16 characters.");
            }

            AccountManager.UpdatePassword(account, password);
            return(string.Format("Updated password for account {0}.", email));
        }
Exemplo n.º 23
0
        public static void HandleInvitation(MooNetClient client, bnet.protocol.invitation.Invitation invitation)
        {
            var invitee = AccountManager.GetAccountByPersistentID(invitation.InviteeIdentity.AccountId.Low);

            //var invitee = Instance.Subscribers.FirstOrDefault(subscriber => subscriber.Account.BnetEntityId.Low == invitation.InviteeIdentity.AccountId.Low);
            if (invitee == null)
            {
                return;                  // if we can't find invite just return - though we should actually check for it until expiration time and store this in database.
            }
            //Check for duplicate invites
            foreach (var oldInvite in OnGoingInvitations.Values)
            {
                if ((oldInvite.InviteeIdentity.AccountId == invitation.InviteeIdentity.AccountId) && (oldInvite.InviterIdentity.AccountId == invitation.InviterIdentity.AccountId))
                {
                    return;
                }
            }

            OnGoingInvitations.Add(invitation.Id, invitation); // track ongoing invitations so we can tranport it forth and back.

            if (invitee.IsOnline)
            {
                var inviter = AccountManager.GetAccountByPersistentID(invitation.InviterIdentity.AccountId.Low);

                var notification = bnet.protocol.friends.InvitationNotification.CreateBuilder().SetInvitation(invitation).SetGameAccountId(inviter.CurrentGameAccount.BnetEntityId);

                invitee.CurrentGameAccount.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                                          bnet.protocol.friends.FriendsNotify.CreateStub(invitee.CurrentGameAccount.LoggedInClient).NotifyReceivedInvitationAdded(null, notification.Build(), callback => { }));
            }
        }
Exemplo n.º 24
0
        public static void HandleAccept(MooNetClient client, bnet.protocol.invitation.GenericRequest request)
        {
            if (!OnGoingInvitations.ContainsKey(request.InvitationId))
            {
                return;
            }
            var invitation = OnGoingInvitations[request.InvitationId];

            var inviter         = AccountManager.GetAccountByPersistentID(invitation.InviterIdentity.AccountId.Low);
            var invitee         = AccountManager.GetAccountByPersistentID(invitation.InviteeIdentity.AccountId.Low);
            var inviteeAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(invitation.InviteeIdentity.AccountId).Build();
            var inviterAsFriend = bnet.protocol.friends.Friend.CreateBuilder().SetId(invitation.InviterIdentity.AccountId).Build();

            var notificationToInviter = bnet.protocol.friends.InvitationNotification.CreateBuilder()
                                        .SetGameAccountId(invitee.BnetEntityId)
                                        .SetInvitation(invitation)
                                        .SetReason((uint)InvitationRemoveReason.Accepted) // success?
                                        .Build();

            var notificationToInvitee = bnet.protocol.friends.InvitationNotification.CreateBuilder()
                                        .SetGameAccountId(inviter.BnetEntityId)
                                        .SetInvitation(invitation)
                                        .SetReason((uint)InvitationRemoveReason.Accepted) // success?
                                        .Build();

            Friends.Add(invitee.BnetEntityId.Low, inviterAsFriend);
            Friends.Add(inviter.BnetEntityId.Low, inviteeAsFriend);
            AddFriendshipToDB(inviter, invitee);

            // send friend added notifications
            var friendAddedNotificationToInviter = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(inviteeAsFriend).SetGameAccountId(invitee.BnetEntityId).Build();
            var friendAddedNotificationToInvitee = bnet.protocol.friends.FriendNotification.CreateBuilder().SetTarget(inviterAsFriend).SetGameAccountId(inviter.BnetEntityId).Build();

            var inviterGameAccounts = GameAccountManager.GetGameAccountsForAccount(inviter);
            var inviteeGameAccounts = GameAccountManager.GetGameAccountsForAccount(invitee);

            foreach (var inviterGameAccount in inviterGameAccounts)
            {
                if (inviterGameAccount.IsOnline)
                {
                    inviterGameAccount.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                                      bnet.protocol.friends.FriendsNotify.CreateStub(inviterGameAccount.LoggedInClient).NotifyReceivedInvitationRemoved(null, notificationToInviter, callback => { }));

                    inviterGameAccount.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                                      bnet.protocol.friends.FriendsNotify.CreateStub(inviterGameAccount.LoggedInClient).NotifyFriendAdded(null, friendAddedNotificationToInviter, callback => { }));
                }
            }

            foreach (var inviteeGameAccount in inviteeGameAccounts)
            {
                if (inviteeGameAccount.IsOnline)
                {
                    inviteeGameAccount.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                                      bnet.protocol.friends.FriendsNotify.CreateStub(inviteeGameAccount.LoggedInClient).NotifyFriendAdded(null, friendAddedNotificationToInvitee, callback => { }));

                    inviteeGameAccount.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                                      bnet.protocol.friends.FriendsNotify.CreateStub(inviteeGameAccount.LoggedInClient).NotifyReceivedInvitationRemoved(null, notificationToInvitee, callback => { }));
                }
            }
        }
Exemplo n.º 25
0
            public string ChangeGender(string[] @params, MooNetClient invokerClient)
            {
                if (invokerClient == null)
                {
                    return("You can not invoke this command from console.");
                }

                if (invokerClient.InGameClient == null)
                {
                    return("You can only invoke this command while ingame.");
                }

                Toon      toon       = invokerClient.Account.CurrentGameAccount.CurrentToon;
                ToonFlags gender     = invokerClient.Account.CurrentGameAccount.CurrentToon.Flags;
                var       dbToon     = DBSessions.AccountSession.Get <DBToon>(toon.PersistentID);
                string    lastGender = toon.DBToon.Flags.ToString();

                if (gender == ToonFlags.Male)
                {
                    toon.DBToon.Flags = ToonFlags.Female;
                }
                else if (gender == ToonFlags.Female)
                {
                    toon.DBToon.Flags = ToonFlags.Male;
                }

                DBSessions.AccountSession.SaveOrUpdate(dbToon);
                DBSessions.AccountSession.Flush();

                return(string.Format("Gender {0} changed to {1}!. Reload to see the change.", lastGender, toon.DBToon.Flags.ToString()));
            }
Exemplo n.º 26
0
        private bnet.protocol.storage.ExecuteResponse LoadAccountDigest(MooNetClient client, bnet.protocol.storage.ExecuteRequest request)
        {
            var results = new List <bnet.protocol.storage.OperationResult>();

            foreach (var operation in request.OperationsList)
            {
                var operationResult = bnet.protocol.storage.OperationResult.CreateBuilder().SetTableId(operation.TableId);
                operationResult.AddData(
                    bnet.protocol.storage.Cell.CreateBuilder()
                    .SetColumnId(request.OperationsList[0].ColumnId)
                    .SetRowId(request.OperationsList[0].RowId)
                    .SetVersion(1)
                    .SetData(client.Account.CurrentGameAccount.Digest.ToByteString())
                    .Build());
                results.Add(operationResult.Build());
            }

            var builder = bnet.protocol.storage.ExecuteResponse.CreateBuilder();

            foreach (var result in results)
            {
                builder.AddResults(result);
            }
            return(builder.Build());
        }
Exemplo n.º 27
0
        public string Search(string[] @params, MooNetClient invokerClient)
        {
            if (@params == null)
            {
                return(this.Fallback());
            }

            var matches = new List <Asset>();

            if (@params.Count() < 1)
            {
                return("Invalid arguments. Type 'help lookup actor' to get help.");
            }

            var pattern = @params[0].ToLower();

            foreach (var groupPair in MPQStorage.Data.Assets)
            {
                foreach (var pair in groupPair.Value)
                {
                    if (pair.Value.Name.ToLower().Contains(pattern))
                    {
                        matches.Add(pair.Value);
                    }
                }
            }

            return(matches.Aggregate(matches.Count >= 1 ? "Matches:\n" : "No matches found.",
                                     (current, match) => current + string.Format("[{0}] [{1}] {2}\n", match.SNOId.ToString("D6"), match.Group, match.Name)));
        }
Exemplo n.º 28
0
        private static void InitAuthentication(MooNetClient client, bnet.protocol.authentication.LogonRequest request)
        {
            var account = AccountManager.GetAccountByEmail(request.Email.ToLower()); // check if account exists.

            if (account == null)                                                     // we should be returning an error to client /raist.
            {
                client.AuthenticationErrorCode = AuthenticationErrorCodes.NoGameAccount;
                client.AuthenticationCompleteSignal.Set();
                return;
            }

            var srp6a = new SRP6a(account); // create srp6 handler to process the authentication.

            OngoingAuthentications.Add(client, srp6a);

            // request client to load password.dll for authentication.
            var moduleLoadRequest = bnet.protocol.authentication.ModuleLoadRequest.CreateBuilder()
                                    .SetModuleHandle(bnet.protocol.ContentHandle.CreateBuilder()
                                                     .SetRegion(0x00005553) // us
                                                     .SetUsage(0x61757468)  // auth - password.dll
                                                     .SetHash(ByteString.CopyFrom(VersionInfo.MooNet.AuthModuleHashMap[client.Platform])))
                                    .SetMessage(ByteString.CopyFrom(srp6a.LogonChallenge))
                                    .Build();

            //client.MakeRPCWithListenerId(request.ListenerId, () =>
            //    bnet.protocol.authentication.AuthenticationClient.CreateStub(client).ModuleLoad(null, moduleLoadRequest, ModuleLoadResponse));
            client.MakeRPC(() => bnet.protocol.authentication.AuthenticationClient.CreateStub(client).ModuleLoad(null, moduleLoadRequest, ModuleLoadResponse));
        }
Exemplo n.º 29
0
        public string ClientServices(string[] @params, MooNetClient invokerClient)
        {
            var client = invokerClient;

            if (client == null && @params.Count() < 1)
            {
                return("Invalid arguments. Type 'help services client' to get help.");
            }

            if (client == null)
            {
                var email   = @params[0];
                var account = AccountManager.GetAccountByEmail(email);

                if (account == null)
                {
                    return(string.Format("No account with email '{0}' exists.", email));
                }

                client = account.LoggedInClient;
                if (client == null)
                {
                    return(string.Format("Account '{0}' is not logged in.", email));
                }
            }

            var output = string.Format("Imported service list for client: {0}\n", client.Account.Email);

            output = client.Services.Aggregate(output, (current, pair) =>
                                               current + string.Format("Id: 0x{0} Hash: 0x{1}\n", pair.Value.ToString("X2"), pair.Key.ToString("X8")));

            return(output);
        }
Exemplo n.º 30
0
        public string Show(string[] @params, MooNetClient invokerClient)
        {
            if (@params.Count() < 1)
            {
                return("Invalid arguments. Type 'help rpcobject show' to get help.");
            }

            ulong localId;
            var   id = @params[0];

            if (!ulong.TryParse(id, out localId))
            {
                return(string.Format("Can not parse '{0}' as valid id.", id));
            }

            if (!RPCObjectManager.Objects.ContainsKey(localId))
            {
                return(string.Format("There exists no RPCObject with dynamidId: {0}", localId));
            }

            var rpcObject = RPCObjectManager.Objects[localId];
            var output    = string.Format("[RPCObject]\nDynamicId: 0x{0}\nType: {1}\nObject: {2}\n", rpcObject.DynamicId,
                                          rpcObject.GetType().Name, rpcObject);

            output += "[Subscribers]\n";
            foreach (var client in rpcObject.Subscribers)
            {
                var remoteId = client.GetRemoteObjectId(rpcObject.DynamicId);
                output += string.Format("RemoteId: 0x{0} - {1}\n", remoteId.ToString("X8"), client.Account.Email);
            }

            return(output);
        }
Exemplo n.º 31
0
        private bnet.protocol.storage.ExecuteResponse GetHeroDigest(MooNetClient client, bnet.protocol.storage.ExecuteRequest request)
        {
            var results = new List <bnet.protocol.storage.OperationResult>();

            foreach (var operation in request.OperationsList)
            {
                Google.ProtocolBuffers.ByteString data = null;

                // find the requested toons entity-id.
                var stream = new MemoryStream(operation.RowId.Hash.ToByteArray());

                // contains ToonHandle in field form with one unknown field (which is not in message definition):
                // int16 unknown; uint8 realm; uint8 region; uint32 program; uint64 id;
                stream.ReadValueU16();      // unknown
                stream.ReadValueU8();       // realm
                stream.ReadValueU8();       // region
                stream.ReadValueU32(false); // program

                var toonId = stream.ReadValueU64(false);

                if (!client.Account.CurrentGameAccount.Toons.ContainsKey(toonId))
                {
                    Logger.Error("Can't find the requested toon: {0}", toonId);
                    continue;
                }

                var toon = client.Account.CurrentGameAccount.Toons[toonId];

                if (operation.ColumnId.Hash.Equals(HeroDigestColumn))
                {
                    data = toon.Digest.ToByteString();
                }
                else
                {
                    Logger.Warn("Unknown ColumndId requested: {0}", operation.ColumnId.Hash.ToByteArray().HexDump());
                }
                //else if (operation.ColumnId.Hash.Equals(HeroNameColumn))
                //    data = toon.NameText.ToByteString();

                var operationResult = bnet.protocol.storage.OperationResult.CreateBuilder().SetTableId(operation.TableId);
                operationResult.AddData(
                    bnet.protocol.storage.Cell.CreateBuilder()
                    .SetColumnId(request.OperationsList[0].ColumnId)
                    .SetRowId(request.OperationsList[0].RowId)
                    .SetVersion(1)
                    .SetData(data)
                    .Build()
                    );
                results.Add(operationResult.Build());
            }

            var builder = bnet.protocol.storage.ExecuteResponse.CreateBuilder();

            foreach (var result in results)
            {
                builder.AddResults(result);
            }
            return(builder.Build());
        }
Exemplo n.º 32
0
 public PacketIn(MooNetClient client, bnet.protocol.Header header)
 {
     this.Client = client;
     this.Header = header;
 }