aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/LuaSL/LuaSL_utilities.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/LuaSL/LuaSL_utilities.c')
-rw-r--r--src/LuaSL/LuaSL_utilities.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/LuaSL/LuaSL_utilities.c b/src/LuaSL/LuaSL_utilities.c
new file mode 100644
index 0000000..40263df
--- /dev/null
+++ b/src/LuaSL/LuaSL_utilities.c
@@ -0,0 +1,60 @@
1#include "LuaSL.h"
2
3
4void sendBack(gameGlobals *ourGlobals, Ecore_Con_Client *client, const char *SID, const char *message, ...)
5{
6 va_list args;
7 char buf[PATH_MAX];
8 int length = strlen(SID);
9
10 strncpy(buf, SID, length);
11 buf[length++] = '.';
12 va_start(args, message);
13 length += vsprintf(&buf[length], message, args);
14 va_end(args);
15 buf[length++] = '\n';
16 buf[length++] = '\0';
17 ecore_con_client_send(client, buf, strlen(buf));
18 ecore_con_client_flush(client);
19}
20
21void sendForth(gameGlobals *ourGlobals, const char *SID, const char *message, ...)
22{
23 va_list args;
24 char buf[PATH_MAX];
25 int length = strlen(SID);
26
27 strncpy(buf, SID, length);
28 buf[length++] = '.';
29 va_start(args, message);
30 length += vsprintf(&buf[length], message, args);
31 va_end(args);
32 buf[length++] = '\n';
33 buf[length++] = '\0';
34 ecore_con_server_send(ourGlobals->server, buf, strlen(buf));
35 ecore_con_server_flush(ourGlobals->server);
36}
37
38float timeDiff(struct timeval *now, struct timeval *then)
39{
40 if (0 == gettimeofday(now, 0))
41 {
42 struct timeval thisTime = { 0, 0 };
43 double result = 0.0;
44
45 thisTime.tv_sec = now->tv_sec;
46 thisTime.tv_usec = now->tv_usec;
47 if (thisTime.tv_usec < then->tv_usec)
48 {
49 thisTime.tv_sec--;
50 thisTime.tv_usec += 1000000;
51 }
52 thisTime.tv_usec -= then->tv_usec;
53 thisTime.tv_sec -= then->tv_sec;
54 result = ((double) thisTime.tv_usec) / ((double) 1000000.0);
55 result += thisTime.tv_sec;
56 return result;
57 }
58 else
59 return 0.0;
60}