Exemple #1
0
        public override void DeleteToon(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.toon.external.DeleteToonRequest request, Action <bnet.protocol.toon.external.DeleteToonResponse> done)
        {
            var id   = request.Toon.Low;
            var toon = ToonManager.GetToonByLowID(id);

            ToonManager.DeleteToon(toon);

            var builder = bnet.protocol.toon.external.DeleteToonResponse.CreateBuilder();

            done(builder.Build());

            Logger.Trace("DeleteToon() {0}", toon);
        }
Exemple #2
0
        private ByteString SelectHero(D3.OnlineService.EntityId hero)
        {
            this.Client.Account.CurrentGameAccount.CurrentToon = ToonManager.GetToonByLowID(hero.IdLow);

            Logger.Trace("SelectToon() {0}", this.Client.Account.CurrentGameAccount.CurrentToon);

            if (this.Client.Account.CurrentGameAccount.CurrentToon.D3EntityID != this.Client.Account.CurrentGameAccount.lastPlayedHeroId)
            {
                this.Client.Account.CurrentGameAccount.NotifyUpdate();
                this.Client.Account.CurrentGameAccount.lastPlayedHeroId = this.Client.Account.CurrentGameAccount.CurrentToon.D3EntityID;
            }
            return(this.Client.Account.CurrentGameAccount.CurrentToon.D3EntityID.ToByteString());
        }
        private ByteString GetToonSettings(D3.GameMessage.GetToonSettings settings)
        {
            Logger.Trace("GetToonSettings");

            if (settings.HasHeroId)
            {
                var toon = ToonManager.GetToonByLowID(settings.HeroId.IdLow);
                return(toon.Settings.ToByteString());
            }
            else
            {
                return(this.Client.Account.CurrentGameAccount.CurrentToon.Settings.ToByteString());
            }
        }
        private ByteString UndeleteHero(D3.GameMessage.UndeleteHero heroId)
        {
            var toon = ToonManager.GetToonByLowID(heroId.UndeleteHeroId.IdLow);

            if (toon != null && toon.Deleted)
            {
                toon.Deleted = false;
                ToonManager.SaveToDB(toon);
                return(toon.Digest.ToByteString());
            }
            else
            {
                return(ByteString.Empty);
            }
        }
        private ByteString SelectHero(D3.OnlineService.EntityId hero)
        {
            var oldToon = this.Client.Account.CurrentGameAccount.CurrentToon;
            var newtoon = ToonManager.GetToonByLowID(hero.IdLow);


            Logger.Trace("SelectToon() {0}", this.Client.Account.CurrentGameAccount.CurrentToon);

            if (oldToon != newtoon)
            {
                this.Client.Account.CurrentGameAccount.CurrentToon = newtoon;
                this.Client.Account.CurrentGameAccount.NotifyUpdate();
                AccountManager.SaveToDB(this.Client.Account);
            }
            return(this.Client.Account.CurrentGameAccount.CurrentToon.D3EntityID.ToByteString());
        }
        private void DeleteHero(D3.OnlineService.EntityId hero)
        {
            //Permanantly delete previously deleted hero
            var deleteHero = ToonManager.GetDeletedToon(this.Client.Account.CurrentGameAccount);

            if (deleteHero != null)
            {
                Logger.Trace("Permanantly deleting hero: {0}", deleteHero);
                ToonManager.DeleteToon(deleteHero);
            }
            //Mark hero as deleted
            var markHero = ToonManager.GetToonByLowID(hero.IdLow);

            markHero.Deleted = true;
            ToonManager.SaveToDB(markHero);

            Logger.Trace("DeleteHero(): Marked {0} as deleted.", markHero);
        }
Exemple #7
0
        public override void Query(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.presence.QueryRequest request, System.Action <bnet.protocol.presence.QueryResponse> done)
        {
            Logger.Trace("Query() {0}: {1}", request.EntityId.GetHighIdType(), request.EntityId.Low);

            var builder = bnet.protocol.presence.QueryResponse.CreateBuilder();
            var toon    = ToonManager.GetToonByLowID(request.EntityId.Low);

            foreach (var key in request.KeyList)
            {
                var field = toon.QueryField(key);
                if (field != null)
                {
                    builder.AddField(field);
                }
            }

            done(builder.Build());
        }
        private ByteString GetHeroDigestList(D3.GameMessage.HeroDigestListRequest request)
        {
            Logger.Trace("GetHeroDigestList()");

            var ListResponse = D3.GameMessage.HeroDigestListResponse.CreateBuilder();

            foreach (var toon in request.ToonIdList)
            {
                var digest = ToonManager.GetToonByLowID(toon.IdLow).Digest;
                ListResponse.AddDigestList(
                    D3.GameMessage.HeroDigestResponse.CreateBuilder()
                    .SetToonId(toon)
                    .SetSuccess(true)
                    .SetHeroDigest(digest)
                    .Build()
                    );
            }
            return(ListResponse.Build().ToByteString());
        }
Exemple #9
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);
                Logger.Trace("Query() {0} {1}", this.Client, account);
                foreach (var key in request.KeyList)
                {
                    var field = account.QueryField(key);
                    if (field != null)
                    {
                        builder.AddField(field);
                    }
                }

                break;

            case EntityIdHelper.HighIdType.ToonId:
                var toon = ToonManager.GetToonByLowID(request.EntityId.Low);
                Logger.Trace("Query() {0} {1}", this.Client, toon);
                foreach (var key in request.KeyList)
                {
                    var field = toon.QueryField(key);
                    if (field != null)
                    {
                        builder.AddField(field);
                    }
                }

                break;
            }

            done(builder.Build());
        }
Exemple #10
0
        public string LevelUp(string[] @params, MooNetClient invokerClient)
        {
            //TODO: Correct it to work while staying in-game by correcting the icon level, and correcting the experience bar.

            //TODO: set a Max of 60.

            if (invokerClient == null)
            {
                return("You can not invoke this command from console.");
            }

            var amount = 1;

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

            //if client in game
            if (invokerClient.InGameClient != null)
            {
                var player = invokerClient.InGameClient.Player;
                player.Attributes[GameAttribute.Level] = amount;
                player.PlayEffect(Net.GS.Message.Definitions.Effect.Effect.LevelUp);
            }

            var hero = ToonManager.GetToonByLowID(invokerClient.Account.CurrentGameAccount.CurrentHeroIdField.Value.IdLow);

            hero.HeroLevelField.Value = amount;
            invokerClient.Account.CurrentGameAccount.NotifyUpdate();

            return(string.Format("If in game log out and log back in for icon update to level: " + amount));
        }
Exemple #11
0
        private void OnJoinGame(GameClient client, JoinBNetGameMessage message)
        {
            var game = GameManager.GetGameById(message.GameId);

            if (game == null)
            {
                Logger.Warn("Client provided message.GameId doesnt exists, dropping him..");
                client.Connection.Disconnect();
                return;
            }
            lock (game)
            {
                var toon = ToonManager.GetToonByLowID((ulong)message.ToonEntityId.Low);

                client.Game = game;

                if (toon.GameAccount.LoggedInClient == null || toon.Dead)
                {
                    Logger.Warn("Client doesn't seem to be connected to moonet, dropping him..");
                    client.Connection.Disconnect();
                    return; // if moonet connection is lost, don't allow him to get in.
                }

                // Set references between MooNetClient and GameClient.
                client.BnetClient = toon.GameAccount.LoggedInClient;
                client.BnetClient.InGameClient = client;

                client.Player = new Player(game.StartingWorld, client, toon);
                Logger.Info("Player {0}[PlayerIndex: {1}] connected.", client.Player.Toon.Name, client.Player.PlayerIndex);

                client.SendMessage(new VersionsMessage(message.SNOPackHash));

                client.SendMessage(new ConnectionEstablishedMessage
                {
                    PlayerIndex = client.Player.PlayerIndex,
                    Field1      = 0x4BB91A16,
                    SNOPackHash = message.SNOPackHash,
                });

                client.SendMessage(new GameSetupMessage // should be the current tick for the game /raist.
                {
                    Field0 = game.TickCounter,
                });

                client.SendMessage(new SavePointInfoMessage
                {
                    snoLevelArea = -1,
                });

                client.SendMessage(new HearthPortalInfoMessage
                {
                    snoLevelArea = -1,
                    Field1       = -1,
                });

                // transition player to act so client can load act related data? /raist
                client.SendMessage(new ActTransitionMessage
                {
                    Field0 = 0x00000000,
                    Field1 = true,
                });

                toon.LoginTime = DateTimeExtensions.ToUnixTime(DateTime.UtcNow);
                Logger.Trace("Log in time:" + toon.LoginTime.ToString());

                game.Enter(client.Player);
            }
        }
        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).

                Logger.Trace(string.Format("NotificationRequest.Whisper by {0} to {1}", this.Client.CurrentToon, ToonManager.GetToonByLowID(request.TargetId.Low)));

                var targetAccount = ToonManager.GetOwnerAccountByToonLowId(request.TargetId.Low);
                if (targetAccount.LoggedInClient == null)
                {
                    return;
                }

                if (targetAccount == this.Client.Account)                                             // 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.CurrentToon.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());
        }