Ejemplo n.º 1
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 = GameAccountManager.GetAccountByPersistentID(invitation.InviterIdentity.AccountId.Low);

            if (inviter == null || inviter.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.LoggedInClient.MakeTargetedRPC(inviter.LoggedInClient.PartyChannel, () =>
                                                   bnet.protocol.channel.ChannelSubscriber.CreateStub(inviter.LoggedInClient).NotifyUpdateChannelState(null, notification.Build(), callback => { }));

            //inviter.LoggedInClient.MakeTargetedRPC(inviter.LoggedInClient.CurrentChannel, () =>
            //    bnet.protocol.channel.ChannelSubscriber.CreateStub(inviter.LoggedInClient).NotifyUpdateChannelState(null, notification.Build(), callback => { }));
        }
Ejemplo n.º 2
0
        public override void SuggestInvitation(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.channel_invitation.SuggestInvitationRequest request, Action <bnet.protocol.NoData> done)
        {
            var suggester = GameAccountManager.GetAccountByPersistentID(request.TargetId.Low);   //wants invite
            var suggestee = GameAccountManager.GetAccountByPersistentID(request.ApprovalId.Low); //approves invite

            if (suggestee == null)
            {
                return;
            }

            Logger.Debug("{0} suggested {1} to invite him.", suggester, suggestee);
            var respone = bnet.protocol.NoData.CreateBuilder();

            done(respone.Build());

            // Even though it makes no sense, the suggester is used for all fields in the caps and is what works with the client. /dustinconrad
            var suggestion = bnet.protocol.invitation.Suggestion.CreateBuilder()
                             .SetChannelId(request.ChannelId)
                             .SetSuggesterId(suggester.BnetEntityId)
                             .SetSuggesterName(suggester.Owner.BattleTag)
                             .SetSuggesteeId(suggester.BnetEntityId)
                             .SetSuggesteeName(suggester.Owner.BattleTag)
                             .Build();

            var notification = bnet.protocol.channel_invitation.SuggestionAddedNotification.CreateBuilder().SetSuggestion(suggestion);

            suggestee.LoggedInClient.MakeTargetedRPC(this._invitationManager, () =>
                                                     bnet.protocol.channel_invitation.ChannelInvitationNotify.CreateStub(suggestee.LoggedInClient).NotifyReceivedSuggestionAdded(null, notification.Build(), callback => { }));
        }
Ejemplo n.º 3
0
        private ByteString GetHeroProfiles(D3.GameMessage.GetHeroProfiles profiles)
        {
            Logger.Trace("GetHeroProfiles()");

            var profileList = D3.Profile.HeroProfileList.CreateBuilder();

            if (profiles.HeroIdsCount > 0)
            {
                foreach (var hero in profiles.HeroIdsList)
                {
                    var toon = ToonManager.GetToonByLowID(hero.IdLow);
                    profileList.AddHeros(toon.Profile);
                }
            }
            else
            {
                var heroList = GameAccountManager.GetAccountByPersistentID(profiles.AccountId.IdLow).Toons;
                foreach (var hero in heroList)
                {
                    profileList.AddHeros(hero.Profile);
                }
            }

            return(profileList.Build().ToByteString());
        }
Ejemplo n.º 4
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];

            var channel = ChannelManager.GetChannelByEntityId(request.ChannelId);

            //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(channel, () =>
                                   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 = GameAccountManager.GetAccountByPersistentID(invitation.InviteeIdentity.AccountId.Low);

            invitee.LoggedInClient.MakeTargetedRPC(this, () =>
                                                   bnet.protocol.channel_invitation.ChannelInvitationNotify.CreateStub(invitee.LoggedInClient).NotifyReceivedInvitationRemoved(null, invitationRemoved.Build(), callback => { }));
        }
Ejemplo n.º 5
0
        public bool CreateAccount(string email, string password, string battleTag)
        {
            if (string.IsNullOrEmpty(email))
            {
                throw new FaultException(new FaultReason("Email parameter can not be null or empty."));
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new FaultException(new FaultReason("Password parameter can not be null or empty."));
            }

            if (string.IsNullOrEmpty(battleTag))
            {
                throw new FaultException(new FaultReason("BattleTag parameter can not be null or empty."));
            }

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

            if (AccountManager.GetAccountByEmail(email.ToLower()) != null)
            {
                throw new FaultException(new FaultReason(string.Format("An account already exists for email address {0}.", email)));
            }

            var account     = AccountManager.CreateAccount(email, password, battleTag);
            var gameAccount = GameAccountManager.CreateGameAccount(account);

            return(true);
        }
Ejemplo n.º 6
0
        public override void Update(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.presence.UpdateRequest request, System.Action <bnet.protocol.NoData> done)
        {
            //Logger.Warn("request:\n{0}", request.ToString());
            // This "UpdateRequest" is not, as it may seem, a request to update the client on the state of an object,
            // but instead the *client* requesting to change fields on an object that it has subscribed to.
            // Check docs/rpc/presence.txt in branch wip-docs (or master)

            switch (request.EntityId.GetHighIdType())
            {
            case EntityIdHelper.HighIdType.AccountId:
                var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
                Logger.Trace("Update() {0} {1} - {2} Operations", this.Client, account, request.FieldOperationCount);
                Logger.Warn("No AccountManager updater.");
                break;

            case EntityIdHelper.HighIdType.GameAccountId:
                var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
                var trace       = string.Format("Update() {0} {1} - {2} Operations", this.Client, gameaccount, request.FieldOperationCount);
                foreach (var fieldOp in request.FieldOperationList)
                {
                    trace += string.Format("\t{0}, {1}, {2}", (FieldKeyHelper.Program)fieldOp.Field.Key.Program, (FieldKeyHelper.OriginatingClass)fieldOp.Field.Key.Group, fieldOp.Field.Key.Field);
                    gameaccount.Update(fieldOp);
                }
                Logger.Trace(trace);
                break;

            default:
                Logger.Warn("Recieved an unhandled Presence.Update request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
                break;
            }

            var builder = bnet.protocol.NoData.CreateBuilder();

            done(builder.Build());
        }
Ejemplo n.º 7
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 => { }));
                }
            }
        }
Ejemplo n.º 8
0
        public override void Unsubscribe(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.presence.UnsubscribeRequest request, System.Action <bnet.protocol.NoData> done)
        {
            switch (request.EntityId.GetHighIdType())
            {
            case EntityIdHelper.HighIdType.AccountId:
                var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
                // The client will probably make sure it doesn't unsubscribe to a null ID, but just to make sure..
                if (account != null)
                {
                    account.RemoveSubscriber(this.Client);
                    Logger.Trace("Unsubscribe() {0} {1}", this.Client, account);
                }
                break;

            case EntityIdHelper.HighIdType.GameAccountId:
                var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
                if (gameaccount != null)
                {
                    gameaccount.RemoveSubscriber(this.Client);
                    Logger.Trace("Unsubscribe() {0} {1}", this.Client, gameaccount);
                }
                break;

            default:
                Logger.Warn("Recieved an unhandled Presence.Unsubscribe request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
                break;
            }

            var builder = bnet.protocol.NoData.CreateBuilder();

            done(builder.Build());
        }
Ejemplo n.º 9
0
        public override void Subscribe(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.presence.SubscribeRequest request, System.Action <bnet.protocol.NoData> done)
        {
            switch (request.EntityId.GetHighIdType())
            {
            case EntityIdHelper.HighIdType.AccountId:
                var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
                if (account != null)
                {
                    Logger.Trace("Subscribe() {0} {1}", this.Client, account);
                    account.AddSubscriber(this.Client, request.ObjectId);
                }
                break;

            case EntityIdHelper.HighIdType.GameAccountId:
                var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
                if (gameaccount != null)
                {
                    Logger.Trace("Subscribe() {0} {1}", this.Client, gameaccount);
                    gameaccount.AddSubscriber(this.Client, request.ObjectId);
                }
                break;

            default:
                Logger.Warn("Recieved an unhandled Presence.Subscribe request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
                break;
            }

            var builder = bnet.protocol.NoData.CreateBuilder();

            done(builder.Build());
        }
Ejemplo n.º 10
0
        public override void SendReport(IRpcController controller, bnet.protocol.report.SendReportRequest request, Action <bnet.protocol.NoData> done)
        {
            Logger.Trace("SendReport()");

            var report = request.Report;

            //TODO: Store reports against accounts
            foreach (var attribute in report.AttributeList)
            {
                switch (attribute.Name)
                {
                case "target_toon_id":     //uint GameAccount.Low
                    var reportee = GameAccountManager.GetAccountByPersistentID(attribute.Value.UintValue);
                    Logger.Trace("{0} reported {1} for \"{2}\".", this.Client.Account.CurrentGameAccount.CurrentToon, reportee, report.ReportType);
                    break;
                    //case "target_account_id": //uint Account.Low
                    //case "target_toon_name": //string
                    //case "target_toon_program": //fourcc
                    //case "target_toon_region": //string
                    //case "note": //string - not currently used in client
                }
            }

            var builder = bnet.protocol.NoData.CreateBuilder();

            done(builder.Build());
        }
Ejemplo n.º 11
0
        private static readonly Logger Logger = LogManager.CreateLogger(); // logger instance.

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;    // Watch for any unhandled exceptions.
            Thread.CurrentThread.CurrentCulture         = CultureInfo.InvariantCulture; // Use invariant culture - we have to set it explicitly for every thread we create to prevent any mpq-reading problems (mostly because of number formats).

            Console.ForegroundColor = ConsoleColor.Yellow;
            PrintBanner();        // print ascii banner.
            PrintLicense();       // print license text.
            Console.ResetColor(); // reset color back to default.

            InitLoggers();        // init logging facility.

            Logger.Info("mooege v{0} warming-up..", Assembly.GetExecutingAssembly().GetName().Version);
            Logger.Info("Required client version: {0}.", VersionInfo.MooNet.RequiredClientVersion);

            // init openssl & wrapper.
            try
            {
                Logger.Info("Found OpenSSL version {0}.", OpenSSL.Core.Version.Library.ToString());
            }
            catch (Exception e)
            {
                Logger.ErrorException(e, "OpenSSL init error.");
                Console.ReadLine();
                return;
            }

            // prefill the database.
            Common.Storage.AccountDataBase.SessionProvider.RebuildSchema();
            if (!DBSessions.AccountSession.Query <DBAccount>().Any())
            {
                Logger.Info("Initing new database, creating first owner account (test@,123456)");
                var account     = AccountManager.CreateAccount("test@", "123456", "test", Account.UserLevels.Owner);
                var gameAccount = GameAccountManager.CreateGameAccount(account);
                account.DBAccount.DBGameAccounts.Add(gameAccount.DBGameAccount);
                account.SaveToDB();
            }

            // init MPQStorage.
            if (!MPQStorage.Initialized)
            {
                Logger.Fatal("Cannot run servers as MPQStorage failed initialization.");
                Console.ReadLine();
                return;
            }

            // load item database.
            Logger.Info("Loading item database..");
            Logger.Trace("Item database loaded with a total of {0} item definitions.", ItemGenerator.TotalItems);

            // load achievements database.
            Logger.Info("Loading achievements database..");
            Logger.Trace("Achievement file parsed with a total of {0} achievements and {1} criteria in {2} categories.",
                         AchievementManager.TotalAchievements, AchievementManager.TotalCriteria, AchievementManager.TotalCategories);


            Logger.Info("Type '!commands' for a list of available commands.");

            StartupServers(); // startup the servers
        }
Ejemplo n.º 12
0
        public static void Main(string[] args)
        {
            // Watch for unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // Use invariant culture - we have to set it explicitly for every thread we create.


            Console.ForegroundColor = ConsoleColor.Yellow;
            PrintBanner();
            PrintLicense();
            Console.ResetColor();

            InitLoggers(); // init logging facility.

            Logger.Info("mooege v{0} warming-up..", Assembly.GetExecutingAssembly().GetName().Version);

            try
            {
                Logger.Info("Found OpenSSL version {0}.", OpenSSL.Core.Version.Library.ToString());
            }
            catch (Exception e)
            {
                Logger.ErrorException(e, "OpenSSL Error");
                Console.ReadLine();
                return;
            }


            //Prefilling Database
            Common.Storage.AccountDataBase.SessionProvider.RebuildSchema();
            if (!DBSessions.AccountSession.Query <DBAccount>().Any())
            {
                Logger.Info("New Database, creating first Test account (Test@,testpass)");
                var account     = AccountManager.CreateAccount("test@", "testpass", "test", Account.UserLevels.Admin);
                var gameAccount = GameAccountManager.CreateGameAccount(account);
                account.DBAccount.DBGameAccounts.Add(gameAccount.DBGameAccount);
                account.SaveToDB();
            }


            if (!MPQStorage.Initialized)
            {
                Logger.Fatal("Cannot run servers as MPQStorage failed initialization.");
                Console.ReadLine();
                return;
            }

            Logger.Info("Loading item database..");
            Logger.Trace("Item database loaded with a total of {0} item definitions.", ItemGenerator.TotalItems);

            Logger.Info("Loading achievements database..");
            Logger.Trace("Achievement file parsed with a total of {0} achievements and {1} criteria in {2} categories.",
                         AchievementManager.TotalAchievements, AchievementManager.TotalCriteria, AchievementManager.TotalCategories);


            Logger.Info("Type '!commands' for a list of available commands");

            StartupServers();
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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 => { }));
            }
        }
Ejemplo n.º 15
0
 public static void Initialize()
 {
     Character   = CharacterManager.GetInstance();
     ClientDB    = ClientDBManager.GetInstance();
     GameAccount = GameAccountManager.GetInstance();
     Redirect    = RedirectManager.GetInstance();
 }
Ejemplo n.º 16
0
        private ByteString GetAccountProfile(D3.GameMessage.GetAccountProfile profile)
        {
            Logger.Trace("GetAccountProfile()");

            var account = GameAccountManager.GetAccountByPersistentID(profile.AccountId.IdLow);

            return(account.Profile.ToByteString());
        }
Ejemplo n.º 17
0
        public override void SelectGameAccount(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.EntityId request, Action <bnet.protocol.NoData> done)
        {
            this.Client.Account.CurrentGameAccount = GameAccountManager.GetAccountByPersistentID(request.Low);
            this.Client.Account.CurrentGameAccount.LoggedInClient = this.Client;

            Logger.Trace("SelectGameAccount(): {0}", this.Client.Account.CurrentGameAccount);

            done(bnet.protocol.NoData.CreateBuilder().Build());
        }
Ejemplo n.º 18
0
        public override void FindGame(IRpcController controller, bnet.protocol.game_master.FindGameRequest request, Action <bnet.protocol.game_master.FindGameResponse> done)
        {
            Logger.Trace("FindGame() {0}", this.Client);

            // find the game.
            var gameFound = GameFactoryManager.FindGame(this.Client, request, ++GameFactoryManager.RequestIdCounter);

            if (Client.CurrentChannel != null)
            {
                //TODO: All these ChannelState updates can be moved to functions someplace else after packet flow is discovered and working -Egris
                //Send current JoinPermission to client before locking it
                var channelStatePermission = bnet.protocol.channel.ChannelState.CreateBuilder()
                                             .AddAttribute(bnet.protocol.attribute.Attribute.CreateBuilder()
                                                           .SetName("D3.Party.JoinPermissionPreviousToLock")
                                                           .SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetIntValue(1).Build())
                                                           .Build()).Build();

                var notificationPermission = bnet.protocol.channel.UpdateChannelStateNotification.CreateBuilder()
                                             .SetAgentId(this.Client.Account.CurrentGameAccount.BnetEntityId)
                                             .SetStateChange(channelStatePermission)
                                             .Build();

                this.Client.MakeTargetedRPC(Client.CurrentChannel, () =>
                                            bnet.protocol.channel.ChannelSubscriber.CreateStub(this.Client).NotifyUpdateChannelState(null, notificationPermission, callback => { }));
            }

            var builder = bnet.protocol.game_master.FindGameResponse.CreateBuilder().SetRequestId(gameFound.RequestId);

            done(builder.Build());

            var clients = (from player in request.PlayerList select GameAccountManager.FindLoadedGameAccountByBnetId(player.Identity.GameAccountId.Low) into gameAccount where gameFound != null select gameAccount.LoggedInClient).ToList();

            // send game found notification.
            var notification = bnet.protocol.notification.Notification.CreateBuilder()
                               .SetSenderId(bnet.protocol.EntityId.CreateBuilder().SetHigh((ulong)EntityIdHelper.HighIdType.GameAccountId).SetLow(0).Build())
                               .SetTargetId(this.Client.Account.CurrentGameAccount.BnetEntityId)
                               .SetType("MM_START");
            var attr = bnet.protocol.attribute.Attribute.CreateBuilder()
                       .SetName("game_request_id")
                       .SetValue(bnet.protocol.attribute.Variant.CreateBuilder().SetUintValue(gameFound.RequestId).Build());

            notification.AddAttribute(attr);

            this.Client.MakeRPC(() =>
                                bnet.protocol.notification.NotificationListener.CreateStub(this.Client).OnNotificationReceived(null, notification.Build(), callback => { }));

            if (gameFound.Started)
            {
                Logger.Info("Client {0} joining game with FactoryID:{1}", this.Client.Account.CurrentGameAccount.CurrentToon.Name, gameFound.FactoryID);
                gameFound.JoinGame(clients, request.FactoryObjectId);
            }
            else
            {
                Logger.Info("Client {0} creating new game", this.Client.Account.CurrentGameAccount.CurrentToon.Name);
                gameFound.StartGame(clients, request.FactoryObjectId);
            }
        }
Ejemplo n.º 19
0
        private ByteString GetGameAccountSettings(D3.GameMessage.GetGameAccountSettings settings)
        {
            Logger.Trace("GetGameAccountSettings()");

            var gameAccount = GameAccountManager.GetAccountByPersistentID(settings.AccountId.IdLow);

            return(gameAccount.Settings.ToByteString());
            //var pref = D3.Client.Preferences.CreateBuilder().SetVersion(105).Build(); //hack since client is expecting this atm -Egris
            //return pref.ToByteString();
        }
Ejemplo n.º 20
0
 public static void Initialize()
 {
     Character   = CharacterManager.GetInstance();
     ClientDB    = ClientDBManager.GetInstance();
     GameAccount = GameAccountManager.GetInstance();
     Redirect    = RedirectManager.GetInstance();
     Session     = SessionManager.GetInstance();
     Player      = PlayerManager.GetInstance();
     Spawns      = SpawnManager.GetInstance();
 }
Ejemplo n.º 21
0
        public override void RemoveMember(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.channel.RemoveMemberRequest request, System.Action <bnet.protocol.NoData> done)
        {
            Logger.Trace("RemoveMember()");
            var channel     = ChannelManager.GetChannelByDynamicId(LastCallHeader.ObjectId);
            var gameAccount = GameAccountManager.GetAccountByPersistentID(request.MemberId.Low);

            var builder = bnet.protocol.NoData.CreateBuilder();

            done(builder.Build());

            channel.RemoveMember(gameAccount.LoggedInClient, Channel.GetRemoveReasonForRequest((Channel.RemoveRequestReason)request.Reason));
        }
Ejemplo n.º 22
0
        private ByteString GetHeroList(D3.GameMessage.GetHeroIds heroIds)
        {
            Logger.Trace("GetHeroList()");

            var HeroList    = D3.Hero.HeroList.CreateBuilder();
            var gameAccount = GameAccountManager.GetAccountByPersistentID(heroIds.AccountId.IdLow);

            foreach (var toon in gameAccount.Toons.Values)
            {
                HeroList.AddHeroIds(toon.D3EntityID);
            }
            return(HeroList.Build().ToByteString());
        }
Ejemplo n.º 23
0
        public override void SendNotification(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.notification.Notification request, Action <bnet.protocol.NoData> done)
        {
            switch (request.GetNotificationType())
            {
            case NotificationTypeHelper.NotificationType.Whisper:

                // NOTE: Real implementation doesn't even handle the situation where neither client knows about the other.
                // Client requires prior knowledge of sender and target (and even then it cannot whisper by using the /whisper command).

                var targetAccount = GameAccountManager.GetAccountByPersistentID(request.TargetId.Low);
                Logger.Trace(string.Format("NotificationRequest.Whisper by {0} to {1}", this.Client.Account.CurrentGameAccount, targetAccount));

                if (targetAccount.LoggedInClient == null)
                {
                    return;
                }

                if (targetAccount == this.Client.Account.CurrentGameAccount)                          // check if whisper targets the account itself.
                {
                    CommandManager.TryParse(request.AttributeList[0].Value.StringValue, this.Client); // try parsing it as a command and respond it if so.
                }
                else
                {
                    var notification = bnet.protocol.notification.Notification.CreateBuilder(request)
                                       .SetSenderId(this.Client.Account.CurrentGameAccount.BnetEntityId)
                                       .SetSenderAccountId(this.Client.Account.BnetEntityId)
                                       .Build();

                    targetAccount.LoggedInClient.MakeRPC(() =>
                                                         bnet.protocol.notification.NotificationListener.CreateStub(targetAccount.LoggedInClient).OnNotificationReceived(controller, notification, callback => { }));
                }
                break;

            default:
                Logger.Warn("Unhandled notification type: {0}", request.Type);
                break;
            }

            var builder = bnet.protocol.NoData.CreateBuilder();

            done(builder.Build());
        }
Ejemplo n.º 24
0
        public string ClientChannels(string[] @params, MooNetClient invokerClient)
        {
            var client = invokerClient;

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


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

                if (!account.IsOnline)
                {
                    return(string.Format("Account '{0}' is not logged in.", email));
                }

                var gameAccounts = GameAccountManager.GetGameAccountsForAccount(account);
                foreach (var gameAccount in gameAccounts)
                {
                    output += this.ClientChannels(null, gameAccount.LoggedInClient);
                }
            }
            else
            {
                output = string.Format("Active channels for account: {0}\n", client.Account.Email);
                output = ChannelManager.Channels.Aggregate(output, (current, pair) =>
                                                           current + string.Format("Id: {0} \tOwner: {1}\n", pair.Value.DynamicId, pair.Value.Owner));
            }
            return(output);
        }
Ejemplo n.º 25
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.");
            }
            var output = "";

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

                if (!account.IsOnline)
                {
                    return(string.Format("Account '{0}' is not logged in.", email));
                }

                var gameAccounts = GameAccountManager.GetGameAccountsForAccount(account);
                foreach (var gameAccount in gameAccounts)
                {
                    output += this.ClientServices(null, gameAccount.LoggedInClient);
                }
            }
            else
            {
                output = string.Format("Imported service list for account: {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);
        }
Ejemplo n.º 26
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();

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

            if (!removed)
            {
                Logger.Warn("No friendship mapping between {0} and {1}", remover.BnetEntityId.Low, removeeAsFriend);
            }
            removed = Friends.Remove(removee.BnetEntityId.Low, removerAsFriend);
            if (!removed)
            {
                Logger.Warn("No friendship mapping between {0} and {1}", removee.BnetEntityId.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 => { }));


            var removeeGameAccounts = GameAccountManager.GetGameAccountsForAccount(removee).Values;

            foreach (var removeeGameAccount in removeeGameAccounts)
            {
                if (removeeGameAccount.GameAccountStatusField.Value) //true if online
                {
                    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 => { }));
                }
            }
        }
Ejemplo n.º 27
0
        public override void Query(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.presence.QueryRequest request, Action <bnet.protocol.presence.QueryResponse> done)
        {
            var builder = bnet.protocol.presence.QueryResponse.CreateBuilder();

            switch (request.EntityId.GetHighIdType())
            {
            case EntityIdHelper.HighIdType.AccountId:
                var account = AccountManager.GetAccountByPersistentID(request.EntityId.Low);
                foreach (var key in request.KeyList)
                {
                    Logger.Trace("Query() {0} {1} - {2}, {3}, {4}", this.Client, account, (FieldKeyHelper.Program)key.Program, (FieldKeyHelper.OriginatingClass)key.Group, key.Field);
                    var field = account.QueryField(key);
                    if (field != null)
                    {
                        builder.AddField(field);
                    }
                }
                break;

            case EntityIdHelper.HighIdType.GameAccountId:
                var gameaccount = GameAccountManager.GetAccountByPersistentID(request.EntityId.Low);
                foreach (var key in request.KeyList)
                {
                    Logger.Trace("Query() {0} {1} - {2}, {3}, {4}", this.Client, gameaccount, (FieldKeyHelper.Program)key.Program, (FieldKeyHelper.OriginatingClass)key.Group, key.Field);
                    var field = gameaccount.QueryField(key);
                    if (field != null)
                    {
                        builder.AddField(field);
                    }
                }
                break;

            default:
                Logger.Warn("Recieved an unhandled Presence.Query request with type {0} (0x{1})", request.EntityId.GetHighIdType(), request.EntityId.High.ToString("X16"));
                break;
            }

            done(builder.Build());
        }
Ejemplo n.º 28
0
        public static void HandleDecline(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 declinedNotification = bnet.protocol.friends.InvitationNotification.CreateBuilder()
                                       .SetInvitation(invitation)
                                       .SetReason((uint)InvitationRemoveReason.Declined).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, declinedNotification, callback => { }));
                }
            }

            foreach (var inviteeGameAccount in inviteeGameAccounts)
            {
                if (inviteeGameAccount.IsOnline)
                {
                    inviteeGameAccount.LoggedInClient.MakeTargetedRPC(FriendManager.Instance, () =>
                                                                      bnet.protocol.friends.FriendsNotify.CreateStub(inviteeGameAccount.LoggedInClient).NotifyReceivedInvitationRemoved(null, declinedNotification, callback => { }));
                }
            }
        }
Ejemplo n.º 29
0
 public Toon(ulong persistentId, string name, int hashCode, byte @class, byte gender, byte level, long accountId, uint timePlayed) // Toon with given persistent ID
     : base(persistentId)
 {
     this.SetFields(name, hashCode, (ToonClass)@class, (ToonFlags)gender, level, GameAccountManager.GetAccountByPersistentID((ulong)accountId), timePlayed);
 }
Ejemplo n.º 30
0
 public static void Initialize()
 {
     GameAccountMgr = GameAccountManager.GetInstance();
 }
Ejemplo n.º 31
0
        public override void SendInvitation(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.invitation.SendInvitationRequest request, Action <bnet.protocol.invitation.SendInvitationResponse> done)
        {
            var invitee = GameAccountManager.GetAccountByPersistentID(request.TargetId.Low);

            //if (this.Client.CurrentChannel.HasMember(invitee)) return; // don't allow a second invitation if invitee is already a member of client's current channel.

            Logger.Debug("{0} invited {1} to his channel.", Client.Account.CurrentGameAccount.CurrentToon, invitee);

            // somehow protobuf lib doesnt handle this extension, so we're using a workaround to get that channelinfo.
            var extensionBytes        = request.Params.UnknownFields.FieldDictionary[105].LengthDelimitedList[0].ToByteArray();
            var channelInvitationInfo = bnet.protocol.channel_invitation.ChannelInvitationParams.ParseFrom(extensionBytes);

            var channel            = ChannelManager.GetChannelByEntityId(channelInvitationInfo.ChannelId);
            var channelDescription = bnet.protocol.channel.ChannelDescription.CreateBuilder()
                                     .SetChannelId(channelInvitationInfo.ChannelId)
                                     .SetCurrentMembers((uint)channel.Members.Count)
                                     .SetState(channel.State);

            var channelInvitation = bnet.protocol.channel_invitation.ChannelInvitation.CreateBuilder()
                                    .SetChannelDescription(channelDescription)
                                    .SetReserved(channelInvitationInfo.Reserved)
                                    .SetServiceType(channelInvitationInfo.ServiceType)
                                    .SetRejoin(false).Build();

            var invitation = bnet.protocol.invitation.Invitation.CreateBuilder();

            invitation.SetId(ChannelInvitationManager.InvitationIdCounter++)
            .SetInviterIdentity(bnet.protocol.Identity.CreateBuilder().SetGameAccountId(Client.Account.CurrentGameAccount.BnetEntityId).Build())
            .SetInviterName(Client.Account.CurrentGameAccount.Owner.BattleTag)
            .SetInviteeIdentity(bnet.protocol.Identity.CreateBuilder().SetGameAccountId(request.TargetId).Build())
            .SetInviteeName(invitee.Owner.BattleTag)
            .SetInvitationMessage(request.Params.InvitationMessage)
            .SetCreationTime(DateTime.Now.ToExtendedEpoch())
            .SetExpirationTime(DateTime.Now.ToUnixTime() + request.Params.ExpirationTime)
            .SetExtension(bnet.protocol.channel_invitation.ChannelInvitation.ChannelInvitationProp, channelInvitation);

            // oh blizz, cmon. your buggy client even doesn't care this message at all but waits the UpdateChannelStateNotification with embedded invitation proto to show "invitation sent message".
            // ADVICE TO POTENTIAL BLIZZ-WORKER READING THIS;
            // change rpc SendInvitation(.bnet.protocol.invitation.SendInvitationRequest) returns (.bnet.protocol.invitation.SendInvitationResponse); to rpc SendInvitation(.bnet.protocol.invitation.SendInvitationRequest) returns (.bnet.protocol.NoData);

            var builder = bnet.protocol.invitation.SendInvitationResponse.CreateBuilder();

            channel.AddInvitation(invitation.Build());

            if (!channel.HasMember(invitee))
            {
                builder.SetInvitation(invitation.Clone()); // clone it because we need that invitation as un-builded below.
            }
            done(builder.Build());

            // send bnet.protocol.channel.UpdateChannelStateNotification to inviter - update him on invitation is sent.

            var notification = bnet.protocol.channel.UpdateChannelStateNotification.CreateBuilder()
                               .SetAgentId(Client.Account.CurrentGameAccount.BnetEntityId)
                               .SetStateChange(bnet.protocol.channel.ChannelState.CreateBuilder().AddInvitation(invitation.Clone()));

            this.Client.MakeTargetedRPC(channel, () =>
                                        bnet.protocol.channel.ChannelSubscriber.CreateStub(Client).NotifyUpdateChannelState(controller, notification.Build(), callback => { }));

            // notify the invitee on invitation.
            this._invitationManager.HandleInvitation(this.Client, invitation.Build());
        }