1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 wadreader
; // for SArray
24 procedure g_Console_Init();
25 procedure g_Console_Update();
26 procedure g_Console_Draw();
27 procedure g_Console_Switch();
28 procedure g_Console_Char(C
: Char);
29 procedure g_Console_Control(K
: Word);
30 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
31 procedure g_Console_Add(L
: String; Show
: Boolean = False);
32 procedure g_Console_Clear();
33 function g_Console_CommandBlacklisted(C
: String): Boolean;
35 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
36 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
38 // <0: no arg; 0/1: true/false
39 function conGetBoolArg (P
: SArray
; idx
: Integer): Integer;
41 procedure g_Console_Chat_Switch(Team
: Boolean = False);
43 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false);
47 gConsoleShow
: Boolean; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
49 gChatTeam
: Boolean = False;
50 gAllowConsoleMessages
: Boolean = True;
51 gChatEnter
: Boolean = True;
52 gJustChatted
: Boolean = False; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
57 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
58 SysUtils
, g_basic
, g_options
, Math
,
59 g_menu
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
, utils
;
64 TCmdProc
= procedure (P
: SArray
);
65 TCmdProcEx
= procedure (me
: PCommand
; P
: SArray
);
73 ptr
: Pointer; // various data
74 msg
: AnsiString; // message for var changes
88 MaxScriptRecursion
= 16;
90 DEBUG_STRING
= 'DEBUG MODE';
94 RecursionDepth
: Word = 0;
95 RecursionLimitHit
: Boolean = False;
97 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
100 //ConsoleHistory: SArray;
101 CommandHistory
: SArray
;
103 Commands
: Array of TCommand
= nil;
104 Aliases
: Array of TAlias
= nil;
106 conSkipLines
: Integer = 0;
107 MsgArray
: Array [0..4] of record
113 // <0: no arg; 0/1: true/false
114 function conGetBoolArg (P
: SArray
; idx
: Integer): Integer;
116 if (idx
< 0) or (idx
> High(P
)) then begin result
:= -1; exit
; end;
118 if (P
[idx
] = '1') or (CompareText(P
[idx
], 'on') = 0) or (CompareText(P
[idx
], 'true') = 0) or
119 (CompareText(P
[idx
], 'tan') = 0) or (CompareText(P
[idx
], 'yes') = 0) then result
:= 1;
123 procedure boolVarHandler (me
: PCommand
; P
: SArray
);
125 procedure binaryFlag (var flag
: Boolean; msg
: string);
127 if (Length(p
) > 2) then
129 conwritefln('too many arguments to ''%s''', [P
[0]]);
133 case conGetBoolArg(P
, 1) of
135 0: if conIsCheatsEnabled
then flag
:= false else begin conwriteln('not available'); exit
; end;
136 1: if conIsCheatsEnabled
then flag
:= true else begin conwriteln('not available'); exit
; end;
138 if flag
then conwritefln('%s: tan', [msg
]) else conwritefln('%s: ona', [msg
]);
143 binaryFlag(PBoolean(me
.ptr
)^, me
.msg
);
147 procedure conRegVar (const conname
: AnsiString; pvar
: PBoolean; const ahelp
: AnsiString; const amsg
: AnsiString; acheat
: Boolean=false);
152 f
:= Length(Commands
);
153 SetLength(Commands
, f
+1);
155 cp
.Cmd
:= LowerCase(conname
);
157 cp
.ProcEx
:= boolVarHandler
;
166 function GetStrACmd(var Str
: String): String;
171 for a
:= 1 to Length(Str
) do
172 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
174 Result
:= Copy(Str
, 1, a
);
181 function ParseAlias(Str
: String): SArray
;
192 SetLength(Result
, Length(Result
)+1);
193 Result
[High(Result
)] := GetStrACmd(Str
);
197 procedure ConsoleCommands(P
: SArray
);
203 Cmd
:= LowerCase(P
[0]);
206 if Cmd
= 'clear' then
208 //ConsoleHistory := nil;
212 for a
:= 0 to High(MsgArray
) do
220 if Cmd
= 'clearhistory' then
221 CommandHistory
:= nil;
223 if Cmd
= 'showhistory' then
224 if CommandHistory
<> nil then
227 for a
:= 0 to High(CommandHistory
) do
228 g_Console_Add(' '+CommandHistory
[a
]);
231 if Cmd
= 'commands' then
234 g_Console_Add('Commands list:');
235 for a
:= High(Commands
) downto 0 do
237 if (Length(Commands
[a
].help
) > 0) then
239 g_Console_Add(' '+Commands
[a
].Cmd
+' -- '+Commands
[a
].help
);
243 g_Console_Add(' '+Commands
[a
].Cmd
);
249 g_Console_Add(TimeToStr(Now
), True);
252 g_Console_Add(DateToStr(Now
), True);
255 if Length(P
) > 1 then
257 if P
[1] = 'ololo' then
262 for a
:= 1 to High(P
) do
264 g_Console_Add(b_Text_Format(s
), True);
273 if ConsoleHistory <> nil then
275 if Length(P) > 1 then
278 s := GameDir+'/console.txt';
283 if IOResult <> 0 then
285 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
290 for a := 0 to High(ConsoleHistory) do
291 WriteLn(F, ConsoleHistory[a]);
294 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
303 if Length(P
) > 1 then
305 s
:= GameDir
+'/'+P
[1];
310 if IOResult
<> 0 then
312 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
316 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
321 if IOResult
<> 0 then
323 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
327 if Pos('#', s
) <> 1 then // script comment
329 // prevents endless loops
331 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
332 if not RecursionLimitHit
then
333 g_Console_Process(s
, True);
337 if (RecursionDepth
= 0) and RecursionLimitHit
then
339 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
340 RecursionLimitHit
:= False;
347 g_Console_Add('exec <script file>');
350 if Cmd
= 'alias' then
352 // alias [alias_name] [commands]
353 if Length(P
) > 1 then
355 for a
:= 0 to High(Aliases
) do
356 if Aliases
[a
].Name
= P
[1] then
358 if Length(P
) > 2 then
359 Aliases
[a
].Commands
:= ParseAlias(P
[2])
361 for b
:= 0 to High(Aliases
[a
].Commands
) do
362 g_Console_Add(Aliases
[a
].Commands
[b
]);
365 SetLength(Aliases
, Length(Aliases
)+1);
367 Aliases
[a
].Name
:= P
[1];
368 if Length(P
) > 2 then
369 Aliases
[a
].Commands
:= ParseAlias(P
[2])
371 for b
:= 0 to High(Aliases
[a
].Commands
) do
372 g_Console_Add(Aliases
[a
].Commands
[b
]);
374 for a
:= 0 to High(Aliases
) do
375 if Aliases
[a
].Commands
<> nil then
376 g_Console_Add(Aliases
[a
].Name
);
382 if Length(P
) > 1 then
384 if Aliases
= nil then
386 for a
:= 0 to High(Aliases
) do
387 if Aliases
[a
].Name
= P
[1] then
389 if Aliases
[a
].Commands
<> nil then
391 // with this system proper endless loop detection seems either impossible
392 // or very dirty to implement, so let's have this instead
393 // prevents endless loops
394 for b
:= 0 to High(Aliases
[a
].Commands
) do
397 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
398 if not RecursionLimitHit
then
399 g_Console_Process(Aliases
[a
].Commands
[b
], True);
402 if (RecursionDepth
= 0) and RecursionLimitHit
then
404 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
405 RecursionLimitHit
:= False;
412 g_Console_Add('call <alias name>');
416 procedure WhitelistCommand(Cmd
: string);
420 SetLength(Whitelist
, Length(Whitelist
)+1);
421 a
:= High(Whitelist
);
422 Whitelist
[a
] := LowerCase(Cmd
);
425 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
; ahelp
: String=''; ahidden
: Boolean=false; acheat
: Boolean=false);
430 SetLength(Commands
, Length(Commands
)+1);
433 cp
.Cmd
:= LowerCase(Cmd
);
437 cp
.hidden
:= ahidden
;
443 procedure g_Console_Init();
447 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
448 Cons_Y
:= -(gScreenHeight
div 2);
449 gConsoleShow
:= False;
454 for a
:= 0 to High(MsgArray
) do
461 AddCommand('clear', ConsoleCommands
, 'clear console');
462 AddCommand('clearhistory', ConsoleCommands
);
463 AddCommand('showhistory', ConsoleCommands
);
464 AddCommand('commands', ConsoleCommands
);
465 AddCommand('time', ConsoleCommands
);
466 AddCommand('date', ConsoleCommands
);
467 AddCommand('echo', ConsoleCommands
);
468 AddCommand('dump', ConsoleCommands
);
469 AddCommand('exec', ConsoleCommands
);
470 AddCommand('alias', ConsoleCommands
);
471 AddCommand('call', ConsoleCommands
);
473 AddCommand('d_window', DebugCommands
);
474 AddCommand('d_sounds', DebugCommands
);
475 AddCommand('d_frames', DebugCommands
);
476 AddCommand('d_winmsg', DebugCommands
);
477 AddCommand('d_monoff', DebugCommands
);
478 AddCommand('d_botoff', DebugCommands
);
479 AddCommand('d_monster', DebugCommands
);
480 AddCommand('d_health', DebugCommands
);
481 AddCommand('d_player', DebugCommands
);
482 AddCommand('d_joy', DebugCommands
);
484 AddCommand('p1_name', GameCVars
);
485 AddCommand('p2_name', GameCVars
);
486 AddCommand('p1_color', GameCVars
);
487 AddCommand('p2_color', GameCVars
);
488 AddCommand('r_showfps', GameCVars
);
489 AddCommand('r_showtime', GameCVars
);
490 AddCommand('r_showscore', GameCVars
);
491 AddCommand('r_showlives', GameCVars
);
492 AddCommand('r_showstat', GameCVars
);
493 AddCommand('r_showkillmsg', GameCVars
);
494 AddCommand('r_showspect', GameCVars
);
495 AddCommand('r_showping', GameCVars
);
496 AddCommand('g_gamemode', GameCVars
);
497 AddCommand('g_friendlyfire', GameCVars
);
498 AddCommand('g_weaponstay', GameCVars
);
499 AddCommand('g_allow_exit', GameCVars
);
500 AddCommand('g_allow_monsters', GameCVars
);
501 AddCommand('g_bot_vsmonsters', GameCVars
);
502 AddCommand('g_bot_vsplayers', GameCVars
);
503 AddCommand('g_scorelimit', GameCVars
);
504 AddCommand('g_timelimit', GameCVars
);
505 AddCommand('g_maxlives', GameCVars
);
506 AddCommand('g_warmuptime', GameCVars
);
507 AddCommand('net_interp', GameCVars
);
508 AddCommand('net_forceplayerupdate', GameCVars
);
509 AddCommand('net_predictself', GameCVars
);
510 AddCommand('sv_name', GameCVars
);
511 AddCommand('sv_passwd', GameCVars
);
512 AddCommand('sv_maxplrs', GameCVars
);
513 AddCommand('sv_public', GameCVars
);
514 AddCommand('sv_intertime', GameCVars
);
516 AddCommand('quit', GameCommands
);
517 AddCommand('exit', GameCommands
);
518 AddCommand('pause', GameCommands
);
519 AddCommand('endgame', GameCommands
);
520 AddCommand('restart', GameCommands
);
521 AddCommand('addbot', GameCommands
);
522 AddCommand('bot_add', GameCommands
);
523 AddCommand('bot_addlist', GameCommands
);
524 AddCommand('bot_addred', GameCommands
);
525 AddCommand('bot_addblue', GameCommands
);
526 AddCommand('bot_removeall', GameCommands
);
527 AddCommand('chat', GameCommands
);
528 AddCommand('teamchat', GameCommands
);
529 AddCommand('game', GameCommands
);
530 AddCommand('host', GameCommands
);
531 AddCommand('map', GameCommands
);
532 AddCommand('nextmap', GameCommands
);
533 AddCommand('endmap', GameCommands
);
534 AddCommand('goodbye', GameCommands
);
535 AddCommand('suicide', GameCommands
);
536 AddCommand('spectate', GameCommands
);
537 AddCommand('ready', GameCommands
);
538 AddCommand('kick', GameCommands
);
539 AddCommand('kick_id', GameCommands
);
540 AddCommand('ban', GameCommands
);
541 AddCommand('permban', GameCommands
);
542 AddCommand('ban_id', GameCommands
);
543 AddCommand('permban_id', GameCommands
);
544 AddCommand('unban', GameCommands
);
545 AddCommand('connect', GameCommands
);
546 AddCommand('disconnect', GameCommands
);
547 AddCommand('reconnect', GameCommands
);
548 AddCommand('say', GameCommands
);
549 AddCommand('tell', GameCommands
);
550 AddCommand('overtime', GameCommands
);
551 AddCommand('rcon_password', GameCommands
);
552 AddCommand('rcon', GameCommands
);
553 AddCommand('callvote', GameCommands
);
554 AddCommand('vote', GameCommands
);
555 AddCommand('clientlist', GameCommands
);
556 AddCommand('event', GameCommands
);
558 AddCommand('god', GameCheats
);
559 AddCommand('notarget', GameCheats
);
560 AddCommand('give', GameCheats
); // "exit" too ;-)
561 AddCommand('open', GameCheats
);
562 AddCommand('fly', GameCheats
);
563 AddCommand('noclip', GameCheats
);
564 AddCommand('speedy', GameCheats
);
565 AddCommand('jumpy', GameCheats
);
566 AddCommand('noreload', GameCheats
);
567 AddCommand('aimline', GameCheats
);
568 AddCommand('automap', GameCheats
);
570 WhitelistCommand('say');
571 WhitelistCommand('tell');
572 WhitelistCommand('overtime');
573 WhitelistCommand('ready');
574 WhitelistCommand('map');
575 WhitelistCommand('nextmap');
576 WhitelistCommand('endmap');
577 WhitelistCommand('restart');
578 WhitelistCommand('kick');
579 WhitelistCommand('ban');
581 WhitelistCommand('addbot');
582 WhitelistCommand('bot_add');
583 WhitelistCommand('bot_addred');
584 WhitelistCommand('bot_addblue');
585 WhitelistCommand('bot_removeall');
587 WhitelistCommand('g_gamemode');
588 WhitelistCommand('g_friendlyfire');
589 WhitelistCommand('g_weaponstay');
590 WhitelistCommand('g_allow_exit');
591 WhitelistCommand('g_allow_monsters');
592 WhitelistCommand('g_scorelimit');
593 WhitelistCommand('g_timelimit');
595 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
599 procedure g_Console_Update();
605 // Â ïðîöåññå îòêðûòèÿ:
606 if gConsoleShow
and (Cons_Y
< 0) then
608 Cons_Y
:= Cons_Y
+Step
;
611 // Â ïðîöåññå çàêðûòèÿ:
612 if (not gConsoleShow
) and
613 (Cons_Y
> -(gScreenHeight
div 2)) then
614 Cons_Y
:= Cons_Y
-Step
;
616 // Îêîí÷àòåëüíî îòêðûëàñü:
620 // Îêîí÷àòåëüíî çàêðûëàñü:
621 if Cons_Y
<= (-(gScreenHeight
div 2)) then
623 Cons_Y
:= -(gScreenHeight
div 2);
629 while a
<= High(MsgArray
) do
631 if MsgArray
[a
].Time
> 0 then
633 if MsgArray
[a
].Time
= 1 then
635 if a
< High(MsgArray
) then
637 for b
:= a
to High(MsgArray
)-1 do
638 MsgArray
[b
] := MsgArray
[b
+1];
640 MsgArray
[High(MsgArray
)].Time
:= 0;
646 Dec(MsgArray
[a
].Time
);
654 procedure drawConsoleText ();
656 CWidth
, CHeight
: Byte;
661 procedure putLine (sp
, ep
: LongWord);
670 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
671 if wdt
+cw
> gScreenWidth
-8 then break
;
672 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
676 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
677 // now print our part
685 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
686 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
699 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
700 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
701 skip
:= conSkipLines
;
702 cbufLastLine(sp
, ep
);
705 if ty
+CHeight
<= 0 then break
;
706 until not cbufLineUp(sp
, ep
);
709 procedure g_Console_Draw();
711 CWidth
, CHeight
: Byte;
715 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
717 for a
:= 0 to High(MsgArray
) do
718 if MsgArray
[a
].Time
> 0 then
719 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
722 if not Cons_Shown
then
728 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
729 gStdFont
, 255, 255, 255, 1, True);
730 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
731 gStdFont
, 255, 255, 255, 1, True);
735 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
736 gStdFont
, 255, 255, 255, 1, True);
737 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
738 gStdFont
, 255, 255, 255, 1, True);
746 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
747 a
:= (gScreenWidth
- 2*mfW
) div 2;
748 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
749 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
750 _RGB(128, 0, 0), 2.0);
753 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
754 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
758 if ConsoleHistory <> nil then
762 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
763 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
765 b := Max(b-Offset, 0);
766 d := Max(High(ConsoleHistory)-Offset, 0);
769 for a := d downto b do
771 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
778 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
781 procedure g_Console_Switch();
783 if gChatShow
then Exit
;
784 gConsoleShow
:= not gConsoleShow
;
788 procedure g_Console_Chat_Switch(Team
: Boolean = False);
790 if gConsoleShow
then Exit
;
791 if not g_Game_IsNet
then Exit
;
792 gChatShow
:= not gChatShow
;
800 procedure g_Console_Char(C
: Char);
802 if gChatShow
and (not gChatEnter
) then
804 Insert(C
, Line
, CPos
);
810 tcomplist
: array of string = nil;
811 tcompidx
: array of Integer = nil;
813 procedure Complete ();
817 ll
, lpfx
, cmd
: string;
819 if (Length(Line
) = 0) then
822 for i
:= 0 to High(Commands
) do
824 if not Commands
[i
].hidden
then
826 if (Length(Commands
[i
].help
) > 0) then
828 g_Console_Add(' '+Commands
[i
].Cmd
+' -- '+Commands
[i
].help
);
832 g_Console_Add(' '+Commands
[i
].Cmd
);
839 ll
:= LowerCase(Line
);
842 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
844 ll
:= Copy(ll
, 0, Length(ll
)-1);
845 for i
:= 0 to High(Commands
) do
847 if Commands
[i
].hidden
then continue
;
848 if (Commands
[i
].Cmd
= ll
) then
850 if (Length(Commands
[i
].help
) > 0) then
852 g_Console_Add(' '+Commands
[i
].Cmd
+' -- '+Commands
[i
].help
);
859 // build completion list
861 for i
:= 0 to High(Commands
) do
863 if Commands
[i
].hidden
then continue
;
864 cmd
:= Commands
[i
].Cmd
;
865 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
867 if (tused
= Length(tcomplist
)) then
869 SetLength(tcomplist
, Length(tcomplist
)+128);
870 SetLength(tcompidx
, Length(tcompidx
)+128);
872 tcomplist
[tused
] := cmd
;
873 tcompidx
[tused
] := i
;
875 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
879 // get longest prefix
880 for i
:= 0 to tused
-1 do
883 for c
:= 1 to Length(lpfx
) do
885 if (c
> Length(cmd
)) then break
;
886 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
890 if (tused
= 0) then exit
;
894 Line
:= tcomplist
[0]+' ';
895 CPos
:= Length(Line
)+1;
899 // has longest prefix?
900 if (Length(lpfx
) > Length(ll
)) then
903 CPos
:= Length(Line
)+1;
908 for i
:= 0 to tused
-1 do
910 if (Length(Commands
[tcompidx
[i
]].help
) > 0) then
912 g_Console_Add(' '+tcomplist
[i
]+' -- '+Commands
[tcompidx
[i
]].help
);
916 g_Console_Add(' '+tcomplist
[i
]);
924 procedure g_Console_Control(K
: Word);
928 if (Length(Line
) > 0) and (CPos
> 1) then
930 Delete(Line
, CPos
-1, 1);
934 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
935 Delete(Line
, CPos
, 1);
939 IK_RIGHT
, IK_KPRIGHT
:
940 if CPos
<= Length(Line
) then
942 IK_RETURN
, IK_KPRETURN
:
945 g_Console_Process(Line
)
949 if (Length(Line
) > 0) and g_Game_IsNet
then
953 if g_Game_IsClient
then
954 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
956 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
957 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
961 if g_Game_IsClient
then
962 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
964 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
972 gJustChatted
:= True;
976 if not gChatShow
then
979 if not gChatShow
then
980 if (CommandHistory
<> nil) and
981 (CmdIndex
< Length(CommandHistory
)) then
983 if CmdIndex
< Length(CommandHistory
)-1 then
984 CmdIndex
:= CmdIndex
+ 1;
985 Line
:= CommandHistory
[CmdIndex
];
986 CPos
:= Length(Line
) + 1;
989 if not gChatShow
then
990 if (CommandHistory
<> nil) and
991 (CmdIndex
<= Length(CommandHistory
)) then
994 CmdIndex
:= CmdIndex
- 1;
995 Line
:= CommandHistory
[CmdIndex
];
996 Cpos
:= Length(Line
) + 1;
998 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
999 if not gChatShow
then Inc(conSkipLines
);
1000 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
1001 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
1005 CPos
:= Length(Line
) + 1;
1009 function GetStr(var Str
: String): String;
1014 if Str
[1] = '"' then
1016 for b
:= 1 to Length(Str
) do
1017 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
1019 Result
:= Copy(Str
, 2, b
-1);
1020 Delete(Str
, 1, b
+1);
1026 for a
:= 1 to Length(Str
) do
1027 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
1029 Result
:= Copy(Str
, 1, a
);
1030 Delete(Str
, 1, a
+1);
1036 function ParseString(Str
: String): SArray
;
1047 SetLength(Result
, Length(Result
)+1);
1048 Result
[High(Result
)] := GetStr(Str
);
1052 procedure g_Console_Add (L
: string; Show
: Boolean=false);
1054 procedure conmsg (s
: AnsiString);
1058 if length(s
) = 0 then exit
;
1059 for a
:= 0 to High(MsgArray
) do
1071 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1072 with MsgArray
[High(MsgArray
)] do
1082 // put it to console
1084 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1086 // now show 'em out of console too
1087 Show
:= Show
and gAllowConsoleMessages
;
1088 if Show
and gShowMessages
then
1090 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1091 while length(L
) > 0 do
1094 if f
<= 0 then f
:= length(L
)+1;
1095 conmsg(Copy(L
, 1, f
-1));
1100 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1101 //ConsoleHistory[High(ConsoleHistory)] := L;
1105 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1112 consolewriterLastWasEOL
: Boolean = false;
1114 procedure consolewriter (constref buf
; len
: SizeUInt
);
1118 if (len
< 1) then exit
;
1120 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1123 if (b
[0] <> 13) and (b
[0] <> 10) then
1125 cbufPut(Char(b
[0]));
1129 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1138 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1139 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1140 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1141 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1143 g_Console_Add(s
, show
);
1147 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1151 g_Console_Add(formatstrf(s
, args
), true);
1155 consolewriterLastWasEOL
:= false;
1156 formatstrf(s
, args
, consolewriter
);
1157 if not consolewriterLastWasEOL
then cbufPut(#10);
1162 procedure g_Console_Clear();
1164 //ConsoleHistory := nil;
1169 procedure AddToHistory(L
: String);
1173 len
:= Length(CommandHistory
);
1176 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1178 SetLength(CommandHistory
, len
+1);
1179 CommandHistory
[len
] := L
;
1182 CmdIndex
:= Length(CommandHistory
);
1185 function g_Console_CommandBlacklisted(C
: String): Boolean;
1194 if Trim(C
) = '' then
1197 Arr
:= ParseString(C
);
1201 for i
:= 0 to High(Whitelist
) do
1202 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1206 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
1213 if Trim(L
) = '' then
1216 conSkipLines
:= 0; // "unscroll"
1218 if L
= 'goobers' then
1223 g_Console_Add('Your memory serves you well.');
1229 g_Console_Add('> '+L
);
1234 Arr
:= ParseString(L
);
1238 if Commands
= nil then
1244 for i
:= 0 to High(Commands
) do
1246 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
1248 if assigned(Commands
[i
].ProcEx
) then
1250 Commands
[i
].ProcEx(@Commands
[i
], Arr
);
1253 if assigned(Commands
[i
].Proc
) then
1255 Commands
[i
].Proc(Arr
);
1261 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));