aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/LuaSL
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-02-05 16:38:58 +1000
committerDavid Walter Seikel2016-02-05 16:38:58 +1000
commit76faf8a71ca29aef0de066fb3a31823227b6d95d (patch)
treee7bd6bf9ddb63569c4b98e1679631fa1103d0300 /src/LuaSL
parentAuthors++ (diff)
downloadSledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.zip
SledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.tar.gz
SledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.tar.bz2
SledjHamr-76faf8a71ca29aef0de066fb3a31823227b6d95d.tar.xz
The next step in cleaning up the network Lua messages.
Diffstat (limited to 'src/LuaSL')
-rw-r--r--src/LuaSL/LuaSL_main.c70
1 files changed, 44 insertions, 26 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
72static void send2server(script *me, const char *message) 72static 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
80static 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
176static void _compileCb(LuaCompiler *compiler) 192static 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
221static Eina_Bool parser(void *data, Connection *connection, char *SID, char *command, char *arguments) 237static 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
289int main(int argc, char **argv) 307int 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;