mirror of
https://github.com/EnergyMech/energymech.git
synced 2025-12-29 16:14:43 +00:00
merged .c files, fixed dcc/telnet clients lost on reset, rewrote reset some
This commit is contained in:
192
src/reset.c
192
src/reset.c
@@ -30,42 +30,29 @@
|
||||
LS int client_type = DCC_ACTIVE;
|
||||
#endif /* TELNET */
|
||||
|
||||
#define mkaxx(x) (0x40404040 + (0x0f0f & x) + ((0xf0f0 & x) << 12))
|
||||
#define getaxx(x) (((x & 0x0f0f0000) >> 12) | (x & 0x00000f0f))
|
||||
|
||||
char *recover_client(char *env)
|
||||
{
|
||||
union {
|
||||
uint32_t num[2];
|
||||
char asc[8];
|
||||
} axx;
|
||||
struct sockaddr_in sai;
|
||||
Client *client;
|
||||
User *user;
|
||||
char *p,*handle;
|
||||
int guid,fd,sz;
|
||||
int guid = 0,fd = 0,sz;
|
||||
|
||||
guid = fd = 0;
|
||||
p = env;
|
||||
|
||||
/*
|
||||
* get the guid number
|
||||
*/
|
||||
while(*p >= '0' && *p <= '9')
|
||||
{
|
||||
guid = (guid * 10) + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
if (*p != ':')
|
||||
if (env[8] != ':')
|
||||
return(env);
|
||||
p++;
|
||||
|
||||
/*
|
||||
* get the fd number
|
||||
*/
|
||||
while(*p >= '0' && *p <= '9')
|
||||
{
|
||||
fd = (fd * 10) + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
if (*p != ':')
|
||||
return(env);
|
||||
p++;
|
||||
memcpy(axx.asc,env,8); // compiler is not stupid and will optimize the shit out of this
|
||||
guid = getaxx(axx.num[0]);
|
||||
fd = getaxx(axx.num[1]);
|
||||
|
||||
handle = p;
|
||||
handle = p = (env = env + 9);
|
||||
while(*p)
|
||||
{
|
||||
if (*p == ' ' || *p == 0)
|
||||
@@ -150,22 +137,21 @@ found_user:
|
||||
|
||||
char *recover_debug(char *env)
|
||||
{
|
||||
union {
|
||||
uint32_t num;
|
||||
char asc[4];
|
||||
} axx;
|
||||
struct stat s;
|
||||
char *p;
|
||||
|
||||
debug_fd = 0;
|
||||
p = env;
|
||||
|
||||
if (env[4] != ' ' && env[4] != 0)
|
||||
return(env);
|
||||
/*
|
||||
* get the fd number
|
||||
*/
|
||||
while(*p >= '0' && *p <= '9')
|
||||
{
|
||||
debug_fd = (debug_fd * 10) + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
if (*p != ' ' && *p != 0)
|
||||
return(env);
|
||||
memcpy(axx.asc,env,4); // compiler is not stupid and will optimize the shit out of this
|
||||
debug_fd = getaxx(axx.num);
|
||||
|
||||
if (fstat(debug_fd,&s) < 0)
|
||||
{
|
||||
@@ -176,71 +162,57 @@ char *recover_debug(char *env)
|
||||
else
|
||||
{
|
||||
dodebug = TRUE;
|
||||
debug("(recover_debug) debug fd recovered\n");
|
||||
debug("(recover_debug) {%i} debug fd recovered\n",debug_fd);
|
||||
CoreClient.sock = debug_fd;
|
||||
}
|
||||
return(p);
|
||||
return(env+4);
|
||||
}
|
||||
|
||||
#endif /* DEBUG */
|
||||
|
||||
//execve( ./energymech, argv = { ./energymech <NULL> <NULL> <NULL> <NULL> }, envp = { MECHRESET=d3 f1881:2:X12 f99:4:X12 } )
|
||||
/*
|
||||
(do_reset) mkaxx(3) = C@@@
|
||||
(do_reset) ircx mkaxx(12) = L@@@
|
||||
(do_reset) sock mkaxx(2) = B@@@
|
||||
(do_reset) guid mkaxx(1881) = IGE@
|
||||
[StS] {2} PING :OT1523818405
|
||||
(do_reset) MECHRESET=dC@@@ fXIGE@B@@@L@@@ tIGE@F@@@:joo [44]
|
||||
execve( ./energymech, argv = { ./energymech <NULL> <NULL> <NULL> <NULL> }, envp = { MECHRESET=dC@@@ fXIGE@B@@@L@@@ tIGE@F@@@:joo } )
|
||||
*/
|
||||
|
||||
char *recover_server(char *env)
|
||||
{
|
||||
union {
|
||||
uint32_t num[4];
|
||||
char asc[16];
|
||||
} axx;
|
||||
struct sockaddr_in sai;
|
||||
char *p;
|
||||
int guid,fd,sz;
|
||||
int guid = 0,fd = 0,sz;
|
||||
#ifdef IRCD_EXTENSIONS
|
||||
int ircx = 0;
|
||||
#endif /* IRCD_EXTENSIONS */
|
||||
|
||||
guid = fd = 0;
|
||||
p = env;
|
||||
|
||||
/*
|
||||
* get the guid number
|
||||
*/
|
||||
while(*p >= '0' && *p <= '9')
|
||||
switch(*env++)
|
||||
{
|
||||
guid = (guid * 10) + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
if (*p != ':')
|
||||
case 'x':
|
||||
sz = 8;
|
||||
break;
|
||||
case 'X':
|
||||
sz = 12;
|
||||
break;
|
||||
default:
|
||||
return(env);
|
||||
p++;
|
||||
|
||||
/*
|
||||
* get the fd number
|
||||
*/
|
||||
while(*p >= '0' && *p <= '9')
|
||||
{
|
||||
fd = (fd * 10) + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
#ifndef IRCD_EXTENSIONS
|
||||
if (*p != ' ' && *p != 0)
|
||||
if (env[sz] != ' ' && env[sz] != 0)
|
||||
return(env);
|
||||
#endif /* ! IRCD_EXTENSIONS */
|
||||
|
||||
memcpy(axx.asc,env,sz); // compiler is not stupid and will optimize the shit out of this
|
||||
env += sz;
|
||||
guid = getaxx(axx.num[0]);
|
||||
fd = getaxx(axx.num[1]);
|
||||
#ifdef IRCD_EXTENSIONS
|
||||
if (*p == ':' && *(p+1) == 'X')
|
||||
{
|
||||
p += 2;
|
||||
/*
|
||||
* get the ircx flags number
|
||||
*/
|
||||
while(*p >= '0' && *p <= '9')
|
||||
{
|
||||
ircx = (ircx * 10) + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
if (*p != ' ' && *p != 0)
|
||||
return(env);
|
||||
}
|
||||
else
|
||||
if (*p != ' ' && *p != 0)
|
||||
return(env);
|
||||
ircx = getaxx(axx.num[2]);
|
||||
#ifdef DEBUG
|
||||
debug("(recover_server) guid = %i; fd = %i, ircx = %i\n",guid,fd,ircx);
|
||||
#endif /* DEBUG */
|
||||
@@ -254,7 +226,7 @@ char *recover_server(char *env)
|
||||
if (getsockname(fd,(struct sockaddr*)&sai,&sz) < 0)
|
||||
{
|
||||
close(fd);
|
||||
return(p);
|
||||
return(env);
|
||||
}
|
||||
for(current=botlist;current;current=current->next)
|
||||
{
|
||||
@@ -282,19 +254,11 @@ char *recover_server(char *env)
|
||||
to_file(fd,"QUIT :I'm no longer wanted *cry*\n");
|
||||
killsock(fd);
|
||||
}
|
||||
return(p);
|
||||
return(env);
|
||||
}
|
||||
|
||||
#ifdef IRCD_EXTENSIONS
|
||||
|
||||
/*
|
||||
#define IRCX_WALLCHOPS 1
|
||||
#define IRCX_WALLVOICES 2
|
||||
#define IRCX_IMODE 4
|
||||
#define IRCX_EMODE 8
|
||||
*/
|
||||
|
||||
#endif /* IRCD_EXTENSIONS */
|
||||
//(do_reset) MECHRESET=dC@@@ fXIGE@A@@@L@@@ tIGE@F@@@:joo [44]
|
||||
//execve( ./energymech, argv = { ./energymech <NULL> <NULL> <NULL> <NULL> }, envp = { MECHRESET=dC@@@ fXIGE@A@@@L@@@ tIGE@F@@@:joo } )
|
||||
|
||||
void recover_reset(void)
|
||||
{
|
||||
@@ -329,17 +293,23 @@ void recover_reset(void)
|
||||
default:
|
||||
env++;
|
||||
}
|
||||
while(*env == ' ')
|
||||
env++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* commands
|
||||
*
|
||||
*/
|
||||
-+=====================================================================================================================+-
|
||||
reset.c commands
|
||||
-+=====================================================================================================================+-
|
||||
*/
|
||||
|
||||
void do_reset(COMMAND_ARGS)
|
||||
{
|
||||
union {
|
||||
uint32_t num[8];
|
||||
char asc[32];
|
||||
} axx;
|
||||
Client *client;
|
||||
Mech *backup;
|
||||
char env[MSGLEN];
|
||||
@@ -372,16 +342,16 @@ void do_reset(COMMAND_ARGS)
|
||||
|
||||
*env = 0;
|
||||
p = stringcat(env,STR_MECHRESET);
|
||||
n = 0;
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
* debug stuff
|
||||
*/
|
||||
if (dodebug && (debug_fd >= 0))
|
||||
{
|
||||
sprintf(p,"d%i",debug_fd);
|
||||
axx.num[0] = mkaxx(debug_fd);
|
||||
axx.num[1] = 0;
|
||||
sprintf(p,"d%s",axx.asc);
|
||||
p = STREND(p);
|
||||
n++;
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
/*
|
||||
@@ -393,15 +363,17 @@ void do_reset(COMMAND_ARGS)
|
||||
if ((current->connect == CN_ONLINE) && ((MSGLEN - (p - env)) > 25))
|
||||
{
|
||||
unset_closeonexec(current->sock);
|
||||
if (n)
|
||||
*(p++) = ' ';
|
||||
axx.num[0] = mkaxx(current->guid);
|
||||
axx.num[1] = mkaxx(current->sock);
|
||||
#ifdef IRCD_EXTENSIONS
|
||||
sprintf(p,"f%i:%i:X%i",current->guid,current->sock,current->ircx_flags);
|
||||
axx.num[2] = mkaxx(current->ircx_flags);
|
||||
axx.num[3] = 0;
|
||||
sprintf(p," fX%s",axx.asc);
|
||||
#else /* IRCD_EXTENSIONS */
|
||||
sprintf(p,"f%i:%i",current->guid,current->sock);
|
||||
axx.num[2] = 0;
|
||||
sprintf(p," fx%s",axx.asc);
|
||||
#endif /* IRCD_EXTENSIONS */
|
||||
p = STREND(p);
|
||||
n++;
|
||||
to_server("PING :OT%lu\n",current->ontime);
|
||||
}
|
||||
for(client=current->clientlist;client;client=client->next)
|
||||
@@ -417,16 +389,16 @@ void do_reset(COMMAND_ARGS)
|
||||
if ((MSGLEN - (p - env)) > sz)
|
||||
{
|
||||
unset_closeonexec(client->sock);
|
||||
if (n)
|
||||
*(p++) = ' ';
|
||||
axx.num[0] = mkaxx(current->guid);
|
||||
axx.num[1] = mkaxx(client->sock);
|
||||
axx.num[2] = 0;
|
||||
#ifdef TELNET
|
||||
sprintf(p,(client->flags & DCC_TELNET) ? "t%i:%i:%s" : "c%i:%i:%s",
|
||||
current->guid,current->sock,client->user->name);
|
||||
sprintf(p,(client->flags & DCC_TELNET) ? " t%s:%s" : " c%s:%s",
|
||||
axx.asc,client->user->name);
|
||||
#else
|
||||
sprintf(p,"c%i:%i:%s",current->guid,current->sock,client->user->name);
|
||||
sprintf(p," c%s:%s",axx.asc,client->user->name);
|
||||
#endif /* TELNET */
|
||||
p = STREND(p);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,7 +408,7 @@ void do_reset(COMMAND_ARGS)
|
||||
debug("(do_reset) %s [%i]\n",env,(int)(p - env));
|
||||
#endif /* DEBUG */
|
||||
|
||||
mechresetenv = (n) ? env : NULL;
|
||||
mechresetenv = (*env) ? env : NULL;
|
||||
|
||||
do_exec = TRUE;
|
||||
mech_exec();
|
||||
|
||||
Reference in New Issue
Block a user