summaryrefslogtreecommitdiff
path: root/settings.c
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-12-20 22:14:39 +0000
committerdominik <dominik@openttd.org>2004-12-20 22:14:39 +0000
commit7cfaa8a418cf5e04d66e3b4207b13a29db134145 (patch)
tree29c55a04aa27eeacd62949e6621a682a22dc3cc0 /settings.c
parent3bbea05a93f922a7e3c98f5474748027032ef2a9 (diff)
downloadopenttd-7cfaa8a418cf5e04d66e3b4207b13a29db134145.tar.xz
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
Diffstat (limited to 'settings.c')
-rw-r--r--settings.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/settings.c b/settings.c
index 35cffb08e..da980d49f 100644
--- a/settings.c
+++ b/settings.c
@@ -923,12 +923,37 @@ static void LoadList(IniFile *ini, const char *grpname, char **list, int len)
}
}
+static void SaveList(IniFile *ini, const char *grpname, char **list, int len)
+{
+ IniGroup *group = ini_getgroup(ini, grpname, -1);
+ IniItem *item;
+ int i;
+ bool first = true;
+
+ if (!group)
+ return;
+ for ( i=0; i != len; i++) {
+ if ( list[i] == '\0' ) continue;
+
+ if (first) { // add first item to the head of the group
+ item = ini_item_alloc(group, list[i], strlen(list[i]));
+ item->value = item->name;
+ group->item = item;
+ first = false;
+ } else { // all other items are attached to the previous one
+ item->next = ini_item_alloc(group, list[i], strlen(list[i]));
+ item = item->next;
+ item->value = item->name;
+ }
+ }
+}
+
void LoadFromConfig()
{
IniFile *ini = ini_load(_config_file);
HandleSettingDescs(ini, load_setting_desc);
LoadList(ini, "newgrf", _newgrf_files, lengthof(_newgrf_files));
- LoadList(ini, "servers", _network_server_list, lengthof(_network_server_list));
+ LoadList(ini, "servers", _network_host_list, lengthof(_network_host_list));
ini_free(ini);
}
@@ -936,6 +961,7 @@ void SaveToConfig()
{
IniFile *ini = ini_load(_config_file);
HandleSettingDescs(ini, save_setting_desc);
+ SaveList(ini, "servers", _network_host_list, lengthof(_network_host_list));
ini_save(_config_file, ini);
ini_free(ini);
}