/* * Copyright (c) 2019, Salvatore Sanfilippo * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Redis nor the names of its contributors may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * ---------------------------------------------------------------------------- * * This file implements the LOLWUT command. The command should do something * fun and interesting, and should be replaced by a new implementation at * each new version of Redis. */ #include "server.h" #include "lolwut.h" /* The LOLWUT 6 command: * * LOLWUT [columns] [rows] * * By default the command uses 80 columns, 40 squares per row * per column. */ void lolwut6Command(client *c) { long cols = 80; long rows = 40; /* Parse the optional arguments if any. */ if (c->argc > 1 && getLongFromObjectOrReply(c,c->argv[1],&cols,NULL) != C_OK) return; if (c->argc > 2 && getLongFromObjectOrReply(c,c->argv[2],&rows,NULL) != C_OK) return; /* Limits. We want LOLWUT to be always reasonably fast and cheap to execute * so we have maximum number of columns, rows, and output resulution. */ if (cols < 1) cols = 1; if (cols > 1000) cols = 1000; if (rows < 1) rows = 1; if (rows > 1000) rows = 1000; /* Generate the city skyline and reply. */ sds rendered = sdsempty(); rendered = sdscat(rendered, "\nDedicated to the 8 bit game developers of the past. Redis ver. "); rendered = sdscat(rendered,REDIS_VERSION); rendered = sdscatlen(rendered,"\n",1); addReplyVerbatim(c,rendered,sdslen(rendered),"txt"); sdsfree(rendered); // lwFreeCanvas(canvas); }