aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/sledjchisl/sledjchisl.c159
1 files changed, 99 insertions, 60 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c
index 4f9fa7c..79a3b57 100644
--- a/src/sledjchisl/sledjchisl.c
+++ b/src/sledjchisl/sledjchisl.c
@@ -1114,7 +1114,7 @@ struct _simData
1114 int locX, locY, sizeX, sizeY, sizeZ, portH, portU, maxPrims; 1114 int locX, locY, sizeX, sizeY, sizeZ, portH, portU, maxPrims;
1115 char *name, *tab, *UUID, *regionType, *estate, *owner; 1115 char *name, *tab, *UUID, *regionType, *estate, *owner;
1116 char *paneID; 1116 char *paneID;
1117 int window, pane; 1117 int window, pane, users;
1118}; 1118};
1119 1119
1120typedef struct _simList simList; 1120typedef struct _simList simList;
@@ -1813,16 +1813,40 @@ void stopSim(simData *simd, char *sim, char *type, int count, int window, int pa
1813 if (checkSimIsRunning(simd->tab)) 1813 if (checkSimIsRunning(simd->tab))
1814 { 1814 {
1815 // Leave empty panes as is. 1815 // Leave empty panes as is.
1816// TODO - should check if there's people there, but don't count NPCs. alert them, wait a while, or just abort the stop. 1816 V("Attempting to shut down sim %s.", simd->tab);
1817/* show users 1817 sendTmuxCmd(simd->paneID, "show users");
1818 1818 sleep(1);
1819Agents connected: 1 1819 char *cmd = xmprintf("%s %s/%s capture-pane -Jt '%s' -p | grep -E '^Agents connected: [[:digit:]]*[[:space:]]*$' | tail -n 1 | cut -d ' ' -f 3 >%s/STOP_%s",
1820 1820 Tcmd, scRun, Tsocket, simd->paneID, scTemp, simd->tab);
1821Firstname Lastname Agent ID child/NPC/root Region Position 1821 int i = system(cmd);
1822Baby Barby 3548202e-1659-4055-b406-d578ef728fe0 NPC Naughtie Nautical <623.2795, 178.0885, 103.8343> 1822 if (WIFEXITED(i))
1823 {
1824 free(cmd);
1825 cmd = xmprintf("%s/STOP_%s", scTemp, simd->tab);
1826 char *r = (char *) qfile_load(cmd, NULL);
1827 if (r)
1828 {
1829 if ('0' == r[0])
1830 sendTmuxCmd(simd->paneID, "quit");
1831 else
1832 {
1833 r[strlen(r) - 1] = '\0';
1834 simd->users = atoi(r);
1835 sendTmuxCmd(simd->paneID, "alert Shutting down this sim, please leave.");
1836 sendTmuxCmd(simd->paneID, "region restart bluebox \"Shutting down this sim, please leave.\" 300");
1837 sendTmuxCmd(simd->paneID, "region restart notice \"Shutting down this sim, please leave.\" 300");
1838 sendTmuxCmd(simd->paneID, "region restart abort \"Shutting down this sim, please leave.\"");
1839 W("Not shutting down %s coz %d people are still on it. They have been warned.", simd->tab, simd->users);
1840 }
1841 free(r);
1842 }
1843 else
1844 E("Problem with shutting down sim %s - Failed to read file %s", simd->tab, cmd);
1845 }
1846 else
1847 E("Problem with shutting down sim %s - Failed to run command \n %s", simd->tab, cmd);
1848 free(cmd);
1823 1849
1824*/
1825 sendTmuxCmd(simd->paneID, "quit");
1826 // There's three things that might happen - 1850 // There's three things that might happen -
1827 // Sim will quit, tmux pane will go away before we can see the shutdown message. 1851 // Sim will quit, tmux pane will go away before we can see the shutdown message.
1828 // pane-exited hook might be useful here. 1852 // pane-exited hook might be useful here.
@@ -2006,11 +2030,19 @@ void stopSims(simData *simd, char *sim, char *type, int count, int window, int p
2006 // NOTE - these sleeps are guesses, seems to work on my super desktop during testing. 2030 // NOTE - these sleeps are guesses, seems to work on my super desktop during testing.
2007 if (checkSimIsRunning(simd->tab)) 2031 if (checkSimIsRunning(simd->tab))
2008 T("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s has NOT stopped YET.", window, type, pane, simd->paneID, scTemp, count, simd->name); 2032 T("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s has NOT stopped YET.", window, type, pane, simd->paneID, scTemp, count, simd->name);
2009 while (checkSimIsRunning(simd->tab)) 2033 if (simd->users)
2010 usleep(100000); 2034 {
2011 usleep(10000); 2035 ourSims->doIt = 0;
2012 doTmuxCmd("kill-pane -t %s", simd->paneID); 2036 W("Not shutting down %s coz %d people are still on it. They have been warned.", simd->tab, simd->users);
2013 I("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s has stopped.", window, type, pane, simd->paneID, scTemp, count, simd->name); 2037 }
2038 else
2039 {
2040 while (checkSimIsRunning(simd->tab))
2041 usleep(100000);
2042 usleep(10000);
2043 doTmuxCmd("kill-pane -t %s", simd->paneID);
2044 I("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s has stopped.", window, type, pane, simd->paneID, scTemp, count, simd->name);
2045 }
2014} 2046}
2015 2047
2016 2048
@@ -8109,60 +8141,67 @@ jit library is loaded or the JIT compiler will not be activated.
8109 if ((STOP == currentMode) && (NULL == ourSims->target)) 8141 if ((STOP == currentMode) && (NULL == ourSims->target))
8110 { 8142 {
8111 // Stop all the sims. 8143 // Stop all the sims.
8144 ourSims->doIt = 1;
8112 forEachSim(NULL, stopSims, NULL); 8145 forEachSim(NULL, stopSims, NULL);
8113 8146
8114 if (checkSimIsRunning("ROBUST")) 8147 if (ourSims->doIt)
8115 { 8148 {
8116 sendTmuxCmd("@0.%0", "quit"); 8149 if (checkSimIsRunning("ROBUST"))
8117 while (checkSimIsRunning("ROBUST")) 8150 {
8118 usleep(100000); 8151 sendTmuxCmd("@0.%0", "quit");
8119 usleep(100000); 8152 while (checkSimIsRunning("ROBUST"))
8120 sendTmuxCmd("@0.%0", "exit"); 8153 usleep(100000);
8121 usleep(100000); 8154 usleep(100000);
8122 sendTmuxCmd("@0.%0", "exit"); 8155 sendTmuxCmd("@0.%0", "exit");
8123 I("ROBUST has stopped in tmux ID @0.%%0."); 8156 usleep(100000);
8124 } 8157 sendTmuxCmd("@0.%0", "exit");
8158 I("ROBUST has stopped in tmux ID @0.%%0.");
8159 }
8125 8160
8126 I("Closing all the other windows."); 8161 if (FLAG(a))
8127 // First figure out what panes and windows are left. 8162 {
8128 snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_ALL.lua", scTemp); 8163 I("Closing all the other windows.");
8129 system(toybuf); 8164 // First figure out what panes and windows are left.
8130 doTmuxCmd("list-panes -s -F '\"#{window_id}.#{pane_id}\",' >> %s/IDs_ALL.lua", scTemp); 8165 snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_ALL.lua", scTemp);
8131 snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_ALL.lua", scTemp); 8166 system(toybuf);
8132 system(toybuf); 8167 doTmuxCmd("list-panes -s -F '\"#{window_id}.#{pane_id}\",' >> %s/IDs_ALL.lua", scTemp);
8133 snprintf(toybuf, sizeof(toybuf), "%s/IDs_ALL.lua", scTemp); 8168 snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_ALL.lua", scTemp);
8134 qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); 8169 system(toybuf);
8135 8170 snprintf(toybuf, sizeof(toybuf), "%s/IDs_ALL.lua", scTemp);
8136 char *c = xmprintf("rm -fr %s/*", scTemp); 8171 qtreetbl_t *IDs = Lua2tree(toybuf, "IDs");
8137 if (!WIFEXITED(system(c))) 8172
8138 E("rm command failed! %s", c); 8173 char *c = xmprintf("rm -fr %s/*", scTemp);
8139 free(c); 8174 if (!WIFEXITED(system(c)))
8175 E("rm command failed! %s", c);
8176 free(c);
8177
8178 qtreetbl_obj_t obj0;
8179 memset((void*)&obj0, 0, sizeof(obj0));
8180 IDs->lock(IDs);
8181 while(IDs->getnext(IDs, &obj0, false) == true)
8182 {
8183 qLua *q0 = obj0.data;
8140 8184
8141 qtreetbl_obj_t obj0; 8185 if ('0' != q0->v.s[1])
8142 memset((void*)&obj0, 0, sizeof(obj0)); 8186 doTmuxCmd("kill-pane -t %s", q0->v.s);
8143 IDs->lock(IDs); 8187 }
8144 while(IDs->getnext(IDs, &obj0, false) == true) 8188 IDs->unlock(IDs);
8145 {
8146 qLua *q0 = obj0.data;
8147 8189
8148 if ('0' != q0->v.s[1]) 8190 I("Closing the original window.");
8149 doTmuxCmd("kill-pane -t %s", q0->v.s); 8191 memset((void*)&obj0, 0, sizeof(obj0));
8150 } 8192 IDs->lock(IDs);
8151 IDs->unlock(IDs); 8193 while(IDs->getnext(IDs, &obj0, false) == true)
8194 {
8195 qLua *q0 = obj0.data;
8152 8196
8153 I("Closing the original window."); 8197 if ('0' == q0->v.s[1])
8154 memset((void*)&obj0, 0, sizeof(obj0)); 8198 doTmuxCmd("kill-pane -t %s", q0->v.s);
8155 IDs->lock(IDs); 8199 }
8156 while(IDs->getnext(IDs, &obj0, false) == true) 8200 IDs->unlock(IDs);
8157 {
8158 qLua *q0 = obj0.data;
8159 8201
8160 if ('0' == q0->v.s[1]) 8202 freeLuaTree(IDs);
8161 doTmuxCmd("kill-pane -t %s", q0->v.s); 8203 }
8162 } 8204 }
8163 IDs->unlock(IDs);
8164
8165 freeLuaTree(IDs);
8166 } 8205 }
8167 else if (START == currentMode) 8206 else if (START == currentMode)
8168 { 8207 {