8b9ef250a34b6c3fff8d245cd63acd70af04bdb0
6 procedure g_Console_Init();
7 procedure g_Console_Update();
8 procedure g_Console_Draw();
9 procedure g_Console_Switch();
10 procedure g_Console_Char(C
: Char);
11 procedure g_Console_Control(K
: Word);
12 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
13 procedure g_Console_Add(L
: String; Show
: Boolean = False);
14 procedure g_Console_Clear();
15 function g_Console_CommandBlacklisted(C
: String): Boolean;
17 procedure g_Console_Chat_Switch(Team
: Boolean = False);
20 gConsoleShow
: Boolean; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ
22 gChatTeam
: Boolean = False;
23 gAllowConsoleMessages
: Boolean = True;
24 gChatEnter
: Boolean = True;
25 gJustChatted
: Boolean = False; // ÷òîáû àäìèí â èíòåðå ÷àòÿñü íå ïðîìàòûâàë ñòàòèñòèêó
30 g_textures
, g_main
, e_graphics
, e_input
, g_game
,
31 SysUtils
, g_basic
, g_options
, wadreader
, Math
,
32 g_menu
, g_language
, g_net
, g_netmsg
, e_log
;
35 TCmdProc
= procedure (P
: SArray
);
51 MaxScriptRecursion
= 16;
53 DEBUG_STRING
= 'DEBUG MODE';
57 RecursionDepth
: Word = 0;
58 RecursionLimitHit
: Boolean = False;
60 Cons_Shown
: Boolean; // Ðèñîâàòü ëè êîíñîëü?
63 ConsoleHistory
: SArray
;
64 CommandHistory
: SArray
;
66 Commands
: Array of TCommand
;
67 Aliases
: Array of TAlias
;
70 MsgArray
: Array [0..4] of record
75 function GetStrACmd(var Str
: String): String;
80 for a
:= 1 to Length(Str
) do
81 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
83 Result
:= Copy(Str
, 1, a
);
90 function ParseAlias(Str
: String): SArray
;
101 SetLength(Result
, Length(Result
)+1);
102 Result
[High(Result
)] := GetStrACmd(Str
);
106 procedure ConsoleCommands(P
: SArray
);
112 Cmd
:= LowerCase(P
[0]);
115 if Cmd
= 'clear' then
117 ConsoleHistory
:= nil;
119 for a
:= 0 to High(MsgArray
) do
127 if Cmd
= 'clearhistory' then
128 CommandHistory
:= nil;
130 if Cmd
= 'showhistory' then
131 if CommandHistory
<> nil then
134 for a
:= 0 to High(CommandHistory
) do
135 g_Console_Add(' '+CommandHistory
[a
]);
138 if Cmd
= 'commands' then
141 g_Console_Add('Commands list:');
142 for a
:= High(Commands
) downto 0 do
143 g_Console_Add(' '+Commands
[a
].Cmd
);
147 g_Console_Add(TimeToStr(Now
), True);
150 g_Console_Add(DateToStr(Now
), True);
153 if Length(P
) > 1 then
155 if P
[1] = 'ololo' then
160 for a
:= 1 to High(P
) do
162 g_Console_Add(b_Text_Format(s
), True);
170 if ConsoleHistory
<> nil then
172 if Length(P
) > 1 then
175 s
:= GameDir
+'/console.txt';
180 if IOResult
<> 0 then
182 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [s
]));
187 for a
:= 0 to High(ConsoleHistory
) do
188 WriteLn(F
, ConsoleHistory
[a
]);
191 g_Console_Add(Format(_lc
[I_CONSOLE_DUMPED
], [s
]));
199 if Length(P
) > 1 then
201 s
:= GameDir
+'/'+P
[1];
206 if IOResult
<> 0 then
208 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
212 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
217 if IOResult
<> 0 then
219 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
223 if Pos('#', s
) <> 1 then // script comment
225 // prevents endless loops
227 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
228 if not RecursionLimitHit
then
229 g_Console_Process(s
, True);
233 if (RecursionDepth
= 0) and RecursionLimitHit
then
235 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
236 RecursionLimitHit
:= False;
243 g_Console_Add('exec <script file>');
246 if Cmd
= 'alias' then
248 // alias [alias_name] [commands]
249 if Length(P
) > 1 then
251 for a
:= 0 to High(Aliases
) do
252 if Aliases
[a
].Name
= P
[1] then
254 if Length(P
) > 2 then
255 Aliases
[a
].Commands
:= ParseAlias(P
[2])
257 for b
:= 0 to High(Aliases
[a
].Commands
) do
258 g_Console_Add(Aliases
[a
].Commands
[b
]);
261 SetLength(Aliases
, Length(Aliases
)+1);
263 Aliases
[a
].Name
:= P
[1];
264 if Length(P
) > 2 then
265 Aliases
[a
].Commands
:= ParseAlias(P
[2])
267 for b
:= 0 to High(Aliases
[a
].Commands
) do
268 g_Console_Add(Aliases
[a
].Commands
[b
]);
270 for a
:= 0 to High(Aliases
) do
271 if Aliases
[a
].Commands
<> nil then
272 g_Console_Add(Aliases
[a
].Name
);
278 if Length(P
) > 1 then
280 if Aliases
= nil then
282 for a
:= 0 to High(Aliases
) do
283 if Aliases
[a
].Name
= P
[1] then
285 if Aliases
[a
].Commands
<> nil then
287 // with this system proper endless loop detection seems either impossible
288 // or very dirty to implement, so let's have this instead
289 // prevents endless loops
290 for b
:= 0 to High(Aliases
[a
].Commands
) do
293 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
294 if not RecursionLimitHit
then
295 g_Console_Process(Aliases
[a
].Commands
[b
], True);
298 if (RecursionDepth
= 0) and RecursionLimitHit
then
300 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
301 RecursionLimitHit
:= False;
308 g_Console_Add('call <alias name>');
312 procedure WhitelistCommand(Cmd
: string);
316 SetLength(Whitelist
, Length(Whitelist
)+1);
317 a
:= High(Whitelist
);
321 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
);
325 SetLength(Commands
, Length(Commands
)+1);
327 Commands
[a
].Cmd
:= Cmd
;
328 Commands
[a
].Proc
:= Proc
;
331 procedure g_Console_Init();
335 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
336 Cons_Y
:= -(gScreenHeight
div 2);
337 gConsoleShow
:= False;
342 for a
:= 0 to High(MsgArray
) do
349 AddCommand('clear', ConsoleCommands
);
350 AddCommand('clearhistory', ConsoleCommands
);
351 AddCommand('showhistory', ConsoleCommands
);
352 AddCommand('commands', ConsoleCommands
);
353 AddCommand('time', ConsoleCommands
);
354 AddCommand('date', ConsoleCommands
);
355 AddCommand('echo', ConsoleCommands
);
356 AddCommand('dump', ConsoleCommands
);
357 AddCommand('exec', ConsoleCommands
);
358 AddCommand('alias', ConsoleCommands
);
359 AddCommand('call', ConsoleCommands
);
361 AddCommand('d_window', DebugCommands
);
362 AddCommand('d_sounds', DebugCommands
);
363 AddCommand('d_frames', DebugCommands
);
364 AddCommand('d_winmsg', DebugCommands
);
365 AddCommand('d_monoff', DebugCommands
);
366 AddCommand('d_botoff', DebugCommands
);
367 AddCommand('d_monster', DebugCommands
);
368 AddCommand('d_health', DebugCommands
);
369 AddCommand('d_player', DebugCommands
);
370 AddCommand('d_joy', DebugCommands
);
372 AddCommand('p1_name', GameCVars
);
373 AddCommand('p2_name', GameCVars
);
374 AddCommand('p1_color', GameCVars
);
375 AddCommand('p2_color', GameCVars
);
376 AddCommand('r_showfps', GameCVars
);
377 AddCommand('r_showtime', GameCVars
);
378 AddCommand('r_showscore', GameCVars
);
379 AddCommand('r_showlives', GameCVars
);
380 AddCommand('r_showstat', GameCVars
);
381 AddCommand('r_showkillmsg', GameCVars
);
382 AddCommand('r_showspect', GameCVars
);
383 AddCommand('r_showping', GameCVars
);
384 AddCommand('g_gamemode', GameCVars
);
385 AddCommand('g_friendlyfire', GameCVars
);
386 AddCommand('g_weaponstay', GameCVars
);
387 AddCommand('g_allow_exit', GameCVars
);
388 AddCommand('g_allow_monsters', GameCVars
);
389 AddCommand('g_bot_vsmonsters', GameCVars
);
390 AddCommand('g_bot_vsplayers', GameCVars
);
391 AddCommand('g_scorelimit', GameCVars
);
392 AddCommand('g_timelimit', GameCVars
);
393 AddCommand('g_maxlives', GameCVars
);
394 AddCommand('g_warmuptime', GameCVars
);
395 AddCommand('net_interp', GameCVars
);
396 AddCommand('net_forceplayerupdate', GameCVars
);
397 AddCommand('net_predictself', GameCVars
);
398 AddCommand('sv_name', GameCVars
);
399 AddCommand('sv_passwd', GameCVars
);
400 AddCommand('sv_maxplrs', GameCVars
);
401 AddCommand('sv_public', GameCVars
);
402 AddCommand('sv_intertime', GameCVars
);
404 AddCommand('quit', GameCommands
);
405 AddCommand('exit', GameCommands
);
406 AddCommand('pause', GameCommands
);
407 AddCommand('endgame', GameCommands
);
408 AddCommand('restart', GameCommands
);
409 AddCommand('addbot', GameCommands
);
410 AddCommand('bot_add', GameCommands
);
411 AddCommand('bot_addlist', GameCommands
);
412 AddCommand('bot_addred', GameCommands
);
413 AddCommand('bot_addblue', GameCommands
);
414 AddCommand('bot_removeall', GameCommands
);
415 AddCommand('chat', GameCommands
);
416 AddCommand('teamchat', GameCommands
);
417 AddCommand('game', GameCommands
);
418 AddCommand('host', GameCommands
);
419 AddCommand('map', GameCommands
);
420 AddCommand('nextmap', GameCommands
);
421 AddCommand('endmap', GameCommands
);
422 AddCommand('goodbye', GameCommands
);
423 AddCommand('suicide', GameCommands
);
424 AddCommand('spectate', GameCommands
);
425 AddCommand('ready', GameCommands
);
426 AddCommand('kick', GameCommands
);
427 AddCommand('kick_id', GameCommands
);
428 AddCommand('ban', GameCommands
);
429 AddCommand('permban', GameCommands
);
430 AddCommand('ban_id', GameCommands
);
431 AddCommand('permban_id', GameCommands
);
432 AddCommand('unban', GameCommands
);
433 AddCommand('connect', GameCommands
);
434 AddCommand('disconnect', GameCommands
);
435 AddCommand('reconnect', GameCommands
);
436 AddCommand('say', GameCommands
);
437 AddCommand('tell', GameCommands
);
438 AddCommand('overtime', GameCommands
);
439 AddCommand('rcon_password', GameCommands
);
440 AddCommand('rcon', GameCommands
);
441 AddCommand('callvote', GameCommands
);
442 AddCommand('vote', GameCommands
);
443 AddCommand('clientlist', GameCommands
);
444 AddCommand('event', GameCommands
);
446 AddCommand('god', GameCheats
);
447 AddCommand('notarget', GameCheats
);
448 AddCommand('give', GameCheats
); // "exit" too ;-)
449 AddCommand('open', GameCheats
);
450 AddCommand('fly', GameCheats
);
451 AddCommand('noclip', GameCheats
);
452 AddCommand('speedy', GameCheats
);
453 AddCommand('jumpy', GameCheats
);
454 AddCommand('noreload', GameCheats
);
455 AddCommand('aimline', GameCheats
);
456 AddCommand('automap', GameCheats
);
458 WhitelistCommand('say');
459 WhitelistCommand('tell');
460 WhitelistCommand('overtime');
461 WhitelistCommand('ready');
462 WhitelistCommand('map');
463 WhitelistCommand('nextmap');
464 WhitelistCommand('endmap');
465 WhitelistCommand('restart');
466 WhitelistCommand('kick');
467 WhitelistCommand('ban');
469 WhitelistCommand('addbot');
470 WhitelistCommand('bot_add');
471 WhitelistCommand('bot_addred');
472 WhitelistCommand('bot_addblue');
473 WhitelistCommand('bot_removeall');
475 WhitelistCommand('g_gamemode');
476 WhitelistCommand('g_friendlyfire');
477 WhitelistCommand('g_weaponstay');
478 WhitelistCommand('g_allow_exit');
479 WhitelistCommand('g_allow_monsters');
480 WhitelistCommand('g_scorelimit');
481 WhitelistCommand('g_timelimit');
483 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
487 procedure g_Console_Update();
493 // Â ïðîöåññå îòêðûòèÿ:
494 if gConsoleShow
and (Cons_Y
< 0) then
496 Cons_Y
:= Cons_Y
+Step
;
499 // Â ïðîöåññå çàêðûòèÿ:
500 if (not gConsoleShow
) and
501 (Cons_Y
> -(gScreenHeight
div 2)) then
502 Cons_Y
:= Cons_Y
-Step
;
504 // Îêîí÷àòåëüíî îòêðûëàñü:
508 // Îêîí÷àòåëüíî çàêðûëàñü:
509 if Cons_Y
<= (-(gScreenHeight
div 2)) then
511 Cons_Y
:= -(gScreenHeight
div 2);
517 while a
<= High(MsgArray
) do
519 if MsgArray
[a
].Time
> 0 then
521 if MsgArray
[a
].Time
= 1 then
523 if a
< High(MsgArray
) then
525 for b
:= a
to High(MsgArray
)-1 do
526 MsgArray
[b
] := MsgArray
[b
+1];
528 MsgArray
[High(MsgArray
)].Time
:= 0;
534 Dec(MsgArray
[a
].Time
);
541 procedure g_Console_Draw();
543 CWidth
, CHeight
: Byte;
547 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
549 for a
:= 0 to High(MsgArray
) do
550 if MsgArray
[a
].Time
> 0 then
551 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
554 if not Cons_Shown
then
560 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
561 gStdFont
, 255, 255, 255, 1, True);
562 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
563 gStdFont
, 255, 255, 255, 1, True);
567 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
568 gStdFont
, 255, 255, 255, 1, True);
569 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
570 gStdFont
, 255, 255, 255, 1, True);
578 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
579 a
:= (gScreenWidth
- 2*mfW
) div 2;
580 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
581 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
582 _RGB(128, 0, 0), 2.0);
585 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
586 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
588 if ConsoleHistory
<> nil then
592 if Length(ConsoleHistory
) > ((gScreenHeight
div 2) div CHeight
)-1 then
593 b
:= Length(ConsoleHistory
)-((gScreenHeight
div 2) div CHeight
)+1;
595 b
:= Max(b
-Offset
, 0);
596 d
:= Max(High(ConsoleHistory
)-Offset
, 0);
599 for a
:= d
downto b
do
601 e_TextureFontPrintFmt(0, (gScreenHeight
div 2)-4-c
*CHeight
-Abs(Cons_Y
), ConsoleHistory
[a
],
607 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
610 procedure g_Console_Switch();
612 if gChatShow
then Exit
;
613 gConsoleShow
:= not gConsoleShow
;
617 procedure g_Console_Chat_Switch(Team
: Boolean = False);
619 if gConsoleShow
then Exit
;
620 if not g_Game_IsNet
then Exit
;
621 gChatShow
:= not gChatShow
;
629 procedure g_Console_Char(C
: Char);
631 if gChatShow
and (not gChatEnter
) then
633 Insert(C
, Line
, CPos
);
637 procedure Complete();
647 for i
:= 0 to High(Commands
) do
648 if LowerCase(Line
) = LowerCase(Copy(Commands
[i
].Cmd
, 0, Length(Line
))) then
650 SetLength(t
, Length(t
) + 1);
651 t
[Length(t
)-1] := Commands
[i
].Cmd
;
657 if Length(t
) = 1 then
660 CPos
:= Length(Line
)+1;
665 for i
:= 0 to High(t
) do
666 g_Console_Add(' '+t
[i
]);
670 procedure g_Console_Control(K
: Word);
674 if (Length(Line
) > 0) and (CPos
> 1) then
676 Delete(Line
, CPos
-1, 1);
680 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
681 Delete(Line
, CPos
, 1);
685 IK_RIGHT
, IK_KPRIGHT
:
686 if CPos
<= Length(Line
) then
688 IK_RETURN
, IK_KPRETURN
:
691 g_Console_Process(Line
)
695 if (Length(Line
) > 0) and g_Game_IsNet
then
699 if g_Game_IsClient
then
700 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
702 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
703 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
707 if g_Game_IsClient
then
708 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
710 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
718 gJustChatted
:= True;
722 if not gChatShow
then
725 if not gChatShow
then
726 if (CommandHistory
<> nil) and
727 (CmdIndex
< Length(CommandHistory
)) then
729 if CmdIndex
< Length(CommandHistory
)-1 then
730 CmdIndex
:= CmdIndex
+ 1;
731 Line
:= CommandHistory
[CmdIndex
];
732 CPos
:= Length(Line
) + 1;
735 if not gChatShow
then
736 if (CommandHistory
<> nil) and
737 (CmdIndex
<= Length(CommandHistory
)) then
740 CmdIndex
:= CmdIndex
- 1;
741 Line
:= CommandHistory
[CmdIndex
];
742 Cpos
:= Length(Line
) + 1;
744 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
745 if not gChatShow
then
746 IncMax(OffSet
, Length(ConsoleHistory
)-1);
747 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
748 if not gChatShow
then
753 CPos
:= Length(Line
) + 1;
757 function GetStr(var Str
: String): String;
764 for b
:= 1 to Length(Str
) do
765 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
767 Result
:= Copy(Str
, 2, b
-1);
774 for a
:= 1 to Length(Str
) do
775 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
777 Result
:= Copy(Str
, 1, a
);
784 function ParseString(Str
: String): SArray
;
795 SetLength(Result
, Length(Result
)+1);
796 Result
[High(Result
)] := GetStr(Str
);
800 procedure g_Console_Add(L
: String; Show
: Boolean = False);
804 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
805 while Pos(#10, L
) > 0 do
807 g_Console_Add(Copy(L
, 1, Pos(#10, L
) - 1), Show
);
808 Delete(L
, 1, Pos(#10, L
));
811 SetLength(ConsoleHistory
, Length(ConsoleHistory
)+1);
812 ConsoleHistory
[High(ConsoleHistory
)] := L
;
814 Show
:= Show
and gAllowConsoleMessages
;
816 if Show
and gShowMessages
then
818 for a
:= 0 to High(MsgArray
) do
827 for a
:= 0 to High(MsgArray
)-1 do
828 MsgArray
[a
] := MsgArray
[a
+1];
830 with MsgArray
[High(MsgArray
)] do
838 e_WriteLog('CON: ' + L
, MSG_NOTIFY
);
842 procedure g_Console_Clear();
844 ConsoleHistory
:= nil;
848 procedure AddToHistory(L
: String);
852 len
:= Length(CommandHistory
);
855 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
857 SetLength(CommandHistory
, len
+1);
858 CommandHistory
[len
] := L
;
861 CmdIndex
:= Length(CommandHistory
);
864 function g_Console_CommandBlacklisted(C
: String): Boolean;
876 Arr
:= ParseString(C
);
880 for i
:= 0 to High(Whitelist
) do
881 if Whitelist
[i
] = LowerCase(Arr
[0]) then
885 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
897 g_Console_Add('> '+L
);
902 Arr
:= ParseString(L
);
906 if Commands
= nil then
912 for i
:= 0 to High(Commands
) do
913 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
914 if @Commands
[i
].Proc
<> nil then
916 Commands
[i
].Proc(Arr
);
920 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));