From 4e2030607818d83b4e5987df2d889f64f8dce3b3 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 17 Jan 2016 17:03:56 +1000 Subject: Unify the message sending code a bit. --- src/LuaSL/LuaSL_main.c | 10 +++---- src/extantz/extantz.c | 6 ++--- src/libraries/SledjHamr.c | 47 +------------------------------- src/libraries/SledjHamr.h | 3 --- src/love/love.c | 68 +++++++++++++++++++++++------------------------ src/purkle/purkle.c | 2 +- 6 files changed, 44 insertions(+), 92 deletions(-) (limited to 'src') diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c index f8931e6..664cdd1 100644 --- a/src/LuaSL/LuaSL_main.c +++ b/src/LuaSL/LuaSL_main.c @@ -168,7 +168,7 @@ void send2server(script *me, const char *message) else { takeScript(me); - sendBack(me->client, me->SID, message); + send2(me->client, me->SID, message); releaseScript(me); } } @@ -181,9 +181,9 @@ static void _compileCb(LuaCompiler *compiler) { #if COMPILE_OUTPUT if (message->type) - sendBack(compiler->client, compiler->SID, "compilerError(%d,%d,%s)", message->line, message->column, message->message); + send2(compiler->client, compiler->SID, "compilerError(%d,%d,%s)", message->line, message->column, message->message); else - sendBack(compiler->client, compiler->SID, "compilerWarning(%d,%d,%s)", message->line, message->column, message->message); + send2(compiler->client, compiler->SID, "compilerWarning(%d,%d,%s)", message->line, message->column, message->message); #endif eina_clist_remove(&(message->node)); free(message); @@ -191,9 +191,9 @@ static void _compileCb(LuaCompiler *compiler) //PD("Compiled %s, bug count %d", compiler->file, compiler->bugCount); if (0 == compiler->bugCount) - sendBack(compiler->client, compiler->SID, "compiled(true)"); + send2(compiler->client, compiler->SID, "compiled(true)"); else - sendBack(compiler->client, compiler->SID, "compiled(false)"); + send2(compiler->client, compiler->SID, "compiled(false)"); } static void _compileCbSingle(LuaCompiler *compiler) diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 840dfec..f9b638a 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -143,7 +143,7 @@ static void _onWorldClick(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void // CUBE_UUID.events.touch_start(1), but we just make one up for now. snprintf(SID, sizeof(SID), FAKE_UUID); - sendForth(ourGlobals.server, SID, "events.touch_start(1)"); + send2(ourGlobals.server, SID, "events.touch_start(1)"); } } } @@ -567,7 +567,7 @@ static Eina_Bool _makeMess(void *data) ecore_job_add((Ecore_Cb) _makeLove, ourGlobals); // ecore_timer_add(0.1, _makeLove, ourGlobals); - ourGlobals->LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals->mainWindow, ourGlobals->world); +// ourGlobals->LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals->mainWindow, ourGlobals->world); return ECORE_CALLBACK_CANCEL; } @@ -615,7 +615,7 @@ static Eina_Bool _makePurkle(void *data) woMan_add(ourGlobals); ourGlobals->purkle = GuiLuaLoad("purkle", ourGlobals->mainWindow, ourGlobals->world); -// ourGlobals->LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals->mainWindow, ourGlobals->world); + ourGlobals->LSLGuiMess = GuiLuaLoad("LSLGuiMess", ourGlobals->mainWindow, ourGlobals->world); // ourGlobals->files = filesAdd(ourGlobals, (char *) prefix_data_get(), EINA_TRUE, EINA_FALSE); // Gotta do this after adding the windows, otherwise the menu renders under the window. diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index dff80ee..4d0efbc 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c @@ -88,31 +88,9 @@ static boolean checkConnection(Connection *conn, char *func, connType wanted, bo return result; } -void sendBack(Connection *conn, const char *SID, const char *message, ...) -{ - va_list args; -// Ecore_Con_Client *client = conn->conn.client.client; - char buf[PATH_MAX * 2]; - int length = strlen(SID); - - strncpy(buf, SID, length); - buf[length++] = '.'; - va_start(args, message); - length += vsprintf(&buf[length], message, args); - va_end(args); - buf[length++] = '\n'; - buf[length] = '\0'; -// PD("sendBack(%s", buf); -// ecore_con_client_send(client, buf, length); -// ecore_con_client_flush(client); -//Connection *conn = ecore_con_client_data_get(client); -if (conn) send2(conn, SID, buf); else PE("sendBack() can't find Connection!"); -} - -void sendForth(Connection *conn, const char *SID, const char *message, ...) +void send2(Connection *conn, const char *SID, const char *message, ...) { va_list args; -// Ecore_Con_Server *server = conn->conn.server.server; char buf[PATH_MAX * 2]; int length = strlen(SID); @@ -123,29 +101,6 @@ void sendForth(Connection *conn, const char *SID, const char *message, ...) va_end(args); buf[length++] = '\n'; buf[length] = '\0'; -// PD("sendForth(%s", buf); -// ecore_con_server_send(server, buf, length); -// ecore_con_server_flush(server); -//Connection *conn = ecore_con_server_data_get(server); -if (conn) send2(conn, SID, buf); else PE("sendForth() can't find Connection!"); -} - -void send2(Connection *conn, const char *SID, const char *message, ...) -{ - va_list args; - char buf[PATH_MAX * 2]; - int length = strlen(SID); - -length = 0; -// strncpy(buf, SID, length); -// buf[length++] = '.'; - va_start(args, message); -// length += vsprintf(&buf[length], message, args); - va_end(args); -strcpy(buf, message); -length = strlen(buf); -// buf[length++] = '\n'; - buf[length] = '\0'; // TODO - Should check if this is always gonna be local? Likely not. if (checkConnection(conn, "send2", conn->type, FALSE)) diff --git a/src/libraries/SledjHamr.h b/src/libraries/SledjHamr.h index 326e423..d5e0b1f 100644 --- a/src/libraries/SledjHamr.h +++ b/src/libraries/SledjHamr.h @@ -66,9 +66,6 @@ struct _Connection void *addMessage(Eina_Clist *list, size_t size, const char *message, ...); -void sendBack(Connection *conn, const char *SID, const char *message, ...); -void sendForth(Connection *conn, const char *SID, const char *message, ...); - void send2(Connection *conn, const char *SID, const char *message, ...); Connection *openArms(char *name, const char *address, int port, void *data, Ecore_Event_Handler_Cb _add, Ecore_Event_Handler_Cb _data, Ecore_Event_Handler_Cb _del, streamParser _parser); Connection *reachOut(char *name, char *command, char *address, int port, void *data, Ecore_Event_Handler_Cb _add, Ecore_Event_Handler_Cb _data, Ecore_Event_Handler_Cb _del, streamParser _parser); diff --git a/src/love/love.c b/src/love/love.c index f8ce522..e6f5b6e 100644 --- a/src/love/love.c +++ b/src/love/love.c @@ -142,7 +142,7 @@ static void dirList_compile(const char *name, const char *path, void *data) snprintf(me->SID, sizeof(me->SID), FAKE_UUID); snprintf(me->fileName, sizeof(me->fileName), "%s/%s", path, name); eina_hash_add(ourGlobals->scripts, me->SID, me); - sendForth(ourGlobals->serverLuaSL, me->SID, "compile(%s)", me->fileName); + send2(ourGlobals->serverLuaSL, me->SID, "compile(%s)", me->fileName); } } } @@ -278,47 +278,47 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm } } //PD("About to run %s", me->fileName); - sendForth(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName); + send2(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName); } else { //PD("FAKING (maybe) %s", command); // Send back some random or fixed values for testing. if (0 == strcmp(command, "llGetKey()")) - sendForth(ourGlobals->serverLuaSL, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); + send2(ourGlobals->serverLuaSL, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); else if (0 == strcmp(command, "llGetOwner()")) - sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey); + send2(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey); else if (0 == strcmp(command, "llGetPermissionsKey()")) - sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey); + send2(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey); else if (0 == strncmp(command, "llRequestPermissions(", 21)) PI("Faked %s", command); else if (0 == strcmp(command, "llGetPos()")) - sendForth(ourGlobals->serverLuaSL, SID, "return {x=128.0, y=128.0, z=128.0}"); + send2(ourGlobals->serverLuaSL, SID, "return {x=128.0, y=128.0, z=128.0}"); else if (0 == strcmp(command, "llGetRot()")) - sendForth(ourGlobals->serverLuaSL, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}"); + send2(ourGlobals->serverLuaSL, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}"); else if (0 == strcmp(command, "llGetFreeMemory()")) - sendForth(ourGlobals->serverLuaSL, SID, "return 654321"); + send2(ourGlobals->serverLuaSL, SID, "return 654321"); else if (0 == strcmp(command, "llGetObjectDesc()")) - sendForth(ourGlobals->serverLuaSL, SID, "return \"\""); + send2(ourGlobals->serverLuaSL, SID, "return \"\""); else if (0 == strncmp(command, "llGetAlpha(", 11)) - sendForth(ourGlobals->serverLuaSL, SID, "return 1.0"); + send2(ourGlobals->serverLuaSL, SID, "return 1.0"); else if (0 == strcmp(command, "llGetInventoryNumber(7)")) - sendForth(ourGlobals->serverLuaSL, SID, "return 3"); + send2(ourGlobals->serverLuaSL, SID, "return 3"); else if (0 == strcmp(command, "llGetLinkNumber()")) - sendForth(ourGlobals->serverLuaSL, SID, "return 1"); + send2(ourGlobals->serverLuaSL, SID, "return 1"); else if (0 == strcmp(command, "llGetInventoryName(7, 2)")) - sendForth(ourGlobals->serverLuaSL, SID, "return \".readme\""); + send2(ourGlobals->serverLuaSL, SID, "return \".readme\""); else if (0 == strcmp(command, "llGetInventoryName(7, 1)")) - sendForth(ourGlobals->serverLuaSL, SID, "return \".POSITIONS\""); + send2(ourGlobals->serverLuaSL, SID, "return \".POSITIONS\""); else if (0 == strcmp(command, "llGetInventoryName(7, 0)")) - sendForth(ourGlobals->serverLuaSL, SID, "return \".MENUITEMS\""); + send2(ourGlobals->serverLuaSL, SID, "return \".MENUITEMS\""); else if (0 == strncmp(command, "llListen(", 9)) { PI("Faked %s", command); - sendForth(ourGlobals->serverLuaSL, SID, "return %d", random()); + send2(ourGlobals->serverLuaSL, SID, "return %d", random()); } else if (0 == strncmp(command, "llSameGroup(", 12)) - sendForth(ourGlobals->serverLuaSL, SID, "return true"); + send2(ourGlobals->serverLuaSL, SID, "return true"); else if (0 == strncmp(command, "llKey2Name(", 11)) { char *temp; @@ -334,7 +334,7 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm temp = "Unknown User"; // TODO - Sanitize the name, no telling what weird shit people put in their names. snprintf(buf, sizeof(buf), "return \"%s\"", temp); - sendForth(ourGlobals->serverLuaSL, SID, buf); + send2(ourGlobals->serverLuaSL, SID, buf); } // Send "back" stuff on to the one and only client. // TODO - All of these output functions should just use one thing to append stuff to either local or an IM tab. @@ -344,34 +344,34 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm // Dialogs, notifications, and other stuff goes through some other functions. else if (0 == strncmp(command, "llOwnerSay(", 11)) { - if (ourGlobals->client) sendBack(ourGlobals->client, SID, command); + if (ourGlobals->client) send2(ourGlobals->client, SID, command); else PW("No where to send %s", command); } else if (0 == strncmp(command, "llWhisper(", 10)) { - if (ourGlobals->client) sendBack(ourGlobals->client, SID, command); + if (ourGlobals->client) send2(ourGlobals->client, SID, command); else PW("No where to send %s", command); } else if (0 == strncmp(command, "llRegionSay(", 12)) { - if (ourGlobals->client) sendBack(ourGlobals->client, SID, command); + if (ourGlobals->client) send2(ourGlobals->client, SID, command); else PW("No where to send %s", command); } else if (0 == strncmp(command, "llSay(", 6)) { - if (ourGlobals->client) sendBack(ourGlobals->client, SID, command); + if (ourGlobals->client) send2(ourGlobals->client, SID, command); else PW("No where to send %s", command); } else if (0 == strncmp(command, "llShout(", 8)) { - if (ourGlobals->client) sendBack(ourGlobals->client, SID, command); + if (ourGlobals->client) send2(ourGlobals->client, SID, command); else PW("No where to send %s", command); // TODO - Temporary so we have a place to log stuff from LSL. PD("SHOUTING %s", command); } else if (0 == strncmp(command, "llDialog(", 9)) { - if (ourGlobals->client) sendBack(ourGlobals->client, SID, command); + if (ourGlobals->client) send2(ourGlobals->client, SID, command); else PW("No where to send %s", command); } else if (0 == strncmp(command, "llMessageLinked(", 16)) @@ -383,7 +383,7 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm scripts = eina_hash_iterator_data_new(ourGlobals->scripts); while(eina_iterator_next(scripts, (void **) &me)) { - sendForth(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]); + send2(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]); } eina_iterator_free(scripts); } @@ -429,7 +429,7 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm } while (temp && (0 < lineNo--)); sprintf(key, FAKE_UUID); - sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", key); + send2(ourGlobals->serverLuaSL, SID, "return \"%s\"", key); // TODO - For now, just send it to everyone. scripts = eina_hash_iterator_data_new(ourGlobals->scripts); @@ -449,10 +449,10 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm buf2[j++] = '\\'; buf2[j++] = temp[i]; } - sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", '%s')", key, buf2); + send2(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", '%s')", key, buf2); } else - sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"EndOfFuckingAround\")", key); + send2(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"EndOfFuckingAround\")", key); } eina_iterator_free(scripts); free(temp); @@ -492,7 +492,7 @@ static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev if (ourGlobals->client) { // TODO - Sending the currently hard coded ownerKey here, should actually deal with logging in / hypergrid TP style things instead. - sendBack(ourGlobals->client, ownerKey, "loadSim('file://%s/Test%%20sim')", prefix_data_get()); + send2(ourGlobals->client, ownerKey, "loadSim('file://%s/Test%%20sim')", prefix_data_get()); } return ECORE_CALLBACK_RENEW; @@ -511,9 +511,9 @@ static Eina_Bool clientParser(void *data, Connection *conn, char *SID, char *com scripts = eina_hash_iterator_data_new(ourGlobals->scripts); while(eina_iterator_next(scripts, (void **) &me)) { - sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); - sendForth(ourGlobals->serverLuaSL, me->SID, "events.detectedNames({\"%s\"})", ownerName); - sendForth(ourGlobals->serverLuaSL, me->SID, "events.touch_start(1)"); + send2(ourGlobals->serverLuaSL, me->SID, "events.detectedKeys({\"%s\"})", ownerKey); + send2(ourGlobals->serverLuaSL, me->SID, "events.detectedNames({\"%s\"})", ownerName); + send2(ourGlobals->serverLuaSL, me->SID, "events.touch_start(1)"); } eina_iterator_free(scripts); } @@ -528,7 +528,7 @@ static Eina_Bool clientParser(void *data, Connection *conn, char *SID, char *com scripts = eina_hash_iterator_data_new(ourGlobals->scripts); while(eina_iterator_next(scripts, (void **) &me)) { - sendForth(ourGlobals->serverLuaSL, me->SID, buf); + send2(ourGlobals->serverLuaSL, me->SID, buf); } eina_iterator_free(scripts); } @@ -543,7 +543,7 @@ static Eina_Bool _delClient(void *data, int type, Ecore_Con_Event_Client_Del *ev gameGlobals *ourGlobals = data; // TODO - I could coax this into something generic, maybe. - sendForth(ourGlobals->serverLuaSL, ownerKey, "exit()"); + send2(ourGlobals->serverLuaSL, ownerKey, "exit()"); return ECORE_CALLBACK_RENEW; } diff --git a/src/purkle/purkle.c b/src/purkle/purkle.c index 9a21700..97253cf 100644 --- a/src/purkle/purkle.c +++ b/src/purkle/purkle.c @@ -56,7 +56,7 @@ static int say(lua_State *L) gl = lua_touserdata(L, -1); lua_pop(L, 1); if (gl && gl->server) - sendForth(gl->server, id, buf); + send2(gl->server, id, buf); else PW("PURKLE NOT SAY, no where to send %s", buf); } -- cgit v1.1