# HG changeset patch # User Matti Hamalainen # Date 1509304160 -7200 # Node ID 4e7bf754789f9ebb8ca2b62fecb194f5f15fe236 # Parent 3d7da273ce3f1be4914e6b5c3b9d9d465eca639d Add some comments. diff -r 3d7da273ce3f -r 4e7bf754789f mapsearch.c --- 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; }