5 procedure g_Console_Init();
6 procedure g_Console_Update();
7 procedure g_Console_Draw();
8 procedure g_Console_Switch();
9 procedure g_Console_Char(C
: Char);
10 procedure g_Console_Control(K
: Word);
11 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
12 procedure g_Console_Add(L
: String; Show
: Boolean = False);
13 procedure g_Console_Clear();
14 function g_Console_CommandBlacklisted(C
: String): Boolean;
16 procedure g_Console_Chat_Switch(Team
: Boolean = False);
19 gConsoleShow
: Boolean; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
21 gChatTeam
: Boolean = False;
22 gAllowConsoleMessages
: Boolean = True;
23 gChatEnter
: Boolean = True;
24 gJustChatted
: Boolean = False; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
29 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
30 SysUtils
, g_basic
, g_options
, wadreader
, Math
,
31 g_menu
, g_language
, g_net
, g_netmsg
, e_log
;
34 TCmdProc
= procedure (P
: SArray
);
50 MaxScriptRecursion
= 16;
52 DEBUG_STRING
= 'DEBUG MODE';
56 RecursionDepth
: Word = 0;
57 RecursionLimitHit
: Boolean = False;
59 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
62 ConsoleHistory
: SArray
;
63 CommandHistory
: SArray
;
65 Commands
: Array of TCommand
;
66 Aliases
: Array of TAlias
;
69 MsgArray
: Array [0..4] of record
74 function GetStrACmd(var Str
: String): String;
79 for a
:= 1 to Length(Str
) do
80 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
82 Result
:= Copy(Str
, 1, a
);
89 function ParseAlias(Str
: String): SArray
;
100 SetLength(Result
, Length(Result
)+1);
101 Result
[High(Result
)] := GetStrACmd(Str
);
105 procedure ConsoleCommands(P
: SArray
);
111 Cmd
:= LowerCase(P
[0]);
114 if Cmd
= 'clear' then
116 ConsoleHistory
:= nil;
118 for a
:= 0 to High(MsgArray
) do
126 if Cmd
= 'clearhistory' then
127 CommandHistory
:= nil;
129 if Cmd
= 'showhistory' then
130 if CommandHistory
<> nil then
133 for a
:= 0 to High(CommandHistory
) do
134 g_Console_Add(' '+CommandHistory
[a
]);
137 if Cmd
= 'commands' then
140 g_Console_Add('Commands list:');
141 for a
:= High(Commands
) downto 0 do
142 g_Console_Add(' '+Commands
[a
].Cmd
);
146 g_Console_Add(TimeToStr(Now
), True);
149 g_Console_Add(DateToStr(Now
), True);
152 if Length(P
) > 1 then
154 if P
[1] = 'ololo' then
159 for a
:= 1 to High(P
) do
161 g_Console_Add(b_Text_Format(s
), True);
169 if ConsoleHistory
<> nil then
171 if Length(P
) > 1 then
174 s
:= GameDir
+'/console.txt';
179 if IOResult
<> 0 then
181 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [s
]));
186 for a
:= 0 to High(ConsoleHistory
) do
187 WriteLn(F
, ConsoleHistory
[a
]);
190 g_Console_Add(Format(_lc
[I_CONSOLE_DUMPED
], [s
]));
198 if Length(P
) > 1 then
200 s
:= GameDir
+'/'+P
[1];
205 if IOResult
<> 0 then
207 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
211 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
216 if IOResult
<> 0 then
218 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
222 if Pos('#', s
) <> 1 then // script comment
224 // prevents endless loops
226 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
227 if not RecursionLimitHit
then
228 g_Console_Process(s
, True);
232 if (RecursionDepth
= 0) and RecursionLimitHit
then
234 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
235 RecursionLimitHit
:= False;
242 g_Console_Add('exec <script file>');
245 if Cmd
= 'alias' then
247 // alias [alias_name] [commands]
248 if Length(P
) > 1 then
250 for a
:= 0 to High(Aliases
) do
251 if Aliases
[a
].Name
= P
[1] then
253 if Length(P
) > 2 then
254 Aliases
[a
].Commands
:= ParseAlias(P
[2])
256 for b
:= 0 to High(Aliases
[a
].Commands
) do
257 g_Console_Add(Aliases
[a
].Commands
[b
]);
260 SetLength(Aliases
, Length(Aliases
)+1);
262 Aliases
[a
].Name
:= P
[1];
263 if Length(P
) > 2 then
264 Aliases
[a
].Commands
:= ParseAlias(P
[2])
266 for b
:= 0 to High(Aliases
[a
].Commands
) do
267 g_Console_Add(Aliases
[a
].Commands
[b
]);
269 for a
:= 0 to High(Aliases
) do
270 if Aliases
[a
].Commands
<> nil then
271 g_Console_Add(Aliases
[a
].Name
);
277 if Length(P
) > 1 then
279 if Aliases
= nil then
281 for a
:= 0 to High(Aliases
) do
282 if Aliases
[a
].Name
= P
[1] then
284 if Aliases
[a
].Commands
<> nil then
286 // with this system proper endless loop detection seems either impossible
287 // or very dirty to implement, so let's have this instead
288 // prevents endless loops
289 for b
:= 0 to High(Aliases
[a
].Commands
) do
292 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
293 if not RecursionLimitHit
then
294 g_Console_Process(Aliases
[a
].Commands
[b
], True);
297 if (RecursionDepth
= 0) and RecursionLimitHit
then
299 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
300 RecursionLimitHit
:= False;
307 g_Console_Add('call <alias name>');
311 procedure WhitelistCommand(Cmd
: string);
315 SetLength(Whitelist
, Length(Whitelist
)+1);
316 a
:= High(Whitelist
);
320 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
);
324 SetLength(Commands
, Length(Commands
)+1);
326 Commands
[a
].Cmd
:= Cmd
;
327 Commands
[a
].Proc
:= Proc
;
330 procedure g_Console_Init();
334 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
335 Cons_Y
:= -(gScreenHeight
div 2);
336 gConsoleShow
:= False;
341 for a
:= 0 to High(MsgArray
) do
348 AddCommand('clear', ConsoleCommands
);
349 AddCommand('clearhistory', ConsoleCommands
);
350 AddCommand('showhistory', ConsoleCommands
);
351 AddCommand('commands', ConsoleCommands
);
352 AddCommand('time', ConsoleCommands
);
353 AddCommand('date', ConsoleCommands
);
354 AddCommand('echo', ConsoleCommands
);
355 AddCommand('dump', ConsoleCommands
);
356 AddCommand('exec', ConsoleCommands
);
357 AddCommand('alias', ConsoleCommands
);
358 AddCommand('call', ConsoleCommands
);
360 AddCommand('d_window', DebugCommands
);
361 AddCommand('d_sounds', DebugCommands
);
362 AddCommand('d_frames', DebugCommands
);
363 AddCommand('d_winmsg', DebugCommands
);
364 AddCommand('d_monoff', DebugCommands
);
365 AddCommand('d_botoff', DebugCommands
);
366 AddCommand('d_monster', DebugCommands
);
367 AddCommand('d_health', DebugCommands
);
368 AddCommand('d_player', DebugCommands
);
369 AddCommand('d_joy', DebugCommands
);
371 AddCommand('p1_name', GameCVars
);
372 AddCommand('p2_name', GameCVars
);
373 AddCommand('p1_color', GameCVars
);
374 AddCommand('p2_color', GameCVars
);
375 AddCommand('r_showfps', GameCVars
);
376 AddCommand('r_showtime', GameCVars
);
377 AddCommand('r_showscore', GameCVars
);
378 AddCommand('r_showlives', GameCVars
);
379 AddCommand('r_showstat', GameCVars
);
380 AddCommand('r_showkillmsg', GameCVars
);
381 AddCommand('r_showspect', GameCVars
);
382 AddCommand('r_showping', GameCVars
);
383 AddCommand('g_gamemode', GameCVars
);
384 AddCommand('g_friendlyfire', GameCVars
);
385 AddCommand('g_weaponstay', GameCVars
);
386 AddCommand('g_allow_exit', GameCVars
);
387 AddCommand('g_allow_monsters', GameCVars
);
388 AddCommand('g_bot_vsmonsters', GameCVars
);
389 AddCommand('g_bot_vsplayers', GameCVars
);
390 AddCommand('g_scorelimit', GameCVars
);
391 AddCommand('g_timelimit', GameCVars
);
392 AddCommand('g_maxlives', GameCVars
);
393 AddCommand('g_warmuptime', GameCVars
);
394 AddCommand('net_interp', GameCVars
);
395 AddCommand('net_forceplayerupdate', GameCVars
);
396 AddCommand('net_predictself', GameCVars
);
397 AddCommand('sv_name', GameCVars
);
398 AddCommand('sv_passwd', GameCVars
);
399 AddCommand('sv_maxplrs', GameCVars
);
400 AddCommand('sv_public', GameCVars
);
401 AddCommand('sv_intertime', GameCVars
);
403 AddCommand('quit', GameCommands
);
404 AddCommand('exit', GameCommands
);
405 AddCommand('pause', GameCommands
);
406 AddCommand('endgame', GameCommands
);
407 AddCommand('restart', GameCommands
);
408 AddCommand('addbot', GameCommands
);
409 AddCommand('bot_add', GameCommands
);
410 AddCommand('bot_addlist', GameCommands
);
411 AddCommand('bot_addred', GameCommands
);
412 AddCommand('bot_addblue', GameCommands
);
413 AddCommand('bot_removeall', GameCommands
);
414 AddCommand('chat', GameCommands
);
415 AddCommand('teamchat', GameCommands
);
416 AddCommand('game', GameCommands
);
417 AddCommand('host', GameCommands
);
418 AddCommand('map', GameCommands
);
419 AddCommand('nextmap', GameCommands
);
420 AddCommand('endmap', GameCommands
);
421 AddCommand('goodbye', GameCommands
);
422 AddCommand('suicide', GameCommands
);
423 AddCommand('spectate', GameCommands
);
424 AddCommand('ready', GameCommands
);
425 AddCommand('kick', GameCommands
);
426 AddCommand('kick_id', GameCommands
);
427 AddCommand('ban', GameCommands
);
428 AddCommand('permban', GameCommands
);
429 AddCommand('ban_id', GameCommands
);
430 AddCommand('permban_id', GameCommands
);
431 AddCommand('unban', GameCommands
);
432 AddCommand('connect', GameCommands
);
433 AddCommand('disconnect', GameCommands
);
434 AddCommand('reconnect', GameCommands
);
435 AddCommand('say', GameCommands
);
436 AddCommand('tell', GameCommands
);
437 AddCommand('overtime', GameCommands
);
438 AddCommand('rcon_password', GameCommands
);
439 AddCommand('rcon', GameCommands
);
440 AddCommand('callvote', GameCommands
);
441 AddCommand('vote', GameCommands
);
442 AddCommand('clientlist', GameCommands
);
443 AddCommand('event', GameCommands
);
445 AddCommand('god', GameCheats
);
446 AddCommand('notarget', GameCheats
);
447 AddCommand('give', GameCheats
); // "exit" too ;-)
448 AddCommand('open', GameCheats
);
449 AddCommand('fly', GameCheats
);
450 AddCommand('noclip', GameCheats
);
451 AddCommand('speedy', GameCheats
);
452 AddCommand('jumpy', GameCheats
);
453 AddCommand('noreload', GameCheats
);
454 AddCommand('aimline', GameCheats
);
455 AddCommand('automap', GameCheats
);
457 WhitelistCommand('say');
458 WhitelistCommand('tell');
459 WhitelistCommand('overtime');
460 WhitelistCommand('ready');
461 WhitelistCommand('map');
462 WhitelistCommand('nextmap');
463 WhitelistCommand('endmap');
464 WhitelistCommand('restart');
465 WhitelistCommand('kick');
466 WhitelistCommand('ban');
468 WhitelistCommand('addbot');
469 WhitelistCommand('bot_add');
470 WhitelistCommand('bot_addred');
471 WhitelistCommand('bot_addblue');
472 WhitelistCommand('bot_removeall');
474 WhitelistCommand('g_gamemode');
475 WhitelistCommand('g_friendlyfire');
476 WhitelistCommand('g_weaponstay');
477 WhitelistCommand('g_allow_exit');
478 WhitelistCommand('g_allow_monsters');
479 WhitelistCommand('g_scorelimit');
480 WhitelistCommand('g_timelimit');
482 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
486 procedure g_Console_Update();
492 // Â ïðîöåññå îòêðûòèÿ:
493 if gConsoleShow
and (Cons_Y
< 0) then
495 Cons_Y
:= Cons_Y
+Step
;
498 // Â ïðîöåññå çàêðûòèÿ:
499 if (not gConsoleShow
) and
500 (Cons_Y
> -(gScreenHeight
div 2)) then
501 Cons_Y
:= Cons_Y
-Step
;
503 // Îêîí÷àòåëüíî îòêðûëàñü:
507 // Îêîí÷àòåëüíî çàêðûëàñü:
508 if Cons_Y
<= (-(gScreenHeight
div 2)) then
510 Cons_Y
:= -(gScreenHeight
div 2);
516 while a
<= High(MsgArray
) do
518 if MsgArray
[a
].Time
> 0 then
520 if MsgArray
[a
].Time
= 1 then
522 if a
< High(MsgArray
) then
524 for b
:= a
to High(MsgArray
)-1 do
525 MsgArray
[b
] := MsgArray
[b
+1];
527 MsgArray
[High(MsgArray
)].Time
:= 0;
533 Dec(MsgArray
[a
].Time
);
540 procedure g_Console_Draw();
542 CWidth
, CHeight
: Byte;
546 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
548 for a
:= 0 to High(MsgArray
) do
549 if MsgArray
[a
].Time
> 0 then
550 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
553 if not Cons_Shown
then
559 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
560 gStdFont
, 255, 255, 255, 1, True);
561 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
562 gStdFont
, 255, 255, 255, 1, True);
566 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
567 gStdFont
, 255, 255, 255, 1, True);
568 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
569 gStdFont
, 255, 255, 255, 1, True);
577 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
578 a
:= (gScreenWidth
- 2*mfW
) div 2;
579 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
580 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
581 _RGB(128, 0, 0), 2.0);
584 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
585 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
587 if ConsoleHistory
<> nil then
591 if Length(ConsoleHistory
) > ((gScreenHeight
div 2) div CHeight
)-1 then
592 b
:= Length(ConsoleHistory
)-((gScreenHeight
div 2) div CHeight
)+1;
594 b
:= Max(b
-Offset
, 0);
595 d
:= Max(High(ConsoleHistory
)-Offset
, 0);
598 for a
:= d
downto b
do
600 e_TextureFontPrintFmt(0, (gScreenHeight
div 2)-4-c
*CHeight
-Abs(Cons_Y
), ConsoleHistory
[a
],
606 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
609 procedure g_Console_Switch();
611 if gChatShow
then Exit
;
612 gConsoleShow
:= not gConsoleShow
;
616 procedure g_Console_Chat_Switch(Team
: Boolean = False);
618 if gConsoleShow
then Exit
;
619 if not g_Game_IsNet
then Exit
;
620 gChatShow
:= not gChatShow
;
628 procedure g_Console_Char(C
: Char);
630 if gChatShow
and (not gChatEnter
) then
632 Insert(C
, Line
, CPos
);
636 procedure Complete();
646 for i
:= 0 to High(Commands
) do
647 if LowerCase(Line
) = LowerCase(Copy(Commands
[i
].Cmd
, 0, Length(Line
))) then
649 SetLength(t
, Length(t
) + 1);
650 t
[Length(t
)-1] := Commands
[i
].Cmd
;
656 if Length(t
) = 1 then
659 CPos
:= Length(Line
)+1;
664 for i
:= 0 to High(t
) do
665 g_Console_Add(' '+t
[i
]);
669 procedure g_Console_Control(K
: Word);
673 if (Length(Line
) > 0) and (CPos
> 1) then
675 Delete(Line
, CPos
-1, 1);
679 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
680 Delete(Line
, CPos
, 1);
684 IK_RIGHT
, IK_KPRIGHT
:
685 if CPos
<= Length(Line
) then
687 IK_RETURN
, IK_KPRETURN
:
690 g_Console_Process(Line
)
694 if (Length(Line
) > 0) and g_Game_IsNet
then
698 if g_Game_IsClient
then
699 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
701 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
702 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
706 if g_Game_IsClient
then
707 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
709 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
717 gJustChatted
:= True;
721 if not gChatShow
then
724 if not gChatShow
then
725 if (CommandHistory
<> nil) and
726 (CmdIndex
< Length(CommandHistory
)) then
728 if CmdIndex
< Length(CommandHistory
)-1 then
729 CmdIndex
:= CmdIndex
+ 1;
730 Line
:= CommandHistory
[CmdIndex
];
731 CPos
:= Length(Line
) + 1;
734 if not gChatShow
then
735 if (CommandHistory
<> nil) and
736 (CmdIndex
<= Length(CommandHistory
)) then
739 CmdIndex
:= CmdIndex
- 1;
740 Line
:= CommandHistory
[CmdIndex
];
741 Cpos
:= Length(Line
) + 1;
743 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
744 if not gChatShow
then
745 IncMax(OffSet
, Length(ConsoleHistory
)-1);
746 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
747 if not gChatShow
then
752 CPos
:= Length(Line
) + 1;
756 function GetStr(var Str
: String): String;
763 for b
:= 1 to Length(Str
) do
764 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
766 Result
:= Copy(Str
, 2, b
-1);
773 for a
:= 1 to Length(Str
) do
774 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
776 Result
:= Copy(Str
, 1, a
);
783 function ParseString(Str
: String): SArray
;
794 SetLength(Result
, Length(Result
)+1);
795 Result
[High(Result
)] := GetStr(Str
);
799 procedure g_Console_Add(L
: String; Show
: Boolean = False);
803 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
804 while Pos(#10, L
) > 0 do
806 g_Console_Add(Copy(L
, 1, Pos(#10, L
) - 1), Show
);
807 Delete(L
, 1, Pos(#10, L
));
810 SetLength(ConsoleHistory
, Length(ConsoleHistory
)+1);
811 ConsoleHistory
[High(ConsoleHistory
)] := L
;
813 Show
:= Show
and gAllowConsoleMessages
;
815 if Show
and gShowMessages
then
817 for a
:= 0 to High(MsgArray
) do
826 for a
:= 0 to High(MsgArray
)-1 do
827 MsgArray
[a
] := MsgArray
[a
+1];
829 with MsgArray
[High(MsgArray
)] do
837 e_WriteLog('CON: ' + L
, MSG_NOTIFY
);
841 procedure g_Console_Clear();
843 ConsoleHistory
:= nil;
847 procedure AddToHistory(L
: String);
851 len
:= Length(CommandHistory
);
854 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
856 SetLength(CommandHistory
, len
+1);
857 CommandHistory
[len
] := L
;
860 CmdIndex
:= Length(CommandHistory
);
863 function g_Console_CommandBlacklisted(C
: String): Boolean;
875 Arr
:= ParseString(C
);
879 for i
:= 0 to High(Whitelist
) do
880 if Whitelist
[i
] = LowerCase(Arr
[0]) then
884 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
896 g_Console_Add('> '+L
);
901 Arr
:= ParseString(L
);
905 if Commands
= nil then
911 for i
:= 0 to High(Commands
) do
912 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
913 if @Commands
[i
].Proc
<> nil then
915 Commands
[i
].Proc(Arr
);
919 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));