Ejemplo n.º 1
0
        public async void CallService(HttpHeader request, BnetChallengeSession session)
        {
            var pathInfo       = request.Path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var pathValueMatch = Regex.Match(pathInfo[1], "^([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");

            if (pathInfo.Length != 2)
            {
                Log.Message(LogTypes.Error, $"Got invalid path '{request.Path}'.");

                session.Dispose();
                return;
            }

            Guid sessionGuid;

            if (!pathValueMatch.Success || !Guid.TryParse(pathValueMatch.Captures[0].Value, out sessionGuid))
            {
                Log.Message(LogTypes.Error, $"Wrong path value for '{request.Host}{request.Path}'.");

                session.Dispose();
                return;
            }

            if (!Manager.Session.Exists(sessionGuid))
            {
                Log.Message(LogTypes.Error, $"Session with guid '{pathValueMatch.Captures[0].Value}' doesn't exists..");

                session.Dispose();
                return;
            }

            request.PathValue = sessionGuid;

            Dictionary <Tuple <string, string>, MethodInfo> restMethods;

            // TODO: Fix host configuration in RestServiceAttribute.
            //if (restServiceHandlers.TryGetValue(request.Host, out restMethods))
            if (restServiceHandlers.TryGetValue("*", out restMethods))
            {
                var methodInfo = Tuple.Create(request.Method, pathInfo[0]);

                MethodInfo method;

                if (restMethods.TryGetValue(methodInfo, out method))
                {
                    // TODO: Test for performance issues and problems with async/await.
                    await Task.Run(() => method.Invoke(null, new object[] { request, session }));
                }
                else
                {
                    Log.Message(LogTypes.Error, $"Got unhandled REST method/path '{methodInfo.Item1}/{methodInfo.Item2}' for '{request.Host}'.");
                }
            }
            else
            {
                Log.Message(LogTypes.Error, $"Got unhandled REST service for host '{request.Host}'.");
            }
        }
Ejemplo n.º 2
0
 //[RestRoute(Method = "POST", Path = "login")]
 public static async void HandleLoginRequest(HttpHeader request, BnetChallengeSession session)
 {
     // TODO: Implement authentication.
     if (false)
     {
     }
     else
         await session.Send(RestResponse.InvalidAccountOrCredentials);
 }
Ejemplo n.º 3
0
 //[RestRoute(Method = "POST", Path = "login")]
 public static async void HandleLoginRequest(HttpHeader request, BnetChallengeSession session)
 {
     // TODO: Implement authentication.
     if (false)
     {
     }
     else
     {
         await session.Send(RestResponse.InvalidAccountOrCredentials);
     }
 }
Ejemplo n.º 4
0
 public static async void HandleConnectRequest(HttpHeader request, BnetChallengeSession session)
 {
     // Login form is the same for all clients...
     await session.Send(RestResponse.LoginForm);
 }
Ejemplo n.º 5
0
 public static async void HandleConnectRequest(HttpHeader request, BnetChallengeSession session)
 {
     // Login form is the same for all clients...
     await session.Send(RestResponse.LoginForm);
 }