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
, WADEDITOR
, Math
,
31 g_menu
, g_language
, g_net
, g_netmsg
;
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 WhitelistCommand('say');
446 WhitelistCommand('tell');
447 WhitelistCommand('overtime');
448 WhitelistCommand('ready');
449 WhitelistCommand('map');
450 WhitelistCommand('nextmap');
451 WhitelistCommand('endmap');
452 WhitelistCommand('restart');
453 WhitelistCommand('kick');
454 WhitelistCommand('ban');
456 WhitelistCommand('addbot');
457 WhitelistCommand('bot_add');
458 WhitelistCommand('bot_addred');
459 WhitelistCommand('bot_addblue');
460 WhitelistCommand('bot_removeall');
462 WhitelistCommand('g_gamemode');
463 WhitelistCommand('g_friendlyfire');
464 WhitelistCommand('g_weaponstay');
465 WhitelistCommand('g_allow_exit');
466 WhitelistCommand('g_allow_monsters');
467 WhitelistCommand('g_scorelimit');
468 WhitelistCommand('g_timelimit');
470 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
474 procedure g_Console_Update();
480 // Â ïðîöåññå îòêðûòèÿ:
481 if gConsoleShow
and (Cons_Y
< 0) then
483 Cons_Y
:= Cons_Y
+Step
;
486 // Â ïðîöåññå çàêðûòèÿ:
487 if (not gConsoleShow
) and
488 (Cons_Y
> -(gScreenHeight
div 2)) then
489 Cons_Y
:= Cons_Y
-Step
;
491 // Îêîí÷àòåëüíî îòêðûëàñü:
495 // Îêîí÷àòåëüíî çàêðûëàñü:
496 if Cons_Y
<= (-(gScreenHeight
div 2)) then
498 Cons_Y
:= -(gScreenHeight
div 2);
504 while a
<= High(MsgArray
) do
506 if MsgArray
[a
].Time
> 0 then
508 if MsgArray
[a
].Time
= 1 then
510 if a
< High(MsgArray
) then
512 for b
:= a
to High(MsgArray
)-1 do
513 MsgArray
[b
] := MsgArray
[b
+1];
515 MsgArray
[High(MsgArray
)].Time
:= 0;
521 Dec(MsgArray
[a
].Time
);
528 procedure g_Console_Draw();
530 CWidth
, CHeight
: Byte;
534 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
536 for a
:= 0 to High(MsgArray
) do
537 if MsgArray
[a
].Time
> 0 then
538 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
541 if not Cons_Shown
then
547 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
548 gStdFont
, 255, 255, 255, 1, True);
549 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
550 gStdFont
, 255, 255, 255, 1, True);
554 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
555 gStdFont
, 255, 255, 255, 1, True);
556 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
557 gStdFont
, 255, 255, 255, 1, True);
565 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
566 a
:= (gScreenWidth
- 2*mfW
) div 2;
567 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
568 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
569 _RGB(128, 0, 0), 2.0);
572 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
573 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
575 if ConsoleHistory
<> nil then
579 if Length(ConsoleHistory
) > ((gScreenHeight
div 2) div CHeight
)-1 then
580 b
:= Length(ConsoleHistory
)-((gScreenHeight
div 2) div CHeight
)+1;
582 b
:= Max(b
-Offset
, 0);
583 d
:= Max(High(ConsoleHistory
)-Offset
, 0);
586 for a
:= d
downto b
do
588 e_TextureFontPrintFmt(0, (gScreenHeight
div 2)-4-c
*CHeight
-Abs(Cons_Y
), ConsoleHistory
[a
],
594 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
597 procedure g_Console_Switch();
599 if gChatShow
then Exit
;
600 gConsoleShow
:= not gConsoleShow
;
604 procedure g_Console_Chat_Switch(Team
: Boolean = False);
606 if gConsoleShow
then Exit
;
607 if not g_Game_IsNet
then Exit
;
608 gChatShow
:= not gChatShow
;
616 procedure g_Console_Char(C
: Char);
618 if gChatShow
and (not gChatEnter
) then
620 Insert(C
, Line
, CPos
);
624 procedure Complete();
634 for i
:= 0 to High(Commands
) do
635 if LowerCase(Line
) = LowerCase(Copy(Commands
[i
].Cmd
, 0, Length(Line
))) then
637 SetLength(t
, Length(t
) + 1);
638 t
[Length(t
)-1] := Commands
[i
].Cmd
;
644 if Length(t
) = 1 then
647 CPos
:= Length(Line
)+1;
652 for i
:= 0 to High(t
) do
653 g_Console_Add(' '+t
[i
]);
657 procedure g_Console_Control(K
: Word);
661 if (Length(Line
) > 0) and (CPos
> 1) then
663 Delete(Line
, CPos
-1, 1);
667 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
668 Delete(Line
, CPos
, 1);
672 IK_RIGHT
, IK_KPRIGHT
:
673 if CPos
<= Length(Line
) then
675 IK_RETURN
, IK_KPRETURN
:
678 g_Console_Process(Line
)
682 if (Length(Line
) > 0) and g_Game_IsNet
then
686 if g_Game_IsClient
then
687 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
689 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
690 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
694 if g_Game_IsClient
then
695 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
697 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
705 gJustChatted
:= True;
709 if not gChatShow
then
712 if not gChatShow
then
713 if (CommandHistory
<> nil) and
714 (CmdIndex
< Length(CommandHistory
)) then
716 if CmdIndex
< Length(CommandHistory
)-1 then
717 CmdIndex
:= CmdIndex
+ 1;
718 Line
:= CommandHistory
[CmdIndex
];
719 CPos
:= Length(Line
) + 1;
722 if not gChatShow
then
723 if (CommandHistory
<> nil) and
724 (CmdIndex
<= Length(CommandHistory
)) then
727 CmdIndex
:= CmdIndex
- 1;
728 Line
:= CommandHistory
[CmdIndex
];
729 Cpos
:= Length(Line
) + 1;
731 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
732 if not gChatShow
then
733 IncMax(OffSet
, Length(ConsoleHistory
)-1);
734 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
735 if not gChatShow
then
740 CPos
:= Length(Line
) + 1;
744 function GetStr(var Str
: String): String;
751 for b
:= 1 to Length(Str
) do
752 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
754 Result
:= Copy(Str
, 2, b
-1);
761 for a
:= 1 to Length(Str
) do
762 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
764 Result
:= Copy(Str
, 1, a
);
771 function ParseString(Str
: String): SArray
;
782 SetLength(Result
, Length(Result
)+1);
783 Result
[High(Result
)] := GetStr(Str
);
787 procedure g_Console_Add(L
: String; Show
: Boolean = False);
791 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
792 while Pos(#10, L
) > 0 do
794 g_Console_Add(Copy(L
, 1, Pos(#10, L
) - 1), Show
);
795 Delete(L
, 1, Pos(#10, L
));
798 SetLength(ConsoleHistory
, Length(ConsoleHistory
)+1);
799 ConsoleHistory
[High(ConsoleHistory
)] := L
;
801 Show
:= Show
and gAllowConsoleMessages
;
803 if Show
and gShowMessages
then
805 for a
:= 0 to High(MsgArray
) do
814 for a
:= 0 to High(MsgArray
)-1 do
815 MsgArray
[a
] := MsgArray
[a
+1];
817 with MsgArray
[High(MsgArray
)] do
825 procedure g_Console_Clear();
827 ConsoleHistory
:= nil;
831 procedure AddToHistory(L
: String);
835 len
:= Length(CommandHistory
);
838 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
840 SetLength(CommandHistory
, len
+1);
841 CommandHistory
[len
] := L
;
844 CmdIndex
:= Length(CommandHistory
);
847 function g_Console_CommandBlacklisted(C
: String): Boolean;
859 Arr
:= ParseString(C
);
863 for i
:= 0 to High(Whitelist
) do
864 if Whitelist
[i
] = LowerCase(Arr
[0]) then
868 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
880 g_Console_Add('> '+L
);
885 Arr
:= ParseString(L
);
889 if Commands
= nil then
895 for i
:= 0 to High(Commands
) do
896 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
897 if @Commands
[i
].Proc
<> nil then
899 Commands
[i
].Proc(Arr
);
903 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));