コード例 #1
0
        public override void GetGameStats(IRpcController controller, bnet.protocol.game_master.GetGameStatsRequest request, Action <bnet.protocol.game_master.GetGameStatsResponse> done)
        {
            var response = bnet.protocol.game_master.GetGameStatsResponse.CreateBuilder()
                           .AddStatsBucket(GameFactoryManager.GetGameStats(request).Build())
                           .Build();

            done(response);
        }
コード例 #2
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);

            //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.CurrentToon.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 = new List <MooNetClient>();

            foreach (var player in request.PlayerList)
            {
                var toon = ToonManager.GetToonByLowID(player.ToonId.Low);
                if (toon.Owner.LoggedInClient == null)
                {
                    continue;
                }
                clients.Add(toon.Owner.LoggedInClient);
            }

            // send game found notification.
            var notificationBuilder = bnet.protocol.game_master.GameFoundNotification.CreateBuilder()
                                      .SetRequestId(gameFound.RequestId)
                                      .SetGameHandle(gameFound.GameHandle);

            this.Client.MakeRPCWithListenerId(request.ObjectId, () =>
                                              bnet.protocol.game_master.GameFactorySubscriber.CreateStub(this.Client).NotifyGameFound(null, notificationBuilder.Build(), callback => { }));

            if (gameFound.Started)
            {
                Logger.Warn("Client {0} joining game with FactoryID:{1}", this.Client.CurrentToon.Name, gameFound.FactoryID);
                gameFound.JoinGame(clients, request.ObjectId);
            }
            else
            {
                Logger.Warn("Client {0} creating new game", this.Client.CurrentToon.Name);
                gameFound.StartGame(clients, request.ObjectId);
            }
        }
コード例 #3
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);
            }
        }