mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r954) -Fix: [Console] Hook fixes (sign_de)
-Add: [Console] Auto sort commands and variables (sign_de)
This commit is contained in:
parent
cef5ac8c8b
commit
1de8e294d8
111
console.c
111
console.c
@ -439,6 +439,7 @@ void IConsoleCmdRegister(const char* name, _iconsole_cmd_addr addr)
|
||||
char* _new;
|
||||
_iconsole_cmd* item;
|
||||
_iconsole_cmd* item_new;
|
||||
_iconsole_cmd* item_before;
|
||||
|
||||
_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_before_exec = NULL;
|
||||
|
||||
item_before = NULL;
|
||||
item = _iconsole_cmds;
|
||||
|
||||
if (item == NULL) {
|
||||
_iconsole_cmds = item_new;
|
||||
} else {
|
||||
while (item->_next != NULL) item = item->_next;
|
||||
item->_next = item_new;
|
||||
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_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)
|
||||
@ -473,17 +500,58 @@ _iconsole_cmd* IConsoleCmdGet(const char* name)
|
||||
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_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 */
|
||||
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;
|
||||
|
||||
switch (type) {
|
||||
case ICONSOLE_VAR_BOOLEAN:
|
||||
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");
|
||||
break;
|
||||
}
|
||||
|
||||
IConsoleVarInsert(item_new, name);
|
||||
|
||||
item_new->type = type;
|
||||
item_new->_malloc = false;
|
||||
|
||||
item_new->hook_access = NULL;
|
||||
item_new->hook_after_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)
|
||||
@ -534,27 +598,6 @@ void IConsoleVarMemRegister(const char* name, _iconsole_var_types type)
|
||||
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* item;
|
||||
|
@ -123,7 +123,7 @@ _iconsole_cmd* IConsoleCmdGet(const char* name);
|
||||
|
||||
void IConsoleVarRegister(const char* name, void* addr, _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* IConsoleVarAlloc(_iconsole_var_types type);
|
||||
void IConsoleVarFree(_iconsole_var* var);
|
||||
|
@ -52,6 +52,10 @@ DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetwork)
|
||||
|
||||
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) {
|
||||
IConsoleError("This variable only makes sense for a network server.");
|
||||
return false;
|
||||
@ -61,7 +65,11 @@ DEF_CONSOLE_VAR_HOOK(ConVarHookNoNetClient)
|
||||
|
||||
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.");
|
||||
return false;
|
||||
}
|
||||
@ -70,8 +78,12 @@ DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetClient)
|
||||
|
||||
DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetServer)
|
||||
{
|
||||
if (!_networking || _network_server) {
|
||||
IConsoleError("You can not use this command for you are a network-server.");
|
||||
if (!_network_available) {
|
||||
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 true;
|
||||
@ -79,6 +91,10 @@ DEF_CONSOLE_CMD_HOOK(ConCmdHookNoNetServer)
|
||||
|
||||
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) {
|
||||
IConsoleError("Not connected. Multiplayer only command.");
|
||||
return false;
|
||||
@ -618,10 +634,12 @@ DEF_CONSOLE_CMD(ConSetPassword) {
|
||||
|
||||
void IConsoleDebugLibRegister()
|
||||
{
|
||||
// stdlib
|
||||
// debugging variables and functions
|
||||
extern bool _stdlib_con_developer; /* XXX extern in .c */
|
||||
|
||||
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_int16", ICONSOLE_VAR_INT16);
|
||||
IConsoleVarMemRegister("temp_int32", ICONSOLE_VAR_INT32);
|
||||
@ -629,8 +647,6 @@ void IConsoleDebugLibRegister()
|
||||
IConsoleVarMemRegister("temp_uint16", ICONSOLE_VAR_UINT16);
|
||||
IConsoleVarMemRegister("temp_uint16_2", ICONSOLE_VAR_UINT16);
|
||||
IConsoleVarMemRegister("temp_uint32", ICONSOLE_VAR_UINT32);
|
||||
IConsoleVarMemRegister("temp_string", ICONSOLE_VAR_STRING);
|
||||
IConsoleVarMemRegister("temp_string2", ICONSOLE_VAR_STRING);
|
||||
IConsoleCmdRegister("resettile", ConResetTile);
|
||||
}
|
||||
#endif
|
||||
@ -644,16 +660,7 @@ void IConsoleStdLibRegister(void)
|
||||
// stdlib
|
||||
extern byte _stdlib_developer; /* XXX extern in .c */
|
||||
|
||||
#ifdef _DEBUG
|
||||
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 */
|
||||
// default variables and functions
|
||||
IConsoleCmdRegister("debug_level", ConDebugLevel);
|
||||
IConsoleCmdRegister("dump_vars", ConListDumpVariables);
|
||||
IConsoleCmdRegister("echo", ConEcho);
|
||||
@ -665,22 +672,20 @@ void IConsoleStdLibRegister(void)
|
||||
IConsoleCmdRegister("info_var", ConInfoVar);
|
||||
IConsoleCmdRegister("list_cmds", ConListCommands);
|
||||
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("printf", ConPrintF);
|
||||
IConsoleCmdRegister("printfc", ConPrintFC);
|
||||
IConsoleCmdRegister("quit", ConExit);
|
||||
IConsoleCmdRegister("random", ConRandom);
|
||||
IConsoleCmdRegister("resetengines", ConResetEngines);
|
||||
#ifdef ENABLE_NETWORK
|
||||
IConsoleCmdHook("resetengines", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetwork);
|
||||
#endif /* ENABLE_NETWORK */
|
||||
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
|
||||
IConsoleCmdRegister("say", ConSay);
|
||||
IConsoleCmdHook("say", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
|
||||
@ -688,28 +693,31 @@ void IConsoleStdLibRegister(void)
|
||||
IConsoleCmdHook("say_player", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
|
||||
IConsoleCmdRegister("say_client", ConSayClient);
|
||||
IConsoleCmdHook("say_client", ICONSOLE_HOOK_ACCESS, ConCmdHookNeedNetwork);
|
||||
#endif /* ENABLE_NETWORK */
|
||||
IConsoleCmdRegister("screenshot", ConScreenShot);
|
||||
IConsoleCmdRegister("script", ConScript);
|
||||
IConsoleCmdRegister("scrollto", ConScrollToTile);
|
||||
#ifdef ENABLE_NETWORK
|
||||
IConsoleCmdRegister("kick", ConKick);
|
||||
IConsoleCmdHook("kick", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
|
||||
IConsoleCmdRegister("protect", ConProtect);
|
||||
IConsoleCmdRegister("name", ConClientName);
|
||||
IConsoleCmdRegister("connect", ConNetworkConnect);
|
||||
IConsoleCmdHook("connect", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetServer);
|
||||
IConsoleCmdRegister("clients", ConNetworkClients);
|
||||
IConsoleCmdRegister("setservername", ConSetServerName);
|
||||
IConsoleCmdHook("setservername", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
|
||||
IConsoleCmdRegister("setpassword", ConSetPassword);
|
||||
IConsoleCmdHook("setpassword", ICONSOLE_HOOK_ACCESS, ConCmdHookNoNetClient);
|
||||
IConsoleCmdRegister("status", ConStatus);
|
||||
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);
|
||||
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);
|
||||
IConsoleVarHook("*net_sync_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient);
|
||||
IConsoleVarHook("net_sync_freq", ICONSOLE_HOOK_ACCESS, ConVarHookNoNetClient);
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
// debugging stuff
|
||||
#ifdef _DEBUG
|
||||
IConsoleDebugLibRegister();
|
||||
#endif
|
||||
|
||||
}
|
||||
/* -------------------- don't cross this line --------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user