Exemplo n.º 1
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).

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

                    var account = ToonManager.GetOwnerAccountByToonLowId(request.TargetId.Low);
                    if (account.LoggedInClient == null) return;

                    if (account is CommandHandlerAccount) // hackish way to enable server commands for players that are not in party.
                        CommandHandlerAccount.Instance.ParseCommand(request, this.Client);
                    else
                    {
                        var notification = bnet.protocol.notification.Notification.CreateBuilder(request)
                            .SetSenderId(this.Client.CurrentToon.BnetEntityID)
                            .Build();

                        account.LoggedInClient.MakeRPC(() => bnet.protocol.notification.NotificationListener.CreateStub(account.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());
        }
Exemplo n.º 2
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).

                    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());
        }
Exemplo n.º 3
0
        public override void SendNotification(Google.ProtocolBuffers.IRpcController controller, bnet.protocol.notification.Notification request, Action<bnet.protocol.NoData> done)
        {
            Logger.Trace("SendNotification()");
            //Logger.Debug("notification:\n{0}", request.ToString());

            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 by {0} to {1}", this.Client.CurrentToon, ToonManager.GetToonByLowID(request.TargetId.Low)));

                    var account = ToonManager.GetOwnerAccountByToonLowId(request.TargetId.Low);
                    if (account.LoggedInClient == null) return;

                    var notification = bnet.protocol.notification.Notification.CreateBuilder(request)
                        .SetSenderId(this.Client.CurrentToon.BnetEntityID)
                        .Build();

                    var method = bnet.protocol.notification.NotificationListener.Descriptor.FindMethodByName("OnNotificationReceived");
                    account.LoggedInClient.CallMethod(method, notification);
                    break;
                default:
                    Logger.Warn("Unhandled notification type: {0}", request.Type);
                    break;
            }

            var builder = bnet.protocol.NoData.CreateBuilder();
            done(builder.Build());
        }