-
Notifications
You must be signed in to change notification settings - Fork 4
/
net_main.pas
1138 lines (944 loc) · 23.7 KB
/
net_main.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
// ------------------------------------------------------------------------------
// DelphiQuake, Copyright (C) 2005-2011 by Jim Valavanis
// E-Mail: jimmyvalavanis@yahoo.gr
//
// Copyright (C) 1996-1997 Id Software, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ------------------------------------------------------------------------------
{$I dquake.inc}
{$Z4}
unit net_main;
// net_main.c
interface
uses
q_delphi,
common,
cvar,
net;
var
serialAvailable: qboolean = false;
ipxAvailable: qboolean = false;
tcpipAvailable: qboolean = false;
var
net_message: sizebuf_t;
function NET_SendUnreliableMessage(sock: Pqsocket_t; data: Psizebuf_t): integer;
procedure NET_Slist_f;
procedure NET_Poll;
function NET_GetMessage(sock: Pqsocket_t): integer;
function NET_CanSendMessage(sock: Pqsocket_t): qboolean;
function NET_SendMessage(sock: Pqsocket_t; data: Psizebuf_t): integer;
procedure NET_Close(sock: Pqsocket_t);
function NET_SendToAll(data: Psizebuf_t; blocktime: integer): integer;
procedure NET_Init;
procedure NET_Shutdown;
function NET_CheckNewConnections: Pqsocket_t;
function NET_Connect(host: PChar): Pqsocket_t;
function NET_NewQSocket: Pqsocket_t;
procedure NET_FreeQSocket(sock: Pqsocket_t);
function SetNetTime: double;
procedure SchedulePollProcedure(proc: PPollProcedure_t; timeOffset: double);
var
hostname: cvar_t = (name: 'hostname'; text: 'UNNAMED');
var
my_ipx_address: array[0..NET_NAMELEN - 1] of char;
my_tcpip_address: array[0..NET_NAMELEN - 1] of char;
var
net_hostport: integer;
DEFAULTnet_hostport: integer = 26000;
var
slistInProgress: qboolean = false;
slistSilent: qboolean = false;
slistLocal: qboolean = true;
var
hostcache: array[0..HOSTCACHESIZE - 1] of hostcache_t;
hostCacheCount: integer = 0;
var
net_activeconnections: integer = 0;
messagesSent: integer = 0;
messagesReceived: integer = 0;
unreliableMessagesSent: integer = 0;
unreliableMessagesReceived: integer = 0;
var
net_time: double;
var
vcrFile: integer = -1;
var
net_driverlevel: integer;
var
net_activeSockets: Pqsocket_t = nil;
net_freeSockets: Pqsocket_t = nil;
implementation
uses
net_vcr,
net_dgrm,
sys_win,
sv_main,
cmd,
console,
net_win,
host_h,
quakedef,
cl_main_h,
client,
zone;
var
net_numsockets: integer = 0;
(*
void (*GetComPortConfig) (int portNumber, int *port, int *irq, int *baud, qboolean *useModem);
void (*SetComPortConfig) (int portNumber, int port, int irq, int baud, qboolean useModem);
void (*GetModemConfig) (int portNumber, char *dialType, char *clear, char *init, char *hangup);
void (*SetModemConfig) (int portNumber, char *dialType, char *clear, char *init, char *hangup);
*)
var
listening: qboolean = false;
var
slistStartTime: double;
slistLastShown: integer;
var
slistSendProcedure: PollProcedure_t;
slistPollProcedure: PollProcedure_t;
var
net_messagetimeout: cvar_t = (name: 'net_messagetimeout'; text: '300');
configRestored: qboolean = false;
config_com_port: cvar_t = (name: '_config_com_port'; text: '1016' {'0x3f8'}; archive: true);
config_com_irq: cvar_t = (name: '_config_com_irq'; text: '4'; archive: true);
config_com_baud: cvar_t = (name: '_config_com_baud'; text: '57600'; archive: true);
config_com_modem: cvar_t = (name: '_config_com_modem'; text: '1'; archive: true);
config_modem_dialtype: cvar_t = (name: '_config_modem_dialtype'; text: 'T'; archive: true);
config_modem_clear: cvar_t = (name: '_config_modem_clear'; text: 'ATZ'; archive: true);
config_modem_init: cvar_t = (name: '_config_modem_init'; text: ''; archive: true);
config_modem_hangup: cvar_t = (name: '_config_modem_hangup'; text: 'AT H'; archive: true);
var
recording: qboolean = false;
function SetNetTime: double;
begin
net_time := Sys_FloatTime;
result := net_time;
end;
(*
===================
NET_NewQSocket
Called by drivers when a new communications endpoint is required
The sequence and buffer fields will be filled in properly
===================
*)
function NET_NewQSocket: Pqsocket_t;
var
sock: Pqsocket_t;
begin
if net_freeSockets = nil then
begin
result := nil;
exit;
end;
if net_activeconnections >= svs.maxclients then
begin
result := nil;
exit;
end;
// get one from free list
sock := net_freeSockets;
net_freeSockets := sock.next;
// add it to active list
sock.next := net_activeSockets;
net_activeSockets := sock;
sock.disconnected := false;
sock.connecttime := net_time;
Q_strcpy(sock.address, 'UNSET ADDRESS');
sock.driver := net_driverlevel;
sock.socket := 0;
sock.driverdata := nil;
sock.canSend := true;
sock.sendNext := false;
sock.lastMessageTime := net_time;
sock.ackSequence := 0;
sock.sendSequence := 0;
sock.unreliableSendSequence := 0;
sock.sendMessageLength := 0;
sock.receiveSequence := 0;
sock.unreliableReceiveSequence := 0;
sock.receiveMessageLength := 0;
result := sock;
end;
procedure NET_FreeQSocket(sock: Pqsocket_t);
var
s: Pqsocket_t;
begin
// remove it from active list
if sock = net_activeSockets then
net_activeSockets := net_activeSockets.next
else
begin
s := net_activeSockets;
while s <> nil do
begin
if s.next = sock then
begin
s.next := sock.next;
break;
end;
s := s.next;
end;
if s = nil then
Sys_Error('NET_FreeQSocket: not active'#10);
end;
// add it to free list
sock.next := net_freeSockets;
net_freeSockets := sock;
sock.disconnected := true;
end;
procedure NET_Listen_f;
var
i: integer;
begin
if Cmd_Argc_f <> 2 then
begin
Con_Printf('"listen" is "%u"'#10, [decide(listening, 1, 0)]);
exit;
end;
listening := decide(Q_atoi(Cmd_Argv_f(1)), true, false);
for i := 0 to net_numdrivers - 1 do
begin
net_driverlevel := i; // JVAL must do this ???
if not net_drivers[net_driverlevel].initialized then
continue;
net_drivers[net_driverlevel].Listen(listening);
end;
end;
procedure MaxPlayers_f;
var
n: integer;
begin
if Cmd_Argc_f <> 2 then
begin
Con_Printf('"maxplayers" is "%u"'#10, [svs.maxclients]);
exit;
end;
if sv.active then
begin
Con_Printf('maxplayers can not be changed while a server is running.'#10);
exit;
end;
n := Q_atoi(Cmd_Argv_f(1));
if n < 1 then
n := 1;
if n > svs.maxclientslimit then
begin
n := svs.maxclientslimit;
Con_Printf('"maxplayers" set to "%u"'#10, [n]);
end;
if (n = 1) and listening then
Cbuf_AddText('listen 0'#10);
if (n > 1) and not listening then
Cbuf_AddText('listen 1'#10);
svs.maxclients := n;
if n = 1 then
Cvar_Set('deathmatch', '0')
else
Cvar_Set('deathmatch', '1');
end;
procedure NET_Port_f;
var
n: integer;
begin
if Cmd_Argc_f <> 2 then
begin
Con_Printf('"port" is "%u"'#10, [net_hostport]);
exit;
end;
n := Q_atoi(Cmd_Argv_f(1));
if (n < 1) or (n > 65534) then
begin
Con_Printf('Bad value, must be between 1 and 65534'#10);
exit;
end;
DEFAULTnet_hostport := n;
net_hostport := n;
if listening then
begin
// force a change to the new port
Cbuf_AddText('listen 0'#10);
Cbuf_AddText('listen 1'#10);
end;
end;
procedure PrintSlistHeader;
begin
Con_Printf('Server Map Users'#10);
Con_Printf('--------------- --------------- -----'#10);
slistLastShown := 0;
end;
procedure PrintSlist;
var
n: integer;
begin
n := slistLastShown;
while n < hostCacheCount do
begin
if boolval(hostcache[n].maxusers) then
Con_Printf('%-15.15s %-15.15s %2u/%2u'#10, [hostcache[n].name, hostcache[n].map, hostcache[n].users, hostcache[n].maxusers])
else
Con_Printf('%-15.15s %-15.15s'#10, [hostcache[n].name, hostcache[n].map]);
inc(n);
end;
slistLastShown := n;
end;
procedure PrintSlistTrailer;
begin
if boolval(hostCacheCount) then
Con_Printf('== end list =='#10#10)
else
Con_Printf('No Quake servers found.'#10#10);
end;
procedure NET_Slist_f;
begin
if slistInProgress then
exit;
if not slistSilent then
begin
Con_Printf('Looking for Quake servers...'#10);
PrintSlistHeader;
end;
slistInProgress := true;
slistStartTime := Sys_FloatTime;
SchedulePollProcedure(@slistSendProcedure, 0.0);
SchedulePollProcedure(@slistPollProcedure, 0.1);
hostCacheCount := 0;
end;
procedure Slist_Send;
label
continue1;
begin
net_driverlevel := 0;
while net_driverlevel < net_numdrivers do
begin
if not slistLocal and (net_driverlevel = 0) then
goto continue1;
if not net_drivers[net_driverlevel].initialized then
goto continue1;
net_drivers[net_driverlevel].SearchForHosts(true);
continue1:
inc(net_driverlevel);
end;
if (Sys_FloatTime - slistStartTime) < 0.5 then
SchedulePollProcedure(@slistSendProcedure, 0.75);
end;
procedure Slist_Poll;
label
continue1;
begin
net_driverlevel := 0;
while net_driverlevel < net_numdrivers do
begin
if not slistLocal and (net_driverlevel = 0) then
goto continue1;
if not net_drivers[net_driverlevel].initialized then
goto continue1;
net_drivers[net_driverlevel].SearchForHosts(false);
continue1:
inc(net_driverlevel);
end;
if not slistSilent then
PrintSlist;
if (Sys_FloatTime - slistStartTime) < 1.5 then
begin
SchedulePollProcedure(@slistPollProcedure, 0.1);
exit;
end;
if not slistSilent then
PrintSlistTrailer;
slistInProgress := false;
slistSilent := false;
slistLocal := true;
end;
(*
===================
NET_Connect
===================
*)
function NET_Connect(host: PChar): Pqsocket_t;
label
JustDoIt;
var
n: integer;
numdrivers: integer;
begin
numdrivers := net_numdrivers;
SetNetTime;
if (host <> nil) and (host^ = #0) then
host := nil;
if host <> nil then
begin
if Q_strcasecmp(host, 'local') = 0 then
begin
numdrivers := 1;
goto JustDoIt;
end;
if hostCacheCount <> 0 then
begin
n := 0;
while n < hostCacheCount do
begin
if Q_strcasecmp(host, hostcache[n].name) = 0 then
begin
host := hostcache[n].cname;
break;
end;
inc(n);
end;
if n < hostCacheCount then
goto JustDoIt;
end;
end;
slistSilent := boolval(host); // JVAL check
NET_Slist_f;
while slistInProgress do
NET_Poll;
if host = nil then
begin
if hostCacheCount <> 1 then
begin
result := nil;
exit;
end;
host := hostcache[0].cname;
Con_Printf('Connecting to...'#10'%s @ %s'#10#10, [hostcache[0].name, host]);
end;
if hostCacheCount <> 0 then
for n := 0 to hostCacheCount - 1 do
if Q_strcasecmp(host, hostcache[n].name) = 0 then
begin
host := hostcache[n].cname;
break;
end;
JustDoIt:
net_driverlevel := 0;
while net_driverlevel < numdrivers do
begin
if net_drivers[net_driverlevel].initialized then
begin
result := net_drivers[net_driverlevel].Connect(host);
if result <> nil then
exit;
end;
inc(net_driverlevel);
end;
if host <> nil then
begin
Con_Printf(#10);
PrintSlistHeader;
PrintSlist;
PrintSlistTrailer;
end;
result := nil;
end;
(*
===================
NET_CheckNewConnections
===================
*)
type
vcrConnect_t = record
time: double;
op: integer;
session: integer;
end;
var
vcrConnect: vcrConnect_t;
function NET_CheckNewConnections: Pqsocket_t;
label
continue1;
begin
SetNetTime;
net_driverlevel := 0;
while net_driverlevel < net_numdrivers do
begin
if not net_drivers[net_driverlevel].initialized then
goto continue1;
if (net_driverlevel <> 0) and not listening then
goto continue1;
result := net_drivers[net_driverlevel].CheckNewConnections;
if result <> nil then
begin
if recording then
begin
vcrConnect.time := host_time;
vcrConnect.op := VCR_OP_CONNECT;
vcrConnect.session := integer(result);
Sys_FileWrite(vcrFile, @vcrConnect, SizeOf(vcrConnect));
Sys_FileWrite(vcrFile, @result.address, NET_NAMELEN);
end;
exit;
end;
continue1:
inc(net_driverlevel);
end;
if recording then
begin
vcrConnect.time := host_time;
vcrConnect.op := VCR_OP_CONNECT;
vcrConnect.session := 0;
Sys_FileWrite(vcrFile, @vcrConnect, SizeOf(vcrConnect));
end;
result := nil;
end;
(*
===================
NET_Close
===================
*)
procedure NET_Close(sock: Pqsocket_t);
begin
if sock = nil then
exit;
if sock.disconnected then
exit;
SetNetTime;
// call the driver_Close function
net_drivers[sock.driver].Close(sock);
NET_FreeQSocket(sock);
end;
(*
=================
NET_GetMessage
If there is a complete message, return it in net_message
returns 0 if no data is waiting
returns 1 if a message was received
returns -1 if connection is invalid
=================
*)
type
vcrGetMessage_t = record
time: double;
op: integer;
session: integer;
ret: integer;
len: integer;
end;
var
vcrGetMessage: vcrGetMessage_t;
function NET_GetMessage(sock: Pqsocket_t): integer;
begin
if sock = nil then
begin
result := -1;
exit;
end;
if sock.disconnected then
begin
Con_Printf('NET_GetMessage: disconnected socket'#10);
result := -1;
exit;
end;
SetNetTime;
result := net_drivers[sock.driver].QGetMessage(sock);
// see if this connection has timed out
if (result = 0) and boolval(sock.driver) then
begin
if (net_time - sock.lastMessageTime) > net_messagetimeout.value then
begin
NET_Close(sock);
result := -1;
exit;
end;
end;
if result > 0 then
begin
if boolval(sock.driver) then
begin
sock.lastMessageTime := net_time;
if result = 1 then
inc(messagesReceived)
else if result = 2 then
inc(unreliableMessagesReceived);
end;
if recording then
begin
vcrGetMessage.time := host_time;
vcrGetMessage.op := VCR_OP_GETMESSAGE;
vcrGetMessage.session := integer(sock);
vcrGetMessage.ret := result;
vcrGetMessage.len := net_message.cursize;
Sys_FileWrite(vcrFile, @vcrGetMessage, 24);
Sys_FileWrite(vcrFile, net_message.data, net_message.cursize);
end;
end
else
begin
if recording then
begin
vcrGetMessage.time := host_time;
vcrGetMessage.op := VCR_OP_GETMESSAGE;
vcrGetMessage.session := integer(sock);
vcrGetMessage.ret := result;
Sys_FileWrite(vcrFile, @vcrGetMessage, 20);
end;
end;
end;
(*
==================
NET_SendMessage
Try to send a complete length+message unit over the reliable stream.
returns 0 if the message cannot be delivered reliably, but the connection
is still considered valid
returns 1 if the message was sent properly
returns -1 if the connection died
==================
*)
type
vcrSendMessage_t = record
time: double;
op: integer;
session: integer;
r: integer;
end;
var
vcrSendMessage: vcrSendMessage_t;
function NET_SendMessage(sock: Pqsocket_t; data: Psizebuf_t): integer;
begin
if sock = nil then
begin
result := -1;
exit;
end;
if sock.disconnected then
begin
Con_Printf('NET_SendMessage: disconnected socket'#10);
result := -1;
exit;
end;
SetNetTime;
result := net_drivers[sock.driver].QSendMessage(sock, data);
if (result = 1) and boolval(sock.driver) then
inc(messagesSent);
if recording then
begin
vcrSendMessage.time := host_time;
vcrSendMessage.op := VCR_OP_SENDMESSAGE;
vcrSendMessage.session := integer(sock);
vcrSendMessage.r := result;
Sys_FileWrite(vcrFile, @vcrSendMessage, 20);
end;
end;
function NET_SendUnreliableMessage(sock: Pqsocket_t; data: Psizebuf_t): integer;
begin
if sock = nil then
begin
result := -1;
exit;
end;
if sock.disconnected then
begin
Con_Printf('NET_SendMessage: disconnected socket'#10);
result := -1;
exit;
end;
SetNetTime;
result := net_drivers[sock.driver].SendUnreliableMessage(sock, data);
if (result = 1) and boolval(sock.driver) then
inc(unreliableMessagesSent);
if recording then
begin
vcrSendMessage.time := host_time;
vcrSendMessage.op := VCR_OP_SENDMESSAGE;
vcrSendMessage.session := integer(sock);
vcrSendMessage.r := result;
Sys_FileWrite(vcrFile, @vcrSendMessage, 20);
end;
end;
(*
==================
NET_CanSendMessage
Returns true or false if the given qsocket can currently accept a
message to be transmitted.
==================
*)
function NET_CanSendMessage(sock: Pqsocket_t): qboolean;
begin
if sock = nil then // JVAL mayby procvalidsock(sock): qboolean ?
begin
result := false;
exit;
end;
if sock.disconnected then
begin
result := false;
exit;
end;
SetNetTime;
result := net_drivers[sock.driver].CanSendMessage(sock);
if recording then
begin
vcrSendMessage.time := host_time;
vcrSendMessage.op := VCR_OP_CANSENDMESSAGE;
vcrSendMessage.session := integer(sock);
vcrSendMessage.r := intval(result);
Sys_FileWrite(vcrFile, @vcrSendMessage, 20);
end;
end;
function NET_SendToAll(data: Psizebuf_t; blocktime: integer): integer;
label
continue1;
var
start: double;
i: integer;
count: integer;
state1: array[0..MAX_SCOREBOARD - 1] of qboolean;
state2: array[0..MAX_SCOREBOARD - 1] of qboolean;
begin
count := 0;
host_client := @svs.clients[0]; // JVAL check!
for i := 0 to svs.maxclients - 1 do
begin
if not boolval(host_client.netconnection) then
goto continue1;
if host_client.active then
begin
if host_client.netconnection.driver = 0 then
begin
NET_SendMessage(host_client.netconnection, data);
state1[i] := true;
state2[i] := true;
goto continue1;
end;
inc(count);
state1[i] := false;
state2[i] := false;
end
else
begin
state1[i] := true;
state2[i] := true;
end;
continue1:
inc(host_client);
end;
start := Sys_FloatTime;
while count <> 0 do
begin
count := 0;
host_client := @svs.clients[0];
for i := 0 to svs.maxclients - 1 do
begin
if not state1[i] then
begin
if NET_CanSendMessage(host_client.netconnection) then
begin
state1[i] := true;
NET_SendMessage(host_client.netconnection, data);
end
else
begin
NET_GetMessage(host_client.netconnection);
end;
inc(count);
end
else if not state2[i] then
begin
if NET_CanSendMessage(host_client.netconnection) then
begin
state2[i] := true;
end
else
begin
NET_GetMessage(host_client.netconnection);
end;
inc(count);
end;
inc(host_client);
end;
if (Sys_FloatTime - start) > blocktime then
break;
end;
result := count;
end;
//=============================================================================
(*
====================
NET_Init
====================
*)
procedure NET_Init;
var
i: integer;
controlSocket: integer;
s: Pqsocket_t;
begin
if COM_CheckParm('-playback') <> 0 then
begin
net_numdrivers := 1;
net_drivers[0].Init := VCR_Init;
end;
if COM_CheckParm('-record') <> 0 then
recording := true;
i := COM_CheckParm('-port');
if i = 0 then
i := COM_CheckParm('-udpport');
if i = 0 then
i := COM_CheckParm('-ipxport');
if i <> 0 then
begin
if i < com_argc - 1 then
DEFAULTnet_hostport := Q_atoi(com_argv[i + 1])
else
Sys_Error('NET_Init: you must specify a number after -port');
end;
net_hostport := DEFAULTnet_hostport;
if (COM_CheckParm('-listen') <> 0) or (cls.state = ca_dedicated) then
listening := true;
net_numsockets := svs.maxclientslimit;
if cls.state <> ca_dedicated then
inc(net_numsockets);
SetNetTime;
for i := 0 to net_numsockets - 1 do
begin
s := Pqsocket_t(Hunk_AllocName(SizeOf(qsocket_t), 'qsocket'));
s.next := net_freeSockets;
net_freeSockets := s;
s.disconnected := true;
end;
// allocate space for network message buffer
SZ_Alloc(@net_message, NET_MAXMESSAGE);
Cvar_RegisterVariable(@net_messagetimeout);
Cvar_RegisterVariable(@hostname);
Cvar_RegisterVariable(@config_com_port);
Cvar_RegisterVariable(@config_com_irq);
Cvar_RegisterVariable(@config_com_baud);
Cvar_RegisterVariable(@config_com_modem);
Cvar_RegisterVariable(@config_modem_dialtype);
Cvar_RegisterVariable(@config_modem_clear);
Cvar_RegisterVariable(@config_modem_init);
Cvar_RegisterVariable(@config_modem_hangup);
Cmd_AddCommand('slist', NET_Slist_f);