1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
-- Some HTML helper functions
local function HTML_Option( value, text, selected )
if( selected == true ) then
return [[<option value="]] .. value .. [[" selected>]] .. text .. [[</option>]]
else
return [[<option value="]] .. value .. [[">]] .. text .. [[</option>"]]
end
end
local function HTML_Select_On_Off( name, defaultValue )
return [[<select name="]] .. name .. [[">]]
.. HTML_Option("1", "On", defaultValue == 1 )
.. HTML_Option("0", "Off", defaultValue == 0 )
.. [[</select>]]
end
local function ShowGeneralSettings( Request )
local Content = ""
local InfoMsg = nil
local SettingsIni = cIniFile("settings.ini")
if( SettingsIni:ReadFile() == false ) then
InfoMsg = "<b style=\"color: red;\">ERROR: Could not read settings.ini!</b>"
end
if( Request.PostParams["general_submit"] ~= nil ) then
SettingsIni:SetValue("Server", "Description",Request.PostParams["Server_Description"],false )
if( tonumber( Request.PostParams["Server_MaxPlayers"] ) ~= nil ) then
SettingsIni:SetValue("Server", "MaxPlayers", Request.PostParams["Server_MaxPlayers"], false )
end
if( tonumber( Request.PostParams["Server_Port"] ) ~= nil ) then
SettingsIni:SetValue("Server", "Port", Request.PostParams["Server_Port"], false )
end
if( tonumber( Request.PostParams["Authentication_Authenticate"] ) ~= nil ) then
SettingsIni:SetValue("Authentication", "Authenticate", Request.PostParams["Authentication_Authenticate"], false )
end
if( SettingsIni:WriteFile() == false ) then
InfoMsg = [[<b style="color: red;">ERROR: Could not write to settings.ini!</b>]]
else
InfoMsg = [[<b style="color: green;">INFO: Successfully saved changes to settings.ini</b>]]
end
end
Content = Content .. [[
<form method="POST">
<h4>General Settings</h4>]]
if( InfoMsg ~= nil ) then
Content = Content .. "<p>" .. InfoMsg .. "</p>"
end
Content = Content .. [[
<table>
<th colspan="2">Server</th>
<tr><td style="width: 50%;">Description:</td>
<td><input type="text" name="Server_Description" value="]] .. SettingsIni:GetValue("Server", "Description") .. [["></td></tr>
<tr><td>Max Players:</td>
<td><input type="text" name="Server_MaxPlayers" value="]] .. SettingsIni:GetValue("Server", "MaxPlayers") .. [["></td></tr>
<tr><td>Port:</td>
<td><input type="text" name="Server_Port" value="]] .. SettingsIni:GetValue("Server", "Port") .. [["></td></tr>
</table><br>
<table>
<th colspan="2">Authentication</th>
<tr><td style="width: 50%;">Authenticate:</td>
<td>]] .. HTML_Select_On_Off("Authentication_Authenticate", SettingsIni:GetValueI("Authentication", "Authenticate") ) .. [[</td></tr>
</table><br>
<input type="submit" value="Save Settings" name="general_submit"> WARNING: Any changes made here might require a server restart in order to be applied!
</form>]]
return Content
end
local function ShowMonstersSettings( Request )
local Content = ""
local InfoMsg = nil
local SettingsIni = cIniFile("settings.ini")
if( SettingsIni:ReadFile() == false ) then
InfoMsg = "<b style=\"color: red;\">ERROR: Could not read settings.ini!</b>"
end
if( Request.PostParams["monsters_submit"] ~= nil ) then
if( tonumber( Request.PostParams["Monsters_AnimalsOn"] ) ~= nil ) then
SettingsIni:SetValue("Monsters", "AnimalsOn", Request.PostParams["Monsters_AnimalsOn"], false )
end
if( tonumber( Request.PostParams["Monsters_AnimalSpawnInterval"] ) ~= nil ) then
SettingsIni:SetValue("Monsters", "AnimalSpawnInterval", Request.PostParams["Monsters_AnimalSpawnInterval"], false )
end
SettingsIni:SetValue("Monsters", "Types", Request.PostParams["Monsters_Types"], false )
if( SettingsIni:WriteFile() == false ) then
InfoMsg = "<b style=\"color: red;\">ERROR: Could not write to settings.ini!</b>"
else
InfoMsg = "<b style=\"color: green;\">INFO: Successfully saved changes to settings.ini</b>"
end
end
Content = Content .. "<form method=\"POST\">"
Content = Content .. "<h4>Monsters Settings</h4>"
if( InfoMsg ~= nil ) then
Content = Content .. "<p>" .. InfoMsg .. "</p>"
end
Content = Content .. [[
<table>
<th colspan="2">Monsters</th>
<tr><td style="width: 50%;">Animals On:</td>
<td>]] .. HTML_Select_On_Off("Monsters_AnimalsOn", SettingsIni:GetValueI("Monsters", "AnimalsOn") ) .. [[</td></tr>
<tr><td>Animal Spawn Interval:</td>
<td><input type="text" name="Monsters_AnimalSpawnInterval" value="]] .. SettingsIni:GetValue("Monsters", "AnimalSpawnInterval") .. [["></td></tr>
<tr><td>Monster Types:</td>
<td><input type="text" name="Monsters_Types" value="]] .. SettingsIni:GetValue("Monsters", "Types") .. [[\"></td></tr>
</table><br>
<input type="submit" value="Save Settings" name="monsters_submit"> WARNING: Any changes made here might require a server restart in order to be applied!
</form>]]
return Content
end
local function ShowWorldsSettings( Request )
return "<p><b>Worlds Settings</b></p>"
end
function HandleRequest_ServerSettings( Request )
local Content = ""
Content = Content .. [[
<p><b>Server Settings</b></p>
<table>
<tr>
<td><a href="?tab=General">General</a></td>
<td><a href="?tab=Monsters">Monsters</a></td>
<td><a href="?tab=Worlds">Worlds</a></td>
</tr>
</table>
<br>]]
if( Request.Params["tab"] == "Monsters" ) then
Content = Content .. ShowMonstersSettings( Request )
elseif( Request.Params["tab"] == "Worlds" ) then
Content = Content .. ShowWorldsSettings( Request )
else
Content = Content .. ShowGeneralSettings( Request ) -- Default to general settings
end
return Content
end
|