Beispiel #1
0
 public void Handle(IVoltronSession session, DBRequestWrapperPDU packet)
 {
     if (packet.Body is cTSONetMessageStandard)
     {
         HandleNetMessage(session, (cTSONetMessageStandard)packet.Body, packet);
     }
 }
Beispiel #2
0
        public void MessageReceived(AriesClient client, object message)
        {
            if (!(message is DBRequestWrapperPDU))
            {
                return;
            }

            DBRequestWrapperPDU response = (DBRequestWrapperPDU)message;

            if (response.Body is cTSONetMessageStandard)
            {
                var body = (cTSONetMessageStandard)response.Body;
                var type = DBResponseTypeUtils.FromResponseID(body.DatabaseType.Value);

                //TODO: I feel like a sequence id would be better for matching up request / responses, perhaps the old protocol has this and we've just missed it
                var callback = PendingRequests[response.SendingAvatarID];//.FirstOrDefault(x => x.ResponseType == type);
                if (callback != null)
                {
                    PendingRequests.Remove(body.SendingAvatarID);

                    GameThread.NextUpdate(x =>
                    {
                        try
                        {
                            callback.Callback(body.ComplexParameter);
                        }
                        catch (Exception ex)
                        {
                            //LOG.Error(ex);
                        }
                    });
                }
            }
        }
        void HandleNetMessage(IVoltronSession session, cTSONetMessageStandard msg, DBRequestWrapperPDU packet)
        {
            if (!msg.DatabaseType.HasValue)
            {
                return;
            }
            var requestType = DBRequestTypeUtils.FromRequestID(msg.DatabaseType.Value);

            object response = null;

            switch (requestType)
            {
            case DBRequestType.LoadAvatarByID:
                response = HandleLoadAvatarById(session, msg);
                break;

            case DBRequestType.SearchExactMatch:
                response = HandleSearchExact(session, msg);
                break;

            case DBRequestType.Search:
                response = HandleSearchWildcard(session, msg);
                break;

            case DBRequestType.GetTopResultSetByID:
                response = HandleGetTop100(session, msg);
                break;
            }

            if (response != null)
            {
                session.Write(new DBRequestWrapperPDU {
                    SendingAvatarID = packet.SendingAvatarID,
                    Badge           = packet.Badge,
                    IsAlertable     = packet.IsAlertable,
                    Sender          = packet.Sender,
                    Body            = response
                });
            }
        }