aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/love
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-14 18:25:51 +1000
committerDavid Walter Seikel2014-05-14 18:25:51 +1000
commit2a943546b7a3c86a2d0a68e64b99fad72caa5e61 (patch)
tree1ac196d37f15cb729f6b17fb27e26f120a555923 /src/love
parentFix up llListInsertList() and llListReplaceList(). (diff)
downloadSledjHamr-2a943546b7a3c86a2d0a68e64b99fad72caa5e61.zip
SledjHamr-2a943546b7a3c86a2d0a68e64b99fad72caa5e61.tar.gz
SledjHamr-2a943546b7a3c86a2d0a68e64b99fad72caa5e61.tar.bz2
SledjHamr-2a943546b7a3c86a2d0a68e64b99fad72caa5e61.tar.xz
Implement llGetNotecardLine().
Plus another fudge of the MLP scripts to get it to work.
Diffstat (limited to 'src/love')
-rw-r--r--src/love/love.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/love/love.c b/src/love/love.c
index dc524d8..db4c557 100644
--- a/src/love/love.c
+++ b/src/love/love.c
@@ -12,6 +12,9 @@ Dedicated to my girl Boots, coz she means the world to me.
12#include <Edje.h> 12#include <Edje.h>
13 13
14#include <unistd.h> 14#include <unistd.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <fcntl.h>
15 18
16#include "LumbrJack.h" 19#include "LumbrJack.h"
17#include "Runnr.h" 20#include "Runnr.h"
@@ -196,6 +199,26 @@ static Eina_Bool _addLuaSL(void *data, int type, Ecore_Con_Event_Server_Add *ev)
196 return ECORE_CALLBACK_RENEW; 199 return ECORE_CALLBACK_RENEW;
197} 200}
198 201
202
203// Borrowed from toybox, though it's real slow.
204// TODO - Replace this quick and dirty llGetNotecardLine() with something using mmap and cached files that assumes more lines will be read soon.
205char *get_rawline(int fd, long *plen, char end)
206{
207 char c, *buf = NULL;
208 long len = 0;
209
210 for (;;) {
211 if (1>read(fd, &c, 1)) break;
212 if (!(len & 63)) buf=realloc(buf, len+65);
213 if ((buf[len++]=c) == end) break;
214 }
215 if (buf) buf[len]=0;
216 if (plen) *plen = len;
217
218 return buf;
219}
220
221
199static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *ev) 222static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *ev)
200{ 223{
201 gameGlobals *ourGlobals = data; 224 gameGlobals *ourGlobals = data;
@@ -361,6 +384,65 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e
361 sendForth(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]); 384 sendForth(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]);
362 } 385 }
363 } 386 }
387 else if (0 == strncmp(command, "llGetNotecardLine(", 18))
388 {
389 char *notecard, *temp, *line, key[PATH_MAX];
390 int lineNo, fd;
391
392 strcpy(buf, &command[19]);
393 notecard = buf;
394 temp = notecard;
395 while ('"' != temp[0])
396 temp++;
397 temp[0] = '\0';
398 while (',' != temp[0])
399 temp++;
400 while (' ' != temp[0])
401 temp++;
402 line = temp;
403 while (')' != temp[0])
404 temp++;
405 temp[0] = '\0';
406 lineNo = atoi(line);
407 snprintf(key, sizeof(key), "%s/Test sim/objects/onefang%%27s%%20test%%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/%s", PACKAGE_DATA_DIR, notecard);
408
409 fd = open(key, O_RDONLY);
410 if (-1 != fd)
411 {
412 Eina_Iterator *scripts;
413 script *me;
414 long len;
415
416 temp = NULL;
417 do
418 {
419 temp = get_rawline(fd, &len, '\n');
420 if (temp)
421 {
422 if (temp[len - 1] == '\n')
423 temp[--len] = '\0';
424 }
425 } while (temp && (0 < lineNo--));
426
427 sprintf(key, "%08lx-%04lx-%04lx-%04lx-%012lx", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random());
428 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", key);
429
430 // TODO - For now, just send it to everyone.
431 scripts = eina_hash_iterator_data_new(ourGlobals->scripts);
432 while(eina_iterator_next(scripts, (void **) &me))
433 {
434 if (temp)
435 {
436 sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"%s\")", key, temp);
437 }
438 else
439 sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", [[\\n\\n\\n]])", key);
440 }
441
442 close(fd);
443 }
444
445 }
364 else 446 else
365 PI("Script %s sent command %s", SID, command); 447 PI("Script %s sent command %s", SID, command);
366 } 448 }