0668507b333bf73cd52bfb3e763705adddbc115d
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 conwriteln (const s
: AnsiString; show
: Boolean=false);
33 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
35 procedure g_Console_Chat_Switch(Team
: Boolean = False);
38 gConsoleShow
: Boolean; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
40 gChatTeam
: Boolean = False;
41 gAllowConsoleMessages
: Boolean = True;
42 gChatEnter
: Boolean = True;
43 gJustChatted
: Boolean = False; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
48 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
49 SysUtils
, g_basic
, g_options
, wadreader
, Math
,
50 g_menu
, g_language
, g_net
, g_netmsg
, e_log
, conbuf
, utils
;
53 TCmdProc
= procedure (P
: SArray
);
71 MaxScriptRecursion
= 16;
73 DEBUG_STRING
= 'DEBUG MODE';
77 RecursionDepth
: Word = 0;
78 RecursionLimitHit
: Boolean = False;
80 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
83 //ConsoleHistory: SArray;
84 CommandHistory
: SArray
;
86 Commands
: Array of TCommand
;
87 Aliases
: Array of TAlias
;
89 conSkipLines
: Integer = 0;
90 MsgArray
: Array [0..4] of record
95 function GetStrACmd(var Str
: String): String;
100 for a
:= 1 to Length(Str
) do
101 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
103 Result
:= Copy(Str
, 1, a
);
110 function ParseAlias(Str
: String): SArray
;
121 SetLength(Result
, Length(Result
)+1);
122 Result
[High(Result
)] := GetStrACmd(Str
);
126 procedure ConsoleCommands(P
: SArray
);
132 Cmd
:= LowerCase(P
[0]);
135 if Cmd
= 'clear' then
137 //ConsoleHistory := nil;
141 for a
:= 0 to High(MsgArray
) do
149 if Cmd
= 'clearhistory' then
150 CommandHistory
:= nil;
152 if Cmd
= 'showhistory' then
153 if CommandHistory
<> nil then
156 for a
:= 0 to High(CommandHistory
) do
157 g_Console_Add(' '+CommandHistory
[a
]);
160 if Cmd
= 'commands' then
163 g_Console_Add('Commands list:');
164 for a
:= High(Commands
) downto 0 do
166 if (Length(Commands
[a
].help
) > 0) then
168 g_Console_Add(' '+Commands
[a
].Cmd
+' -- '+Commands
[a
].help
);
172 g_Console_Add(' '+Commands
[a
].Cmd
);
178 g_Console_Add(TimeToStr(Now
), True);
181 g_Console_Add(DateToStr(Now
), True);
184 if Length(P
) > 1 then
186 if P
[1] = 'ololo' then
191 for a
:= 1 to High(P
) do
193 g_Console_Add(b_Text_Format(s
), True);
202 if ConsoleHistory <> nil then
204 if Length(P) > 1 then
207 s := GameDir+'/console.txt';
212 if IOResult <> 0 then
214 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
219 for a := 0 to High(ConsoleHistory) do
220 WriteLn(F, ConsoleHistory[a]);
223 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
232 if Length(P
) > 1 then
234 s
:= GameDir
+'/'+P
[1];
239 if IOResult
<> 0 then
241 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
245 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
250 if IOResult
<> 0 then
252 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
256 if Pos('#', s
) <> 1 then // script comment
258 // prevents endless loops
260 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
261 if not RecursionLimitHit
then
262 g_Console_Process(s
, True);
266 if (RecursionDepth
= 0) and RecursionLimitHit
then
268 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
269 RecursionLimitHit
:= False;
276 g_Console_Add('exec <script file>');
279 if Cmd
= 'alias' then
281 // alias [alias_name] [commands]
282 if Length(P
) > 1 then
284 for a
:= 0 to High(Aliases
) do
285 if Aliases
[a
].Name
= P
[1] then
287 if Length(P
) > 2 then
288 Aliases
[a
].Commands
:= ParseAlias(P
[2])
290 for b
:= 0 to High(Aliases
[a
].Commands
) do
291 g_Console_Add(Aliases
[a
].Commands
[b
]);
294 SetLength(Aliases
, Length(Aliases
)+1);
296 Aliases
[a
].Name
:= P
[1];
297 if Length(P
) > 2 then
298 Aliases
[a
].Commands
:= ParseAlias(P
[2])
300 for b
:= 0 to High(Aliases
[a
].Commands
) do
301 g_Console_Add(Aliases
[a
].Commands
[b
]);
303 for a
:= 0 to High(Aliases
) do
304 if Aliases
[a
].Commands
<> nil then
305 g_Console_Add(Aliases
[a
].Name
);
311 if Length(P
) > 1 then
313 if Aliases
= nil then
315 for a
:= 0 to High(Aliases
) do
316 if Aliases
[a
].Name
= P
[1] then
318 if Aliases
[a
].Commands
<> nil then
320 // with this system proper endless loop detection seems either impossible
321 // or very dirty to implement, so let's have this instead
322 // prevents endless loops
323 for b
:= 0 to High(Aliases
[a
].Commands
) do
326 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
327 if not RecursionLimitHit
then
328 g_Console_Process(Aliases
[a
].Commands
[b
], True);
331 if (RecursionDepth
= 0) and RecursionLimitHit
then
333 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
334 RecursionLimitHit
:= False;
341 g_Console_Add('call <alias name>');
345 procedure WhitelistCommand(Cmd
: string);
349 SetLength(Whitelist
, Length(Whitelist
)+1);
350 a
:= High(Whitelist
);
351 Whitelist
[a
] := LowerCase(Cmd
);
354 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
; ahelp
: String=''; ahidden
: Boolean=false);
358 SetLength(Commands
, Length(Commands
)+1);
360 Commands
[a
].Cmd
:= LowerCase(Cmd
);
361 Commands
[a
].Proc
:= Proc
;
362 Commands
[a
].hidden
:= ahidden
;
363 Commands
[a
].help
:= ahelp
;
366 procedure g_Console_Init();
370 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
371 Cons_Y
:= -(gScreenHeight
div 2);
372 gConsoleShow
:= False;
377 for a
:= 0 to High(MsgArray
) do
384 AddCommand('clear', ConsoleCommands
, 'clear console');
385 AddCommand('clearhistory', ConsoleCommands
);
386 AddCommand('showhistory', ConsoleCommands
);
387 AddCommand('commands', ConsoleCommands
);
388 AddCommand('time', ConsoleCommands
);
389 AddCommand('date', ConsoleCommands
);
390 AddCommand('echo', ConsoleCommands
);
391 AddCommand('dump', ConsoleCommands
);
392 AddCommand('exec', ConsoleCommands
);
393 AddCommand('alias', ConsoleCommands
);
394 AddCommand('call', ConsoleCommands
);
396 AddCommand('d_window', DebugCommands
);
397 AddCommand('d_sounds', DebugCommands
);
398 AddCommand('d_frames', DebugCommands
);
399 AddCommand('d_winmsg', DebugCommands
);
400 AddCommand('d_monoff', DebugCommands
);
401 AddCommand('d_botoff', DebugCommands
);
402 AddCommand('d_monster', DebugCommands
);
403 AddCommand('d_health', DebugCommands
);
404 AddCommand('d_player', DebugCommands
);
405 AddCommand('d_joy', DebugCommands
);
407 AddCommand('pf_draw_frame', ProfilerCommands
, 'draw frame rendering profiles');
408 //AddCommand('pf_update_frame', ProfilerCommands);
409 AddCommand('pf_coldet', ProfilerCommands
, 'draw collision detection profiles');
410 AddCommand('pf_los', ProfilerCommands
, 'draw monster LOS profiles');
411 AddCommand('r_sq_draw', ProfilerCommands
, 'accelerated spatial queries in rendering');
412 AddCommand('cd_sq_enabled', ProfilerCommands
, 'accelerated spatial queries in map coldet');
413 AddCommand('mon_sq_enabled', ProfilerCommands
, 'use accelerated spatial queries for monsters');
414 AddCommand('wtrace_sq_enabled', ProfilerCommands
, 'use accelerated weapon hitscan trace');
416 AddCommand('pr_enabled', ProfilerCommands
, 'enable/disable particles');
417 AddCommand('pr_phys_enabled', ProfilerCommands
, 'enable/disable particle physics');
418 AddCommand('los_enabled', ProfilerCommands
, 'enable/disable LOS calculations');
420 AddCommand('mon_think', ProfilerCommands
, 'enable/disable monster thinking');
421 AddCommand('dbg_holmes', ProfilerCommands
, 'turn Holmes on/off');
423 AddCommand('p1_name', GameCVars
);
424 AddCommand('p2_name', GameCVars
);
425 AddCommand('p1_color', GameCVars
);
426 AddCommand('p2_color', GameCVars
);
427 AddCommand('r_showfps', GameCVars
);
428 AddCommand('r_showtime', GameCVars
);
429 AddCommand('r_showscore', GameCVars
);
430 AddCommand('r_showlives', GameCVars
);
431 AddCommand('r_showstat', GameCVars
);
432 AddCommand('r_showkillmsg', GameCVars
);
433 AddCommand('r_showspect', GameCVars
);
434 AddCommand('r_showping', GameCVars
);
435 AddCommand('g_gamemode', GameCVars
);
436 AddCommand('g_friendlyfire', GameCVars
);
437 AddCommand('g_weaponstay', GameCVars
);
438 AddCommand('g_allow_exit', GameCVars
);
439 AddCommand('g_allow_monsters', GameCVars
);
440 AddCommand('g_bot_vsmonsters', GameCVars
);
441 AddCommand('g_bot_vsplayers', GameCVars
);
442 AddCommand('g_scorelimit', GameCVars
);
443 AddCommand('g_timelimit', GameCVars
);
444 AddCommand('g_maxlives', GameCVars
);
445 AddCommand('g_warmuptime', GameCVars
);
446 AddCommand('net_interp', GameCVars
);
447 AddCommand('net_forceplayerupdate', GameCVars
);
448 AddCommand('net_predictself', GameCVars
);
449 AddCommand('sv_name', GameCVars
);
450 AddCommand('sv_passwd', GameCVars
);
451 AddCommand('sv_maxplrs', GameCVars
);
452 AddCommand('sv_public', GameCVars
);
453 AddCommand('sv_intertime', GameCVars
);
455 AddCommand('quit', GameCommands
);
456 AddCommand('exit', GameCommands
);
457 AddCommand('pause', GameCommands
);
458 AddCommand('endgame', GameCommands
);
459 AddCommand('restart', GameCommands
);
460 AddCommand('addbot', GameCommands
);
461 AddCommand('bot_add', GameCommands
);
462 AddCommand('bot_addlist', GameCommands
);
463 AddCommand('bot_addred', GameCommands
);
464 AddCommand('bot_addblue', GameCommands
);
465 AddCommand('bot_removeall', GameCommands
);
466 AddCommand('chat', GameCommands
);
467 AddCommand('teamchat', GameCommands
);
468 AddCommand('game', GameCommands
);
469 AddCommand('host', GameCommands
);
470 AddCommand('map', GameCommands
);
471 AddCommand('nextmap', GameCommands
);
472 AddCommand('endmap', GameCommands
);
473 AddCommand('goodbye', GameCommands
);
474 AddCommand('suicide', GameCommands
);
475 AddCommand('spectate', GameCommands
);
476 AddCommand('ready', GameCommands
);
477 AddCommand('kick', GameCommands
);
478 AddCommand('kick_id', GameCommands
);
479 AddCommand('ban', GameCommands
);
480 AddCommand('permban', GameCommands
);
481 AddCommand('ban_id', GameCommands
);
482 AddCommand('permban_id', GameCommands
);
483 AddCommand('unban', GameCommands
);
484 AddCommand('connect', GameCommands
);
485 AddCommand('disconnect', GameCommands
);
486 AddCommand('reconnect', GameCommands
);
487 AddCommand('say', GameCommands
);
488 AddCommand('tell', GameCommands
);
489 AddCommand('overtime', GameCommands
);
490 AddCommand('rcon_password', GameCommands
);
491 AddCommand('rcon', GameCommands
);
492 AddCommand('callvote', GameCommands
);
493 AddCommand('vote', GameCommands
);
494 AddCommand('clientlist', GameCommands
);
495 AddCommand('event', GameCommands
);
497 AddCommand('god', GameCheats
);
498 AddCommand('notarget', GameCheats
);
499 AddCommand('give', GameCheats
); // "exit" too ;-)
500 AddCommand('open', GameCheats
);
501 AddCommand('fly', GameCheats
);
502 AddCommand('noclip', GameCheats
);
503 AddCommand('speedy', GameCheats
);
504 AddCommand('jumpy', GameCheats
);
505 AddCommand('noreload', GameCheats
);
506 AddCommand('aimline', GameCheats
);
507 AddCommand('automap', GameCheats
);
509 WhitelistCommand('say');
510 WhitelistCommand('tell');
511 WhitelistCommand('overtime');
512 WhitelistCommand('ready');
513 WhitelistCommand('map');
514 WhitelistCommand('nextmap');
515 WhitelistCommand('endmap');
516 WhitelistCommand('restart');
517 WhitelistCommand('kick');
518 WhitelistCommand('ban');
520 WhitelistCommand('addbot');
521 WhitelistCommand('bot_add');
522 WhitelistCommand('bot_addred');
523 WhitelistCommand('bot_addblue');
524 WhitelistCommand('bot_removeall');
526 WhitelistCommand('g_gamemode');
527 WhitelistCommand('g_friendlyfire');
528 WhitelistCommand('g_weaponstay');
529 WhitelistCommand('g_allow_exit');
530 WhitelistCommand('g_allow_monsters');
531 WhitelistCommand('g_scorelimit');
532 WhitelistCommand('g_timelimit');
534 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
538 procedure g_Console_Update();
544 // Â ïðîöåññå îòêðûòèÿ:
545 if gConsoleShow
and (Cons_Y
< 0) then
547 Cons_Y
:= Cons_Y
+Step
;
550 // Â ïðîöåññå çàêðûòèÿ:
551 if (not gConsoleShow
) and
552 (Cons_Y
> -(gScreenHeight
div 2)) then
553 Cons_Y
:= Cons_Y
-Step
;
555 // Îêîí÷àòåëüíî îòêðûëàñü:
559 // Îêîí÷àòåëüíî çàêðûëàñü:
560 if Cons_Y
<= (-(gScreenHeight
div 2)) then
562 Cons_Y
:= -(gScreenHeight
div 2);
568 while a
<= High(MsgArray
) do
570 if MsgArray
[a
].Time
> 0 then
572 if MsgArray
[a
].Time
= 1 then
574 if a
< High(MsgArray
) then
576 for b
:= a
to High(MsgArray
)-1 do
577 MsgArray
[b
] := MsgArray
[b
+1];
579 MsgArray
[High(MsgArray
)].Time
:= 0;
585 Dec(MsgArray
[a
].Time
);
593 procedure drawConsoleText ();
595 CWidth
, CHeight
: Byte;
600 procedure putLine (sp
, ep
: LongWord);
609 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
610 if wdt
+cw
> gScreenWidth
-8 then break
;
611 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
615 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
616 // now print our part
624 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
625 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
638 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
639 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
640 skip
:= conSkipLines
;
641 cbufLastLine(sp
, ep
);
644 if ty
+CHeight
<= 0 then break
;
645 until not cbufLineUp(sp
, ep
);
648 procedure g_Console_Draw();
650 CWidth
, CHeight
: Byte;
654 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
656 for a
:= 0 to High(MsgArray
) do
657 if MsgArray
[a
].Time
> 0 then
658 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
661 if not Cons_Shown
then
667 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
668 gStdFont
, 255, 255, 255, 1, True);
669 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
670 gStdFont
, 255, 255, 255, 1, True);
674 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
675 gStdFont
, 255, 255, 255, 1, True);
676 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
677 gStdFont
, 255, 255, 255, 1, True);
685 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
686 a
:= (gScreenWidth
- 2*mfW
) div 2;
687 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
688 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
689 _RGB(128, 0, 0), 2.0);
692 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
693 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
697 if ConsoleHistory <> nil then
701 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
702 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
704 b := Max(b-Offset, 0);
705 d := Max(High(ConsoleHistory)-Offset, 0);
708 for a := d downto b do
710 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
717 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
720 procedure g_Console_Switch();
722 if gChatShow
then Exit
;
723 gConsoleShow
:= not gConsoleShow
;
727 procedure g_Console_Chat_Switch(Team
: Boolean = False);
729 if gConsoleShow
then Exit
;
730 if not g_Game_IsNet
then Exit
;
731 gChatShow
:= not gChatShow
;
739 procedure g_Console_Char(C
: Char);
741 if gChatShow
and (not gChatEnter
) then
743 Insert(C
, Line
, CPos
);
749 tcomplist
: array of string = nil;
750 tcompidx
: array of Integer = nil;
752 procedure Complete ();
756 ll
, lpfx
, cmd
: string;
758 if (Length(Line
) = 0) then
761 for i
:= 0 to High(Commands
) do
763 if not Commands
[i
].hidden
then
765 if (Length(Commands
[i
].help
) > 0) then
767 g_Console_Add(' '+Commands
[i
].Cmd
+' -- '+Commands
[i
].help
);
771 g_Console_Add(' '+Commands
[i
].Cmd
);
778 ll
:= LowerCase(Line
);
781 if (Length(ll
) > 1) and (ll
[Length(ll
)] = ' ') then
783 ll
:= Copy(ll
, 0, Length(ll
)-1);
784 for i
:= 0 to High(Commands
) do
786 if Commands
[i
].hidden
then continue
;
787 if (Commands
[i
].Cmd
= ll
) then
789 if (Length(Commands
[i
].help
) > 0) then
791 g_Console_Add(' '+Commands
[i
].Cmd
+' -- '+Commands
[i
].help
);
798 // build completion list
800 for i
:= 0 to High(Commands
) do
802 if Commands
[i
].hidden
then continue
;
803 cmd
:= Commands
[i
].Cmd
;
804 if (Length(cmd
) >= Length(ll
)) and (ll
= Copy(cmd
, 0, Length(ll
))) then
806 if (tused
= Length(tcomplist
)) then
808 SetLength(tcomplist
, Length(tcomplist
)+128);
809 SetLength(tcompidx
, Length(tcompidx
)+128);
811 tcomplist
[tused
] := cmd
;
812 tcompidx
[tused
] := i
;
814 if (Length(cmd
) > Length(lpfx
)) then lpfx
:= cmd
;
818 // get longest prefix
819 for i
:= 0 to tused
-1 do
822 for c
:= 1 to Length(lpfx
) do
824 if (c
> Length(cmd
)) then break
;
825 if (cmd
[c
] <> lpfx
[c
]) then begin lpfx
:= Copy(lpfx
, 0, c
-1); break
; end;
829 if (tused
= 0) then exit
;
833 Line
:= tcomplist
[0]+' ';
834 CPos
:= Length(Line
)+1;
838 // has longest prefix?
839 if (Length(lpfx
) > Length(ll
)) then
842 CPos
:= Length(Line
)+1;
847 for i
:= 0 to tused
-1 do
849 if (Length(Commands
[tcompidx
[i
]].help
) > 0) then
851 g_Console_Add(' '+tcomplist
[i
]+' -- '+Commands
[tcompidx
[i
]].help
);
855 g_Console_Add(' '+tcomplist
[i
]);
863 procedure g_Console_Control(K
: Word);
867 if (Length(Line
) > 0) and (CPos
> 1) then
869 Delete(Line
, CPos
-1, 1);
873 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
874 Delete(Line
, CPos
, 1);
878 IK_RIGHT
, IK_KPRIGHT
:
879 if CPos
<= Length(Line
) then
881 IK_RETURN
, IK_KPRETURN
:
884 g_Console_Process(Line
)
888 if (Length(Line
) > 0) and g_Game_IsNet
then
892 if g_Game_IsClient
then
893 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
895 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
896 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
900 if g_Game_IsClient
then
901 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
903 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
911 gJustChatted
:= True;
915 if not gChatShow
then
918 if not gChatShow
then
919 if (CommandHistory
<> nil) and
920 (CmdIndex
< Length(CommandHistory
)) then
922 if CmdIndex
< Length(CommandHistory
)-1 then
923 CmdIndex
:= CmdIndex
+ 1;
924 Line
:= CommandHistory
[CmdIndex
];
925 CPos
:= Length(Line
) + 1;
928 if not gChatShow
then
929 if (CommandHistory
<> nil) and
930 (CmdIndex
<= Length(CommandHistory
)) then
933 CmdIndex
:= CmdIndex
- 1;
934 Line
:= CommandHistory
[CmdIndex
];
935 Cpos
:= Length(Line
) + 1;
937 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
938 if not gChatShow
then Inc(conSkipLines
);
939 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
940 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
944 CPos
:= Length(Line
) + 1;
948 function GetStr(var Str
: String): String;
955 for b
:= 1 to Length(Str
) do
956 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
958 Result
:= Copy(Str
, 2, b
-1);
965 for a
:= 1 to Length(Str
) do
966 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
968 Result
:= Copy(Str
, 1, a
);
975 function ParseString(Str
: String): SArray
;
986 SetLength(Result
, Length(Result
)+1);
987 Result
[High(Result
)] := GetStr(Str
);
991 procedure g_Console_Add (L
: string; Show
: Boolean=false);
993 procedure conmsg (s
: AnsiString);
997 if length(s
) = 0 then exit
;
998 for a
:= 0 to High(MsgArray
) do
1010 for a
:= 0 to High(MsgArray
)-1 do MsgArray
[a
] := MsgArray
[a
+1];
1011 with MsgArray
[High(MsgArray
)] do
1021 // put it to console
1023 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
1025 // now show 'em out of console too
1026 Show
:= Show
and gAllowConsoleMessages
;
1027 if Show
and gShowMessages
then
1029 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
1030 while length(L
) > 0 do
1033 if f
<= 0 then f
:= length(L
)+1;
1034 conmsg(Copy(L
, 1, f
-1));
1039 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
1040 //ConsoleHistory[High(ConsoleHistory)] := L;
1044 e_WriteLog('CON: ' + L, MSG_NOTIFY);
1051 consolewriterLastWasEOL
: Boolean = false;
1053 procedure consolewriter (constref buf
; len
: SizeUInt
);
1057 if (len
< 1) then exit
;
1059 consolewriterLastWasEOL
:= (b
[len
-1] = 13) or (b
[len
-1] = 10);
1062 if (b
[0] <> 13) and (b
[0] <> 10) then
1064 cbufPut(Char(b
[0]));
1068 if (len
> 1) and (b
[0] = 13) then begin len
-= 1; b
+= 1; end;
1077 // returns formatted string if `writerCB` is `nil`, empty string otherwise
1078 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
1079 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
1080 procedure conwriteln (const s
: AnsiString; show
: Boolean=false);
1082 g_Console_Add(s
, show
);
1086 procedure conwritefln (const s
: AnsiString; args
: array of const; show
: Boolean=false);
1090 g_Console_Add(formatstrf(s
, args
), true);
1094 consolewriterLastWasEOL
:= false;
1095 formatstrf(s
, args
, consolewriter
);
1096 if not consolewriterLastWasEOL
then cbufPut(#10);
1101 procedure g_Console_Clear();
1103 //ConsoleHistory := nil;
1108 procedure AddToHistory(L
: String);
1112 len
:= Length(CommandHistory
);
1115 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
1117 SetLength(CommandHistory
, len
+1);
1118 CommandHistory
[len
] := L
;
1121 CmdIndex
:= Length(CommandHistory
);
1124 function g_Console_CommandBlacklisted(C
: String): Boolean;
1133 if Trim(C
) = '' then
1136 Arr
:= ParseString(C
);
1140 for i
:= 0 to High(Whitelist
) do
1141 if Whitelist
[i
] = LowerCase(Arr
[0]) then
1145 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
1152 if Trim(L
) = '' then
1155 conSkipLines
:= 0; // "unscroll"
1157 if L
= 'goobers' then
1162 g_Console_Add('Your memory serves you well.');
1168 g_Console_Add('> '+L
);
1173 Arr
:= ParseString(L
);
1177 if Commands
= nil then
1183 for i
:= 0 to High(Commands
) do
1184 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
1185 if @Commands
[i
].Proc
<> nil then
1187 Commands
[i
].Proc(Arr
);
1191 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));