-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathUServer.Manager.pas
245 lines (218 loc) · 6.14 KB
/
UServer.Manager.pas
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
unit UServer.Manager;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
System.Win.ScktComp, Vcl.Buttons, UServer.Main, sSpeedButton;
type
TFormManager = class(TForm)
ServerSocket: TServerSocket;
PanelRCON: TPanel;
Panel5: TPanel;
ImageRCON: TImage;
EditUser: TEdit;
Label1: TLabel;
Label2: TLabel;
EditPass: TEdit;
Panel1: TPanel;
Label3: TLabel;
Panel2: TPanel;
Image1: TImage;
EditPort: TEdit;
Panel3: TPanel;
Label4: TLabel;
Panel4: TPanel;
Image2: TImage;
EditPath: TEdit;
SpeedButtonOpenDir: TsSpeedButton;
Panel6: TPanel;
Panel7: TPanel;
Image3: TImage;
ButtonStart: TButton;
Button2: TButton;
ListBoxLog: TListBox;
LabelConnected: TLabel;
procedure ButtonStartClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ServerSocketListen(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerSocketClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketThreadStart(Sender: TObject;
Thread: TServerClientThread);
procedure ServerSocketThreadEnd(Sender: TObject;
Thread: TServerClientThread);
procedure ServerSocketGetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket;
var SocketThread: TServerClientThread);
procedure ServerSocketGetSocket(Sender: TObject; Socket: NativeInt;
var ClientSocket: TServerClientWinSocket);
procedure ServerSocketClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocketClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerSocketClientError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure ServerSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
private
FServerPort:string;
FServerUser:string;
FServerPass:string;
FClientConnected:Boolean;
FClientAdr:string;
FAutorized:Boolean;
FClientSocket:TCustomWinSocket;
procedure OnConnect(Socket: TCustomWinSocket);
procedure OnDisconnect;
procedure ProcessMSG(SocketData:string);
public
procedure MainLog(Value:string);
end;
var
FormManager: TFormManager;
implementation
{$R *.dfm}
procedure TFormManager.MainLog(Value: string);
begin
ListBoxLog.Items.Add(Value);
end;
procedure TFormManager.OnConnect(Socket: TCustomWinSocket);
begin
FClientAdr:=Socket.RemoteAddress+':'+IntToStr(Socket.RemotePort);
MainLog(FClientAdr);
LabelConnected.Caption:='Ïðèñîåäèí¸í ê '+FClientAdr;
end;
procedure TFormManager.OnDisconnect;
begin
FClientAdr:='';
FAutorized:=False;
MainLog('Ñîåäèíåíèå çàêðûòî');
LabelConnected.Caption:='Îæèäàþ ïîäêëþ÷åíèÿ';
end;
procedure TFormManager.ProcessMSG(SocketData: string);
var MSGData:TStringList;
begin
MainLog(SocketData);
MSGData:=TStringList.Create;
MSGData.Text:=SocketData;
if MSGData.Count > 0 then
begin
if Pos('login ', MSGData[0]) <> 0 then FClientSocket.SendText(seAutorizateOK);
end;
MSGData.Free;
end;
procedure TFormManager.ServerSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
begin
MainLog('ServerSocketAccept');
end;
procedure TFormManager.ServerSocketClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
FClientConnected:=True;
Socket.Lock;
OnConnect(Socket);
end;
procedure TFormManager.ServerSocketClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
FClientConnected:=False;
Socket.Unlock;
OnDisconnect;
end;
procedure TFormManager.ServerSocketClientError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
MainLog('ServerSocketClientError');
end;
procedure TFormManager.ServerSocketClientRead(Sender: TObject; Socket: TCustomWinSocket);
var MSGData:TStringList;
SDT, tmp:string;
begin
MainLog('ServerSocketClientRead');
SDT:=UTF8ToString(Socket.ReceiveText);
if not FAutorized then
begin
MSGData:=TStringList.Create;
MSGData.Text:=SDT;
if MSGData.Count > 0 then
begin
if Pos('login ', MSGData[0]) <> 0 then
begin
if MSGData[0] = Format(formatAutorizate, [FServerUser, FServerPass]) then
begin
FAutorized:=True;
FClientSocket:=Socket;
end;
end;
end;
if not FAutorized then
begin
Socket.SendText(seAutorizateError);
Socket.Close;
Exit;
end;
end;
ProcessMSG(SDT);
MSGData.Free;
end;
procedure TFormManager.ServerSocketClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
begin
MainLog('ServerSocketClientWrite');
end;
procedure TFormManager.ServerSocketGetSocket(Sender: TObject; Socket: NativeInt; var ClientSocket: TServerClientWinSocket);
begin
MainLog('ServerSocketGetSocket');
end;
procedure TFormManager.ServerSocketGetThread(Sender: TObject;
ClientSocket: TServerClientWinSocket; var SocketThread: TServerClientThread);
begin
MainLog('ServerSocketGetThread');
end;
procedure TFormManager.ServerSocketListen(Sender: TObject; Socket: TCustomWinSocket);
begin
MainLog('ServerSocketListen');
end;
procedure TFormManager.ServerSocketThreadEnd(Sender: TObject;
Thread: TServerClientThread);
begin
MainLog('ServerSocketThreadEnd');
end;
procedure TFormManager.ServerSocketThreadStart(Sender: TObject;
Thread: TServerClientThread);
begin
MainLog('ServerSocketThreadStart');
end;
procedure TFormManager.Button2Click(Sender: TObject);
begin
ServerSocket.Close;
MainLog('Îñòàíîâëåí');
end;
procedure TFormManager.ButtonStartClick(Sender: TObject);
begin
if ServerSocket.Active then Exit;
FServerPort:=EditPort.Text;
FServerUser:=EditUser.Text;
FServerPass:=EditPass.Text;
try
ServerSocket.Port:=StrToInt(FServerPort);
except
begin
MainLog('Ïðîâåðüòå ïîðò');
Exit;
end;
end;
try
ServerSocket.Open;
MainLog('Çàïóùåí');
except
on E:Exception do
begin
MainLog(E.Message);
Exit;
end;
end;
end;
procedure TFormManager.FormCreate(Sender: TObject);
begin
FAutorized:=False;
end;
end.