From 022ec48aa446dce7fb97023a206d0f1479e63d82 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 19 Jan 2016 02:40:23 +1000 Subject: Clean up LSL command and argument passing. --- src/LuaSL/LuaSL_main.c | 20 +++++--- src/extantz/extantz.c | 23 ++++----- src/libraries/SledjHamr.c | 2 +- src/love/love.c | 123 +++++++++++++++++++++------------------------- 4 files changed, 82 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c index b72a155..d7223f9 100644 --- a/src/LuaSL/LuaSL_main.c +++ b/src/LuaSL/LuaSL_main.c @@ -69,7 +69,7 @@ static script *findThem(gameGlobals *ourGlobals, const char *base, const char *t return eina_hash_find(ourGlobals->names, name); } -void send2server(script *me, const char *message) +static void send2server(script *me, const char *message) { gameGlobals *ourGlobals = me->data; @@ -224,13 +224,13 @@ static Eina_Bool parser(void *data, Connection *connection, char *SID, char *com char buf[PATH_MAX]; //PD("PARSE COMMAND - %s", command); - if (0 == strncmp(command, "compile(", 8)) + if (0 == strcmp(command, "compile")) { char *temp; char *file; LuaCompiler *compiler; - strcpy(buf, &command[8]); + strcpy(buf, arguments); temp = buf; file = temp; while (')' != temp[0]) @@ -242,13 +242,13 @@ static Eina_Bool parser(void *data, Connection *connection, char *SID, char *com PI("Compiling script %s", file); compileScript(compiler, TRUE); } - else if (0 == strncmp(command, "run(", 4)) + else if (0 == strcmp(command, "run")) { char *temp; char *file; script *me; - strcpy(buf, &command[4]); + strcpy(buf, arguments); temp = buf; file = temp; while (')' != temp[0]) @@ -268,15 +268,19 @@ static Eina_Bool parser(void *data, Connection *connection, char *SID, char *com else PE("Failed to run script %s", me->fileName); } - else if (0 == strcmp(command, "exit()")) + else if (0 == strcmp(command, "exit")) { PI("Told to exit."); ecore_main_loop_quit(); } else { -//PD("Sending -> script %s : %s", SID, command); - send2script(SID, command); + if (0 == strcmp("return", command)) + snprintf(buf, sizeof(buf), "%s %s", command, arguments); + else + snprintf(buf, sizeof(buf), "%s(%s", command, arguments); +//PD("Sending -> script %s : %s", SID, buf); + send2script(SID, buf); } return ECORE_CALLBACK_RENEW; diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index f9b638a..f4f602e 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -37,12 +37,12 @@ static Eina_Bool clientParser(void *data, Connection *connection, char *SID, cha globals *ourGlobals = data; char buf[PATH_MAX]; - if ((0 == strncmp(command, "llOwnerSay(", 11)) - || (0 == strncmp(command, "llWhisper(", 10)) - || (0 == strncmp(command, "llSay(", 6)) - || (0 == strncmp(command, "llShout(", 8))) + if ((0 == strcmp(command, "llOwnerSay")) + || (0 == strcmp(command, "llWhisper")) + || (0 == strcmp(command, "llSay")) + || (0 == strcmp(command, "llShout"))) { - sprintf(buf, "%s: %s", SID, command); + sprintf(buf, "%s: %s(%s", SID, command, arguments); if (ourGlobals->purkle) { int _P; @@ -54,7 +54,7 @@ static Eina_Bool clientParser(void *data, Connection *connection, char *SID, cha else PE("No purkle to put - %s", buf); } - else if (0 == strncmp(command, "llDialog(", 9)) + else if (0 == strcmp(command, "llDialog")) { if (ourGlobals->LSLGuiMess) { @@ -64,12 +64,13 @@ static Eina_Bool clientParser(void *data, Connection *connection, char *SID, cha _M = lua_gettop(ourGlobals->LSLGuiMess->L); // TODO - Somewhere in the chain the new lines that MLP likes to put into llDialog's message munge things. Fix that. - push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", command, 0); + sprintf(buf, "%s(%s", command, arguments); + push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", buf, 0); } else - PE("No LSLGuiMess to send - %s", command); + PE("No LSLGuiMess to send - %s(%s", command, arguments); } - else if (0 == strncmp(command, "loadSim(", 8)) + else if (0 == strcmp(command, "loadSim")) { #if USE_EVAS_3D char *p, *t; @@ -80,7 +81,7 @@ static Eina_Bool clientParser(void *data, Connection *connection, char *SID, cha strcpy(ourGlobals->uuid, SID); PI("Your UUID is %s.", ourGlobals->uuid); #if USE_EVAS_3D - strcpy(buf, &command[8]); + strcpy(buf, arguments); p = buf; while ('"' == p[0]) p++; @@ -109,7 +110,7 @@ static Eina_Bool clientParser(void *data, Connection *connection, char *SID, cha #endif } else - PI("Some random command %s", command); + PI("Some random command %s(%s", command, arguments); return ECORE_CALLBACK_RENEW; } diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index 4d0efbc..abd5b1c 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c @@ -159,7 +159,7 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi { streamParser func = eina_hash_find(conn->commands, command); -// ext[0] = '\0'; + ext[0] = '\0'; // Need a callback if we can't find the command. if (NULL == func) func = conn->unknownCommand; diff --git a/src/love/love.c b/src/love/love.c index e6f5b6e..9ad9842 100644 --- a/src/love/love.c +++ b/src/love/love.c @@ -199,14 +199,14 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm //PD("COMMAND - %s - %s", SID, command); me = eina_hash_find(ourGlobals->scripts, SID); - if (0 == strncmp(command, "compilerWarning(", 16)) + if (0 == strcmp(command, "compilerWarning")) { char *temp; char *line; char *column; char *text; - strcpy(buf, &command[16]); + strcpy(buf, arguments); temp = buf; line = temp; while (',' != temp[0]) @@ -224,14 +224,14 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm if (me) me->warnings++; } - else if (0 == strncmp(command, "compilerError(", 14)) + else if (0 == strcmp(command, "compilerError")) { char *temp; char *line; char *column; char *text; - strcpy(buf, &command[14]); + strcpy(buf, arguments); temp = buf; line = temp; while (',' != temp[0]) @@ -249,9 +249,8 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm if (me) me->bugs++; } - else if (0 == strcmp(command, "compiled(false)")) + else if (0 == strcmp(command, "compiled")) { -// PE("The compile of %s failed!", SID); if (me) { struct timeval now; @@ -263,67 +262,61 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm PI("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total); } } - } - else if (0 == strcmp(command, "compiled(true)")) - { - if (me) - { - struct timeval now; - compiledCount++; - if (compiledCount == scriptCount) - { - float total = timeDiff(&now, &startTime); - PI("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total); - } - } + if ('t' == arguments[0]) + { //PD("About to run %s", me->fileName); - send2(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName); + send2(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName); + } + else + { +// PE("The compile of %s failed!", SID); + } } else { //PD("FAKING (maybe) %s", command); // Send back some random or fixed values for testing. - if (0 == strcmp(command, "llGetKey()")) + if (0 == strcmp(command, "llGetKey")) send2(ourGlobals->serverLuaSL, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); - else if (0 == strcmp(command, "llGetOwner()")) + else if (0 == strcmp(command, "llGetOwner")) send2(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey); - else if (0 == strcmp(command, "llGetPermissionsKey()")) + else if (0 == strcmp(command, "llGetPermissionsKey")) send2(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey); - else if (0 == strncmp(command, "llRequestPermissions(", 21)) - PI("Faked %s", command); - else if (0 == strcmp(command, "llGetPos()")) + else if (0 == strcmp(command, "llRequestPermissions")) + PI("Faked %s(%s", command, arguments); + else if (0 == strcmp(command, "llGetPos")) send2(ourGlobals->serverLuaSL, SID, "return {x=128.0, y=128.0, z=128.0}"); - else if (0 == strcmp(command, "llGetRot()")) + else if (0 == strcmp(command, "llGetRot")) send2(ourGlobals->serverLuaSL, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}"); - else if (0 == strcmp(command, "llGetFreeMemory()")) + else if (0 == strcmp(command, "llGetFreeMemory")) send2(ourGlobals->serverLuaSL, SID, "return 654321"); - else if (0 == strcmp(command, "llGetObjectDesc()")) + else if (0 == strcmp(command, "llGetObjectDesc")) send2(ourGlobals->serverLuaSL, SID, "return \"\""); - else if (0 == strncmp(command, "llGetAlpha(", 11)) + else if (0 == strcmp(command, "llGetAlpha")) send2(ourGlobals->serverLuaSL, SID, "return 1.0"); - else if (0 == strcmp(command, "llGetInventoryNumber(7)")) + else if (0 == strcmp(command, "llGetInventoryNumber") && (0 == strcmp(arguments, "7)"))) send2(ourGlobals->serverLuaSL, SID, "return 3"); - else if (0 == strcmp(command, "llGetLinkNumber()")) + else if (0 == strcmp(command, "llGetLinkNumber")) send2(ourGlobals->serverLuaSL, SID, "return 1"); - else if (0 == strcmp(command, "llGetInventoryName(7, 2)")) + else if (0 == strcmp(command, "llGetInventoryName") && (0 == strcmp(arguments, "7, 2)"))) send2(ourGlobals->serverLuaSL, SID, "return \".readme\""); - else if (0 == strcmp(command, "llGetInventoryName(7, 1)")) + else if (0 == strcmp(command, "llGetInventoryName") && (0 == strcmp(arguments, "7, 1)"))) send2(ourGlobals->serverLuaSL, SID, "return \".POSITIONS\""); - else if (0 == strcmp(command, "llGetInventoryName(7, 0)")) + else if (0 == strcmp(command, "llGetInventoryName") && (0 == strcmp(arguments, "7, 0)"))) send2(ourGlobals->serverLuaSL, SID, "return \".MENUITEMS\""); - else if (0 == strncmp(command, "llListen(", 9)) + else if (0 == strcmp(command, "llListen")) { - PI("Faked %s", command); + PI("Faked %s(%s", command, arguments); send2(ourGlobals->serverLuaSL, SID, "return %d", random()); } - else if (0 == strncmp(command, "llSameGroup(", 12)) + else if (0 == strcmp(command, "llSameGroup")) send2(ourGlobals->serverLuaSL, SID, "return true"); - else if (0 == strncmp(command, "llKey2Name(", 11)) + else if (0 == strcmp(command, "llKey2Name")) { char *temp; - strcpy(buf, &command[12]); + strcpy(buf, arguments); temp = buf; while (')' != temp[0]) temp++; @@ -342,57 +335,55 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm // Extantz registering any channel it wants to listen to, mostly for client side scripts. // Extantz is then only responsible for the registered channels, it can do what it likes with them. // Dialogs, notifications, and other stuff goes through some other functions. - else if (0 == strncmp(command, "llOwnerSay(", 11)) + else if (0 == strcmp(command, "llOwnerSay")) { - if (ourGlobals->client) send2(ourGlobals->client, SID, command); - else PW("No where to send %s", command); + if (ourGlobals->client) send2(ourGlobals->client, SID, "%s(%s", command, arguments); + else PW("No where to send %s(%s", command, arguments); } - else if (0 == strncmp(command, "llWhisper(", 10)) + else if (0 == strcmp(command, "llWhisper")) { - if (ourGlobals->client) send2(ourGlobals->client, SID, command); - else PW("No where to send %s", command); + if (ourGlobals->client) send2(ourGlobals->client, SID, "%s(%s", command, arguments); + else PW("No where to send %s(%s", command, arguments); } - else if (0 == strncmp(command, "llRegionSay(", 12)) + else if (0 == strcmp(command, "llRegionSay")) { - if (ourGlobals->client) send2(ourGlobals->client, SID, command); - else PW("No where to send %s", command); + if (ourGlobals->client) send2(ourGlobals->client, SID, "%s(%s", command, arguments); + else PW("No where to send %s(%s", command, arguments); } - else if (0 == strncmp(command, "llSay(", 6)) + else if (0 == strcmp(command, "llSay")) { - if (ourGlobals->client) send2(ourGlobals->client, SID, command); - else PW("No where to send %s", command); + if (ourGlobals->client) send2(ourGlobals->client, SID, "%s(%s", command, arguments); + else PW("No where to send %s(%s", command, arguments); } - else if (0 == strncmp(command, "llShout(", 8)) + else if (0 == strcmp(command, "llShout")) { - if (ourGlobals->client) send2(ourGlobals->client, SID, command); - else PW("No where to send %s", command); + if (ourGlobals->client) send2(ourGlobals->client, SID, "%s(%s", command, arguments); + else PW("No where to send %s(%s", command, arguments); // TODO - Temporary so we have a place to log stuff from LSL. PD("SHOUTING %s", command); } - else if (0 == strncmp(command, "llDialog(", 9)) + else if (0 == strcmp(command, "llDialog")) { - if (ourGlobals->client) send2(ourGlobals->client, SID, command); - else PW("No where to send %s", command); + if (ourGlobals->client) send2(ourGlobals->client, SID, "%s(%s", command, arguments); } - else if (0 == strncmp(command, "llMessageLinked(", 16)) + else if (0 == strcmp(command, "llMessageLinked")) { Eina_Iterator *scripts; LoveScript *me; - // TODO - For now, just send it to everyone. scripts = eina_hash_iterator_data_new(ourGlobals->scripts); while(eina_iterator_next(scripts, (void **) &me)) { - send2(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]); + send2(ourGlobals->serverLuaSL, me->SID, "events.link_message(%s", arguments); } eina_iterator_free(scripts); } - else if (0 == strncmp(command, "llGetNotecardLine(", 18)) + else if (0 == strcmp(command, "llGetNotecardLine")) { char *notecard, *temp, *line, key[PATH_MAX]; int lineNo, fd; - strcpy(buf, &command[19]); + strcpy(buf, &arguments[1]); notecard = buf; temp = notecard; while ('"' != temp[0]) @@ -462,7 +453,7 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm } else - PI("Script %s sent command %s", SID, command); + PI("Script %s sent command %s(%s", SID, command, arguments); } return ECORE_CALLBACK_RENEW; @@ -502,7 +493,7 @@ static Eina_Bool clientParser(void *data, Connection *conn, char *SID, char *com { gameGlobals *ourGlobals = data; - if (0 == strncmp(command, "events.touch_start(", 19)) + if (0 == strcmp(command, "events.touch_start")) { Eina_Iterator *scripts; LoveScript *me; @@ -517,7 +508,7 @@ static Eina_Bool clientParser(void *data, Connection *conn, char *SID, char *com } eina_iterator_free(scripts); } - else if (0 == strncmp(command, "events.listen(", 14)) + else if (0 == strcmp(command, "events.listen")) { Eina_Iterator *scripts; LoveScript *me; -- cgit v1.1