Skip to content

Commit 264f776

Browse files
Merge pull request #67 from Aperture-Development/development
MSync 1.3.0 Update
2 parents 230655a + 50e9785 commit 264f776

File tree

16 files changed

+1080
-239
lines changed

16 files changed

+1080
-239
lines changed

lua/msync/client_gui/cl_admin_gui.lua

Lines changed: 137 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ MSync.AdminPanel = MSync.AdminPanel or {}
77
Returns: panel
88
]]
99
function MSync.AdminPanel.InitMySQL( sheet )
10+
11+
MSync.log(MSYNC_DBG_DEBUG, "Initializing MySQL settings panel")
12+
1013
local pnl = vgui.Create( "DPanel", sheet )
1114

1215
local mysqlip_text = vgui.Create( "DLabel", pnl )
@@ -75,32 +78,82 @@ function MSync.AdminPanel.InitMySQL( sheet )
7578
title_info:SetSize(400, 15)
7679
title_info:SetText( "--Information--" )
7780

78-
local info = vgui.Create( "DLabel", pnl )
79-
info:SetPos( 200, 30 )
80-
info:SetColor( Color( 0, 0, 0 ) )
81-
info:SetSize(400, 200)
82-
info:SetText( [[
83-
Support: https://www.Aperture-Development.de
84-
GitHub: https://github.com/Aperture-Development/MSync-2
85-
LICENCE: To know what you are allowed to do and what not,
86-
read the LICENCE file in the root directory of the addon.
87-
If there is no file, the Licence by-nc-sa 4.0 International applies.
88-
89-
Developer: This Addon was created by Aperture Development.
90-
Copyright 2018 - Aperture Development
91-
]] )
81+
local info = vgui.Create( "RichText", pnl )
82+
info:SetPos( 200, 45 )
83+
info:SetSize(350, 150)
84+
info:InsertColorChange(10, 10, 10, 255)
85+
info:AppendText("MSync2 - Now with Steak\n\nSupport: ")
86+
info:InsertColorChange(72, 72, 155, 255)
87+
info:InsertClickableTextStart("OpenWebsite")
88+
info:AppendText("https://www.Aperture-Development.de")
89+
info:InsertClickableTextEnd()
90+
info:InsertColorChange(10, 10, 10, 255)
91+
info:AppendText("\nGitHub: ")
92+
info:InsertColorChange(72, 72, 155, 255)
93+
info:InsertClickableTextStart("OpenGitHub")
94+
info:AppendText("https://github.com/Aperture-Development/MSync-2")
95+
info:InsertClickableTextEnd()
96+
info:InsertColorChange(10, 10, 10, 255)
97+
info:AppendText("\nLicence:\n")
98+
info:InsertColorChange(80, 80, 80, 255)
99+
info:AppendText("To know what you are allowed to do and what not, read the LICENCE file in the root directory of the addon. If there is no file, the licence by-nc-sa 4.0 International applies.\n\n")
100+
info:InsertColorChange(10, 10, 10, 255)
101+
info:AppendText("This addon was created by Aperture Development\n")
102+
info:InsertColorChange(10, 10, 10, 255)
103+
info:AppendText("Copyright 2018 - Aperture Development")
104+
105+
info.Paint = function( pnl, w, h )
106+
draw.RoundedBox( 5, 0, 0, w, h, Color(215, 215, 215) )
107+
end
108+
109+
info.ActionSignal = function( pnl, signalName, signalValue )
110+
if signalName == "TextClicked" then
111+
if signalValue == "OpenWebsite" then
112+
gui.OpenURL( "https://www.Aperture-Development.de" )
113+
elseif signalValue == "OpenGitHub" then
114+
gui.OpenURL( "https://github.com/Aperture-Development/MSync-2" )
115+
end
116+
end
117+
end
92118

93119
local dbstatus = vgui.Create( "DLabel", pnl )
94120
dbstatus:SetPos( 200, 210 )
95121
dbstatus:SetColor( Color( 0, 0, 0 ) )
96122
dbstatus:SetSize(400, 15)
97-
dbstatus:SetText( "DB Connection status: -Not Implemented-" )
123+
dbstatus:SetText( "Database Status: " )
124+
125+
local dbstatus_info = vgui.Create( "DLabel", pnl )
126+
dbstatus_info:SetPos( 300, 210 )
127+
dbstatus_info:SetColor( Color( 80, 80, 80 ) )
128+
dbstatus_info:SetSize(400, 15)
129+
dbstatus_info:SetText( "Please wait..." )
130+
131+
local function getConnectionStatus()
132+
dbstatus_info:SetColor( Color( 80, 80, 80 ) )
133+
dbstatus_info:SetText( "Please wait..." )
134+
timer.Simple(3, function()
135+
MSync.net.getDBStatus()
136+
timer.Create("msync.dbConnectionStatus", 3, 10, function()
137+
if MSync.DBStatus == nil then return end
138+
139+
if MSync.DBStatus then
140+
dbstatus_info:SetColor( Color( 80, 255, 80 ) )
141+
dbstatus_info:SetText( "Connected" )
142+
else
143+
dbstatus_info:SetColor( Color( 255, 80, 80 ) )
144+
dbstatus_info:SetText( "Not Connected" )
145+
end
146+
timer.Remove("msync.dbConnectionStatus")
147+
end)
148+
end)
149+
end
98150

99151
local save_button = vgui.Create( "DButton", pnl )
100152
save_button:SetText( "Save Settings" )
101153
save_button:SetPos( 25, 290 )
102154
save_button:SetSize( 130, 30 )
103155
save_button.DoClick = function()
156+
MSync.log(MSYNC_DBG_DEBUG, "Saving settings")
104157
MSync.settings.mysql.host = mysqlip:GetValue()
105158
MSync.settings.mysql.port = mysqlport:GetValue()
106159
MSync.settings.mysql.database = mysqldb:GetValue()
@@ -115,6 +168,7 @@ function MSync.AdminPanel.InitMySQL( sheet )
115168
saveconnect_button:SetPos( 155, 290 )
116169
saveconnect_button:SetSize( 130, 30 )
117170
saveconnect_button.DoClick = function()
171+
MSync.log(MSYNC_DBG_DEBUG, "Saving settings and connecting to the database")
118172
MSync.settings.mysql.host = mysqlip:GetValue()
119173
MSync.settings.mysql.port = mysqlport:GetValue()
120174
MSync.settings.mysql.database = mysqldb:GetValue()
@@ -123,34 +177,70 @@ function MSync.AdminPanel.InitMySQL( sheet )
123177
MSync.settings.serverGroup = servergroup:GetValue()
124178
MSync.net.sendSettings(MSync.settings)
125179
MSync.net.connectDB()
180+
getConnectionStatus()
126181
end
127182

128183
local connect_button = vgui.Create( "DButton", pnl )
129184
connect_button:SetText( "Connect" )
130185
connect_button:SetPos( 285, 290 )
131186
connect_button:SetSize( 130, 30 )
132187
connect_button.DoClick = function()
188+
MSync.log(MSYNC_DBG_DEBUG, "Connecting to the database")
133189
MSync.net.connectDB()
190+
getConnectionStatus()
134191
end
135192

136193
local reset_button = vgui.Create( "DButton", pnl )
137194
reset_button:SetText( "Reset Settings" )
138195
reset_button:SetPos( 415, 290 )
139196
reset_button:SetSize( 130, 30 )
140197
reset_button.DoClick = function()
141-
mysqlip:SetText("127.0.0.1")
142-
mysqlport:SetText("3306")
143-
mysqldb:SetText("msync")
144-
mysqluser:SetText("root")
145-
mysqlpassword:SetText("****")
146-
servergroup:SetText("allserver")
147-
MSync.settings.mysql.host = mysqlip:GetValue()
148-
MSync.settings.mysql.port = mysqlport:GetValue()
149-
MSync.settings.mysql.database = mysqldb:GetValue()
150-
MSync.settings.mysql.username = mysqluser:GetValue()
151-
MSync.settings.mysql.password = ""
152-
MSync.settings.serverGroup = servergroup:GetValue()
153-
MSync.net.sendSettings(MSync.settings)
198+
MSync.log(MSYNC_DBG_DEBUG, "Reset confirm request");
199+
200+
local resetConfirm_panel = vgui.Create( "DFrame" )
201+
resetConfirm_panel:SetSize( 350, 100 )
202+
resetConfirm_panel:SetTitle( "MSync Reset - Confirm" )
203+
resetConfirm_panel:Center()
204+
resetConfirm_panel:MakePopup()
205+
206+
local save_text = vgui.Create( "DLabel", resetConfirm_panel )
207+
save_text:SetPos( 15, 20 )
208+
save_text:SetColor( Color( 255, 255, 255 ) )
209+
save_text:SetText( "This action will reset all MySQL settings back to default, causing MSync to be unable to connect to the database when restarting the server. Are you sure you want to do that?" )
210+
save_text:SetSize(320, 50)
211+
save_text:SetWrap( true )
212+
213+
local accept_button = vgui.Create( "DButton", resetConfirm_panel )
214+
accept_button:SetText( "Yes" )
215+
accept_button:SetPos( 15, 70 )
216+
accept_button:SetSize( 160, 20 )
217+
accept_button.DoClick = function()
218+
MSync.log(MSYNC_DBG_DEBUG, "Reset of MySQL configuration confirmed")
219+
mysqlip:SetText("127.0.0.1")
220+
mysqlport:SetText("3306")
221+
mysqldb:SetText("msync")
222+
mysqluser:SetText("root")
223+
mysqlpassword:SetText("****")
224+
servergroup:SetText("allserver")
225+
MSync.settings.mysql.host = mysqlip:GetValue()
226+
MSync.settings.mysql.port = mysqlport:GetValue()
227+
MSync.settings.mysql.database = mysqldb:GetValue()
228+
MSync.settings.mysql.username = mysqluser:GetValue()
229+
MSync.settings.mysql.password = ""
230+
MSync.settings.serverGroup = servergroup:GetValue()
231+
MSync.net.sendSettings(MSync.settings)
232+
233+
resetConfirm_panel:Close()
234+
end
235+
236+
local deny_button = vgui.Create( "DButton", resetConfirm_panel )
237+
deny_button:SetText( "No" )
238+
deny_button:SetPos( 175, 70 )
239+
deny_button:SetSize( 160, 20 )
240+
deny_button.DoClick = function()
241+
MSync.log(MSYNC_DBG_INFO, "Reset of MySQL configuration cancelled");
242+
resetConfirm_panel:Close()
243+
end
154244
end
155245

156246
if not MSync.settings == nil then
@@ -163,6 +253,8 @@ function MSync.AdminPanel.InitMySQL( sheet )
163253
timer.Create("msync.t.checkForSettings", 0.5, 0, function()
164254
if not MSync.settings or not MSync.settings.mysql then return end;
165255

256+
MSync.log(MSYNC_DBG_DEBUG, "Got server settings, updating MySQL settings panel")
257+
166258
mysqlip:SetText(MSync.settings.mysql.host)
167259
mysqlport:SetText(MSync.settings.mysql.port)
168260
mysqldb:SetText(MSync.settings.mysql.database)
@@ -172,6 +264,8 @@ function MSync.AdminPanel.InitMySQL( sheet )
172264
end)
173265
end
174266

267+
getConnectionStatus()
268+
175269
return pnl
176270
end
177271

@@ -181,6 +275,9 @@ end
181275
Returns: panel
182276
]]
183277
function MSync.AdminPanel.InitModules( sheet )
278+
279+
MSync.log(MSYNC_DBG_DEBUG, "Initializing modulestate panel")
280+
184281
local pnl = vgui.Create( "DPanel", sheet )
185282

186283
local ModuleList = vgui.Create( "DListView", pnl )
@@ -203,12 +300,17 @@ function MSync.AdminPanel.InitModules( sheet )
203300
local cursor_x, cursor_y = ModuleList:CursorPos()
204301
local DMenu = vgui.Create("DMenu", ModuleList)
205302
DMenu:SetPos(cursor_x, cursor_y)
206-
DMenu:AddOption(MSync.serverModules[ident].Description)
303+
DMenu:AddOption(MSync.serverModules[ident].Description):SetDisabled(true)
207304
DMenu:AddSpacer()
208305
DMenu:AddOption("Enable")
209306
DMenu:AddOption("Disable")
210307
DMenu.OptionSelected = function(menu,optPnl,optStr)
211308
MSync.net.toggleModule(ident, optStr)
309+
if optStr == "Enable" then
310+
line:SetColumnText( 3, "true" )
311+
elseif optStr == "Disable" then
312+
line:SetColumnText( 3, "false" )
313+
end
212314
end
213315
end
214316
return pnl
@@ -220,6 +322,9 @@ end
220322
Returns: panel
221323
]]
222324
function MSync.AdminPanel.InitModuleSettings( sheet )
325+
326+
MSync.log(MSYNC_DBG_DEBUG, "Initializing module settings panel")
327+
223328
local pnl = vgui.Create( "DColumnSheet", sheet )
224329

225330
local files, _ = file.Find("msync/client_gui/modules/*.lua", "LUA")
@@ -231,6 +336,7 @@ function MSync.AdminPanel.InitModuleSettings( sheet )
231336
MSync.modules[info.ModuleIdentifier]["init"]()
232337
MSync.modules[info.ModuleIdentifier]["net"]()
233338
pnl:AddSheet( info.Name, MSync.modules[info.ModuleIdentifier].adminPanel(pnl))
339+
MSync.log(MSYNC_DBG_DEBUG, "Added settings tab for module: ")
234340
end
235341
end
236342

@@ -243,6 +349,8 @@ end
243349
]]
244350
function MSync.AdminPanel.InitPanel()
245351

352+
MSync.log(MSYNC_DBG_DEBUG, "Opening Admin GUI")
353+
246354
--if not LocalPlayer():query("msync.admingui") then return false end;
247355

248356
MSync.net.getSettings()

lua/msync/client_gui/cl_modules.lua

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function MSync.initModules()
2727
v["net"]()
2828
v["ulx"]()
2929
v["hooks"]()
30-
print("["..v["info"]["Name"].."] Module loaded")
30+
MSync.log(MSYNC_DBG_INFO, "["..v["info"]["Name"].."] Module loaded")
3131
end
3232
end
3333

@@ -39,14 +39,48 @@ end
3939
Returns: nothing
4040
]]
4141
function MSync.loadModule(path)
42-
local initTransaction = MSync.DBServer:createTransaction()
4342
local info = include(path)
4443

4544
MSync.modules[info.ModuleIdentifier].init()
4645
MSync.modules[info.ModuleIdentifier].net()
4746
MSync.modules[info.ModuleIdentifier].ulx()
4847
MSync.modules[info.ModuleIdentifier].hooks()
4948

50-
print("["..MSync.modules[info.Name].."] Module loaded")
49+
MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[info.ModuleIdentifier]["info"]["Name"].."] Module loaded")
5150

5251
end
52+
53+
--[[
54+
Description: Enables a single already loaded clientside module
55+
Arguments: Module path
56+
Returns: nothing
57+
]]
58+
function MSync.enableModule( module )
59+
if MSync.modules[module] then
60+
MSync.modules[module].init()
61+
MSync.modules[module].net()
62+
MSync.modules[module].ulx()
63+
MSync.modules[module].hooks()
64+
MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module loaded")
65+
else
66+
MSync.log(MSYNC_DBG_WARNING, "Cannot enable non-existant module \"" .. module .. "\"")
67+
end
68+
end
69+
70+
--[[
71+
Description: Disabled a single already loaded clientside module
72+
Arguments: Module path
73+
Returns: nothing
74+
]]
75+
function MSync.disableModule( module )
76+
if MSync.modules[module] then
77+
if MSync.modules[module].disable then
78+
MSync.modules[module].disable()
79+
MSync.log(MSYNC_DBG_INFO, "["..MSync.modules[module]["info"]["Name"].."] Module disabled")
80+
else
81+
MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"")
82+
end
83+
else
84+
MSync.log(MSYNC_DBG_WARNING, "Cannot disable non-existant module \"" .. module .. "\"")
85+
end
86+
end

0 commit comments

Comments
 (0)