-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclientlib.hws
68 lines (61 loc) · 2.24 KB
/
clientlib.hws
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
; Connect to the specified Server and Port number
Function p_ConnectToServer(server$, port$)
If prefs.server$ = "" Then prefs.server$ = "127.0.0.1"
If prefs.port$ = "" Then prefs.port$ = 2550
p_Log("Attempting to connect to server " .. prefs.server$ .. ", port " .. prefs.port$ .. "...")
; Open a connection and get the Id in a variable
connectionId = OpenConnection(Nil, prefs.server$, prefs.port$)
p_Log("Connected!")
; Add connectionId to list of active Connections
p_AddConnection(connectionId)
; Change UI state
p_SetUIState("connected")
EndFunction
; Disconnect from the currently connected Server
Function p_DisconnectFromServer()
CloseConnection(connectionId)
p_RemoveConnection(connectionId)
p_SetUIState("disconnected")
EndFunction
; Handle received data from a connected client
Function p_ReceiveData(msg)
Local data$ = ReceiveData(msg.id, #RECEIVELINE)
p_Log("Message received: " .. data$)
p_ProcessMessagesByType(data$)
EndFunction
; Disable or enable UI elements based on current state
Function p_SetUIState(state$)
If state$ = "connected"
moai.Set("CmdDir", "disabled", True)
moai.Set("ProjectsDir", "disabled", True)
moai.Set("txtServer", "disabled", True)
moai.Set("txtPort", "disabled", True)
moai.Set("connect","disabled", True)
moai.Set("Nick", "disabled", True)
moai.Set("AltNick", "disabled", True)
moai.Set("disconnect","disabled", False)
ElseIf state$ = "disconnected"
moai.Set("CmdDir", "disabled", False)
moai.Set("ProjectsDir", "disabled", False)
moai.Set("txtServer", "disabled", False)
moai.Set("txtPort", "disabled", False)
moai.Set("connect","disabled", False)
moai.Set("Nick", "disabled", False)
moai.Set("AltNick", "disabled", False)
moai.Set("disconnect","disabled", True)
EndIf
EndFunction
Function p_ApplySettings()
prefs.server$ = moai.Get("txtServer", "Text")
prefs.port$ = moai.Get("txtPort", "Text")
prefs.nick$ = moai.Get("Nick", "Text")
prefs.lwsn$ = moai.Get("LWSN", "File")
prefs.commandDir$ = moai.Get("CmdDir", "Path")
EndFunction
Function p_PrefsToGui()
moai.Set("txtServer", "Text", prefs.server$)
moai.Set("txtPort", "Text", prefs.port$)
moai.Set("Nick", "Text", prefs.nick$)
moai.Set("LWSN", "File", prefs.lwsn$)
moai.Set("CmdDir", "Path", prefs.commandDir$)
EndFunction