changeset 1796:4e7bf754789f

Add some comments.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 29 Oct 2017 21:09:20 +0200
parents 3d7da273ce3f
children bd0e0b62c8f9
files mapsearch.c
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mapsearch.c	Sun Oct 29 20:56:47 2017 +0200
+++ b/mapsearch.c	Sun Oct 29 21:09:20 2017 +0200
@@ -669,7 +669,9 @@
     // Clean the pattern from characters we do not want to match
     mapBlockClean(pattern, optCleanChars);
 
-    // Search maps ..
+    //
+    // Search the maps .. enabled or if none specified, all of them
+    //
     for (int nmap = 0; nmap < optNMaps; nmap++)
     {
         MAPInfoCtx *info = &optMaps[nmap];
@@ -677,9 +679,11 @@
         for (int oy = 0; oy < info->map->height - height - 1; oy++)
         for (int ox = 0; ox < info->map->width - width - 1; ox++)
         {
+            // Check for match
             double accuracy = mapMatchBlock(info->map, pattern, ox, oy, 0, TRUE);
             if (accuracy > 99.5f)
             {
+                // Okay, add the match to our list
                 MAPMatch *match = &matches[nmatches++];
 
                 match->map = info->locFile.continent;
@@ -704,6 +708,7 @@
 
     if (nmatches > 0)
     {
+        // We got some matches, output them as a JSON array
         char *buf = NULL;
         size_t bufLen = 0, bufSize = 0;
 
@@ -751,8 +756,10 @@
             unsigned char *udata = (unsigned char *) in;
             char *verr = NULL;
 
+            // Check what the request is about?
             if (len >= 10 && strncmp(data, "MAPSEARCH\n", 10) == 0)
             {
+                // A map search query!
                 if (len <= 10 + 1)
                     verr = "Search pattern data too small.";
                 else
@@ -761,6 +768,7 @@
             else
             if (len >= 7 && strncmp(data, "GETMAPS", 7) == 0)
             {
+                // Client wants a list of available maps
                 char *buf = NULL;
                 size_t bufLen = 0, bufSize = 0;
 
@@ -785,9 +793,11 @@
             }
             else
             {
+                // Unknown or invalid query
                 verr = "Invalid command/search query, not enough data.";
             }
 
+            // Check for errors ..
             if (verr != NULL)
             {
                 THERR("%s\n", verr);
@@ -796,11 +806,13 @@
                 th_free(vstr);
             }
 
+            // End communication
             verr = "END";
             lws_write(wsi, (unsigned char *) verr, strlen(verr), LWS_WRITE_TEXT);
             lws_close_reason(wsi, LWS_CLOSE_STATUS_NOSTATUS, NULL, 0);
             }
             break;
+
         default:
             break;
     }