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
);
68 MaxScriptRecursion
= 16;
70 DEBUG_STRING
= 'DEBUG MODE';
74 RecursionDepth
: Word = 0;
75 RecursionLimitHit
: Boolean = False;
77 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
80 //ConsoleHistory: SArray;
81 CommandHistory
: SArray
;
83 Commands
: Array of TCommand
;
84 Aliases
: Array of TAlias
;
86 conSkipLines
: Integer = 0;
87 MsgArray
: Array [0..4] of record
92 function GetStrACmd(var Str
: String): String;
97 for a
:= 1 to Length(Str
) do
98 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
100 Result
:= Copy(Str
, 1, a
);
107 function ParseAlias(Str
: String): SArray
;
118 SetLength(Result
, Length(Result
)+1);
119 Result
[High(Result
)] := GetStrACmd(Str
);
123 procedure ConsoleCommands(P
: SArray
);
129 Cmd
:= LowerCase(P
[0]);
132 if Cmd
= 'clear' then
134 //ConsoleHistory := nil;
138 for a
:= 0 to High(MsgArray
) do
146 if Cmd
= 'clearhistory' then
147 CommandHistory
:= nil;
149 if Cmd
= 'showhistory' then
150 if CommandHistory
<> nil then
153 for a
:= 0 to High(CommandHistory
) do
154 g_Console_Add(' '+CommandHistory
[a
]);
157 if Cmd
= 'commands' then
160 g_Console_Add('Commands list:');
161 for a
:= High(Commands
) downto 0 do
163 if (Length(Commands
[a
].help
) > 0) then
165 g_Console_Add(' '+Commands
[a
].Cmd
+' -- '+Commands
[a
].help
);
169 g_Console_Add(' '+Commands
[a
].Cmd
);
175 g_Console_Add(TimeToStr(Now
), True);
178 g_Console_Add(DateToStr(Now
), True);
181 if Length(P
) > 1 then
183 if P
[1] = 'ololo' then
188 for a
:= 1 to High(P
) do
190 g_Console_Add(b_Text_Format(s
), True);
199 if ConsoleHistory <> nil then
201 if Length(P) > 1 then
204 s := GameDir+'/console.txt';
209 if IOResult <> 0 then
211 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
216 for a := 0 to High(ConsoleHistory) do
217 WriteLn(F, ConsoleHistory[a]);
220 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
229 if Length(P
) > 1 then
231 s
:= GameDir
+'/'+P
[1];
236 if IOResult
<> 0 then
238 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
242 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
247 if IOResult
<> 0 then
249 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
253 if Pos('#', s
) <> 1 then // script comment
255 // prevents endless loops
257 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
258 if not RecursionLimitHit
then
259 g_Console_Process(s
, True);
263 if (RecursionDepth
= 0) and RecursionLimitHit
then
265 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
266 RecursionLimitHit
:= False;
273 g_Console_Add('exec <script file>');
276 if Cmd
= 'alias' then
278 // alias [alias_name] [commands]
279 if Length(P
) > 1 then
281 for a
:= 0 to High(Aliases
) do
282 if Aliases
[a
].Name
= P
[1] then
284 if Length(P
) > 2 then
285 Aliases
[a
].Commands
:= ParseAlias(P
[2])
287 for b
:= 0 to High(Aliases
[a
].Commands
) do
288 g_Console_Add(Aliases
[a
].Commands
[b
]);
291 SetLength(Aliases
, Length(Aliases
)+1);
293 Aliases
[a
].Name
:= P
[1];
294 if Length(P
) > 2 then
295 Aliases
[a
].Commands
:= ParseAlias(P
[2])
297 for b
:= 0 to High(Aliases
[a
].Commands
) do
298 g_Console_Add(Aliases
[a
].Commands
[b
]);
300 for a
:= 0 to High(Aliases
) do
301 if Aliases
[a
].Commands
<> nil then
302 g_Console_Add(Aliases
[a
].Name
);
308 if Length(P
) > 1 then
310 if Aliases
= nil then
312 for a
:= 0 to High(Aliases
) do
313 if Aliases
[a
].Name
= P
[1] then
315 if Aliases
[a
].Commands
<> nil then
317 // with this system proper endless loop detection seems either impossible
318 // or very dirty to implement, so let's have this instead
319 // prevents endless loops
320 for b
:= 0 to High(Aliases
[a
].Commands
) do
323 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
324 if not RecursionLimitHit
then
325 g_Console_Process(Aliases
[a
].Commands
[b
], True);
328 if (RecursionDepth
= 0) and RecursionLimitHit
then
330 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
331 RecursionLimitHit
:= False;
338 g_Console_Add('call <alias name>');
342 procedure WhitelistCommand(Cmd
: string);
346 SetLength(Whitelist
, Length(Whitelist
)+1);
347 a
:= High(Whitelist
);
348 Whitelist
[a
] := LowerCase(Cmd
);
351 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
; ahelp
: String=''; ahidden
: Boolean=false);
355 SetLength(Commands
, Length(Commands
)+1);
357 Commands
[a
].Cmd
:= LowerCase(Cmd
);
358 Commands
[a
].Proc
:= Proc
;
359 Commands
[a
].hidden
:= ahidden
;
360 Commands
[a
].help
:= ahelp
;
363 procedure g_Console_Init();
367 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
368 Cons_Y
:= -(gScreenHeight
div 2);
369 gConsoleShow
:= False;
374 for a
:= 0 to High(MsgArray
) do
381 AddCommand('clear', ConsoleCommands
, 'clear console');
382 AddCommand('clearhistory', ConsoleCommands
);
383 AddCommand('showhistory', ConsoleCommands
);
384 AddCommand('commands', ConsoleCommands
);
385 AddCommand('time', ConsoleCommands
);
386 AddCommand('date', ConsoleCommands
);
387 AddCommand('echo', ConsoleCommands
);
388 AddCommand('dump', ConsoleCommands
);
389 AddCommand('exec', ConsoleCommands
);
390 AddCommand('alias', ConsoleCommands
);
391 AddCommand('call', ConsoleCommands
);
393 AddCommand('d_window', DebugCommands
);
394 AddCommand('d_sounds', DebugCommands
);
395 AddCommand('d_frames', DebugCommands
);
396 AddCommand('d_winmsg', DebugCommands
);
397 AddCommand('d_monoff', DebugCommands
);
398 AddCommand('d_botoff', DebugCommands
);
399 AddCommand('d_monster', DebugCommands
);
400 AddCommand('d_health', DebugCommands
);
401 AddCommand('d_player', DebugCommands
);
402 AddCommand('d_joy', DebugCommands
);
404 AddCommand('pf_draw_frame', ProfilerCommands
, 'draw frame rendering profiles');
405 //AddCommand('pf_update_frame', ProfilerCommands);
406 AddCommand('pf_coldet', ProfilerCommands
, 'draw collision detection profiles');
407 AddCommand('r_sq_draw', ProfilerCommands
, 'accelerated spatial queries in rendering');
408 AddCommand('r_sq_use_grid', ProfilerCommands
, 'use grid for render acceleration');
409 AddCommand('r_sq_use_tree', ProfilerCommands
, 'use tree for render acceleration');
410 AddCommand('dbg_sq_coldet', ProfilerCommands
, 'accelerated spatial queries in map coldet');
412 AddCommand('t_dump_node_queries', ProfilerCommands
);
414 AddCommand('sq_use_grid', ProfilerCommands
, 'use grid for map coldet acceleration');
415 AddCommand('sq_use_tree', ProfilerCommands
, 'use tree for map coldet acceleration');
417 AddCommand('mon_sq_enabled', ProfilerCommands
, 'use accelerated spatial queries for monsters');
419 AddCommand('p1_name', GameCVars
);
420 AddCommand('p2_name', GameCVars
);
421 AddCommand('p1_color', GameCVars
);
422 AddCommand('p2_color', GameCVars
);
423 AddCommand('r_showfps', GameCVars
);
424 AddCommand('r_showtime', GameCVars
);
425 AddCommand('r_showscore', GameCVars
);
426 AddCommand('r_showlives', GameCVars
);
427 AddCommand('r_showstat', GameCVars
);
428 AddCommand('r_showkillmsg', GameCVars
);
429 AddCommand('r_showspect', GameCVars
);
430 AddCommand('r_showping', GameCVars
);
431 AddCommand('g_gamemode', GameCVars
);
432 AddCommand('g_friendlyfire', GameCVars
);
433 AddCommand('g_weaponstay', GameCVars
);
434 AddCommand('g_allow_exit', GameCVars
);
435 AddCommand('g_allow_monsters', GameCVars
);
436 AddCommand('g_bot_vsmonsters', GameCVars
);
437 AddCommand('g_bot_vsplayers', GameCVars
);
438 AddCommand('g_scorelimit', GameCVars
);
439 AddCommand('g_timelimit', GameCVars
);
440 AddCommand('g_maxlives', GameCVars
);
441 AddCommand('g_warmuptime', GameCVars
);
442 AddCommand('net_interp', GameCVars
);
443 AddCommand('net_forceplayerupdate', GameCVars
);
444 AddCommand('net_predictself', GameCVars
);
445 AddCommand('sv_name', GameCVars
);
446 AddCommand('sv_passwd', GameCVars
);
447 AddCommand('sv_maxplrs', GameCVars
);
448 AddCommand('sv_public', GameCVars
);
449 AddCommand('sv_intertime', GameCVars
);
451 AddCommand('quit', GameCommands
);
452 AddCommand('exit', GameCommands
);
453 AddCommand('pause', GameCommands
);
454 AddCommand('endgame', GameCommands
);
455 AddCommand('restart', GameCommands
);
456 AddCommand('addbot', GameCommands
);
457 AddCommand('bot_add', GameCommands
);
458 AddCommand('bot_addlist', GameCommands
);
459 AddCommand('bot_addred', GameCommands
);
460 AddCommand('bot_addblue', GameCommands
);
461 AddCommand('bot_removeall', GameCommands
);
462 AddCommand('chat', GameCommands
);
463 AddCommand('teamchat', GameCommands
);
464 AddCommand('game', GameCommands
);
465 AddCommand('host', GameCommands
);
466 AddCommand('map', GameCommands
);
467 AddCommand('nextmap', GameCommands
);
468 AddCommand('endmap', GameCommands
);
469 AddCommand('goodbye', GameCommands
);
470 AddCommand('suicide', GameCommands
);
471 AddCommand('spectate', GameCommands
);
472 AddCommand('ready', GameCommands
);
473 AddCommand('kick', GameCommands
);
474 AddCommand('kick_id', GameCommands
);
475 AddCommand('ban', GameCommands
);
476 AddCommand('permban', GameCommands
);
477 AddCommand('ban_id', GameCommands
);
478 AddCommand('permban_id', GameCommands
);
479 AddCommand('unban', GameCommands
);
480 AddCommand('connect', GameCommands
);
481 AddCommand('disconnect', GameCommands
);
482 AddCommand('reconnect', GameCommands
);
483 AddCommand('say', GameCommands
);
484 AddCommand('tell', GameCommands
);
485 AddCommand('overtime', GameCommands
);
486 AddCommand('rcon_password', GameCommands
);
487 AddCommand('rcon', GameCommands
);
488 AddCommand('callvote', GameCommands
);
489 AddCommand('vote', GameCommands
);
490 AddCommand('clientlist', GameCommands
);
491 AddCommand('event', GameCommands
);
493 AddCommand('god', GameCheats
);
494 AddCommand('notarget', GameCheats
);
495 AddCommand('give', GameCheats
); // "exit" too ;-)
496 AddCommand('open', GameCheats
);
497 AddCommand('fly', GameCheats
);
498 AddCommand('noclip', GameCheats
);
499 AddCommand('speedy', GameCheats
);
500 AddCommand('jumpy', GameCheats
);
501 AddCommand('noreload', GameCheats
);
502 AddCommand('aimline', GameCheats
);
503 AddCommand('automap', GameCheats
);
505 WhitelistCommand('say');
506 WhitelistCommand('tell');
507 WhitelistCommand('overtime');
508 WhitelistCommand('ready');
509 WhitelistCommand('map');
510 WhitelistCommand('nextmap');
511 WhitelistCommand('endmap');
512 WhitelistCommand('restart');
513 WhitelistCommand('kick');
514 WhitelistCommand('ban');
516 WhitelistCommand('addbot');
517 WhitelistCommand('bot_add');
518 WhitelistCommand('bot_addred');
519 WhitelistCommand('bot_addblue');
520 WhitelistCommand('bot_removeall');
522 WhitelistCommand('g_gamemode');
523 WhitelistCommand('g_friendlyfire');
524 WhitelistCommand('g_weaponstay');
525 WhitelistCommand('g_allow_exit');
526 WhitelistCommand('g_allow_monsters');
527 WhitelistCommand('g_scorelimit');
528 WhitelistCommand('g_timelimit');
530 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
534 procedure g_Console_Update();
540 // Â ïðîöåññå îòêðûòèÿ:
541 if gConsoleShow
and (Cons_Y
< 0) then
543 Cons_Y
:= Cons_Y
+Step
;
546 // Â ïðîöåññå çàêðûòèÿ:
547 if (not gConsoleShow
) and
548 (Cons_Y
> -(gScreenHeight
div 2)) then
549 Cons_Y
:= Cons_Y
-Step
;
551 // Îêîí÷àòåëüíî îòêðûëàñü:
555 // Îêîí÷àòåëüíî çàêðûëàñü:
556 if Cons_Y
<= (-(gScreenHeight
div 2)) then
558 Cons_Y
:= -(gScreenHeight
div 2);
564 while a
<= High(MsgArray
) do
566 if MsgArray
[a
].Time
> 0 then
568 if MsgArray
[a
].Time
= 1 then
570 if a
< High(MsgArray
) then
572 for b
:= a
to High(MsgArray
)-1 do
573 MsgArray
[b
] := MsgArray
[b
+1];
575 MsgArray
[High(MsgArray
)].Time
:= 0;
581 Dec(MsgArray
[a
].Time
);
589 procedure drawConsoleText ();
591 CWidth
, CHeight
: Byte;
596 procedure putLine (sp
, ep
: LongWord);
605 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
606 if wdt
+cw
> gScreenWidth
-8 then break
;
607 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
611 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
612 // now print our part
620 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
621 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
634 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
635 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
636 skip
:= conSkipLines
;
637 cbufLastLine(sp
, ep
);
640 if ty
+CHeight
<= 0 then break
;
641 until not cbufLineUp(sp
, ep
);
644 procedure g_Console_Draw();
646 CWidth
, CHeight
: Byte;
650 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
652 for a
:= 0 to High(MsgArray
) do
653 if MsgArray
[a
].Time
> 0 then
654 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
657 if not Cons_Shown
then
663 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
664 gStdFont
, 255, 255, 255, 1, True);
665 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
666 gStdFont
, 255, 255, 255, 1, True);
670 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
671 gStdFont
, 255, 255, 255, 1, True);
672 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
673 gStdFont
, 255, 255, 255, 1, True);
681 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
682 a
:= (gScreenWidth
- 2*mfW
) div 2;
683 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
684 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
685 _RGB(128, 0, 0), 2.0);
688 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
689 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
693 if ConsoleHistory <> nil then
697 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
698 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
700 b := Max(b-Offset, 0);
701 d := Max(High(ConsoleHistory)-Offset, 0);
704 for a := d downto b do
706 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
713 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
716 procedure g_Console_Switch();
718 if gChatShow
then Exit
;
719 gConsoleShow
:= not gConsoleShow
;
723 procedure g_Console_Chat_Switch(Team
: Boolean = False);
725 if gConsoleShow
then Exit
;
726 if not g_Game_IsNet
then Exit
;
727 gChatShow
:= not gChatShow
;
735 procedure g_Console_Char(C
: Char);
737 if gChatShow
and (not gChatEnter
) then
739 Insert(C
, Line
, CPos
);
745 tcomplist
: array of string = nil;
746 tcompidx
: array of Integer = nil;
748 procedure Complete ();
752 ll
, lpfx
, cmd
: string;
754 if (Length(Line
) = 0) then
757 for i
:= 0 to High(Commands
) do
759 if not Commands
[i
].hidden
then
761 if (Length(Commands
[i
].help
) > 0) then
763 g_Console_Add(' '+Commands
[i
].Cmd
+' -- '+Commands
[i
].help
);
767 g_Console_Add(' '+Commands
[i
].Cmd
);
774 ll
:= LowerCase(Line
);
777 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
779 ll
:= Copy(ll
, 0, Length(ll
)-1);
780 for i
:= 0 to High(Commands
) do
782 if Commands
[i
].hidden
then continue
;
783 if (Commands
[i
].Cmd
= ll
) then
785 if (Length(Commands
[i
].help
) > 0) then
787 g_Console_Add(' '+Commands
[i
].Cmd
+' -- '+Commands
[i
].help
);
794 // build completion list
796 for i
:= 0 to High(Commands
) do
798 if Commands
[i
].hidden
then continue
;
799 cmd
:= Commands
[i
].Cmd
;
800 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
802 if (tused
= Length(tcomplist
)) then
804 SetLength(tcomplist
, Length(tcomplist
)+128);
805 SetLength(tcompidx
, Length(tcompidx
)+128);
807 tcomplist
[tused
] := cmd
;
808 tcompidx
[tused
] := i
;
810 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
814 // get longest prefix
815 for i
:= 0 to tused
-1 do
818 for c
:= 1 to Length(lpfx
) do
820 if (c
> Length(cmd
)) then break
;
821 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
825 if (tused
= 0) then exit
;
829 Line
:= tcomplist
[0]+' ';
830 CPos
:= Length(Line
)+1;
834 // has longest prefix?
835 if (Length(lpfx
) > Length(ll
)) then
838 CPos
:= Length(Line
)+1;
843 for i
:= 0 to tused
-1 do
845 if (Length(Commands
[tcompidx
[i
]].help
) > 0) then
847 g_Console_Add(' '+tcomplist
[i
]+' -- '+Commands
[tcompidx
[i
]].help
);
851 g_Console_Add(' '+tcomplist
[i
]);
859 procedure g_Console_Control(K
: Word);
863 if (Length(Line
) > 0) and (CPos
> 1) then
865 Delete(Line
, CPos
-1, 1);
869 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
870 Delete(Line
, CPos
, 1);
874 IK_RIGHT
, IK_KPRIGHT
:
875 if CPos
<= Length(Line
) then
877 IK_RETURN
, IK_KPRETURN
:
880 g_Console_Process(Line
)
884 if (Length(Line
) > 0) and g_Game_IsNet
then
888 if g_Game_IsClient
then
889 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
891 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
892 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
896 if g_Game_IsClient
then
897 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
899 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
907 gJustChatted
:= True;
911 if not gChatShow
then
914 if not gChatShow
then
915 if (CommandHistory
<> nil) and
916 (CmdIndex
< Length(CommandHistory
)) then
918 if CmdIndex
< Length(CommandHistory
)-1 then
919 CmdIndex
:= CmdIndex
+ 1;
920 Line
:= CommandHistory
[CmdIndex
];
921 CPos
:= Length(Line
) + 1;
924 if not gChatShow
then
925 if (CommandHistory
<> nil) and
926 (CmdIndex
<= Length(CommandHistory
)) then
929 CmdIndex
:= CmdIndex
- 1;
930 Line
:= CommandHistory
[CmdIndex
];
931 Cpos
:= Length(Line
) + 1;
933 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
934 if not gChatShow
then Inc(conSkipLines
);
935 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
936 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
940 CPos
:= Length(Line
) + 1;
944 function GetStr(var Str
: String): String;
951 for b
:= 1 to Length(Str
) do
952 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
954 Result
:= Copy(Str
, 2, b
-1);
961 for a
:= 1 to Length(Str
) do
962 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
964 Result
:= Copy(Str
, 1, a
);
971 function ParseString(Str
: String): SArray
;
982 SetLength(Result
, Length(Result
)+1);
983 Result
[High(Result
)] := GetStr(Str
);
987 procedure g_Console_Add (L
: string; Show
: Boolean=false);
989 procedure conmsg (s
: AnsiString);
993 if length(s
) = 0 then exit
;
994 for a
:= 0 to High(MsgArray
) do
1006 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1007 with MsgArray
[High(MsgArray
)] do
1017 // put it to console
1019 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1021 // now show 'em out of console too
1022 Show
:= Show
and gAllowConsoleMessages
;
1023 if Show
and gShowMessages
then
1025 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1026 while length(L
) > 0 do
1029 if f
<= 0 then f
:= length(L
)+1;
1030 conmsg(Copy(L
, 1, f
-1));
1035 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1036 //ConsoleHistory[High(ConsoleHistory)] := L;
1040 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1045 procedure g_Console_Clear();
1047 //ConsoleHistory := nil;
1052 procedure AddToHistory(L
: String);
1056 len
:= Length(CommandHistory
);
1059 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1061 SetLength(CommandHistory
, len
+1);
1062 CommandHistory
[len
] := L
;
1065 CmdIndex
:= Length(CommandHistory
);
1068 function g_Console_CommandBlacklisted(C
: String): Boolean;
1077 if Trim(C
) = '' then
1080 Arr
:= ParseString(C
);
1084 for i
:= 0 to High(Whitelist
) do
1085 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1089 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
1096 if Trim(L
) = '' then
1099 conSkipLines
:= 0; // "unscroll"
1101 if L
= 'goobers' then
1106 g_Console_Add('Your memory serves you well.');
1112 g_Console_Add('> '+L
);
1117 Arr
:= ParseString(L
);
1121 if Commands
= nil then
1127 for i
:= 0 to High(Commands
) do
1128 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
1129 if @Commands
[i
].Proc
<> nil then
1131 Commands
[i
].Proc(Arr
);
1135 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));