-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMissionCommunicationU.pas
1154 lines (984 loc) · 44.2 KB
/
MissionCommunicationU.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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit MissionCommunicationU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
IdTCPServer, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
{INDY10}
IdCustomTCPServer, IdContext, IdTask,
{ENDE INDY10}
WinSock , NB30
//Trotz dem IdAntiFreeze friert es, wenn ein Fehler auftritt.
//, IdAntiFreeze
;
const PASSWORD = 'PASS';
const COM_VERSION = 11 ;
const //command
LOGIN_REQUEST_ = 1;
LOGIN_OK_ = 2;
LOGIN_CLIENT_REQUEST_ = 3;
QUIT_ = 4;
HELLO_ = 5;
GET_ = 11;
SET_ = 12;
CREATE_NEW_SWITCH_ = 21;
START_ = 60;
STOP_ = 61;
RESTART_ = 62;
GET_FILE_ = 80;
SEND_FILE_ = 81;
const //param
ID = 1;
SESSION_ID = 2;
CONTROLLER_IP = 11;
CONTROLLER_PORT = 12;
PACKET_RECEIVED = 51;
PACKET_SENT = 52;
PACKET_MEANTIME = 53;
PACKET_P_SECOND = 54;
PACKET_VAR = 55;
USLEEP_BATCHPROCESS = 61;
const //error
NO_ERROR_OK = 100;
COMMAND_NOT_RECOGNIZED = 104;
COMMAND_NOT_READY = 105;
PARAMETER_NOT_RECOGNIZED = 114;
PARAMETER_WRONG = 115;
type TCriticalQueryEvent = procedure(Sender: TObject; var paBoAllowed: Boolean) of object;
type TSpecialFunction = procedure (Sender: Tobject; AContext: TIdContext; var uintCommand: word; var uintError: Word; var intPayloadLength: cardinal; var msPayload: TMemoryStream) of object; //
type TMCComObj = class
private
public
IP : String;
Port : Integer;
AContext : TIdContext;
Active : Boolean;
ID : Integer;
end;
// TCP Server
type TCPServer = class(TIdTCPServer)
private
FOnShutdownQuery : TCriticalQueryEvent;
FOnRebootQuery : TCriticalQueryEvent;
FOnLogoffQuery : TCriticalQueryEvent;
FOnPoweroffQuery : TCriticalQueryEvent;
FOnProgramRestartQuery: TCriticalQueryEvent;
FOnCheckShutdownQuery : TCriticalQueryEvent;
FOnCheckRebootQuery : TCriticalQueryEvent;
FOnCheckProgramRestartQuery: TCriticalQueryEvent;
FOnCheckLogoffQuery : TCriticalQueryEvent;
FOnCheckPoweroffQuery : TCriticalQueryEvent;
FOnSpecialFunction : TSpecialFunction;
FOnHeartbeatIMAlliveMessage : TSpecialFunction;
FOnHeartbetProgramStateMessage : TSpecialFunction;
procedure CommandPicker(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Wellcome(AContext: TIdContext); //Cypher, in the future
procedure GetCommand(AContext: TIdContext);
//Commands
procedure LoginRequest__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure LoginClientRequest_(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Hello__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Get__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Set__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Start__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Stop__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Restart__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure GetFile__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure SendFile__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure Quit__ (AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure ReturnedPacketReceived(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
procedure ReturnedPacketSent(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
procedure ReturnedMeantime(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
procedure ReturnedPPSecond(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
public
Constructor Create; overload;
function CommandChecker(intCommand: integer): boolean;
procedure SendCommand(AContext: TIdContext ; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
procedure SendStream(AContext: TIdContext ; var msPayload : TMemoryStream);
procedure Start(Port:integer);
procedure Stop();
procedure SendHello(AContext: TIdContext);
procedure SendCreateNewSwitch(AContext: TIdContext);
procedure SendStop(AContext: TIdContext);
procedure SendStart(AContext: TIdContext);
procedure SendQuit(AContext: TIdContext);
procedure SendClientStop(AContext: TIdContext; const paIntSwitchNr: Integer);
procedure SendClientQuit(AContext: TIdContext);
function SendSetId(AContext: TIdContext): Integer;
function SendGetReceived(AContext: TIdContext): Int64;
function SendGetMeantime(AContext: TIdContext): Int64;
function SendGetPS(AContext: TIdContext): Int64;
procedure SendSet(AContext: TIdContext; const paIntParam: Smallint; const paStrValue: String);
procedure SendGet(AContext: TIdContext; const paIntParam: Smallint);
property OnShutdownQuery : TCriticalQueryEvent read FOnShutdownQuery write FOnShutdownQuery;
property OnRebootQuery : TCriticalQueryEvent read FOnRebootQuery write FOnRebootQuery;
property OnLogoffQuery : TCriticalQueryEvent read FOnLogoffQuery write FOnLogoffQuery;
property OnProgramRestartQuery: TCriticalQueryEvent read FOnProgramRestartQuery write FOnProgramRestartQuery;
property OnCheckShutdownQuery : TCriticalQueryEvent read FOnCheckShutdownQuery write FOnCheckShutdownQuery;
property OnCheckRebootQuery : TCriticalQueryEvent read FOnCheckRebootQuery write FOnCheckRebootQuery;
property OnCheckLogoffQuery : TCriticalQueryEvent read FOnCheckLogoffQuery write FOnCheckLogoffQuery;
property OnCheckProgramRestartQuery: TCriticalQueryEvent read FOnCheckProgramRestartQuery write FOnCheckProgramRestartQuery;
property OnCheckPoweroffQuery: TCriticalQueryEvent read FOnCheckPoweroffQuery write FOnCheckPoweroffQuery;
property OnSpecialFunction : TSpecialFunction read FOnSpecialFunction write FOnSpecialFunction;
end;
type TStreamMethods = class
public
class procedure StringToStream(const paStrString : AnsiString ; var PaStream : TMemoryStream; const paBoClearStream : Boolean = true); Overload;
class function StreamToString(var paStream : TMemoryStream ; const paIntLength : cardinal): AnsiString;
class procedure BooleanToStream(const paBoBoolean : Boolean; var paStream : TMemoryStream);
class function StreamToBoolean(var paStream : TMemoryStream): Boolean;
class function CommandToString(const paIntCommand: Integer): AnsiString;
class function ParamToString(const paIntCommand: Integer): AnsiString;
class function ErrorToString(const paIntCommand: Integer): AnsiString;
end;
//#############################################################################server############################################
var MissionControlServer : TCPServer;
FGlobalID : Integer;
implementation
Uses MControl;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.Create
Autor: zsolt
Beschreibung: TCPServer Constructor.
Argumente:
Rückgabewert: None
------------------------------------------------------------------------------------------------------------}
constructor TCPServer.Create();
begin
inherited Create();
Self.OnExecute := GetCommand;
Self.OnConnect := Wellcome;
end;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.Start
Autor: zsolt
Beschreibung: Startet den Server.
Argumente: Port:integer
Rückgabewert: None
------------------------------------------------------------------------------------------------------------}
procedure TCPServer.Start(Port:integer);
begin
try
self.defaultport := Port;
self.Active := true;
except
On E: Exception do begin
E.Message := 'TCPServer.Start: '+ E.Message;
Raise;
end;
end;
end;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.Stop
Autor: zsolt
Beschreibung: Stoppt den Server.
Argumente:
Rückgabewert: None
------------------------------------------------------------------------------------------------------------}
procedure TCPServer.Stop();
begin
try
self.active := false;
except
On E: Exception do begin
E.Message := 'TCPServer.Stop: ' + E.Message;
Raise;
end;
end;
self.Destroy;
end;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.GetCommand
Autor: zsolt
Beschreibung: Command an Server.
Argumente: AContext: TIdContext
Rückgabewert: None
------------------------------------------------------------------------------------------------------------}
procedure TCPServer.GetCommand(AContext: TIdContext);
var
uintVersion : SmallInt;
uintCommand : SmallInt;
uintParam : SmallInt;
uintError : SmallInt;
intPayloadLength : LongInt;
msPayload : TMemoryStream;
begin
//showmessage(inttostr(AContext.Binding.PeerPort));
//FTestContext := AContext;
msPayload := TMemoryStream.Create;
frmMissionControl.lbInfo.Items.Add('GET COMMAND:');
try
//read version
uintVersion := AContext.Connection.IOHandler.ReadSmallInt;
frmMissionControl.lbInfo.Items.Add('-GET-Ver:'+ inttostr(uintVersion));
//read command
uintCommand := AContext.Connection.IOHandler.ReadSmallInt;
frmMissionControl.lbInfo.Items.Add('-GET-Command:'+ TStreamMethods.CommandToString(uintCommand));
//check command
if (CommandChecker(uintCommand)) then begin
frmMissionControl.lbInfo.Items.Add('-GET-CommandCeck OK');
//read param
uintParam := AContext.Connection.IOHandler.ReadSmallInt;
frmMissionControl.lbInfo.Items.Add('-GET-Param:'+ inttostr(uintParam));
//read error
uintError := AContext.Connection.IOHandler.ReadSmallInt;
frmMissionControl.lbInfo.Items.Add('-GET-Error:'+ inttostr(uintError));
//read payload length
intPayloadLength := AContext.Connection.IOHandler.ReadLongInt;
frmMissionControl.lbInfo.Items.Add('-GET-PayloadLength:'+ inttostr(intPayloadLength));
//read payload
msPayload.Position := 0;
AContext.Connection.IOHandler.ReadStream(msPayload,intPayloadLength);
msPayload.Position := 0;
//send to command
CommandPicker(AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
end else begin
frmMissionControl.lbInfo.Items.Add('-GET-CommandCeck FAILED');
AContext.Connection.Disconnect;
end;
except
On E: Exception do begin
E.Message := 'TCPServer.GetCommand: '+ E.Message;
frmMissionControl.lbInfo.Items.Add(E.Message);
Raise;
end;
end;
msPayload.Free;
end;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.CommandPicker
Autor: zsolt
Beschreibung: Command forwarding.
Argumente: AContext: TIdContext; var uintCommand, uintError: Word; var intPayload: cardinal; var msPayload: TMemoryStream
Rückgabewert: None
------------------------------------------------------------------------------------------------------------}
procedure TCPServer.CommandPicker(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
case uintCommand of
LOGIN_REQUEST_ : LoginRequest__(AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
LOGIN_CLIENT_REQUEST_ : LoginClientRequest_(AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
QUIT_ : Quit__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
HELLO_ : Hello__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
GET_ : Get__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
SET_ : Set__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
START_ : Start__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
STOP_ : Stop__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
RESTART_ : Restart__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
GET_FILE_ : GetFile__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
SEND_FILE_ : SendFile__ (AContext, uintVersion, uintCommand, uintParam, uintError, intPayloadLength, msPayload);
else
//SendCommandNotRecognized(AContext);
end;
end;
procedure TCPServer.Wellcome(AContext: TIdContext);
begin
try
AContext.Connection.IOHandler.Writeln('SERVERHELLO');
except
On E: Exception do begin
E.Message := 'TCPServer.Wellcome: ' + E.Message;
Raise;
end;
end;
end;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.CommandChecker
Autor: zsolt
Beschreibung: Prüft ob der Command existiert.
Argumente: intCommand: integer
Rückgabewert: boolean
------------------------------------------------------------------------------------------------------------}
function TCPServer.CommandChecker(intCommand: integer): boolean;
begin
case intCommand of
LOGIN_REQUEST_: result:=true;
LOGIN_CLIENT_REQUEST_ : result:=true;
QUIT_ : result:=true;
HELLO_ : result:=true;
GET_ : result:=true;
SET_ : result:=true;
START_ : result:=true;
STOP_ : result:=true;
RESTART_ : result:=true;
GET_FILE_ : result:=true;
SEND_FILE_ : result:=true;
else
result := False;
end;
end;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.SendCommand
Autor: zsolt
Beschreibung: Sendet ein Command mit Daten
Argumente: AContext: TIdContext; var uintCommand: word; var uintError: Word; var intPayloadLength: cardinal; var msPayload: TMemoryStream
Rückgabewert: None
------------------------------------------------------------------------------------------------------------}
procedure TCPServer.SendCommand(AContext: TIdContext ; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
var
intVersion: SmallInt;
msMessageHeader: TMemoryStream;
intSize : Integer;
begin
try
//write version
{intVersion := COM_VERSION;
AContext.Connection.IOHandler.Write(intVersion);
// var intPayloadLength: LongInt ; var msPayload : TMemoryStream
//write command
AContext.Connection.IOHandler.Write(uintCommand);
//write param
AContext.Connection.IOHandler.Write(uintParam);
//write error
AContext.Connection.IOHandler.Write(uintError);
//write payload length
AContext.Connection.IOHandler.Write(intPayloadLength);;
//write payload
if intPayloadLength > 0 then begin
msPayload.Position := 0;
AContext.Connection.IOHandler.Write(msPayload,intPayloadLength);
msPayload.Position := 0;
end;
}
msMessageHeader := TMemoryStream.Create;
try
msMessageHeader.Position := 0;
intVersion := COM_VERSION;
msMessageHeader.Write(intVersion,sizeof(intVersion));
msMessageHeader.Write(uintCommand,SizeOf(uintCommand));
msMessageHeader.Write(uintParam,SizeOf(uintParam));
msMessageHeader.Write(uintError,SizeOf(uintError));
msMessageHeader.Write(intPayloadLength,SizeOf(intPayloadLength));
msMessageHeader.Position := 0;
AContext.Connection.IOHandler.Write(msMessageHeader, msMessageHeader.Size);
if intPayloadLength > 0 then begin
msPayload.Position := 0;
AContext.Connection.IOHandler.Write(msPayload,intPayloadLength);
msPayload.Position := 0;
end;
finally
msMessageHeader.Destroy;
end;
except
On E: Exception do begin
E.Message := 'TCPServer.SendCommand: ' + E.Message;
Raise;
end;
end;
end;
procedure TCPServer.SendStream(AContext: TIdContext ; var msPayload : TMemoryStream);
begin
msPayload.Position := 0;
try
AContext.Connection.IOHandler.Write(msPayload,msPayload.Size);
except
on e: Exception do begin
Showmessage('');
end;
end;
end;
{------------------------------------------------------------------------------------------------------------
Prozedur: TCPServer.ClientQuit
Autor: zsolt
Beschreibung: Der Klient sendet ein Quit Command.
Argumente: AContext: TIdContext; var uintCommand: word; var uintError: Word; var intPayloadLength: cardinal; var msPayload: TMemoryStream
Rückgabewert: None
------------------------------------------------------------------------------------------------------------}
procedure TCPServer.Quit__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
AContext.Connection.Disconnect;
end;
procedure TCPServer.LoginRequest__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
var
strPass: AnsiString;
intLength : Integer;
intResponseCommand : SmallInt;
msResponsePayload: TMemoryStream;
strPassword: PChar;
chrNull : Char;
tmpConObj : TMCComObj;
intID : Integer;
strIP, strPort : String;
begin
FTestContext := AContext; //erreichbarkeit über den Knopf
frmMissionControl.lbInfo.Items.Add('-SW-LOGIN REQUEST');
frmMissionControl.lbInfo.Items.Add('-SW-Version:'+ inttostr(uintVersion));
frmMissionControl.lbInfo.Items.Add('-SW-Command:'+ TStreamMethods.CommandToString(uintCommand));
frmMissionControl.lbInfo.Items.Add('-SW-Param:'+ TStreamMethods.ParamToString(uintParam));
frmMissionControl.lbInfo.Items.Add('-SW-Error:'+ TStreamMethods.ErrorToString(uintError));
strPass := TStreamMethods.StreamToString(msPayload,intPayloadLength);
frmMissionControl.lbInfo.Items.Add('-SW-Payload:'+strPass);
if ((uintVersion = COM_VERSION) and (uintError = NO_ERROR_OK) and (strPass = PASSWORD)) then begin
frmMissionControl.lbInfo.Items.Add('-SW-Authentication OK!');
intLength := 0;
intResponseCommand := LOGIN_OK_;
msResponsePayload := TMemoryStream.Create;
strPassword := StrAlloc(sizeof(PASSWORD)+1);
try
TStreamMethods.StringToStream(PASSWORD,msResponsePayload);
TStreamMethods.StringToStream(#0,msResponsePayload,false); // '\0'-ended, don't clear
//StrCopy(strPassword,PASSWORD);
//msResponsePayload.Clear;
//msResponsePayload.Write(strPassword, Sizeof(strPassword));
//chrNull := #0;
//msResponsePayload.Write(chrNull, 1);
//msResponsePayload.Position := 0;
intLength := msResponsePayload.Size;
SendCommand(AContext,intResponseCommand,uintParam,uintError,intLength,msResponsePayload);
//SetID command, da der Switch eine Globalen ID kriegt
intId := SendSetId(AContext);
strIP := frmMissionControl.edControllerIp.Text;
strPort:= frmMissionControl.edControllerPort.Text;
//SetController IP,Port
SendSet(AContext,CONTROLLER_IP,strIP);
SendSet(AContext,CONTROLLER_PORT,strPort);
//Insert into list
tmpConObj := TMCComObj.Create;
tmpConObj.IP := AContext.Connection.Socket.Binding.PeerIP;
tmpConObj.Port := AContext.Connection.Socket.Binding.PeerPort;
tmpConObj.AContext := AContext;
tmpConObj.Active := true;
frmMissionControl.sgSwitches.Objects[0,frmMissionControl.sgSwitches.RowCount-1] := tmpConObj;
frmMissionControl.sgSwitches.Cells[0,frmMissionControl.sgSwitches.RowCount-1] := IntToStr(intID);//IntToStr(frmMissionControl.sgSwitches.RowCount-1);
frmMissionControl.sgSwitches.Cells[1,frmMissionControl.sgSwitches.RowCount-1] := tmpConObj.IP;
frmMissionControl.sgSwitches.Cells[2,frmMissionControl.sgSwitches.RowCount-1] := IntToStr(tmpConObj.Port);
frmMissionControl.sgSwitches.RowCount := frmMissionControl.sgSwitches.RowCount + 1;
//List defragmentation
frmMissionControl.DefragmentLists;
finally
msResponsePayload.Destroy;
StrDispose(strPassword);
end;
end;
end;
procedure TCPServer.LoginClientRequest_(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
var
strPass: AnsiString;
intLength : Integer;
intResponseCommand : SmallInt;
msResponsePayload: TMemoryStream;
strPassword: PChar;
chrNull : Char;
tmpConObj : TMCComObj;
begin
FClientTestContext := AContext; //erreichbarkeit über den Knopf
frmMissionControl.lbInfo.Items.Add('-CLI-LOGIN CLIENT REQUEST');
frmMissionControl.lbInfo.Items.Add('-CLI-Version:'+ inttostr(uintVersion));
frmMissionControl.lbInfo.Items.Add('-CLI-Command:'+ TStreamMethods.CommandToString(uintCommand));
frmMissionControl.lbInfo.Items.Add('-CLI-Param:'+ TStreamMethods.ParamToString(uintParam));
frmMissionControl.lbInfo.Items.Add('-CLI-Error:'+ TStreamMethods.ErrorToString(uintError));
strPass := TStreamMethods.StreamToString(msPayload,intPayloadLength);
frmMissionControl.lbInfo.Items.Add('-CLI-Payload:'+strPass);
if ((uintVersion = COM_VERSION) and (uintError = NO_ERROR_OK) and (strPass = PASSWORD)) then begin
frmMissionControl.lbInfo.Items.Add('-CLI-Authentication Client OK!');
intLength := 0;
intResponseCommand := LOGIN_OK_;
msResponsePayload := TMemoryStream.Create;
strPassword := StrAlloc(sizeof(PASSWORD)+1);
try
TStreamMethods.StringToStream(PASSWORD,msResponsePayload);
TStreamMethods.StringToStream(#0,msResponsePayload,false); // '\0'-ended, don't clear
//StrCopy(strPassword,PASSWORD);
//msResponsePayload.Clear;
//msResponsePayload.Write(strPassword, Sizeof(strPassword));
//chrNull := #0;
//msResponsePayload.Write(chrNull, 1);
//msResponsePayload.Position := 0;
intLength := msResponsePayload.Size;
SendCommand(AContext,intResponseCommand,uintParam,uintError,intLength,msResponsePayload);
//Insert into list
tmpConObj := TMCComObj.Create;
tmpConObj.IP := AContext.Connection.Socket.Binding.PeerIP;
tmpConObj.Port := AContext.Connection.Socket.Binding.PeerPort;
tmpConObj.AContext := AContext;
tmpConObj.Active := true;
frmMissionControl.sgClients.Objects[0,frmMissionControl.sgClients.RowCount-1] := tmpConObj;
frmMissionControl.sgClients.Cells[0,frmMissionControl.sgClients.RowCount-1] := IntToStr(frmMissionControl.sgClients.RowCount-1);
frmMissionControl.sgClients.Cells[1,frmMissionControl.sgClients.RowCount-1] := tmpConObj.IP;
frmMissionControl.sgClients.Cells[2,frmMissionControl.sgClients.RowCount-1] := IntToStr(tmpConObj.Port);
frmMissionControl.sgClients.RowCount := frmMissionControl.sgClients.RowCount + 1;
//List defragmentation
frmMissionControl.DefragmentLists;
finally
msResponsePayload.Destroy;
StrDispose(strPassword);
end;
end;
end;
procedure TCPServer.Hello__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
end;
procedure TCPServer.Get__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
case uintParam of
//PACKET_RECEIVED : ReturnedPacketReceived(AContext, uintError, msPayload);
//PACKET_SENT : ReturnedPacketSent(AContext, uintError, msPayload);
//PACKET_MEANTIME : ReturnedMeantime(AContext, uintError, msPayload);
//PACKET_P_SECOND : ReturnedPPSecond(AContext, uintError, msPayload);
PACKET_RECEIVED : frmMissionControl.UpdateList(AContext.Binding.PeerIP, IntToStr(AContext.Binding.PeerPort),PACKET_RECEIVED, msPayload);
PACKET_SENT : frmMissionControl.UpdateList(AContext.Binding.PeerIP, IntToStr(AContext.Binding.PeerPort),PACKET_SENT, msPayload);
PACKET_MEANTIME : frmMissionControl.UpdateList(AContext.Binding.PeerIP, IntToStr(AContext.Binding.PeerPort),PACKET_MEANTIME, msPayload);
PACKET_P_SECOND : frmMissionControl.UpdateList(AContext.Binding.PeerIP, IntToStr(AContext.Binding.PeerPort),PACKET_P_SECOND, msPayload);
PACKET_VAR : frmMissionControl.UpdateList(AContext.Binding.PeerIP, IntToStr(AContext.Binding.PeerPort),PACKET_VAR, msPayload);
USLEEP_BATCHPROCESS : frmMissionControl.UpdateList(AContext.Binding.PeerIP, IntToStr(AContext.Binding.PeerPort),USLEEP_BATCHPROCESS, msPayload);
SESSION_ID : frmMissionControl.UpdateList(AContext.Binding.PeerIP, IntToStr(AContext.Binding.PeerPort),SESSION_ID, msPayload);
end;
end;
procedure TCPServer.Set__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
end;
procedure TCPServer.Start__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
end;
procedure TCPServer.Stop__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
end;
procedure TCPServer.Restart__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
end;
procedure TCPServer.GetFile__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
end;
procedure TCPServer.SendFile__(AContext: TIdContext ; var uintVersion: SmallInt; var uintCommand: SmallInt; var uintParam: SmallInt; var uintError: SmallInt; var intPayloadLength: LongInt ; var msPayload : TMemoryStream);
begin
end;
procedure TCPServer.ReturnedPacketReceived(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
var
strPayload : String;
begin
strPayload := TStreamMethods.StreamToString(msPayload,msPayload.Size);
//showmessage('Payload: '+strPayload);
end;
procedure TCPServer.ReturnedPacketSent(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
var
strPayload : String;
begin
strPayload := TStreamMethods.StreamToString(msPayload,msPayload.Size);
//showmessage('Payload: '+strPayload);
end;
procedure TCPServer.ReturnedMeantime(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
var
strPayload : String;
begin
strPayload := TStreamMethods.StreamToString(msPayload,msPayload.Size);
//showmessage('Payload: '+strPayload);
end;
procedure TCPServer.ReturnedPPSecond(AContext: TIdContext; var uintError: SmallInt; msPayload: TMemoryStream);
var
strPayload : String;
begin
strPayload := TStreamMethods.StreamToString(msPayload,msPayload.Size);
//showmessage('Payload: '+strPayload);
end;
{=================================== S E N D ====================================================}
procedure TCPServer.SendHello(AContext: TIdContext);
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= HELLO_;
intParam := ID;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendCreateNewSwitch(AContext: TIdContext);
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= CREATE_NEW_SWITCH_;
intParam := 1;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendClientStop(AContext: TIdContext; const paIntSwitchNr: Integer);
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= STOP_;
intParam := 1;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendClientQuit(AContext: TIdContext);
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= QUIT_;
intParam := 1;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
function TCPServer.SendSetId(AContext: TIdContext): Integer;
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
result := 0;
msPayload := TMemoryStream.Create;
try
intCommand:= SET_;
intParam := ID;
intError := NO_ERROR_OK;
intLength := 0;
inc(FGlobalID);
result := FGlobalID;
TStreamMethods.StringToStream(intToStr(FGlobalID),msPayload);
TStreamMethods.StringToStream(#0,msPayload,false); // '\0'-ended, don't clear
intLength := msPayload.Size;
//SendCommand(AContext,intResponseCommand,uintParam,uintError,intLength,msResponsePayload);
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
function TCPServer.SendGetReceived(AContext: TIdContext): Int64;
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
result := 0;
msPayload := TMemoryStream.Create;
try
intCommand:= GET_;
intParam := PACKET_RECEIVED;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
//Receive answer
finally
msPayload.Destroy;
end;
end;
function TCPServer.SendGetPS(AContext: TIdContext): Int64;
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
result := 0;
msPayload := TMemoryStream.Create;
try
intCommand:= GET_;
intParam := PACKET_P_SECOND;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
//Receive answer
finally
msPayload.Destroy;
end;
end;
function TCPServer.SendGetMeantime(AContext: TIdContext): Int64;
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
result := 0;
msPayload := TMemoryStream.Create;
try
intCommand:= GET_;
intParam := PACKET_MEANTIME;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
//Receive answer
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendSet(AContext: TIdContext; const paIntParam: Smallint; const paStrValue: String);
var
intVersion: SmallInt;
intCommand: SmallInt;
intError : SmallInt;
intParam : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= SET_;
intError := NO_ERROR_OK;
intParam := paIntParam;
TStreamMethods.StringToStream(paStrValue,msPayload);
TStreamMethods.StringToStream(#0,msPayload,false); // '\0'-ended, don't clear
intLength := msPayload.Size;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendGet(AContext: TIdContext; const paIntParam: Smallint);
var
intVersion: SmallInt;
intCommand: SmallInt;
intError : SmallInt;
intParam : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= GET_;
intParam := paIntParam;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
//showmessage('Sned to PeerPort: '+ IntToStr(Acontext.Binding.PeerPort));
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendStop(AContext: TIdContext);
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= STOP_;
intParam := 1;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendStart(AContext: TIdContext);
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= START_;
intParam := 1;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
procedure TCPServer.SendQuit(AContext: TIdContext);
var
intVersion: SmallInt;
intCommand: SmallInt;
intParam : SmallInt;
intError : SmallInt;
intLength : Integer;
msPayload : TMemoryStream;
begin
msPayload := TMemoryStream.Create;
try
intCommand:= QUIT_;
intParam := 1;
intError := NO_ERROR_OK;
intLength := 0;
SendCommand(AContext,intCommand,intParam,intError,intLength,msPayload);
finally
msPayload.Destroy;
end;
end;
{ StreamMethods }