aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/love/love.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/love/love.c')
-rw-r--r--src/love/love.c577
1 files changed, 269 insertions, 308 deletions
diff --git a/src/love/love.c b/src/love/love.c
index 0465ee5..372141d 100644
--- a/src/love/love.c
+++ b/src/love/love.c
@@ -33,9 +33,8 @@ typedef struct _gameGlobals
33 Evas *canvas; // The canvas for drawing directly onto. 33 Evas *canvas; // The canvas for drawing directly onto.
34 Evas_Object *bg; // Our background edje, also the game specific stuff. 34 Evas_Object *bg; // Our background edje, also the game specific stuff.
35 Evas_Object *edje; // The edje of the background. 35 Evas_Object *edje; // The edje of the background.
36 Ecore_Con_Server *serverLuaSL; 36 Connection *serverLuaSL;
37 Ecore_Con_Server *server; 37 Connection *client; // TODO - Really should be a bunch of these.
38 Ecore_Con_Client *client; // TODO - Really should be a bunch of these.
39 Eina_Hash *scripts; 38 Eina_Hash *scripts;
40 const char *address; 39 const char *address;
41 int port; 40 int port;
@@ -52,7 +51,6 @@ typedef struct _Lscript
52 51
53 52
54int logDom = -1; // Our logging domain. 53int logDom = -1; // Our logging domain.
55static Eina_Strbuf *LuaSLStream;
56static int scriptCount = 0; 54static int scriptCount = 0;
57static int compiledCount = 0; 55static int compiledCount = 0;
58static struct timeval startTime; 56static struct timeval startTime;
@@ -149,12 +147,14 @@ static void dirList_compile(const char *name, const char *path, void *data)
149 } 147 }
150} 148}
151 149
150
152static Eina_Bool _addLuaSL(void *data, int type, Ecore_Con_Event_Server_Add *ev) 151static Eina_Bool _addLuaSL(void *data, int type, Ecore_Con_Event_Server_Add *ev)
153{ 152{
154 gameGlobals *ourGlobals = data; 153 gameGlobals *ourGlobals = data;
155 char buf[PATH_MAX]; 154 char buf[PATH_MAX];
156 155
157 ourGlobals->serverLuaSL = ev->server; 156 PI("LuaSL server added, sending it scripts to compile and run.");
157 ourGlobals->serverLuaSL = ecore_con_server_data_get(ev->server);
158 158
159 // Zero everything. 159 // Zero everything.
160 eina_hash_free(ourGlobals->scripts); 160 eina_hash_free(ourGlobals->scripts);
@@ -191,299 +191,277 @@ char *get_rawline(int fd, long *plen, char end)
191} 191}
192 192
193 193
194static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *ev) 194static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *command, char *arguments)
195{ 195{
196 gameGlobals *ourGlobals = data; 196 gameGlobals *ourGlobals = data;
197
198 char buf[PATH_MAX]; 197 char buf[PATH_MAX];
199 char SID[PATH_MAX]; 198 LoveScript *me;
200 const char *command;
201 char *ext;
202 199
203 eina_strbuf_append_length(LuaSLStream, ev->data, ev->size); 200PW("COMMAND - %s - %s", SID, command);
204 command = eina_strbuf_string_get(LuaSLStream); 201 me = eina_hash_find(ourGlobals->scripts, SID);
205 while ((ext = index(command, '\n'))) 202 if (0 == strncmp(command, "compilerWarning(", 16))
206 { 203 {
207 int length = ext - command; 204 char *temp;
208 205 char *line;
209 strncpy(SID, command, length + 1); 206 char *column;
210 SID[length] = '\0'; 207 char *text;
211 eina_strbuf_remove(LuaSLStream, 0, length + 1); 208
212 ext = index(SID, '.'); 209 strcpy(buf, &command[16]);
213 if (ext) 210 temp = buf;
211 line = temp;
212 while (',' != temp[0])
213 temp++;
214 temp[0] = '\0';
215 column = ++temp;
216 while (',' != temp[0])
217 temp++;
218 temp[0] = '\0';
219 text = ++temp;
220 while (')' != temp[0])
221 temp++;
222 temp[0] = '\0';
223 PW("%s @ line %s, column %s.", text, line, column);
224 if (me)
225 me->warnings++;
226 }
227 else if (0 == strncmp(command, "compilerError(", 14))
228 {
229 char *temp;
230 char *line;
231 char *column;
232 char *text;
233
234 strcpy(buf, &command[14]);
235 temp = buf;
236 line = temp;
237 while (',' != temp[0])
238 temp++;
239 temp[0] = '\0';
240 column = ++temp;
241 while (',' != temp[0])
242 temp++;
243 temp[0] = '\0';
244 text = ++temp;
245 while (')' != temp[0])
246 temp++;
247 temp[0] = '\0';
248 PE("%s @ line %s, column %s.", text, line, column);
249 if (me)
250 me->bugs++;
251 }
252 else if (0 == strcmp(command, "compiled(false)"))
253 {
254// PE("The compile of %s failed!", SID);
255 if (me)
214 { 256 {
215 LoveScript *me; 257 struct timeval now;
216 258
217 ext[0] = '\0'; 259 compiledCount++;
218 command = ext + 1; 260 if (compiledCount == scriptCount)
219 me = eina_hash_find(ourGlobals->scripts, SID);
220 if (0 == strncmp(command, "compilerWarning(", 16))
221 { 261 {
222 char *temp; 262 float total = timeDiff(&now, &startTime);
223 char *line; 263 PD("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total);
224 char *column;
225 char *text;
226
227 strcpy(buf, &command[16]);
228 temp = buf;
229 line = temp;
230 while (',' != temp[0])
231 temp++;
232 temp[0] = '\0';
233 column = ++temp;
234 while (',' != temp[0])
235 temp++;
236 temp[0] = '\0';
237 text = ++temp;
238 while (')' != temp[0])
239 temp++;
240 temp[0] = '\0';
241 PW("%s @ line %s, column %s.", text, line, column);
242 if (me)
243 me->warnings++;
244 } 264 }
245 else if (0 == strncmp(command, "compilerError(", 14)) 265 }
266 }
267 else if (0 == strcmp(command, "compiled(true)"))
268 {
269 if (me)
270 {
271 struct timeval now;
272
273 compiledCount++;
274 if (compiledCount == scriptCount)
246 { 275 {
247 char *temp; 276 float total = timeDiff(&now, &startTime);
248 char *line; 277 PD("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total);
249 char *column;
250 char *text;
251
252 strcpy(buf, &command[14]);
253 temp = buf;
254 line = temp;
255 while (',' != temp[0])
256 temp++;
257 temp[0] = '\0';
258 column = ++temp;
259 while (',' != temp[0])
260 temp++;
261 temp[0] = '\0';
262 text = ++temp;
263 while (')' != temp[0])
264 temp++;
265 temp[0] = '\0';
266 PE("%s @ line %s, column %s.", text, line, column);
267 if (me)
268 me->bugs++;
269 } 278 }
270 else if (0 == strcmp(command, "compiled(false)")) 279 }
271 { 280 PD("About to run %s", me->fileName);
272// PE("The compile of %s failed!", SID); 281 sendForth(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName);
273 if (me) 282 }
274 { 283 else
275 struct timeval now; 284 {
285 // Send back some random or fixed values for testing.
286 if (0 == strcmp(command, "llGetKey()"))
287 sendForth(ourGlobals->serverLuaSL, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random());
288 else if (0 == strcmp(command, "llGetOwner()"))
289 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey);
290 else if (0 == strcmp(command, "llGetPermissionsKey()"))
291 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey);
292 else if (0 == strncmp(command, "llRequestPermissions(", 21))
293 PI("Faked %s", command);
294 else if (0 == strcmp(command, "llGetPos()"))
295 sendForth(ourGlobals->serverLuaSL, SID, "return {x=128.0, y=128.0, z=128.0}");
296 else if (0 == strcmp(command, "llGetRot()"))
297 sendForth(ourGlobals->serverLuaSL, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}");
298 else if (0 == strcmp(command, "llGetFreeMemory()"))
299 sendForth(ourGlobals->serverLuaSL, SID, "return 654321");
300 else if (0 == strcmp(command, "llGetObjectDesc()"))
301 sendForth(ourGlobals->serverLuaSL, SID, "return \"\"");
302 else if (0 == strncmp(command, "llGetAlpha(", 11))
303 sendForth(ourGlobals->serverLuaSL, SID, "return 1.0");
304 else if (0 == strcmp(command, "llGetInventoryNumber(7)"))
305 sendForth(ourGlobals->serverLuaSL, SID, "return 3");
306 else if (0 == strcmp(command, "llGetLinkNumber()"))
307 sendForth(ourGlobals->serverLuaSL, SID, "return 1");
308 else if (0 == strcmp(command, "llGetInventoryName(7, 2)"))
309 sendForth(ourGlobals->serverLuaSL, SID, "return \".readme\"");
310 else if (0 == strcmp(command, "llGetInventoryName(7, 1)"))
311 sendForth(ourGlobals->serverLuaSL, SID, "return \".POSITIONS\"");
312 else if (0 == strcmp(command, "llGetInventoryName(7, 0)"))
313 sendForth(ourGlobals->serverLuaSL, SID, "return \".MENUITEMS\"");
314 else if (0 == strncmp(command, "llListen(", 9))
315 {
316 PI("Faked %s", command);
317 sendForth(ourGlobals->serverLuaSL, SID, "return %d", random());
318 }
319 else if (0 == strncmp(command, "llSameGroup(", 12))
320 sendForth(ourGlobals->serverLuaSL, SID, "return true");
321 else if (0 == strncmp(command, "llKey2Name(", 11))
322 {
323 char *temp;
324
325 strcpy(buf, &command[12]);
326 temp = buf;
327 while (')' != temp[0])
328 temp++;
329 temp[0] = '\0';
330 if (0 == strcmp(buf, ownerKey))
331 temp = ownerName;
332 else
333 temp = "Unknown User";
334 // TODO - Sanitize the name, no telling what weird shit people put in their names.
335 snprintf(buf, sizeof(buf), "return \"%s\"", temp);
336 sendForth(ourGlobals->serverLuaSL, SID, buf);
337 }
338 // Send "back" stuff on to the one and only client.
339 // TODO - All of these output functions should just use one thing to append stuff to either local or an IM tab.
340 // Love filtering out stuff that should not go there.
341 // Extantz registering any channel it wants to listen to, mostly for client side scripts.
342 // Extantz is then only responsible for the registered channels, it can do what it likes with them.
343 // Dialogs, notifications, and other stuff goes through some other functions.
344 else if (0 == strncmp(command, "llOwnerSay(", 11))
345 {
346 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
347 else PW("No where to send %s", command);
348 }
349 else if (0 == strncmp(command, "llWhisper(", 10))
350 {
351 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
352 else PW("No where to send %s", command);
353 }
354 else if (0 == strncmp(command, "llRegionSay(", 12))
355 {
356 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
357 else PW("No where to send %s", command);
358 }
359 else if (0 == strncmp(command, "llSay(", 6))
360 {
361 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
362 else PW("No where to send %s", command);
363 }
364 else if (0 == strncmp(command, "llShout(", 8))
365 {
366 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
367 else PW("No where to send %s", command);
368 // TODO - Temporary so we have a place to log stuff from LSL.
369 PD("SHOUTING %s", command);
370 }
371 else if (0 == strncmp(command, "llDialog(", 9))
372 {
373 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
374 else PW("No where to send %s", command);
375 }
376 else if (0 == strncmp(command, "llMessageLinked(", 16))
377 {
378 Eina_Iterator *scripts;
379 LoveScript *me;
276 380
277 compiledCount++; 381 // TODO - For now, just send it to everyone.
278 if (compiledCount == scriptCount) 382 scripts = eina_hash_iterator_data_new(ourGlobals->scripts);
279 { 383 while(eina_iterator_next(scripts, (void **) &me))
280 float total = timeDiff(&now, &startTime);
281 PD("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total);
282 }
283 }
284 }
285 else if (0 == strcmp(command, "compiled(true)"))
286 { 384 {
287 if (me) 385 sendForth(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]);
288 {
289 struct timeval now;
290
291 compiledCount++;
292 if (compiledCount == scriptCount)
293 {
294 float total = timeDiff(&now, &startTime);
295 PD("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total);
296 }
297 }
298 sendForth(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName);
299 } 386 }
300 else 387 eina_iterator_free(scripts);
388 }
389 else if (0 == strncmp(command, "llGetNotecardLine(", 18))
390 {
391 char *notecard, *temp, *line, key[PATH_MAX];
392 int lineNo, fd;
393
394 strcpy(buf, &command[19]);
395 notecard = buf;
396 temp = notecard;
397 while ('"' != temp[0])
398 temp++;
399 temp[0] = '\0';
400 while (',' != temp[0])
401 temp++;
402 while (' ' != temp[0])
403 temp++;
404 line = temp;
405 while (')' != temp[0])
406 temp++;
407 temp[0] = '\0';
408 lineNo = atoi(line);
409 snprintf(key, sizeof(key), "%s/Test%%20sim/onefang%%27s%%20test%%20bed/%s", prefix_data_get(), notecard);
410
411 fd = open(key, O_RDONLY);
412 if (-1 != fd)
301 { 413 {
302 // Send back some random or fixed values for testing. 414 Eina_Iterator *scripts;
303 if (0 == strcmp(command, "llGetKey()")) 415 LoveScript *me;
304 sendForth(ourGlobals->serverLuaSL, SID, "return \"%08lx-%04lx-%04lx-%04lx-%012lx\"", random(), random() % 0xFFFF, random() % 0xFFFF, random() % 0xFFFF, random()); 416 long len;
305 else if (0 == strcmp(command, "llGetOwner()"))
306 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey);
307 else if (0 == strcmp(command, "llGetPermissionsKey()"))
308 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", ownerKey);
309 else if (0 == strncmp(command, "llRequestPermissions(", 21))
310 PI("Faked %s", command);
311 else if (0 == strcmp(command, "llGetPos()"))
312 sendForth(ourGlobals->serverLuaSL, SID, "return {x=128.0, y=128.0, z=128.0}");
313 else if (0 == strcmp(command, "llGetRot()"))
314 sendForth(ourGlobals->serverLuaSL, SID, "return {x=0.0, y=0.0, z=0.0, s=1.0}");
315 else if (0 == strcmp(command, "llGetFreeMemory()"))
316 sendForth(ourGlobals->serverLuaSL, SID, "return 654321");
317 else if (0 == strcmp(command, "llGetObjectDesc()"))
318 sendForth(ourGlobals->serverLuaSL, SID, "return \"\"");
319 else if (0 == strncmp(command, "llGetAlpha(", 11))
320 sendForth(ourGlobals->serverLuaSL, SID, "return 1.0");
321 else if (0 == strcmp(command, "llGetInventoryNumber(7)"))
322 sendForth(ourGlobals->serverLuaSL, SID, "return 3");
323 else if (0 == strcmp(command, "llGetLinkNumber()"))
324 sendForth(ourGlobals->serverLuaSL, SID, "return 1");
325 else if (0 == strcmp(command, "llGetInventoryName(7, 2)"))
326 sendForth(ourGlobals->serverLuaSL, SID, "return \".readme\"");
327 else if (0 == strcmp(command, "llGetInventoryName(7, 1)"))
328 sendForth(ourGlobals->serverLuaSL, SID, "return \".POSITIONS\"");
329 else if (0 == strcmp(command, "llGetInventoryName(7, 0)"))
330 sendForth(ourGlobals->serverLuaSL, SID, "return \".MENUITEMS\"");
331 else if (0 == strncmp(command, "llListen(", 9))
332 {
333 PI("Faked %s", command);
334 sendForth(ourGlobals->serverLuaSL, SID, "return %d", random());
335 }
336 else if (0 == strncmp(command, "llSameGroup(", 12))
337 sendForth(ourGlobals->serverLuaSL, SID, "return true");
338 else if (0 == strncmp(command, "llKey2Name(", 11))
339 {
340 char *temp;
341
342 strcpy(buf, &command[12]);
343 temp = buf;
344 while (')' != temp[0])
345 temp++;
346 temp[0] = '\0';
347 if (0 == strcmp(buf, ownerKey))
348 temp = ownerName;
349 else
350 temp = "Unknown User";
351 // TODO - Sanitize the name, no telling what weird shit people put in their names.
352 snprintf(buf, sizeof(buf), "return \"%s\"", temp);
353 sendForth(ourGlobals->serverLuaSL, SID, buf);
354 }
355 // Send "back" stuff on to the one and only client.
356 // TODO - All of these output functions should just use one thing to append stuff to either local or an IM tab.
357 // Love filtering out stuff that should not go there.
358 // Extantz registering any channel it wants to listen to, mostly for client side scripts.
359 // Extantz is then only responsible for the registered channels, it can do what it likes with them.
360 // Dialogs, notifications, and other stuff goes through some other functions.
361 else if (0 == strncmp(command, "llOwnerSay(", 11))
362 {
363 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
364 else PW("No where to send %s", command);
365 }
366 else if (0 == strncmp(command, "llWhisper(", 10))
367 {
368 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
369 else PW("No where to send %s", command);
370 }
371 else if (0 == strncmp(command, "llRegionSay(", 12))
372 {
373 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
374 else PW("No where to send %s", command);
375 }
376 else if (0 == strncmp(command, "llSay(", 6))
377 {
378 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
379 else PW("No where to send %s", command);
380 }
381 else if (0 == strncmp(command, "llShout(", 8))
382 {
383 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
384 else PW("No where to send %s", command);
385 // TODO - Temporary so we have a place to log stuff from LSL.
386 PD("SHOUTING %s", command);
387 }
388 else if (0 == strncmp(command, "llDialog(", 9))
389 {
390 if (ourGlobals->client) sendBack(ourGlobals->client, SID, command);
391 else PW("No where to send %s", command);
392 }
393 else if (0 == strncmp(command, "llMessageLinked(", 16))
394 {
395 Eina_Iterator *scripts;
396 LoveScript *me;
397 417
398 // TODO - For now, just send it to everyone. 418 temp = NULL;
399 scripts = eina_hash_iterator_data_new(ourGlobals->scripts); 419 do
400 while(eina_iterator_next(scripts, (void **) &me))
401 {
402 sendForth(ourGlobals->serverLuaSL, me->SID, "events.link_message%s", &command[15]);
403 }
404 eina_iterator_free(scripts);
405 }
406 else if (0 == strncmp(command, "llGetNotecardLine(", 18))
407 { 420 {
408 char *notecard, *temp, *line, key[PATH_MAX]; 421 free(temp);
409 int lineNo, fd; 422 temp = get_rawline(fd, &len, '\n');
410 423 if (temp)
411 strcpy(buf, &command[19]);
412 notecard = buf;
413 temp = notecard;
414 while ('"' != temp[0])
415 temp++;
416 temp[0] = '\0';
417 while (',' != temp[0])
418 temp++;
419 while (' ' != temp[0])
420 temp++;
421 line = temp;
422 while (')' != temp[0])
423 temp++;
424 temp[0] = '\0';
425 lineNo = atoi(line);
426 snprintf(key, sizeof(key), "%s/Test%%20sim/onefang%%27s%%20test%%20bed/%s", prefix_data_get(), notecard);
427
428 fd = open(key, O_RDONLY);
429 if (-1 != fd)
430 { 424 {
431 Eina_Iterator *scripts; 425 if (temp[len - 1] == '\n')
432 LoveScript *me; 426 temp[--len] = '\0';
433 long len; 427 }
428 } while (temp && (0 < lineNo--));
434 429
435 temp = NULL; 430 sprintf(key, FAKE_UUID);
436 do 431 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", key);
437 {
438 free(temp);
439 temp = get_rawline(fd, &len, '\n');
440 if (temp)
441 {
442 if (temp[len - 1] == '\n')
443 temp[--len] = '\0';
444 }
445 } while (temp && (0 < lineNo--));
446 432
447 sprintf(key, FAKE_UUID); 433 // TODO - For now, just send it to everyone.
448 sendForth(ourGlobals->serverLuaSL, SID, "return \"%s\"", key); 434 scripts = eina_hash_iterator_data_new(ourGlobals->scripts);
435 while(eina_iterator_next(scripts, (void **) &me))
436 {
437 if (temp)
438 {
439 char buf2[PATH_MAX];
440 int i, j, len = strlen(temp);
449 441
450 // TODO - For now, just send it to everyone. 442 // Escape ' and \ characters.
451 scripts = eina_hash_iterator_data_new(ourGlobals->scripts); 443 for (i = 0, j = 0; i <= len; i++)
452 while(eina_iterator_next(scripts, (void **) &me))
453 { 444 {
454 if (temp) 445 if ('\'' == temp[i])
455 { 446 buf2[j++] = '\\';
456 char buf2[PATH_MAX]; 447 if ('\\' == temp[i])
457 int i, j, len = strlen(temp); 448 buf2[j++] = '\\';
458 449 buf2[j++] = temp[i];
459 // Escape ' and \ characters.
460 for (i = 0, j = 0; i <= len; i++)
461 {
462 if ('\'' == temp[i])
463 buf2[j++] = '\\';
464 if ('\\' == temp[i])
465 buf2[j++] = '\\';
466 buf2[j++] = temp[i];
467 }
468 sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", '%s')", key, buf2);
469 }
470 else
471 sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"EndOfFuckingAround\")", key);
472 } 450 }
473 eina_iterator_free(scripts); 451 sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", '%s')", key, buf2);
474 free(temp);
475
476 close(fd);
477 } 452 }
478 453 else
454 sendForth(ourGlobals->serverLuaSL, me->SID, "events.dataserver(\"%s\", \"EndOfFuckingAround\")", key);
479 } 455 }
480 else 456 eina_iterator_free(scripts);
481 PI("Script %s sent command %s", SID, command); 457 free(temp);
458
459 close(fd);
482 } 460 }
483 }
484 461
485 // Get the next blob to check it. 462 }
486 command = eina_strbuf_string_get(LuaSLStream); 463 else
464 PI("Script %s sent command %s", SID, command);
487 } 465 }
488 466
489 return ECORE_CALLBACK_RENEW; 467 return ECORE_CALLBACK_RENEW;
@@ -492,26 +470,9 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e
492static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) 470static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev)
493{ 471{
494 gameGlobals *ourGlobals = data; 472 gameGlobals *ourGlobals = data;
495 static int count = 0;
496 473
497 ourGlobals->serverLuaSL = NULL; 474 ourGlobals->serverLuaSL = NULL;
498 475
499 // Let it fail a couple of times during startup, then try to start our own script server.
500 count++;
501 if (1 < count)
502 {
503 char buf[PATH_MAX];
504
505 PW("Failed to connect to a script server, starting our own.");
506 sprintf(buf, "%s/LuaSL &", prefix_bin_get());
507 system(buf);
508 count = 0;
509 // TODO - There's also the question of what to do if the connection failed.
510 // Did the server crash, or was it just the connection?
511 // Probably gonna need some smarts, for now we just restart all the scripts.
512 // Which I think gets done on server add.
513 }
514
515 // TODO - May want to renew even if it's not running the GUI, but then we still need some sort of "shut down" signal, which we don't need during testing. 476 // TODO - May want to renew even if it's not running the GUI, but then we still need some sort of "shut down" signal, which we don't need during testing.
516// if (ourGlobals->ui) 477// if (ourGlobals->ui)
517 return ECORE_CALLBACK_RENEW; 478 return ECORE_CALLBACK_RENEW;
@@ -525,7 +486,7 @@ static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev
525{ 486{
526 gameGlobals *ourGlobals = data; 487 gameGlobals *ourGlobals = data;
527 488
528 ourGlobals->client = ev->client; 489 ourGlobals->client = ecore_con_client_data_get(ev->client);
529 490
530 if (ourGlobals->client) 491 if (ourGlobals->client)
531 { 492 {
@@ -536,12 +497,11 @@ static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev
536 return ECORE_CALLBACK_RENEW; 497 return ECORE_CALLBACK_RENEW;
537} 498}
538 499
539 500static Eina_Bool clientParser(void *data, Connection *conn, char *SID, char *command, char *arguments)
540Eina_Bool clientParser(void *data, Connection *connection, char *SID, char *command, char *arguments)
541{ 501{
542 gameGlobals *ourGlobals = data; 502 gameGlobals *ourGlobals = data;
543 503
544 if (0 == strncmp(command, "events.touch_start", 18)) 504 if (0 == strncmp(command, "events.touch_start(", 19))
545 { 505 {
546 Eina_Iterator *scripts; 506 Eina_Iterator *scripts;
547 LoveScript *me; 507 LoveScript *me;
@@ -556,7 +516,7 @@ Eina_Bool clientParser(void *data, Connection *connection, char *SID, char *comm
556 } 516 }
557 eina_iterator_free(scripts); 517 eina_iterator_free(scripts);
558 } 518 }
559 else if (0 == strncmp(command, "events.listen", 13)) 519 else if (0 == strncmp(command, "events.listen(", 14))
560 { 520 {
561 Eina_Iterator *scripts; 521 Eina_Iterator *scripts;
562 LoveScript *me; 522 LoveScript *me;
@@ -605,11 +565,6 @@ int main(int argc, char **argv)
605 565
606 if (ecore_con_init()) 566 if (ecore_con_init())
607 { 567 {
608 LuaSLStream = eina_strbuf_new();
609 reachOut("127.0.0.1", 8211, &ourGlobals, (Ecore_Event_Handler_Cb) _addLuaSL, (Ecore_Event_Handler_Cb) _dataLuaSL, (Ecore_Event_Handler_Cb) _delLuaSL);
610
611 if (openArms("love", ourGlobals.address, ourGlobals.port + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _addClient, NULL, (Ecore_Event_Handler_Cb) _delClient, clientParser))
612 {
613 if (ecore_evas_init()) 568 if (ecore_evas_init())
614 { 569 {
615 if (edje_init()) 570 if (edje_init())
@@ -721,20 +676,30 @@ int main(int argc, char **argv)
721 edje_object_signal_callback_add(ourGlobals.edje, "*", "game_*", _edje_signal_cb, &ourGlobals); 676 edje_object_signal_callback_add(ourGlobals.edje, "*", "game_*", _edje_signal_cb, &ourGlobals);
722 } 677 }
723 678
724 ecore_main_loop_begin(); 679 PD("About to try connecting to a LuaSL server.");
725 PD("Fell out of the main loop"); 680 // Try to connect to a local LuaSL server.
681 reachOut("LuaSL", "./LuaSL", "127.0.0.1", ourGlobals.port, &ourGlobals, (Ecore_Event_Handler_Cb) _addLuaSL, /*(Ecore_Event_Handler_Cb) _dataLuaSL*/ NULL, (Ecore_Event_Handler_Cb) _delLuaSL, LuaSLParser);
682
683 PD("Love is about to try creating a love server.");
684 if (openArms("love", ourGlobals.address, ourGlobals.port + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _addClient, NULL, (Ecore_Event_Handler_Cb) _delClient, clientParser))
685 {
686 ecore_main_loop_begin();
687 PD("Fell out of the main loop");
726 688
727 if (ourGlobals.server) ecore_con_server_del(ourGlobals.server); 689// if (ourGlobals.server) ecore_con_server_del(ourGlobals.server);
728 if (ourGlobals.serverLuaSL) ecore_con_server_del(ourGlobals.serverLuaSL); 690// if (ourGlobals.serverLuaSL) ecore_con_server_del(ourGlobals.serverLuaSL);
691
692 }
693 else
694 PC("Failed to add server!");
729 695
730 if (ourGlobals.ui) 696 if (ourGlobals.ui)
731 { 697 {
732 ecore_animator_del(ani); 698 ecore_animator_del(ani);
733 ecore_evas_free(ourGlobals.ee); 699 ecore_evas_free(ourGlobals.ee);
734 } 700 }
735 }
736
737 edje_shutdown(); 701 edje_shutdown();
702 }
738 } 703 }
739 else 704 else
740 PC("Failed to init edje!"); 705 PC("Failed to init edje!");
@@ -743,10 +708,6 @@ int main(int argc, char **argv)
743 else 708 else
744 PC("Failed to init ecore_evas!"); 709 PC("Failed to init ecore_evas!");
745 710
746 }
747 else
748 PC("Failed to add server!");
749
750 ecore_con_shutdown(); 711 ecore_con_shutdown();
751 } 712 }
752 else 713 else