diff options
author | David Walter Seikel | 2016-02-05 16:38:58 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-02-05 16:38:58 +1000 |
commit | 76faf8a71ca29aef0de066fb3a31823227b6d95d (patch) | |
tree | e7bd6bf9ddb63569c4b98e1679631fa1103d0300 | |
parent | Authors++ (diff) | |
download | SledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.zip SledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.tar.gz SledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.tar.bz2 SledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.tar.xz |
The next step in cleaning up the network Lua messages.
-rw-r--r-- | src/LuaSL/LuaSL_main.c | 70 | ||||
-rw-r--r-- | src/extantz/extantz.c | 8 | ||||
-rw-r--r-- | src/libraries/SledjHamr.c | 211 | ||||
-rw-r--r-- | src/libraries/SledjHamr.h | 8 | ||||
-rw-r--r-- | src/love/love.c | 32 |
5 files changed, 195 insertions, 134 deletions
diff --git a/src/LuaSL/LuaSL_main.c b/src/LuaSL/LuaSL_main.c index d7223f9..cf3c946 100644 --- a/src/LuaSL/LuaSL_main.c +++ b/src/LuaSL/LuaSL_main.c | |||
@@ -71,19 +71,37 @@ static script *findThem(gameGlobals *ourGlobals, const char *base, const char *t | |||
71 | 71 | ||
72 | static void send2server(script *me, const char *message) | 72 | static void send2server(script *me, const char *message) |
73 | { | 73 | { |
74 | gameGlobals *ourGlobals = me->data; | 74 | takeScript(me); |
75 | // NOTE - This gets intercepted by send2parser() below, before possibly being sent away. | ||
76 | send2(me->client, me->SID, message); | ||
77 | releaseScript(me); | ||
78 | } | ||
79 | |||
80 | static boolean send2parser(void *data, Connection *connection, char *SID, char *command, char *arguments) | ||
81 | { | ||
82 | gameGlobals *ourGlobals = data; | ||
83 | char buf[PATH_MAX]; | ||
84 | script *me = getScript(SID); | ||
85 | |||
86 | if (NULL == me) | ||
87 | { | ||
88 | // PE("GOT MESSAGE from UNKNOWN script %s - '%s' (%s", SID, command, arguments); | ||
89 | return FALSE; | ||
90 | } | ||
91 | |||
92 | sprintf(buf, "%s(%s", command, arguments); | ||
75 | 93 | ||
76 | //PD("GOT MESSAGE from script %s - '%s'", me->name, message); | 94 | //PD("GOT MESSAGE from script %s - '%s'", me->name, buf); |
77 | 95 | ||
78 | if (0 == strncmp(message, "llSleep(", 8)) | 96 | if (0 == strncmp(buf, "llSleep(", 8)) |
79 | ecore_timer_add(atof(&(message)[8]), _sleep_timer_cb, me); | 97 | ecore_timer_add(atof(&(buf)[8]), _sleep_timer_cb, me); |
80 | else if (0 == strncmp(message, "llResetTime(", 12)) | 98 | else if (0 == strncmp(buf, "llResetTime(", 12)) |
81 | { | 99 | { |
82 | takeScript(me); | 100 | takeScript(me); |
83 | gettimeofday(&me->startTime, NULL); | 101 | gettimeofday(&me->startTime, NULL); |
84 | releaseScript(me); | 102 | releaseScript(me); |
85 | } | 103 | } |
86 | else if (0 == strncmp(message, "llGetTime(", 10)) | 104 | else if (0 == strncmp(buf, "llGetTime(", 10)) |
87 | { | 105 | { |
88 | struct timeval now; | 106 | struct timeval now; |
89 | float time = timeDiff(&now, &me->startTime); | 107 | float time = timeDiff(&now, &me->startTime); |
@@ -92,7 +110,7 @@ static void send2server(script *me, const char *message) | |||
92 | snprintf(result, sizeof(result), "return %f", time); | 110 | snprintf(result, sizeof(result), "return %f", time); |
93 | send2script(me->SID, result); | 111 | send2script(me->SID, result); |
94 | } | 112 | } |
95 | else if (0 == strncmp(message, "llGetAndResetTime(", 18)) | 113 | else if (0 == strncmp(buf, "llGetAndResetTime(", 18)) |
96 | { | 114 | { |
97 | struct timeval now; | 115 | struct timeval now; |
98 | float time = timeDiff(&now, &me->startTime); | 116 | float time = timeDiff(&now, &me->startTime); |
@@ -105,10 +123,10 @@ static void send2server(script *me, const char *message) | |||
105 | snprintf(result, sizeof(result), "return %f", time); | 123 | snprintf(result, sizeof(result), "return %f", time); |
106 | send2script(me->SID, result); | 124 | send2script(me->SID, result); |
107 | } | 125 | } |
108 | else if (0 == strncmp(message, "llSetTimerEvent(", 16)) | 126 | else if (0 == strncmp(buf, "llSetTimerEvent(", 16)) |
109 | { | 127 | { |
110 | takeScript(me); | 128 | takeScript(me); |
111 | me->timerTime = atof(&(message)[16]); | 129 | me->timerTime = atof(&(buf)[16]); |
112 | if (0.0 == me->timerTime) | 130 | if (0.0 == me->timerTime) |
113 | { | 131 | { |
114 | if (me->timer) | 132 | if (me->timer) |
@@ -119,13 +137,13 @@ static void send2server(script *me, const char *message) | |||
119 | me->timer = ecore_timer_add(me->timerTime, _timer_timer_cb, me); | 137 | me->timer = ecore_timer_add(me->timerTime, _timer_timer_cb, me); |
120 | releaseScript(me); | 138 | releaseScript(me); |
121 | } | 139 | } |
122 | else if (0 == strncmp(message, "llSetScriptState(", 17)) | 140 | else if (0 == strncmp(buf, "llSetScriptState(", 17)) |
123 | { | 141 | { |
124 | script *them; | 142 | script *them; |
125 | 143 | ||
126 | if ((them = findThem(ourGlobals, me->fileName, &(message[18])))) | 144 | if ((them = findThem(ourGlobals, me->fileName, &(buf[18])))) |
127 | { | 145 | { |
128 | char *temp = rindex(&(message[18]), ','); | 146 | char *temp = rindex(&(buf[18]), ','); |
129 | 147 | ||
130 | if (temp) | 148 | if (temp) |
131 | { | 149 | { |
@@ -143,34 +161,32 @@ static void send2server(script *me, const char *message) | |||
143 | } | 161 | } |
144 | else | 162 | else |
145 | { | 163 | { |
146 | char *temp = rindex(&(message[18]), '"'); | 164 | char *temp = rindex(&(buf[18]), '"'); |
147 | 165 | ||
148 | if (temp) | 166 | if (temp) |
149 | *temp = '\0'; | 167 | *temp = '\0'; |
150 | PE("Can't stop script, can't find %s", &(message[18])); | 168 | PE("Can't stop script, can't find %s", &(buf[18])); |
151 | } | 169 | } |
152 | } | 170 | } |
153 | else if (0 == strncmp(message, "llResetOtherScript(", 19)) | 171 | else if (0 == strncmp(buf, "llResetOtherScript(", 19)) |
154 | { | 172 | { |
155 | script *them; | 173 | script *them; |
156 | 174 | ||
157 | if ((them = findThem(ourGlobals, me->fileName, &(message[20])))) | 175 | if ((them = findThem(ourGlobals, me->fileName, &(buf[20])))) |
158 | { | 176 | { |
159 | PD("RESETTING OTHER %s", them->name); | 177 | PD("RESETTING OTHER %s", them->name); |
160 | resetScript(them); | 178 | resetScript(them); |
161 | } | 179 | } |
162 | } | 180 | } |
163 | else if (0 == strncmp(message, "llResetScript(", 14)) | 181 | else if (0 == strncmp(buf, "llResetScript(", 14)) |
164 | { | 182 | { |
165 | PD("RESETTING %s", me->name); | 183 | PD("RESETTING %s", me->name); |
166 | resetScript(me); | 184 | resetScript(me); |
167 | } | 185 | } |
168 | else | 186 | else |
169 | { | 187 | return FALSE; |
170 | takeScript(me); | 188 | |
171 | send2(me->client, me->SID, message); | 189 | return TRUE; |
172 | releaseScript(me); | ||
173 | } | ||
174 | } | 190 | } |
175 | 191 | ||
176 | static void _compileCb(LuaCompiler *compiler) | 192 | static void _compileCb(LuaCompiler *compiler) |
@@ -218,12 +234,12 @@ static void _compileCbSingle(LuaCompiler *compiler) | |||
218 | printf("Compile of %s failed!\n", compiler->file); | 234 | printf("Compile of %s failed!\n", compiler->file); |
219 | } | 235 | } |
220 | 236 | ||
221 | static Eina_Bool parser(void *data, Connection *connection, char *SID, char *command, char *arguments) | 237 | static boolean parser(void *data, Connection *connection, char *SID, char *command, char *arguments) |
222 | { | 238 | { |
223 | gameGlobals *ourGlobals = data; | 239 | gameGlobals *ourGlobals = data; |
224 | char buf[PATH_MAX]; | 240 | char buf[PATH_MAX]; |
225 | 241 | ||
226 | //PD("PARSE COMMAND - %s", command); | 242 | //PD("PARSE COMMAND %s - '%s' (%s", SID, command, arguments); |
227 | if (0 == strcmp(command, "compile")) | 243 | if (0 == strcmp(command, "compile")) |
228 | { | 244 | { |
229 | char *temp; | 245 | char *temp; |
@@ -275,6 +291,8 @@ static Eina_Bool parser(void *data, Connection *connection, char *SID, char *com | |||
275 | } | 291 | } |
276 | else | 292 | else |
277 | { | 293 | { |
294 | // TODO - Even after moving the above into the command hash, this bit might still remain, unless script.return() can make it go away. | ||
295 | // Though perhaps the "else" part stays? | ||
278 | if (0 == strcmp("return", command)) | 296 | if (0 == strcmp("return", command)) |
279 | snprintf(buf, sizeof(buf), "%s %s", command, arguments); | 297 | snprintf(buf, sizeof(buf), "%s %s", command, arguments); |
280 | else | 298 | else |
@@ -283,7 +301,7 @@ static Eina_Bool parser(void *data, Connection *connection, char *SID, char *com | |||
283 | send2script(SID, buf); | 301 | send2script(SID, buf); |
284 | } | 302 | } |
285 | 303 | ||
286 | return ECORE_CALLBACK_RENEW; | 304 | return TRUE; |
287 | } | 305 | } |
288 | 306 | ||
289 | int main(int argc, char **argv) | 307 | int main(int argc, char **argv) |
@@ -320,7 +338,7 @@ int main(int argc, char **argv) | |||
320 | else if (ecore_con_init()) | 338 | else if (ecore_con_init()) |
321 | { | 339 | { |
322 | // PD("LuaSL is about to try creating a LuaSL server."); | 340 | // PD("LuaSL is about to try creating a LuaSL server."); |
323 | if (openArms("LuaSL", ourGlobals.address, ourGlobals.port, &ourGlobals, NULL, NULL, NULL, parser)) | 341 | if (openArms("LuaSL", ourGlobals.address, ourGlobals.port, &ourGlobals, NULL, NULL, NULL, parser, send2parser)) |
324 | { | 342 | { |
325 | Eina_Iterator *scripts; | 343 | Eina_Iterator *scripts; |
326 | script *me; | 344 | script *me; |
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 6dc7c3b..089cc41 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c | |||
@@ -33,7 +33,7 @@ static Eina_Bool _add(void *data, int type, Ecore_Con_Event_Server_Add *ev) | |||
33 | return ECORE_CALLBACK_RENEW; | 33 | return ECORE_CALLBACK_RENEW; |
34 | } | 34 | } |
35 | 35 | ||
36 | static Eina_Bool clientParser(void *data, Connection *connection, char *SID, char *command, char *arguments) | 36 | static boolean clientParser(void *data, Connection *connection, char *SID, char *command, char *arguments) |
37 | { | 37 | { |
38 | globals *ourGlobals = data; | 38 | globals *ourGlobals = data; |
39 | char buf[PATH_MAX]; | 39 | char buf[PATH_MAX]; |
@@ -111,9 +111,9 @@ static Eina_Bool clientParser(void *data, Connection *connection, char *SID, cha | |||
111 | #endif | 111 | #endif |
112 | } | 112 | } |
113 | else | 113 | else |
114 | PI("Some random command %s(%s", command, arguments); | 114 | return FALSE; |
115 | 115 | ||
116 | return ECORE_CALLBACK_RENEW; | 116 | return TRUE; |
117 | } | 117 | } |
118 | 118 | ||
119 | static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) | 119 | static Eina_Bool _del(void *data, int type, Ecore_Con_Event_Server_Del *ev) |
@@ -560,7 +560,7 @@ static Eina_Bool _makeSkang(void *data) | |||
560 | #if USE_LOVE | 560 | #if USE_LOVE |
561 | case 5 : | 561 | case 5 : |
562 | // PD("About to try connecting to a love server."); | 562 | // PD("About to try connecting to a love server."); |
563 | reachOut("love", "./love", "127.0.0.1", 8211 + 1, ourGlobals, (Ecore_Event_Handler_Cb) _add, /*(Ecore_Event_Handler_Cb) _data*/ NULL, (Ecore_Event_Handler_Cb) _del, clientParser); | 563 | reachOut("love", "./love", "127.0.0.1", 8211 + 1, ourGlobals, (Ecore_Event_Handler_Cb) _add, /*(Ecore_Event_Handler_Cb) _data*/ NULL, (Ecore_Event_Handler_Cb) _del, clientParser, NULL); |
564 | break; | 564 | break; |
565 | #endif | 565 | #endif |
566 | 566 | ||
diff --git a/src/libraries/SledjHamr.c b/src/libraries/SledjHamr.c index b44c1cb..7092c10 100644 --- a/src/libraries/SledjHamr.c +++ b/src/libraries/SledjHamr.c | |||
@@ -88,78 +88,41 @@ static boolean checkConnection(Connection *conn, char *func, connType wanted, bo | |||
88 | return result; | 88 | return result; |
89 | } | 89 | } |
90 | 90 | ||
91 | void send2(Connection *conn, const char *SID, const char *message, ...) | ||
92 | { | ||
93 | va_list args; | ||
94 | char buf[PATH_MAX * 2]; | ||
95 | int length = strlen(SID); | ||
96 | |||
97 | strncpy(buf, SID, length); | ||
98 | buf[length++] = '.'; | ||
99 | va_start(args, message); | ||
100 | length += vsprintf(&buf[length], message, args); | ||
101 | va_end(args); | ||
102 | buf[length++] = '\n'; | ||
103 | buf[length] = '\0'; | ||
104 | 91 | ||
105 | // TODO - Should check if this is always gonna be local? Likely not. | 92 | typedef boolean (* notFoundCb)(Connection *conn, char *command, int len); |
106 | // TODO - Figure out what the above line meant. Then ... | ||
107 | // Check a hashtable somewhere for a command extracted from the message. | ||
108 | // conn->commands[command](message ...) | ||
109 | if (checkConnection(conn, "send2", conn->type, FALSE)) | ||
110 | { | ||
111 | switch (conn->type) | ||
112 | { | ||
113 | case CT_CLIENT : | ||
114 | // PD("vvv send2(%*s", length, buf); | ||
115 | ecore_con_client_send(conn->conn.client.client, strndup(buf, length), length); | ||
116 | ecore_con_client_flush(conn->conn.client.client); | ||
117 | break; | ||
118 | |||
119 | case CT_SERVER : | ||
120 | // PD("^^^ send2(%*s", length, buf); | ||
121 | ecore_con_server_send(conn->conn.server.server, strndup(buf, length), length); | ||
122 | ecore_con_server_flush(conn->conn.server.server); | ||
123 | break; | ||
124 | |||
125 | default : | ||
126 | PE("send2() unable to send to partially bogus Connection object!"); | ||
127 | break; | ||
128 | } | ||
129 | } | ||
130 | else | ||
131 | PE("send2() unable to send to bogus Connection object!"); | ||
132 | } | ||
133 | 93 | ||
134 | static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, void *ev) | 94 | /* TODO - |
95 | It should loop through all lines, looking for the closing ) before dealing with it. | ||
96 | If we get to the end, and there's left over open ( or something, then return the length. | ||
97 | Bitch and move on if it's not well formed. | ||
98 | */ | ||
99 | static int _checkForCommand(Connection *conn, char *commands, notFoundCb notFound, boolean in) | ||
135 | { | 100 | { |
136 | Connection *conn = data; | 101 | int result = 0; |
137 | char SID[PATH_MAX]; | 102 | boolean handled = FALSE; |
138 | const char *command; | 103 | char *ext, *ext2; |
139 | char *ext; | ||
140 | 104 | ||
141 | if (NULL == conn->stream) | 105 | while ((ext = index(commands, '\n'))) |
142 | conn->stream = eina_strbuf_new(); | 106 | { |
107 | char SID[PATH_MAX * 3]; | ||
108 | int length = ext - commands; | ||
143 | 109 | ||
144 | eina_strbuf_append_length(conn->stream, evData, evSize); | 110 | strncpy(SID, commands, length + 1); |
145 | command = eina_strbuf_string_get(conn->stream); | 111 | |
146 | while ((ext = index(command, '\n'))) | 112 | SID[length] = '\0'; |
113 | |||
114 | ext = index(SID, '.'); | ||
115 | if (ext) | ||
147 | { | 116 | { |
148 | int length = ext - command; | 117 | char *command = ext + 1; |
149 | 118 | ||
150 | strncpy(SID, command, length + 1); | 119 | ext[0] = '\0'; |
151 | SID[length] = '\0'; | 120 | ext2 = index(command, '('); |
152 | eina_strbuf_remove(conn->stream, 0, length + 1); | 121 | if (NULL == ext2) |
153 | ext = index(SID, '.'); | 122 | ext2 = index(command, ' '); |
154 | if (ext) | 123 | if (ext2) |
155 | { | 124 | { |
156 | ext[0] = '\0'; | 125 | ext2[0] = '\0'; |
157 | command = ext + 1; | ||
158 | ext = index(command, '('); | ||
159 | if (NULL == ext) | ||
160 | ext = index(command, ' '); | ||
161 | if (ext) | ||
162 | { | ||
163 | // TODO - Currently SID.command(arguments), should change that to nameSpace.command(arguments) | 126 | // TODO - Currently SID.command(arguments), should change that to nameSpace.command(arguments) |
164 | // Not sure what to do with SID, but there maybe some common parameters we can shift around differently. | 127 | // Not sure what to do with SID, but there maybe some common parameters we can shift around differently. |
165 | // - First check if the connection has a hashtable of conn->commands. | 128 | // - First check if the connection has a hashtable of conn->commands. |
@@ -171,22 +134,101 @@ static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, voi | |||
171 | // Finally pass it to conn->unknownCommand() | 134 | // Finally pass it to conn->unknownCommand() |
172 | // * The Lua check can live in unknownCommand(). | 135 | // * The Lua check can live in unknownCommand(). |
173 | // else bitch. | 136 | // else bitch. |
174 | streamParser func = eina_hash_find(conn->commands, command); | 137 | |
175 | 138 | // Check if it's in the connections hash table. | |
176 | ext[0] = '\0'; | 139 | streamParser func = eina_hash_find(conn->commands, command); |
177 | // Need a callback if we can't find the command. | 140 | |
178 | if (NULL == func) | 141 | if (NULL == func) |
179 | func = conn->unknownCommand; | 142 | { |
180 | if (func) | 143 | // Check if the connection has a function for handling it. |
181 | func(conn->pointer, conn, SID, (char *) command, ext + 1); | 144 | if (in) |
182 | else | 145 | func = conn->unknownInCommand; |
183 | PE("parseStream() No function found for command %s!", command); | 146 | else |
184 | } | 147 | func = conn->unknownOutCommand; |
148 | } | ||
149 | |||
150 | // Try it out if we have a function. | ||
151 | if (func) | ||
152 | { | ||
153 | handled = func(conn->pointer, conn, SID, command, ext2 + 1); | ||
154 | if (handled) | ||
155 | notFound = NULL; | ||
185 | } | 156 | } |
186 | 157 | ||
187 | // Get the next blob to check it. | 158 | // Last resort, let the caller deal with it. |
188 | command = eina_strbuf_string_get(conn->stream); | 159 | if (notFound) |
160 | handled = notFound(conn, commands, length + 1); | ||
161 | if (!handled) | ||
162 | PE("No function found for command %s(%s!", command, ext2 + 1); | ||
163 | |||
164 | result += length; | ||
165 | } | ||
166 | } | ||
167 | |||
168 | commands = &commands[length + 1]; | ||
169 | } | ||
170 | |||
171 | return result; | ||
172 | } | ||
173 | |||
174 | static boolean _actuallySendIt(Connection *conn, char *command, int len) | ||
175 | { | ||
176 | if (checkConnection(conn, "send2", conn->type, FALSE)) | ||
177 | { | ||
178 | switch (conn->type) | ||
179 | { | ||
180 | case CT_CLIENT : | ||
181 | // PD("vvv send2(%*s", len, command); | ||
182 | ecore_con_client_send(conn->conn.client.client, strndup(command, len), len); | ||
183 | ecore_con_client_flush(conn->conn.client.client); | ||
184 | return TRUE; | ||
185 | |||
186 | case CT_SERVER : | ||
187 | // PD("^^^ send2(%*s", len, command); | ||
188 | ecore_con_server_send(conn->conn.server.server, strndup(command, len), len); | ||
189 | ecore_con_server_flush(conn->conn.server.server); | ||
190 | return TRUE; | ||
191 | |||
192 | default : | ||
193 | PE("send2() unable to send to partially bogus Connection object!"); | ||
194 | break; | ||
195 | } | ||
189 | } | 196 | } |
197 | else | ||
198 | PE("send2() unable to send to bogus Connection object!"); | ||
199 | |||
200 | return FALSE; | ||
201 | } | ||
202 | |||
203 | void send2(Connection *conn, const char *SID, const char *message, ...) | ||
204 | { | ||
205 | va_list args; | ||
206 | char buf[PATH_MAX * 3]; | ||
207 | int length = strlen(SID); | ||
208 | |||
209 | strncpy(buf, SID, length); | ||
210 | buf[length++] = '.'; | ||
211 | va_start(args, message); | ||
212 | length += vsprintf(&buf[length], message, args); | ||
213 | va_end(args); | ||
214 | buf[length++] = '\n'; | ||
215 | buf[length] = '\0'; | ||
216 | |||
217 | //PD("%s", (char *) buf); | ||
218 | // TODO - Do we care about the returned length? Either the caller sent us proper commands, or they didn't. | ||
219 | _checkForCommand(conn, buf, _actuallySendIt, FALSE); | ||
220 | } | ||
221 | |||
222 | static Eina_Bool parseStream(void *data, int type, void *evData, int evSize, void *ev) | ||
223 | { | ||
224 | Connection *conn = data; | ||
225 | |||
226 | if (NULL == conn->stream) | ||
227 | conn->stream = eina_strbuf_new(); | ||
228 | |||
229 | eina_strbuf_append_length(conn->stream, evData, evSize); | ||
230 | //PD("%s", (char *) eina_strbuf_string_get(conn->stream)); | ||
231 | eina_strbuf_remove(conn->stream, 0, _checkForCommand(conn, (char *) eina_strbuf_string_get(conn->stream), NULL, TRUE)); | ||
190 | 232 | ||
191 | if (conn->_data) | 233 | if (conn->_data) |
192 | conn->_data(conn->pointer, type, ev); | 234 | conn->_data(conn->pointer, type, ev); |
@@ -234,7 +276,8 @@ static Eina_Bool clientAdd(void *data, int type, Ecore_Con_Event_Client_Add *ev) | |||
234 | conn->_add = connection->_add; | 276 | conn->_add = connection->_add; |
235 | conn->_data = connection->_data; | 277 | conn->_data = connection->_data; |
236 | conn->_del = connection->_del; | 278 | conn->_del = connection->_del; |
237 | conn->unknownCommand = connection->unknownCommand; | 279 | conn->unknownInCommand = connection->unknownInCommand; |
280 | conn->unknownOutCommand = connection->unknownOutCommand; | ||
238 | conn->commands = eina_hash_string_superfast_new(NULL); | 281 | conn->commands = eina_hash_string_superfast_new(NULL); |
239 | ecore_con_client_data_set(ev->client, conn); | 282 | ecore_con_client_data_set(ev->client, conn); |
240 | 283 | ||
@@ -284,7 +327,7 @@ static Eina_Bool clientDel(void *data, int type, Ecore_Con_Event_Client_Del *ev) | |||
284 | return ECORE_CALLBACK_RENEW; | 327 | return ECORE_CALLBACK_RENEW; |
285 | } | 328 | } |
286 | 329 | ||
287 | 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) | 330 | 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 _inParser, streamParser _outParser) |
288 | { | 331 | { |
289 | Connection *conn = calloc(1, sizeof(Connection)); | 332 | Connection *conn = calloc(1, sizeof(Connection)); |
290 | Ecore_Con_Server *server; | 333 | Ecore_Con_Server *server; |
@@ -299,7 +342,8 @@ Connection *openArms(char *name, const char *address, int port, void *data, Ecor | |||
299 | conn->_add = _add; | 342 | conn->_add = _add; |
300 | conn->_data = _data; | 343 | conn->_data = _data; |
301 | conn->_del = _del; | 344 | conn->_del = _del; |
302 | conn->unknownCommand = _parser; | 345 | conn->unknownInCommand = _inParser; |
346 | conn->unknownOutCommand = _outParser; | ||
303 | conn->commands = eina_hash_string_superfast_new(NULL); | 347 | conn->commands = eina_hash_string_superfast_new(NULL); |
304 | 348 | ||
305 | conn->add = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) clientAdd, conn); | 349 | conn->add = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb) clientAdd, conn); |
@@ -449,7 +493,7 @@ static Eina_Bool _reachOutTimer(void *data) | |||
449 | return result; | 493 | return result; |
450 | } | 494 | } |
451 | 495 | ||
452 | 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) | 496 | 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 _inParser, streamParser _outParser) |
453 | { | 497 | { |
454 | Connection *conn = calloc(1, sizeof(Connection)); | 498 | Connection *conn = calloc(1, sizeof(Connection)); |
455 | 499 | ||
@@ -464,7 +508,8 @@ Connection *reachOut(char *name, char *command, char *address, int port, void *d | |||
464 | conn->_add = _add; | 508 | conn->_add = _add; |
465 | conn->_data = _data; | 509 | conn->_data = _data; |
466 | conn->_del = _del; | 510 | conn->_del = _del; |
467 | conn->unknownCommand = _parser; | 511 | conn->unknownInCommand = _inParser; |
512 | conn->unknownOutCommand = _outParser; | ||
468 | conn->commands = eina_hash_string_superfast_new(NULL); | 513 | conn->commands = eina_hash_string_superfast_new(NULL); |
469 | 514 | ||
470 | conn->add = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) serverAdd, conn); | 515 | conn->add = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb) serverAdd, conn); |
diff --git a/src/libraries/SledjHamr.h b/src/libraries/SledjHamr.h index d5e0b1f..061f081 100644 --- a/src/libraries/SledjHamr.h +++ b/src/libraries/SledjHamr.h | |||
@@ -10,7 +10,7 @@ | |||
10 | 10 | ||
11 | typedef struct _Connection Connection; | 11 | typedef struct _Connection Connection; |
12 | 12 | ||
13 | typedef Eina_Bool (* streamParser)(void *data, Connection *connection, char *SID, char *command, char *arguments); | 13 | typedef boolean (* streamParser)(void *data, Connection *connection, char *SID, char *command, char *arguments); |
14 | 14 | ||
15 | typedef enum | 15 | typedef enum |
16 | { | 16 | { |
@@ -59,7 +59,7 @@ struct _Connection | |||
59 | void *pointer; | 59 | void *pointer; |
60 | Ecore_Event_Handler_Cb _add, _data, _del; | 60 | Ecore_Event_Handler_Cb _add, _data, _del; |
61 | Ecore_Event_Handler *add, *data, *del, *died; | 61 | Ecore_Event_Handler *add, *data, *del, *died; |
62 | streamParser unknownCommand; | 62 | streamParser unknownInCommand, unknownOutCommand; |
63 | 63 | ||
64 | int stage; // Stage of creation for the Connection. | 64 | int stage; // Stage of creation for the Connection. |
65 | }; | 65 | }; |
@@ -67,7 +67,7 @@ struct _Connection | |||
67 | 67 | ||
68 | void *addMessage(Eina_Clist *list, size_t size, const char *message, ...); | 68 | void *addMessage(Eina_Clist *list, size_t size, const char *message, ...); |
69 | void send2(Connection *conn, const char *SID, const char *message, ...); | 69 | void send2(Connection *conn, const char *SID, const char *message, ...); |
70 | 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); | 70 | 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 _inParser, streamParser _outParser); |
71 | 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); | 71 | 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 _inParser, streamParser _outParser); |
72 | 72 | ||
73 | #endif | 73 | #endif |
diff --git a/src/love/love.c b/src/love/love.c index 9ad9842..8d1bcd4 100644 --- a/src/love/love.c +++ b/src/love/love.c | |||
@@ -191,7 +191,7 @@ char *get_rawline(int fd, long *plen, char end) | |||
191 | } | 191 | } |
192 | 192 | ||
193 | 193 | ||
194 | static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *command, char *arguments) | 194 | static boolean LuaSLParser(void *data, Connection *conn, char *SID, char *command, char *arguments) |
195 | { | 195 | { |
196 | gameGlobals *ourGlobals = data; | 196 | gameGlobals *ourGlobals = data; |
197 | char buf[PATH_MAX]; | 197 | char buf[PATH_MAX]; |
@@ -256,22 +256,20 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm | |||
256 | struct timeval now; | 256 | struct timeval now; |
257 | 257 | ||
258 | compiledCount++; | 258 | compiledCount++; |
259 | if ('t' == arguments[0]) | ||
260 | send2(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName); | ||
261 | else | ||
262 | PE("The compile of %s.%s failed!", SID, me->fileName); | ||
263 | |||
259 | if (compiledCount == scriptCount) | 264 | if (compiledCount == scriptCount) |
260 | { | 265 | { |
261 | float total = timeDiff(&now, &startTime); | 266 | float total = timeDiff(&now, &startTime); |
267 | |||
262 | PI("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total); | 268 | PI("Compile speed scripts: %d time: %fs total: %f scripts per second", compiledCount, total, compiledCount / total); |
263 | } | 269 | } |
264 | } | 270 | } |
265 | |||
266 | if ('t' == arguments[0]) | ||
267 | { | ||
268 | //PD("About to run %s", me->fileName); | ||
269 | send2(ourGlobals->serverLuaSL, SID, "run(%s)", me->fileName); | ||
270 | } | ||
271 | else | 271 | else |
272 | { | 272 | PE("We got a compiled() on non existing script - %s?", SID); |
273 | // PE("The compile of %s failed!", SID); | ||
274 | } | ||
275 | } | 273 | } |
276 | else | 274 | else |
277 | { | 275 | { |
@@ -453,10 +451,10 @@ static Eina_Bool LuaSLParser(void *data, Connection *conn, char *SID, char *comm | |||
453 | 451 | ||
454 | } | 452 | } |
455 | else | 453 | else |
456 | PI("Script %s sent command %s(%s", SID, command, arguments); | 454 | return FALSE; |
457 | } | 455 | } |
458 | 456 | ||
459 | return ECORE_CALLBACK_RENEW; | 457 | return TRUE; |
460 | } | 458 | } |
461 | 459 | ||
462 | static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) | 460 | static Eina_Bool _delLuaSL(void *data, int type, Ecore_Con_Event_Server_Del *ev) |
@@ -489,7 +487,7 @@ static Eina_Bool _addClient(void *data, int type, Ecore_Con_Event_Client_Add *ev | |||
489 | return ECORE_CALLBACK_RENEW; | 487 | return ECORE_CALLBACK_RENEW; |
490 | } | 488 | } |
491 | 489 | ||
492 | static Eina_Bool clientParser(void *data, Connection *conn, char *SID, char *command, char *arguments) | 490 | static boolean clientParser(void *data, Connection *conn, char *SID, char *command, char *arguments) |
493 | { | 491 | { |
494 | gameGlobals *ourGlobals = data; | 492 | gameGlobals *ourGlobals = data; |
495 | 493 | ||
@@ -524,9 +522,9 @@ static Eina_Bool clientParser(void *data, Connection *conn, char *SID, char *com | |||
524 | eina_iterator_free(scripts); | 522 | eina_iterator_free(scripts); |
525 | } | 523 | } |
526 | else | 524 | else |
527 | PW("Unknown command from client - %s(%s", command, arguments); | 525 | return FALSE; |
528 | 526 | ||
529 | return ECORE_CALLBACK_RENEW; | 527 | return TRUE; |
530 | } | 528 | } |
531 | 529 | ||
532 | static Eina_Bool _delClient(void *data, int type, Ecore_Con_Event_Client_Del *ev) | 530 | static Eina_Bool _delClient(void *data, int type, Ecore_Con_Event_Client_Del *ev) |
@@ -670,10 +668,10 @@ int main(int argc, char **argv) | |||
670 | 668 | ||
671 | // PD("About to try connecting to a LuaSL server."); | 669 | // PD("About to try connecting to a LuaSL server."); |
672 | // Try to connect to a local LuaSL server. | 670 | // Try to connect to a local LuaSL server. |
673 | 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); | 671 | 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, NULL); |
674 | 672 | ||
675 | // PD("Love is about to try creating a love server."); | 673 | // PD("Love is about to try creating a love server."); |
676 | if (openArms("love", ourGlobals.address, ourGlobals.port + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _addClient, NULL, (Ecore_Event_Handler_Cb) _delClient, clientParser)) | 674 | if (openArms("love", ourGlobals.address, ourGlobals.port + 1, &ourGlobals, (Ecore_Event_Handler_Cb) _addClient, NULL, (Ecore_Event_Handler_Cb) _delClient, clientParser, NULL)) |
677 | { | 675 | { |
678 | ecore_main_loop_begin(); | 676 | ecore_main_loop_begin(); |
679 | PD("Fell out of the main loop"); | 677 | PD("Fell out of the main loop"); |