Exemple #1
0
 public async Task <ActionResult> GetServerInfo([FromQuery] string address = "whipit.de", [FromQuery] ushort port = 1337)
 {
     // TODO: Think about how I wanna cache responses
     if (!await Utils.IsValidAddress(address))
     {
         return(BadRequest());
     }
     try
     {
         TopicSource topic         = new TopicSource(address, port);
         var         queryResponse = topic.Query("status");
         return(Ok(new SS13Status(queryResponse.AsText)));
     }
     catch (System.Net.Sockets.SocketException e)
     {
         // Return badrequest to tell the consumer they f****d up
         return(BadRequest(new
         {
             Title = "One or more validation errors occured",
             Status = 400,
             ErrorMessage = e.Message,
             Errors = new Dictionary <string, string[]> {
                 { "address", new[] { $"The value '{address}' is not valid" } }
             }
         }));
     }
 }
Exemple #2
0
 public ActionResult Test([FromQuery] string address = "whipit.de", [FromQuery] ushort port = 1337, [FromQuery] string query = "status")
 {
     try
     {
         TopicSource topic         = new TopicSource(address, port);
         var         queryResponse = topic.Query(query);
         return(Ok(queryResponse.ToString()));
     }
     catch (System.Net.Sockets.SocketException e)
     {
         return(BadRequest(new
         {
             Title = "One or more validation errors occured",
             Status = 400,
             ErrorMessage = e.Message,
             Errors = new Dictionary <string, string[]> {
                 { "address", new[] { $"The value '{address}' is not valid" } }
             }
         }));
     }
 }