1
0
Fork 0

(svn r954) -Fix: [Console] Hook fixes (sign_de)

-Add: [Console] Auto sort commands and variables (sign_de)
release/0.4.5
truelight 2004-12-05 12:25:25 +00:00
parent cef5ac8c8b
commit 1de8e294d8
3 changed files with 122 additions and 71 deletions

111
console.c
View File

@ -439,6 +439,7 @@ void IConsoleCmdRegister(const char* name, _iconsole_cmd_addr addr)
char* _new; char* _new;
_iconsole_cmd* item; _iconsole_cmd* item;
_iconsole_cmd* item_new; _iconsole_cmd* item_new;
_iconsole_cmd* item_before;
_new = strdup(name); _new = strdup(name);
@ -452,13 +453,39 @@ void IConsoleCmdRegister(const char* name, _iconsole_cmd_addr addr)
item_new->hook_after_exec = NULL; item_new->hook_after_exec = NULL;
item_new->hook_before_exec = NULL; item_new->hook_before_exec = NULL;
item_before = NULL;
item = _iconsole_cmds; item = _iconsole_cmds;
if (item == NULL) { if (item == NULL) {
_iconsole_cmds = item_new; _iconsole_cmds = item_new;
} else { } else {
while (item->_next != NULL) item = item->_next; while ((item->_next != NULL) && (strcmp(item->name,item_new->name)<=0)) {
item->_next = item_new; item_before = item;
item = item->_next;
}
// insertion sort
if (item_before==NULL) {
if (strcmp(item->name,item_new->name)<=0) {
// appending
item ->_next = item_new;
} else {
// inserting as startitem
_iconsole_cmds = item_new;
item_new ->_next = item;
}
} else {
if (strcmp(item->name,item_new->name)<=0) {
// appending
item ->_next = item_new;
} else {
// inserting
item_new ->_next = item_before->_next;
item_before ->_next = item_new;
}
}
// insertion sort end
} }
} }
_iconsole_cmd* IConsoleCmdGet(const char* name) _iconsole_cmd* IConsoleCmdGet(const char* name)
@ -473,17 +500,58 @@ _iconsole_cmd* IConsoleCmdGet(const char* name)
return NULL; return NULL;
} }
void IConsoleVarRegister(const char* name, void* addr, _iconsole_var_types type) void IConsoleVarInsert(_iconsole_var* item_new, const char* name)
{ {
_iconsole_var* item; _iconsole_var* item;
_iconsole_var* item_new; _iconsole_var* item_before;
item_new = malloc(sizeof(_iconsole_var)); /* XXX unchecked malloc */ item_new->_next = NULL;
item_new->name = malloc(strlen(name) + 2); /* XXX unchecked malloc */ item_new->name = malloc(strlen(name) + 2); /* XXX unchecked malloc */
sprintf(item_new->name, "%s", name); sprintf(item_new->name, "%s", name);
item_before = NULL;
item = _iconsole_vars;
if (item == NULL) {
_iconsole_vars = item_new;
} else {
while ((item->_next != NULL) && (strcmp(item->name,item_new->name)<=0)) {
item_before = item;
item = item->_next;
}
// insertion sort
if (item_before==NULL) {
if (strcmp(item->name,item_new->name)<=0) {
// appending
item ->_next = item_new;
} else {
// inserting as startitem
_iconsole_vars = item_new;
item_new ->_next = item;
}
} else {
if (strcmp(item->name,item_new->name)<=0) {
// appending
item ->_next = item_new;
} else {
// inserting
item_new ->_next = item_before->_next;
item_before ->_next = item_new;
}
}
// insertion sort end
}
}
void IConsoleVarRegister(const char* name, void* addr, _iconsole_var_types type)
{
_iconsole_var* item_new;
item_new = malloc(sizeof(_iconsole_var)); /* XXX unchecked malloc */
item_new->_next = NULL; item_new->_next = NULL;
switch (type) { switch (type) {
case ICONSOLE_VAR_BOOLEAN: case ICONSOLE_VAR_BOOLEAN:
item_new->data.bool_ = addr; item_new->data.bool_ = addr;
@ -511,20 +579,16 @@ void IConsoleVarRegister(const char* name, void* addr, _iconsole_var_types type)
error("unknown console variable type"); error("unknown console variable type");
break; break;
} }
IConsoleVarInsert(item_new, name);
item_new->type = type; item_new->type = type;
item_new->_malloc = false; item_new->_malloc = false;
item_new->hook_access = NULL; item_new->hook_access = NULL;
item_new->hook_after_change = NULL; item_new->hook_after_change = NULL;
item_new->hook_before_change = NULL; item_new->hook_before_change = NULL;
item = _iconsole_vars;
if (item == NULL) {
_iconsole_vars = item_new;
} else {
while (item->_next != NULL) item = item->_next;
item->_next = item_new;
}
} }
void IConsoleVarMemRegister(const char* name, _iconsole_var_types type) void IConsoleVarMemRegister(const char* name, _iconsole_var_types type)
@ -534,27 +598,6 @@ void IConsoleVarMemRegister(const char* name, _iconsole_var_types type)
IConsoleVarInsert(item, name); IConsoleVarInsert(item, name);
} }
void IConsoleVarInsert(_iconsole_var* var, const char* name)
{
_iconsole_var* item;
// disallow building variable rings
if (var->_next != NULL) return;
var->name = malloc(strlen(name) + 2); /* XXX unchecked malloc */
sprintf(var->name, "%s", name);
item = _iconsole_vars;
if (item == NULL) {
_iconsole_vars = var;
} else {
while (item->_next != NULL) item = item->_next;
item->_next = var;
}
}
_iconsole_var* IConsoleVarGet(const char* name) _iconsole_var* IConsoleVarGet(const char* name)
{ {
_iconsole_var* item; _iconsole_var* item;

View File

@ -123,7 +123,7 @@ _iconsole_cmd* IConsoleCmdGet(const char* name);
void IConsoleVarRegister(const char* name, void* addr, _iconsole_var_types type); void IConsoleVarRegister(const char* name, void* addr, _iconsole_var_types type);
void IConsoleVarMemRegister(const char* name, _iconsole_var_types type); void IConsoleVarMemRegister(const char* name, _iconsole_var_types type);
void IConsoleVarInsert(_iconsole_var* var, const char* name); void IConsoleVarInsert(_iconsole_var* item_new, const char* name);
_iconsole_var* IConsoleVarGet(const char* name); _iconsole_var* IConsoleVarGet(const char* name);
_iconsole_var* IConsoleVarAlloc(_iconsole_var_types type); _iconsole_var* IConsoleVarAlloc(_iconsole_var_types type);
void IConsoleVarFree(_iconsole_var* var); void IConsoleVarFree(_iconsole_var* var);

View File

@ -52,6 +52,10 @@ DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetwork)
DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient) DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient)
{ {
if (!_network_available) {
IConsoleError("You can not use this command because there is no network available.");
return false;
}
if (!_network_server) { if (!_network_server) {
IConsoleError("This variable only makes sense for a network server."); IConsoleError("This variable only makes sense for a network server.");
return false; return false;
@ -61,7 +65,11 @@ DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient)
DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetClient) DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetClient)
{ {
if (!_networking || !_network_server) { if (!_network_available) {
IConsoleError("You can not use this command because there is no network available.");
return false;
}
if (!_network_server) {
IConsoleError("This command is only available for a network server."); IConsoleError("This command is only available for a network server.");
return false; return false;
} }
@ -70,8 +78,12 @@ DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetClient)
DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetServer) DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetServer)
{ {
if (!_networking || _network_server) { if (!_network_available) {
IConsoleError("You can not use this command for you are a network-server."); IConsoleError("You can not use this command because there is no network available.");
return false;
}
if (_network_server) {
IConsoleError("You can not use this command because you are a network-server.");
return false; return false;
} }
return true; return true;
@ -79,6 +91,10 @@ DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetServer)
DEF_CONSOLE_CMD_HOOK(ConCmdHookNeedNetwork) DEF_CONSOLE_CMD_HOOK(ConCmdHookNeedNetwork)
{ {
if (!_network_available) {
IConsoleError("You can not use this command because there is no network available.");
return false;
}
if (!_networking) { if (!_networking) {
IConsoleError("Not connected. Multiplayer only command."); IConsoleError("Not connected. Multiplayer only command.");
return false; return false;
@ -618,10 +634,12 @@ DEF_CONSOLE_CMD(ConSetPassword) {
void IConsoleDebugLibRegister() void IConsoleDebugLibRegister()
{ {
// stdlib // debugging variables and functions
extern bool _stdlib_con_developer; /* XXX extern in .c */ extern bool _stdlib_con_developer; /* XXX extern in .c */
IConsoleVarRegister("con_developer", &_stdlib_con_developer, ICONSOLE_VAR_BOOLEAN); IConsoleVarRegister("con_developer", &_stdlib_con_developer, ICONSOLE_VAR_BOOLEAN);
IConsoleVarMemRegister("temp_string", ICONSOLE_VAR_STRING);
IConsoleVarMemRegister("temp_string2", ICONSOLE_VAR_STRING);
IConsoleVarMemRegister("temp_bool", ICONSOLE_VAR_BOOLEAN); IConsoleVarMemRegister("temp_bool", ICONSOLE_VAR_BOOLEAN);
IConsoleVarMemRegister("temp_int16", ICONSOLE_VAR_INT16); IConsoleVarMemRegister("temp_int16", ICONSOLE_VAR_INT16);
IConsoleVarMemRegister("temp_int32", ICONSOLE_VAR_INT32); IConsoleVarMemRegister("temp_int32", ICONSOLE_VAR_INT32);
@ -629,8 +647,6 @@ void IConsoleDebugLibRegister()
IConsoleVarMemRegister("temp_uint16", ICONSOLE_VAR_UINT16); IConsoleVarMemRegister("temp_uint16", ICONSOLE_VAR_UINT16);
IConsoleVarMemRegister("temp_uint16_2", ICONSOLE_VAR_UINT16); IConsoleVarMemRegister("temp_uint16_2", ICONSOLE_VAR_UINT16);
IConsoleVarMemRegister("temp_uint32", ICONSOLE_VAR_UINT32); IConsoleVarMemRegister("temp_uint32", ICONSOLE_VAR_UINT32);
IConsoleVarMemRegister("temp_string", ICONSOLE_VAR_STRING);
IConsoleVarMemRegister("temp_string2", ICONSOLE_VAR_STRING);
IConsoleCmdRegister("resettile", ConResetTile); IConsoleCmdRegister("resettile", ConResetTile);
} }
#endif #endif
@ -644,16 +660,7 @@ void IConsoleStdLibRegister(void)
// stdlib // stdlib
extern byte _stdlib_developer; /* XXX extern in .c */ extern byte _stdlib_developer; /* XXX extern in .c */
#ifdef _DEBUG // default variables and functions
IConsoleDebugLibRegister();
#endif
// functions [please add them alphabetically]
#ifdef ENABLE_NETWORK
IConsoleCmdRegister("connect", ConNetworkConnect);
IConsoleCmdHook("connect", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetServer);
IConsoleCmdRegister("clients", ConNetworkClients);
#endif /* ENABLE_NETWORK */
IConsoleCmdRegister("debug_level", ConDebugLevel); IConsoleCmdRegister("debug_level", ConDebugLevel);
IConsoleCmdRegister("dump_vars", ConListDumpVariables); IConsoleCmdRegister("dump_vars", ConListDumpVariables);
IConsoleCmdRegister("echo", ConEcho); IConsoleCmdRegister("echo", ConEcho);
@ -665,22 +672,20 @@ void IConsoleStdLibRegister(void)
IConsoleCmdRegister("info_var", ConInfoVar); IConsoleCmdRegister("info_var", ConInfoVar);
IConsoleCmdRegister("list_cmds", ConListCommands); IConsoleCmdRegister("list_cmds", ConListCommands);
IConsoleCmdRegister("list_vars", ConListVariables); IConsoleCmdRegister("list_vars", ConListVariables);
#ifdef ENABLE_NETWORK
IConsoleCmdRegister("kick", ConKick);
IConsoleCmdHook("kick", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdRegister("protect", ConProtect);
IConsoleCmdRegister("name", ConClientName);
#endif
IConsoleCmdRegister("newgame", ConNewGame); IConsoleCmdRegister("newgame", ConNewGame);
IConsoleCmdRegister("printf", ConPrintF); IConsoleCmdRegister("printf", ConPrintF);
IConsoleCmdRegister("printfc", ConPrintFC); IConsoleCmdRegister("printfc", ConPrintFC);
IConsoleCmdRegister("quit", ConExit); IConsoleCmdRegister("quit", ConExit);
IConsoleCmdRegister("random", ConRandom); IConsoleCmdRegister("random", ConRandom);
IConsoleCmdRegister("resetengines", ConResetEngines); IConsoleCmdRegister("resetengines", ConResetEngines);
#ifdef ENABLE_NETWORK
IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);
#endif /* ENABLE_NETWORK */
IConsoleCmdRegister("return", ConReturn); IConsoleCmdRegister("return", ConReturn);
IConsoleCmdRegister("screenshot", ConScreenShot);
IConsoleCmdRegister("script", ConScript);
IConsoleCmdRegister("scrollto", ConScrollToTile);
IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE);
// networking variables and functions
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
IConsoleCmdRegister("say", ConSay); IConsoleCmdRegister("say", ConSay);
IConsoleCmdHook("say", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork); IConsoleCmdHook("say", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
@ -688,28 +693,31 @@ void IConsoleStdLibRegister(void)
IConsoleCmdHook("say_player", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork); IConsoleCmdHook("say_player", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
IConsoleCmdRegister("say_client", ConSayClient); IConsoleCmdRegister("say_client", ConSayClient);
IConsoleCmdHook("say_client", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork); IConsoleCmdHook("say_client", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
#endif /* ENABLE_NETWORK */ IConsoleCmdRegister("kick", ConKick);
IConsoleCmdRegister("screenshot", ConScreenShot); IConsoleCmdHook("kick", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdRegister("script", ConScript); IConsoleCmdRegister("protect", ConProtect);
IConsoleCmdRegister("scrollto", ConScrollToTile); IConsoleCmdRegister("name", ConClientName);
#ifdef ENABLE_NETWORK IConsoleCmdRegister("connect", ConNetworkConnect);
IConsoleCmdHook("connect", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetServer);
IConsoleCmdRegister("clients", ConNetworkClients);
IConsoleCmdRegister("setservername", ConSetServerName); IConsoleCmdRegister("setservername", ConSetServerName);
IConsoleCmdHook("setservername", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient); IConsoleCmdHook("setservername", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdRegister("setpassword", ConSetPassword); IConsoleCmdRegister("setpassword", ConSetPassword);
IConsoleCmdHook("setpassword", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient); IConsoleCmdHook("setpassword", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
IConsoleCmdRegister("status", ConStatus); IConsoleCmdRegister("status", ConStatus);
IConsoleCmdHook("status", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient); IConsoleCmdHook("status", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
#endif /* ENABLE_NETWORK */ IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);
// variables [please add them alphabeticaly]
IConsoleVarRegister("developer", &_stdlib_developer, ICONSOLE_VAR_BYTE);
#ifdef ENABLE_NETWORK
IConsoleVarRegister("net_frame_freq", &_network_frame_freq, ICONSOLE_VAR_UINT8); IConsoleVarRegister("net_frame_freq", &_network_frame_freq, ICONSOLE_VAR_UINT8);
IConsoleVarHook("*net_frame_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient); IConsoleVarHook("net_frame_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient);
IConsoleVarRegister("net_sync_freq", &_network_sync_freq, ICONSOLE_VAR_UINT16); IConsoleVarRegister("net_sync_freq", &_network_sync_freq, ICONSOLE_VAR_UINT16);
IConsoleVarHook("*net_sync_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient); IConsoleVarHook("net_sync_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient);
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
// debugging stuff
#ifdef _DEBUG
IConsoleDebugLibRegister();
#endif
} }
/* -------------------- don't cross this line --------------------- */ /* -------------------- don't cross this line --------------------- */