aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/extantz/extantz.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-01-03 00:06:41 +1000
committerDavid Walter Seikel2016-01-03 00:06:41 +1000
commitd7bc357b2d1ec596e1b7fc982d0e299db3b4135c (patch)
treec429506e16efc4df624c12086c60cc47a2e9e069 /src/extantz/extantz.c
parentRejig the build, test, and kill scripts a little bit. (diff)
downloadSledjHamr-d7bc357b2d1ec596e1b7fc982d0e299db3b4135c.zip
SledjHamr-d7bc357b2d1ec596e1b7fc982d0e299db3b4135c.tar.gz
SledjHamr-d7bc357b2d1ec596e1b7fc982d0e299db3b4135c.tar.bz2
SledjHamr-d7bc357b2d1ec596e1b7fc982d0e299db3b4135c.tar.xz
Beat the server connection manegement into shape.
Diffstat (limited to 'src/extantz/extantz.c')
-rw-r--r--src/extantz/extantz.c181
1 files changed, 70 insertions, 111 deletions
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index 5a7d030..49e2ebe 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -12,7 +12,6 @@ static void on_pixels(void *data, Evas_Object *obj);
12 12
13int logDom = -1; // Our logging domain. 13int logDom = -1; // Our logging domain.
14globals ourGlobals; 14globals ourGlobals;
15static Eina_Strbuf *serverStream;
16//static char *myKey = "12345678-1234-4321-abcd-0123456789ab"; 15//static char *myKey = "12345678-1234-4321-abcd-0123456789ab";
17//static char *myName = "onefang rejected"; 16//static char *myName = "onefang rejected";
18 17
@@ -22,8 +21,8 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
22{ 21{
23 globals *ourGlobals = data; 22 globals *ourGlobals = data;
24 23
25 PI("Connected to love server."); 24 PI("Spread the love.");
26 ourGlobals->server = ev->server; 25 ourGlobals->server = ecore_con_server_data_get(ev->server);
27 if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server; 26 if (ourGlobals->LSLGuiMess) ourGlobals->LSLGuiMess->server = ourGlobals->server;
28 if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server; 27 if (ourGlobals->purkle) ourGlobals->purkle->server = ourGlobals->server;
29 28
@@ -33,110 +32,86 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
33 return ECORE_CALLBACK_RENEW; 32 return ECORE_CALLBACK_RENEW;
34} 33}
35 34
36static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) 35static Eina_Bool clientParser(void *data, Connection *connection, char *SID, char *command, char *arguments)
37{ 36{
38 globals *ourGlobals = data; 37 globals *ourGlobals = data;
39 char buf[PATH_MAX]; 38 char buf[PATH_MAX];
40 char SID[PATH_MAX];
41 const char *command;
42 char *ext;
43 39
44 eina_strbuf_append_length(serverStream, ev->data, ev->size); 40 if ((0 == strncmp(command, "llOwnerSay(", 11))
45 command = eina_strbuf_string_get(serverStream); 41 || (0 == strncmp(command, "llWhisper(", 10))
46 while ((ext = index(command, '\n'))) 42 || (0 == strncmp(command, "llSay(", 6))
43 || (0 == strncmp(command, "llShout(", 8)))
47 { 44 {
48 int length = ext - command;
49 45
50 strncpy(SID, command, length + 1); 46 sprintf(buf, "%s: %s", SID, command);
51 SID[length] = '\0'; 47 if (ourGlobals->purkle)
52 eina_strbuf_remove(serverStream, 0, length + 1);
53 ext = index(SID, '.');
54 if (ext)
55 { 48 {
56 ext[0] = '\0'; 49 int _P;
57 command = ext + 1; 50
58 if ((0 == strncmp(command, "llOwnerSay(", 11)) 51 lua_getfield(ourGlobals->purkle->L, LUA_REGISTRYINDEX, ourGlobals->purkle->name);
59 || (0 == strncmp(command, "llWhisper(", 10)) 52 _P = lua_gettop(ourGlobals->purkle->L);
60 || (0 == strncmp(command, "llSay(", 6)) 53 push_lua(ourGlobals->purkle->L, "@ ( $ )", _P, "append", buf, 0);
61 || (0 == strncmp(command, "llShout(", 8))) 54 }
62 { 55 else
63 56 PW("No purkle to put - %s", buf);
64 sprintf(buf, "%s: %s", SID, command); 57 }
65 if (ourGlobals->purkle) 58 else if (0 == strncmp(command, "llDialog(", 9))
66 { 59 {
67 int _P; 60 if (ourGlobals->LSLGuiMess)
68 61 {
69 lua_getfield(ourGlobals->purkle->L, LUA_REGISTRYINDEX, ourGlobals->purkle->name); 62 int _M;
70 _P = lua_gettop(ourGlobals->purkle->L); 63
71 push_lua(ourGlobals->purkle->L, "@ ( $ )", _P, "append", buf, 0); 64 lua_getfield(ourGlobals->LSLGuiMess->L, LUA_REGISTRYINDEX, ourGlobals->LSLGuiMess->name);
72 } 65 _M = lua_gettop(ourGlobals->LSLGuiMess->L);
73 else 66
74 PW("No purkle to put - %s", buf); 67 // TODO - Somewhere in the chain the new lines that MLP likes to put into llDialog's message munge things. Fix that.
75 } 68 push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", command, 0);
76 else if (0 == strncmp(command, "llDialog(", 9)) 69 }
77 { 70 else
78 if (ourGlobals->LSLGuiMess) 71 PE("No LSLGuiMess to send - %s", command);
79 { 72
80 int _M; 73 }
81 74 else if (0 == strncmp(command, "loadSim(", 8))
82 lua_getfield(ourGlobals->LSLGuiMess->L, LUA_REGISTRYINDEX, ourGlobals->LSLGuiMess->name); 75 {
83 _M = lua_gettop(ourGlobals->LSLGuiMess->L);
84
85 // TODO - Somewhere in the chain the new lines that MLP likes to put into llDialog's message munge things. Fix that.
86 push_lua(ourGlobals->LSLGuiMess->L, "@ ( $ )", _M, "doLua", command, 0);
87 }
88 else
89 PE("No LSLGuiMess to send - %s", command);
90
91 }
92 else if (0 == strncmp(command, "loadSim(", 8))
93 {
94#if USE_EVAS_3D 76#if USE_EVAS_3D
95 char *p, *t; 77 char *p, *t;
96 int scenriLua; 78 int scenriLua;
97#endif 79#endif
98 80
99 // Pretend we logged in. Actually in the case of a local love server, we realy have logged in now. 81 // Pretend we logged in. Actually in the case of a local love server, we realy have logged in now.
100 strcpy(ourGlobals->uuid, SID); 82 strcpy(ourGlobals->uuid, SID);
101 PI("Your UUID is %s.", ourGlobals->uuid); 83 PI("Your UUID is %s.", ourGlobals->uuid);
102#if USE_EVAS_3D 84#if USE_EVAS_3D
103 strcpy(buf, &command[8]); 85 strcpy(buf, &command[8]);
104 p = buf; 86 p = buf;
105 while ('"' == p[0]) 87 while ('"' == p[0])
106 p++; 88 p++;
107 while ('\'' == p[0]) 89 while ('\'' == p[0])
108 p++; 90 p++;
109 t = p; 91 t = p;
110 while (('"' != p[0]) && ('\'' != p[0])) 92 while (('"' != p[0]) && ('\'' != p[0]))
111 p++; 93 p++;
112 p[0] = '\0'; 94 p[0] = '\0';
113 // TODO - For now, assume it's a file:// URL. 95 // TODO - For now, assume it's a file:// URL.
114 t += 7; 96 t += 7;
115 //strcat(t, "/index.omg"); 97 //strcat(t, "/index.omg");
116 strcpy(ourGlobals->scene->sim, t); 98 strcpy(ourGlobals->scene->sim, t);
117 PI("Loading local sim from %s", t); 99 PI("Loading local sim from %s", t);
118 100
119 // TODO - Later do the same with eet files in C code, but keep both implementations. 101 // TODO - Later do the same with eet files in C code, but keep both implementations.
120 lua_getglobal(ourGlobals->scene->L, "package"); 102 lua_getglobal(ourGlobals->scene->L, "package");
121 lua_getfield(ourGlobals->scene->L, lua_gettop(ourGlobals->scene->L), "loaded"); 103 lua_getfield(ourGlobals->scene->L, lua_gettop(ourGlobals->scene->L), "loaded");
122 lua_remove(ourGlobals->scene->L, -2); // Removes "package" 104 lua_remove(ourGlobals->scene->L, -2); // Removes "package"
123 lua_getfield(ourGlobals->scene->L, lua_gettop(ourGlobals->scene->L), "scenriLua"); 105 lua_getfield(ourGlobals->scene->L, lua_gettop(ourGlobals->scene->L), "scenriLua");
124 lua_remove(ourGlobals->scene->L, -2); // Removes "loaded" 106 lua_remove(ourGlobals->scene->L, -2); // Removes "loaded"
125 scenriLua = lua_gettop(ourGlobals->scene->L); 107 scenriLua = lua_gettop(ourGlobals->scene->L);
126 108
127 push_lua(ourGlobals->scene->L, "@ ( $ )", scenriLua, "loadSim", t, 0); 109 push_lua(ourGlobals->scene->L, "@ ( $ )", scenriLua, "loadSim", t, 0);
128 PI("Loaded local sim from %s", t); 110 PI("Loaded local sim from %s", t);
129#endif 111#endif
130 }
131 else
132 {
133 PI("Some random command %s", command);
134 }
135 }
136
137 // Get the next blob to check it.
138 command = eina_strbuf_string_get(serverStream);
139 } 112 }
113 else
114 PI("Some random command %s", command);
140 115
141 return ECORE_CALLBACK_RENEW; 116 return ECORE_CALLBACK_RENEW;
142} 117}
@@ -144,26 +119,12 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
144static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) 119static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev)
145{ 120{
146 globals *ourGlobals = data; 121 globals *ourGlobals = data;
147 static int count = 0;
148 122
149 ourGlobals->server = NULL; 123 ourGlobals->server = NULL;
150 124
151 // Let it fail a couple of times during startup, then try to start our own love server.
152 count++;
153 if (1 < count)
154 {
155 char buf[PATH_MAX];
156
157 PW("Failed to connect to a world server, starting our own.");
158
159 // TODO - Should use Ecore_Exe for this sort of thing.
160 sprintf(buf, "%s/love &", prefix_bin_get());
161 system(buf);
162 count = 0;
163 }
164
165 if (ourGlobals->running) 125 if (ourGlobals->running)
166 return ECORE_CALLBACK_RENEW; 126 return ECORE_CALLBACK_RENEW;
127
167 return ECORE_CALLBACK_CANCEL; 128 return ECORE_CALLBACK_CANCEL;
168} 129}
169 130
@@ -710,8 +671,6 @@ EAPI_MAIN int elm_main(int argc, char **argv)
710 ephysics_world_del(ourGlobals.world); 671 ephysics_world_del(ourGlobals.world);
711 ephysics_shutdown(); 672 ephysics_shutdown();
712 673
713 if (ourGlobals.server) ecore_con_server_del(ourGlobals.server);
714
715 if (ourGlobals.win) 674 if (ourGlobals.win)
716 { 675 {
717 ecore_animator_del(ourGlobals.animator); 676 ecore_animator_del(ourGlobals.animator);