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}
21 procedure g_Console_Init();
22 procedure g_Console_Update();
23 procedure g_Console_Draw();
24 procedure g_Console_Switch();
25 procedure g_Console_Char(C
: Char);
26 procedure g_Console_Control(K
: Word);
27 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
28 procedure g_Console_Add(L
: String; Show
: Boolean = False);
29 procedure g_Console_Clear();
30 function g_Console_CommandBlacklisted(C
: String): Boolean;
32 procedure g_Console_Chat_Switch(Team
: Boolean = False);
35 gConsoleShow
: Boolean; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
37 gChatTeam
: Boolean = False;
38 gAllowConsoleMessages
: Boolean = True;
39 gChatEnter
: Boolean = True;
40 gJustChatted
: Boolean = False; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
45 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
46 SysUtils
, g_basic
, g_options
, wadreader
, Math
,
47 g_menu
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
;
50 TCmdProc
= procedure (P
: SArray
);
66 MaxScriptRecursion
= 16;
68 DEBUG_STRING
= 'DEBUG MODE';
72 RecursionDepth
: Word = 0;
73 RecursionLimitHit
: Boolean = False;
75 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
78 //ConsoleHistory: SArray;
79 CommandHistory
: SArray
;
81 Commands
: Array of TCommand
;
82 Aliases
: Array of TAlias
;
84 conSkipLines
: Integer = 0;
85 MsgArray
: Array [0..4] of record
90 function GetStrACmd(var Str
: String): String;
95 for a
:= 1 to Length(Str
) do
96 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
98 Result
:= Copy(Str
, 1, a
);
105 function ParseAlias(Str
: String): SArray
;
116 SetLength(Result
, Length(Result
)+1);
117 Result
[High(Result
)] := GetStrACmd(Str
);
121 procedure ConsoleCommands(P
: SArray
);
127 Cmd
:= LowerCase(P
[0]);
130 if Cmd
= 'clear' then
132 //ConsoleHistory := nil;
136 for a
:= 0 to High(MsgArray
) do
144 if Cmd
= 'clearhistory' then
145 CommandHistory
:= nil;
147 if Cmd
= 'showhistory' then
148 if CommandHistory
<> nil then
151 for a
:= 0 to High(CommandHistory
) do
152 g_Console_Add(' '+CommandHistory
[a
]);
155 if Cmd
= 'commands' then
158 g_Console_Add('Commands list:');
159 for a
:= High(Commands
) downto 0 do
160 g_Console_Add(' '+Commands
[a
].Cmd
);
164 g_Console_Add(TimeToStr(Now
), True);
167 g_Console_Add(DateToStr(Now
), True);
170 if Length(P
) > 1 then
172 if P
[1] = 'ololo' then
177 for a
:= 1 to High(P
) do
179 g_Console_Add(b_Text_Format(s
), True);
188 if ConsoleHistory <> nil then
190 if Length(P) > 1 then
193 s := GameDir+'/console.txt';
198 if IOResult <> 0 then
200 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
205 for a := 0 to High(ConsoleHistory) do
206 WriteLn(F, ConsoleHistory[a]);
209 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
218 if Length(P
) > 1 then
220 s
:= GameDir
+'/'+P
[1];
225 if IOResult
<> 0 then
227 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
231 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
236 if IOResult
<> 0 then
238 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
242 if Pos('#', s
) <> 1 then // script comment
244 // prevents endless loops
246 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
247 if not RecursionLimitHit
then
248 g_Console_Process(s
, True);
252 if (RecursionDepth
= 0) and RecursionLimitHit
then
254 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
255 RecursionLimitHit
:= False;
262 g_Console_Add('exec <script file>');
265 if Cmd
= 'alias' then
267 // alias [alias_name] [commands]
268 if Length(P
) > 1 then
270 for a
:= 0 to High(Aliases
) do
271 if Aliases
[a
].Name
= P
[1] then
273 if Length(P
) > 2 then
274 Aliases
[a
].Commands
:= ParseAlias(P
[2])
276 for b
:= 0 to High(Aliases
[a
].Commands
) do
277 g_Console_Add(Aliases
[a
].Commands
[b
]);
280 SetLength(Aliases
, Length(Aliases
)+1);
282 Aliases
[a
].Name
:= P
[1];
283 if Length(P
) > 2 then
284 Aliases
[a
].Commands
:= ParseAlias(P
[2])
286 for b
:= 0 to High(Aliases
[a
].Commands
) do
287 g_Console_Add(Aliases
[a
].Commands
[b
]);
289 for a
:= 0 to High(Aliases
) do
290 if Aliases
[a
].Commands
<> nil then
291 g_Console_Add(Aliases
[a
].Name
);
297 if Length(P
) > 1 then
299 if Aliases
= nil then
301 for a
:= 0 to High(Aliases
) do
302 if Aliases
[a
].Name
= P
[1] then
304 if Aliases
[a
].Commands
<> nil then
306 // with this system proper endless loop detection seems either impossible
307 // or very dirty to implement, so let's have this instead
308 // prevents endless loops
309 for b
:= 0 to High(Aliases
[a
].Commands
) do
312 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
313 if not RecursionLimitHit
then
314 g_Console_Process(Aliases
[a
].Commands
[b
], True);
317 if (RecursionDepth
= 0) and RecursionLimitHit
then
319 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
320 RecursionLimitHit
:= False;
327 g_Console_Add('call <alias name>');
331 procedure WhitelistCommand(Cmd
: string);
335 SetLength(Whitelist
, Length(Whitelist
)+1);
336 a
:= High(Whitelist
);
337 Whitelist
[a
] := LowerCase(Cmd
);
340 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
);
344 SetLength(Commands
, Length(Commands
)+1);
346 Commands
[a
].Cmd
:= LowerCase(Cmd
);
347 Commands
[a
].Proc
:= Proc
;
350 procedure g_Console_Init();
354 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
355 Cons_Y
:= -(gScreenHeight
div 2);
356 gConsoleShow
:= False;
361 for a
:= 0 to High(MsgArray
) do
368 AddCommand('clear', ConsoleCommands
);
369 AddCommand('clearhistory', ConsoleCommands
);
370 AddCommand('showhistory', ConsoleCommands
);
371 AddCommand('commands', ConsoleCommands
);
372 AddCommand('time', ConsoleCommands
);
373 AddCommand('date', ConsoleCommands
);
374 AddCommand('echo', ConsoleCommands
);
375 AddCommand('dump', ConsoleCommands
);
376 AddCommand('exec', ConsoleCommands
);
377 AddCommand('alias', ConsoleCommands
);
378 AddCommand('call', ConsoleCommands
);
380 AddCommand('d_window', DebugCommands
);
381 AddCommand('d_sounds', DebugCommands
);
382 AddCommand('d_frames', DebugCommands
);
383 AddCommand('d_winmsg', DebugCommands
);
384 AddCommand('d_monoff', DebugCommands
);
385 AddCommand('d_botoff', DebugCommands
);
386 AddCommand('d_monster', DebugCommands
);
387 AddCommand('d_health', DebugCommands
);
388 AddCommand('d_player', DebugCommands
);
389 AddCommand('d_joy', DebugCommands
);
391 AddCommand('pf_draw_frame', ProfilerCommands
);
392 AddCommand('pf_update_frame', ProfilerCommands
);
393 AddCommand('pf_coldet', ProfilerCommands
);
394 AddCommand('r_sq_draw', ProfilerCommands
);
395 AddCommand('r_sq_use_grid', ProfilerCommands
);
396 AddCommand('r_sq_use_tree', ProfilerCommands
);
397 AddCommand('dbg_sq_coldet', ProfilerCommands
);
399 AddCommand('t_dump_node_queries', ProfilerCommands
);
401 AddCommand('sq_use_grid', ProfilerCommands
);
402 AddCommand('sq_use_tree', ProfilerCommands
);
404 AddCommand('mon_sq_enabled', ProfilerCommands
);
406 AddCommand('p1_name', GameCVars
);
407 AddCommand('p2_name', GameCVars
);
408 AddCommand('p1_color', GameCVars
);
409 AddCommand('p2_color', GameCVars
);
410 AddCommand('r_showfps', GameCVars
);
411 AddCommand('r_showtime', GameCVars
);
412 AddCommand('r_showscore', GameCVars
);
413 AddCommand('r_showlives', GameCVars
);
414 AddCommand('r_showstat', GameCVars
);
415 AddCommand('r_showkillmsg', GameCVars
);
416 AddCommand('r_showspect', GameCVars
);
417 AddCommand('r_showping', GameCVars
);
418 AddCommand('g_gamemode', GameCVars
);
419 AddCommand('g_friendlyfire', GameCVars
);
420 AddCommand('g_weaponstay', GameCVars
);
421 AddCommand('g_allow_exit', GameCVars
);
422 AddCommand('g_allow_monsters', GameCVars
);
423 AddCommand('g_bot_vsmonsters', GameCVars
);
424 AddCommand('g_bot_vsplayers', GameCVars
);
425 AddCommand('g_scorelimit', GameCVars
);
426 AddCommand('g_timelimit', GameCVars
);
427 AddCommand('g_maxlives', GameCVars
);
428 AddCommand('g_warmuptime', GameCVars
);
429 AddCommand('net_interp', GameCVars
);
430 AddCommand('net_forceplayerupdate', GameCVars
);
431 AddCommand('net_predictself', GameCVars
);
432 AddCommand('sv_name', GameCVars
);
433 AddCommand('sv_passwd', GameCVars
);
434 AddCommand('sv_maxplrs', GameCVars
);
435 AddCommand('sv_public', GameCVars
);
436 AddCommand('sv_intertime', GameCVars
);
438 AddCommand('quit', GameCommands
);
439 AddCommand('exit', GameCommands
);
440 AddCommand('pause', GameCommands
);
441 AddCommand('endgame', GameCommands
);
442 AddCommand('restart', GameCommands
);
443 AddCommand('addbot', GameCommands
);
444 AddCommand('bot_add', GameCommands
);
445 AddCommand('bot_addlist', GameCommands
);
446 AddCommand('bot_addred', GameCommands
);
447 AddCommand('bot_addblue', GameCommands
);
448 AddCommand('bot_removeall', GameCommands
);
449 AddCommand('chat', GameCommands
);
450 AddCommand('teamchat', GameCommands
);
451 AddCommand('game', GameCommands
);
452 AddCommand('host', GameCommands
);
453 AddCommand('map', GameCommands
);
454 AddCommand('nextmap', GameCommands
);
455 AddCommand('endmap', GameCommands
);
456 AddCommand('goodbye', GameCommands
);
457 AddCommand('suicide', GameCommands
);
458 AddCommand('spectate', GameCommands
);
459 AddCommand('ready', GameCommands
);
460 AddCommand('kick', GameCommands
);
461 AddCommand('kick_id', GameCommands
);
462 AddCommand('ban', GameCommands
);
463 AddCommand('permban', GameCommands
);
464 AddCommand('ban_id', GameCommands
);
465 AddCommand('permban_id', GameCommands
);
466 AddCommand('unban', GameCommands
);
467 AddCommand('connect', GameCommands
);
468 AddCommand('disconnect', GameCommands
);
469 AddCommand('reconnect', GameCommands
);
470 AddCommand('say', GameCommands
);
471 AddCommand('tell', GameCommands
);
472 AddCommand('overtime', GameCommands
);
473 AddCommand('rcon_password', GameCommands
);
474 AddCommand('rcon', GameCommands
);
475 AddCommand('callvote', GameCommands
);
476 AddCommand('vote', GameCommands
);
477 AddCommand('clientlist', GameCommands
);
478 AddCommand('event', GameCommands
);
480 AddCommand('god', GameCheats
);
481 AddCommand('notarget', GameCheats
);
482 AddCommand('give', GameCheats
); // "exit" too ;-)
483 AddCommand('open', GameCheats
);
484 AddCommand('fly', GameCheats
);
485 AddCommand('noclip', GameCheats
);
486 AddCommand('speedy', GameCheats
);
487 AddCommand('jumpy', GameCheats
);
488 AddCommand('noreload', GameCheats
);
489 AddCommand('aimline', GameCheats
);
490 AddCommand('automap', GameCheats
);
492 WhitelistCommand('say');
493 WhitelistCommand('tell');
494 WhitelistCommand('overtime');
495 WhitelistCommand('ready');
496 WhitelistCommand('map');
497 WhitelistCommand('nextmap');
498 WhitelistCommand('endmap');
499 WhitelistCommand('restart');
500 WhitelistCommand('kick');
501 WhitelistCommand('ban');
503 WhitelistCommand('addbot');
504 WhitelistCommand('bot_add');
505 WhitelistCommand('bot_addred');
506 WhitelistCommand('bot_addblue');
507 WhitelistCommand('bot_removeall');
509 WhitelistCommand('g_gamemode');
510 WhitelistCommand('g_friendlyfire');
511 WhitelistCommand('g_weaponstay');
512 WhitelistCommand('g_allow_exit');
513 WhitelistCommand('g_allow_monsters');
514 WhitelistCommand('g_scorelimit');
515 WhitelistCommand('g_timelimit');
517 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
521 procedure g_Console_Update();
527 // Â ïðîöåññå îòêðûòèÿ:
528 if gConsoleShow
and (Cons_Y
< 0) then
530 Cons_Y
:= Cons_Y
+Step
;
533 // Â ïðîöåññå çàêðûòèÿ:
534 if (not gConsoleShow
) and
535 (Cons_Y
> -(gScreenHeight
div 2)) then
536 Cons_Y
:= Cons_Y
-Step
;
538 // Îêîí÷àòåëüíî îòêðûëàñü:
542 // Îêîí÷àòåëüíî çàêðûëàñü:
543 if Cons_Y
<= (-(gScreenHeight
div 2)) then
545 Cons_Y
:= -(gScreenHeight
div 2);
551 while a
<= High(MsgArray
) do
553 if MsgArray
[a
].Time
> 0 then
555 if MsgArray
[a
].Time
= 1 then
557 if a
< High(MsgArray
) then
559 for b
:= a
to High(MsgArray
)-1 do
560 MsgArray
[b
] := MsgArray
[b
+1];
562 MsgArray
[High(MsgArray
)].Time
:= 0;
568 Dec(MsgArray
[a
].Time
);
576 procedure drawConsoleText ();
578 CWidth
, CHeight
: Byte;
583 procedure putLine (sp
, ep
: LongWord);
592 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
593 if wdt
+cw
> gScreenWidth
-8 then break
;
594 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
598 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
599 // now print our part
607 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
608 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
621 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
622 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
623 skip
:= conSkipLines
;
624 cbufLastLine(sp
, ep
);
627 if ty
+CHeight
<= 0 then break
;
628 until not cbufLineUp(sp
, ep
);
631 procedure g_Console_Draw();
633 CWidth
, CHeight
: Byte;
637 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
639 for a
:= 0 to High(MsgArray
) do
640 if MsgArray
[a
].Time
> 0 then
641 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
644 if not Cons_Shown
then
650 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
651 gStdFont
, 255, 255, 255, 1, True);
652 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
653 gStdFont
, 255, 255, 255, 1, True);
657 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
658 gStdFont
, 255, 255, 255, 1, True);
659 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
660 gStdFont
, 255, 255, 255, 1, True);
668 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
669 a
:= (gScreenWidth
- 2*mfW
) div 2;
670 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
671 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
672 _RGB(128, 0, 0), 2.0);
675 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
676 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
680 if ConsoleHistory <> nil then
684 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
685 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
687 b := Max(b-Offset, 0);
688 d := Max(High(ConsoleHistory)-Offset, 0);
691 for a := d downto b do
693 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
700 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
703 procedure g_Console_Switch();
705 if gChatShow
then Exit
;
706 gConsoleShow
:= not gConsoleShow
;
710 procedure g_Console_Chat_Switch(Team
: Boolean = False);
712 if gConsoleShow
then Exit
;
713 if not g_Game_IsNet
then Exit
;
714 gChatShow
:= not gChatShow
;
722 procedure g_Console_Char(C
: Char);
724 if gChatShow
and (not gChatEnter
) then
726 Insert(C
, Line
, CPos
);
732 tcomplist
: array of string = nil;
734 procedure Complete ();
738 ll
, lpfx
, cmd
: string;
740 if (Length(Line
) = 0) then
743 for i
:= 0 to High(Commands
) do
745 if (Commands
[i
].Cmd
<> 'goobers') then
747 g_Console_Add(' '+Commands
[i
].Cmd
);
753 ll
:= LowerCase(Line
);
756 // build completion list
758 for i
:= 0 to High(Commands
) do
760 cmd
:= Commands
[i
].Cmd
;
761 if (cmd
= 'goobers') then continue
;
762 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
764 if (tused
= Length(tcomplist
)) then SetLength(tcomplist
, Length(tcomplist
)+128);
765 tcomplist
[tused
] := cmd
;
767 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
771 // get longest prefix
772 for i
:= 0 to tused
-1 do
775 for c
:= 1 to Length(lpfx
) do
777 if (c
> Length(cmd
)) then break
;
778 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
782 if (tused
= 0) then exit
;
786 Line
:= tcomplist
[0]+' ';
787 CPos
:= Length(Line
)+1;
791 // has longest prefix?
792 if (Length(lpfx
) > Length(ll
)) then
795 CPos
:= Length(Line
)+1;
800 for i
:= 0 to tused
-1 do g_Console_Add(' '+tcomplist
[i
]);
806 procedure g_Console_Control(K
: Word);
810 if (Length(Line
) > 0) and (CPos
> 1) then
812 Delete(Line
, CPos
-1, 1);
816 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
817 Delete(Line
, CPos
, 1);
821 IK_RIGHT
, IK_KPRIGHT
:
822 if CPos
<= Length(Line
) then
824 IK_RETURN
, IK_KPRETURN
:
827 g_Console_Process(Line
)
831 if (Length(Line
) > 0) and g_Game_IsNet
then
835 if g_Game_IsClient
then
836 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
838 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
839 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
843 if g_Game_IsClient
then
844 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
846 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
854 gJustChatted
:= True;
858 if not gChatShow
then
861 if not gChatShow
then
862 if (CommandHistory
<> nil) and
863 (CmdIndex
< Length(CommandHistory
)) then
865 if CmdIndex
< Length(CommandHistory
)-1 then
866 CmdIndex
:= CmdIndex
+ 1;
867 Line
:= CommandHistory
[CmdIndex
];
868 CPos
:= Length(Line
) + 1;
871 if not gChatShow
then
872 if (CommandHistory
<> nil) and
873 (CmdIndex
<= Length(CommandHistory
)) then
876 CmdIndex
:= CmdIndex
- 1;
877 Line
:= CommandHistory
[CmdIndex
];
878 Cpos
:= Length(Line
) + 1;
880 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
881 if not gChatShow
then Inc(conSkipLines
);
882 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
883 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
887 CPos
:= Length(Line
) + 1;
891 function GetStr(var Str
: String): String;
898 for b
:= 1 to Length(Str
) do
899 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
901 Result
:= Copy(Str
, 2, b
-1);
908 for a
:= 1 to Length(Str
) do
909 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
911 Result
:= Copy(Str
, 1, a
);
918 function ParseString(Str
: String): SArray
;
929 SetLength(Result
, Length(Result
)+1);
930 Result
[High(Result
)] := GetStr(Str
);
934 procedure g_Console_Add (L
: string; Show
: Boolean=false);
936 procedure conmsg (s
: AnsiString);
940 if length(s
) = 0 then exit
;
941 for a
:= 0 to High(MsgArray
) do
953 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
954 with MsgArray
[High(MsgArray
)] do
966 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
968 // now show 'em out of console too
969 Show
:= Show
and gAllowConsoleMessages
;
970 if Show
and gShowMessages
then
972 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
973 while length(L
) > 0 do
976 if f
<= 0 then f
:= length(L
)+1;
977 conmsg(Copy(L
, 1, f
-1));
982 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
983 //ConsoleHistory[High(ConsoleHistory)] := L;
987 e_WriteLog('CON: ' + L, MSG_NOTIFY);
992 procedure g_Console_Clear();
994 //ConsoleHistory := nil;
999 procedure AddToHistory(L
: String);
1003 len
:= Length(CommandHistory
);
1006 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1008 SetLength(CommandHistory
, len
+1);
1009 CommandHistory
[len
] := L
;
1012 CmdIndex
:= Length(CommandHistory
);
1015 function g_Console_CommandBlacklisted(C
: String): Boolean;
1024 if Trim(C
) = '' then
1027 Arr
:= ParseString(C
);
1031 for i
:= 0 to High(Whitelist
) do
1032 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1036 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
1043 if Trim(L
) = '' then
1046 conSkipLines
:= 0; // "unscroll"
1048 if L
= 'goobers' then
1053 g_Console_Add('Your memory serves you well.');
1059 g_Console_Add('> '+L
);
1064 Arr
:= ParseString(L
);
1068 if Commands
= nil then
1074 for i
:= 0 to High(Commands
) do
1075 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
1076 if @Commands
[i
].Proc
<> nil then
1078 Commands
[i
].Proc(Arr
);
1082 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));