Added LICENSE; Added GPL2 header to all source code files
[ArenaLive.git] / action.c
blob11045f35089b2d0b1126b1caee83334edde9054f
1 /*
2 * (C) Copyright 2009 ZeXx86 (zexx86@gmail.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <stdio.h>
22 #include <ctype.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <sys/un.h>
29 #include "glugin.h"
31 int plugin_action_0 (pluginData *pd)
33 Log ("action_0");
35 return creat ("/tmp/.arenalivep", 0777);
39 int plugin_action_1 (pluginData *pd)
41 int s, s2, t, l;
42 struct sockaddr_un local, remote;
44 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) {
45 Log ("socket == -1");
46 return -1;
49 local.sun_family = AF_UNIX;
50 strcpy (local.sun_path, "/tmp/.arenalive");
51 unlink (local.sun_path);
53 l = strlen (local.sun_path) + sizeof (local.sun_family);
55 if (bind (s, (struct sockaddr *) &local, l) == -1) {
56 Log ("bind == -1");
57 return -1;
60 if (listen (s, 5) == -1)
61 return -1;
63 t = sizeof (remote);
65 pid_t child = fork ();
67 if (child == -1)
68 return -1;
70 if (!child) {
71 char *user = getenv ("USER");
73 if (!user)
74 return -1;
76 char cmd[512];
77 sprintf (cmd, "/home/%s/.arenalive/%s %s &> /home/%s/.arenalive/log",
78 user, "arenalive-linux", pd->conparam, user);
80 Log ("-- %s", cmd);
82 system (cmd);
84 /*system ("/home/tomas/Programming/arenalive/ioquake3_1.34-rc3/build/release-linux-x86_64/ioquake3.x86_64 +set fs_basepath \"/usr/share/games/quake3/\" +set r_fullscreen 0 +set r_mode 4 &> /home/tomas/glugin/log");*/
86 _exit (0);
89 if ((s2 = accept (s, (struct sockaddr *) &remote, (unsigned *) &t)) == -1) {
90 Log ("accept == -1");
91 return -1;
94 char str[sizeof (Window)+1];
96 memcpy (str, &pd->win, sizeof (Window));
98 if (send (s2, str, sizeof (Window), 0) < 0)
99 return -1;
101 close (s2);
103 /* plugin loop */
104 glugin_proc (pd);
106 return 0;
109 int plugin_action (pluginData *pd)
111 switch (pd->action) {
112 case 0:
113 return plugin_action_0 (pd);
114 case 1:
115 return plugin_action_1 (pd);
118 return -1;