Пример #1
0
 /// <summary>
 /// Returns the NotificationType for the given notification.
 /// </summary>
 /// <param name="notification">The notification</param>
 /// <returns><see cref="NotificationType"/></returns>
 public static NotificationType GetNotificationType(this bnet.protocol.notification.Notification notification)
 {
     switch (notification.Type)
     {
     case "WHISPER":
         return(NotificationType.Whisper);
     }
     return(NotificationType.Unknown);
 }
Пример #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());
        }