aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-18 13:27:05 +1000
committerDavid Walter Seikel2014-05-18 13:27:05 +1000
commit5b3f4f59112aeb4c91806103c487ca3148b63486 (patch)
tree15f234b9ab9551b8129465a136430d16a4eff3b9 /src
parentNo need to say this is where the history is show now that it's actually being... (diff)
downloadSledjHamr-5b3f4f59112aeb4c91806103c487ca3148b63486.zip
SledjHamr-5b3f4f59112aeb4c91806103c487ca3148b63486.tar.gz
SledjHamr-5b3f4f59112aeb4c91806103c487ca3148b63486.tar.bz2
SledjHamr-5b3f4f59112aeb4c91806103c487ca3148b63486.tar.xz
Clean up the server startup and connection a bit.
Diffstat (limited to 'src')
-rw-r--r--src/extantz/extantz.c40
-rw-r--r--src/libraries/SledjHamr.c19
-rw-r--r--src/love/love.c46
3 files changed, 45 insertions, 60 deletions
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index 74a0c58..ff418c0 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -19,7 +19,7 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
19{ 19{
20 globals *ourGlobals = data; 20 globals *ourGlobals = data;
21 21
22 PI("Server connected."); 22 PI("Connected to love server.");
23 ourGlobals->server = ev->server; 23 ourGlobals->server = ev->server;
24 if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server; 24 if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server;
25 if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server; 25 if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server;
@@ -104,32 +104,29 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
104 return ECORE_CALLBACK_RENEW; 104 return ECORE_CALLBACK_RENEW;
105} 105}
106 106
107// Forward declare a circular reference.
108static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev);
109
110static Eina_Bool _serverDelTimer(void *data)
111{
112 globals *ourGlobals = data;
113
114 ourGlobals->server = reachOut("127.0.0.1", 8211 + 1, ourGlobals, (Ecore_Event_Handler_Cb) _add, (Ecore_Event_Handler_Cb) _data, (Ecore_Event_Handler_Cb) _del);
115 return ECORE_CALLBACK_CANCEL;
116}
117
118static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) 107static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev)
119{ 108{
120 globals *ourGlobals = data; 109 globals *ourGlobals = data;
110 static int count = 0;
111
112 ourGlobals->server = NULL;
121 113
122 if (ev->server) 114 // Let it fail a couple of times during startup, then try to start our own love server.
115 count++;
116 if (1 < count)
123 { 117 {
124 ecore_con_server_del(ev->server); 118 char buf[PATH_MAX];
125 ourGlobals->server = NULL; 119
126 if (ourGlobals->running) 120 PW("Failed to connect to a world server, starting our own.");
127 { 121
128 PW("Server dropped out, trying to reconnect."); 122 // TODO - Should use Ecore_Exe for this sort of thing.
129 ecore_timer_add(1.0, _serverDelTimer, ourGlobals); 123 sprintf(buf, "%s/love &", elm_app_bin_dir_get());
130 } 124 system(buf);
125 count = 0;
131 } 126 }
132 127
128 if (ourGlobals->running)
129 return ECORE_CALLBACK_RENEW;
133 return ECORE_CALLBACK_CANCEL; 130 return ECORE_CALLBACK_CANCEL;
134} 131}
135 132
@@ -576,9 +573,6 @@ EAPI_MAIN int elm_main(int argc, char **argv)
576 logDom = loggingStartup("extantz", logDom); 573 logDom = loggingStartup("extantz", logDom);
577 ourGlobals.running = 1; 574 ourGlobals.running = 1;
578 575
579 // TODO - Should use Ecore_Exe for this sort of thing.
580 sprintf(buf, "%s/love &", elm_app_bin_dir_get());
581 system(buf);
582 576
583 // Don't do this, we need to clean up other stuff to, so set a clean up function below. 577 // Don't do this, we need to clean up other stuff to, so set a clean up function below.
584 //elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); 578 //elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c
index 26df012..7fcede7 100644
--- a/src/libraries/SledjHamr.c
+++ b/src/libraries/SledjHamr.c
@@ -16,18 +16,10 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Del *ev)
16{ 16{
17 struct _conct *this = data; 17 struct _conct *this = data;
18 18
19 ecore_event_handler_del(this->add);
20 ecore_event_handler_del(this->del);
21
22 if (this->addCb) 19 if (this->addCb)
23 {
24 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, this->addCb, this->pointer);
25 this->addCb(this->pointer, type, ev); 20 this->addCb(this->pointer, type, ev);
26 }
27 if (this->dataCb) 21 if (this->dataCb)
28 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, this->dataCb, this->pointer); 22 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, this->dataCb, this->pointer);
29 if (this->delCb)
30 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, this->delCb, this->pointer);
31 23
32 return ECORE_CALLBACK_RENEW; 24 return ECORE_CALLBACK_RENEW;
33} 25}
@@ -44,11 +36,18 @@ static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev)
44{ 36{
45 struct _conct *this = data; 37 struct _conct *this = data;
46 38
47 printf("FAILED to connect to server %s:%d, trying again in a second!\n", this->address, this->port); 39 printf("FAILED connection to server %s:%d, trying again in a second!\n", this->address, this->port);
48 ecore_event_handler_del(this->add); 40 ecore_event_handler_del(this->add);
49 ecore_event_handler_del(this->del); 41 ecore_event_handler_del(this->del);
42
43 if (this->delCb)
44 {
45 if (ECORE_CALLBACK_RENEW == this->delCb(this->pointer, type, ev))
46 ecore_timer_add(1.0, _delTimer, this);
47 }
48
50 if (ev->server) ecore_con_server_del(ev->server); 49 if (ev->server) ecore_con_server_del(ev->server);
51 ecore_timer_add(1.0, _delTimer, this); 50
52 return ECORE_CALLBACK_CANCEL; 51 return ECORE_CALLBACK_CANCEL;
53} 52}
54 53
diff --git a/src/love/love.c b/src/love/love.c
index 257d957..91c9d95 100644
--- a/src/love/love.c
+++ b/src/love/love.c
@@ -472,37 +472,33 @@ static Eina_Bool _dataLuaSL(void *data, int type, Ecore_Con_Event_Server_Data *e
472 return ECORE_CALLBACK_RENEW; 472 return ECORE_CALLBACK_RENEW;
473} 473}
474 474
475// Forward declare a circular reference. 475static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev)
476static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev);
477
478static Eina_Bool _serverDelTimer(void *data)
479{ 476{
480 gameGlobals *ourGlobals = data; 477 gameGlobals *ourGlobals = data;
478 static int count = 0;
481 479
482 ourGlobals->serverLuaSL = reachOut("127.0.0.1", 8211, ourGlobals, (Ecore_Event_Handler_Cb) _addLuaSL, (Ecore_Event_Handler_Cb) _dataLuaSL, (Ecore_Event_Handler_Cb) _delLuaSL); 480 ourGlobals->serverLuaSL = NULL;
483 return ECORE_CALLBACK_CANCEL;
484}
485 481
486static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) 482 // Let it fail a couple of times during startup, then try to start our own script server.
487{ 483 count++;
488 gameGlobals *ourGlobals = data; 484 if (1 < count)
485 {
486 char buf[PATH_MAX];
489 487
490 if (ev->server) 488 PW("Failed to connect to a script server, starting our own.");
491 { 489 sprintf(buf, "%s/LuaSL &", PACKAGE_BIN_DIR);
492 ecore_con_server_del(ev->server); 490 system(buf);
493 ourGlobals->serverLuaSL = NULL; 491 count = 0;
494 if (!ourGlobals->ui) 492 }
495 ecore_main_loop_quit();
496 else
497 {
498 PW("Server dropped out, trying to reconnect.");
499 ecore_timer_add(1.0, _serverDelTimer, ourGlobals);
500 }
501 }
502 493
494 // 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.
495// if (ourGlobals->ui)
503 return ECORE_CALLBACK_RENEW; 496 return ECORE_CALLBACK_RENEW;
504}
505 497
498// ecore_main_loop_quit();
499
500// return ECORE_CALLBACK_CANCEL;
501}
506 502
507static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev) 503static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev)
508{ 504{
@@ -606,10 +602,6 @@ int main(int argc, char **argv)
606 char *programName = argv[0]; 602 char *programName = argv[0];
607 boolean badArgs = FALSE; 603 boolean badArgs = FALSE;
608 int result = EXIT_FAILURE; 604 int result = EXIT_FAILURE;
609 char buf[PATH_MAX];
610
611 sprintf(buf, "%s/LuaSL &", PACKAGE_BIN_DIR);
612 system(buf);
613 605
614 memset(&ourGlobals, 0, sizeof(gameGlobals)); 606 memset(&ourGlobals, 0, sizeof(gameGlobals));
615 ourGlobals.address = "127.0.0.1"; 607 ourGlobals.address = "127.0.0.1";