-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUCliForm.pas
More file actions
320 lines (268 loc) · 8.91 KB
/
UCliForm.pas
File metadata and controls
320 lines (268 loc) · 8.91 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Author: François PIETTE
Description: Demonstration for Server program using TWSocket.
EMail: francois.piette@ping.be http://www.rtfm.be/fpiette
francois.piette@rtfm.be
Creation: 8 december 1997
Version: 1.00
WebSite: http://www.rtfm.be/fpiette/indexuk.htm
Support: Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1997 by François PIETTE <francois.piette@ping.be>
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it
and redistribute it freely, subject to the following
restrictions:
1. The origin of this software must not be misrepresented,
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is
not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Updates:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit UCliForm;
interface
uses
WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, WSocket, StdCtrls, ExtCtrls, zLogGlobal;
const LBCODE = #13{+#10};
type
TCliForm = class(TForm)
CliSocket: TWSocket;
Panel1: TPanel;
SendEdit: TEdit;
SendButton: TButton;
Panel2: TPanel;
DisconnectButton: TButton;
ListBox: TListBox;
Button1: TButton;
procedure CreateParams(var Params: TCreateParams); override;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CliSocketDataAvailable(Sender: TObject; Error: Word);
procedure CliSocketSessionClosed(Sender: TObject; Error: Word);
procedure SendButtonClick(Sender: TObject);
procedure DisconnectButtonClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
Initialized : Boolean;
//Buffer : array [0..1023] of char;
//Count : Integer;
LineBuffer : TStringList;
CommTemp : string; //work string for parsing LineBuffer
public
ClientNumber : Integer;
Bands : array[b19..HiBand] of boolean;
CurrentBand : TBand;
CurrentOperator : string;
procedure ParseLineBuffer;
procedure SendStr(str : string);
procedure SetCaption;
procedure AddConsole(S : string);
end;
var
CliForm: TCliForm;
implementation
uses UServerForm;
{$R *.DFM}
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{$IFDEF VER80}
procedure SetLength(var S: string; NewLength: Integer);
begin
S[0] := chr(NewLength);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TrimRight(Str : String) : String;
var
i : Integer;
begin
i := Length(Str);
while (i > 0) and (Str[i] = ' ') do
i := i - 1;
Result := Copy(Str, 1, i);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TrimLeft(Str : String) : String;
var
i : Integer;
begin
if Str[1] <> ' ' then
Result := Str
else begin
i := 1;
while (i <= Length(Str)) and (Str[i] = ' ') do
i := i + 1;
Result := Copy(Str, i, Length(Str) - i + 1);
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function Trim(Str : String) : String;
begin
Result := TrimLeft(TrimRight(Str));
end;
{$ENDIF}
procedure TCliForm.AddConsole(S : string);
var _VisRows : integer;
_TopRow : integer;
begin
ListBox.Items.Add(S);
_VisRows := ListBox.ClientHeight div ListBox.ItemHeight;
_TopRow := ListBox.Items.Count - _VisRows + 1;
if _TopRow > 0 then
ListBox.TopIndex := _TopRow
else
ListBox.TopIndex := 0;
end;
procedure TCliForm.SetCaption;
var S : string;
begin
S := BandString[CurrentBand];
if CurrentOperator <> '' then
S := S + ' by ' + CurrentOperator;
Caption := S;
end;
procedure TCliForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;
procedure TCliForm.SendStr(str : string);
begin
CliSocket.SendStr(str);
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.FormShow(Sender: TObject);
var B : TBand;
begin
if not Initialized then begin
Initialized := TRUE;
//DisplayMemo.Clear;
SendEdit.Text := '';
ActiveControl := SendEdit;
LineBuffer := TStringList.Create;
CurrentBand := b35;
CurrentOperator := '';
for B := b19 to HiBand do
Bands[B] := False;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
LineBuffer.Clear;
LineBuffer.Free;
PostMessage(TForm(Owner).Handle, WM_USER, 0, LongInt(Self));
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.ParseLineBuffer;
var max , i, j, x : integer;
str: string;
begin
max := LineBuffer.Count - 1;
if max < 0 then exit;
for i := 0 to max do
begin
str := LineBuffer.Strings[0];
for j := 1 to length(str) do
begin
if str[j] = Chr($0D) then
begin
x := Pos(ZLinkHeader, CommTemp);
if x > 0 then
begin
CommTemp := copy(CommTemp, x, 255);
ServerForm.CommandQue.Add(FillRight(IntToStr(ClientNumber), 3)+' '+CommTemp);
end;
CommTemp := '';
end
else
CommTemp := CommTemp + str[j];
end;
LineBuffer.Delete(0);
end;
end;
(*
procedure TCliForm.ParseLineBuffer;
var max , i, j, x : integer;
str, work : string;
begin
max := LineBuffer.Count - 1;
if max < 0 then exit;
for i := 0 to max do
begin
str := LineBuffer.Strings[0];
for j := 1 to length(str) do
begin
if str[j] = Chr($0D) then
begin
x := Pos(ZLinkHeader, CommTemp);
if x > 0 then
begin
CommTemp := copy(CommTemp, x, 255);
ServerForm.CommandQue.Add(FillRight(IntToStr(ClientNumber), 3)+' '+CommTemp);
end;
CommTemp := '';
end
else
CommTemp := CommTemp + str[j];
end;
LineBuffer.Delete(0);
end;
end;
*)
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.CliSocketDataAvailable(Sender: TObject; Error: Word);
var
str : string;
begin
str := CliSocket.ReceiveStr;
if ServerForm.ChatOnly = False then
AddConsole(str);
{ if ServerForm.Transparent then
if str <> '' then
begin
ServerForm.SendAllButFrom(str, ClientNumber);
exit;
end; }
LineBuffer.Add(str);
ParseLineBuffer;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.CliSocketSessionClosed(Sender: TObject; Error: Word);
var temp : string;
begin
temp := ZLinkHeader + ' PUTMESSAGE !'+MHzString[CurrentBand]+ ' MHz client disconnected from network.';
temp := FillRight(IntToStr(ClientNumber), 3)+ ' ' + temp;
ServerForm.ProcessCommand(temp);
Close;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.SendButtonClick(Sender: TObject);
var S : string;
begin
S := ZLinkHeader + ' PUTMESSAGE ZServer> '+SendEdit.Text + LBCODE;
CliSocket.SendStr(S);
S := 'ZServer> '+ SendEdit.Text + LBCODE;
AddConsole(S);
SendEdit.Clear;
ActiveControl := SendEdit;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.DisconnectButtonClick(Sender: TObject);
begin
Close;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TCliForm.Button1Click(Sender: TObject);
begin
Caption := 'Parsing...';
ParseLineBuffer;
Caption := 'Done!';
end;
end.