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;
78 for a
:= 1 to Length(Str
) do
79 if (a
= Length(Str
)) or (Str
[a
+1] = ';') then
81 Result
:= Copy(Str
, 1, a
);
88 function ParseAlias(Str
: String): SArray
;
99 SetLength(Result
, Length(Result
)+1);
100 Result
[High(Result
)] := GetStrACmd(Str
);
104 procedure ConsoleCommands(P
: SArray
);
110 Cmd
:= LowerCase(P
[0]);
112 if Cmd
= 'clear' then
114 ConsoleHistory
:= nil;
116 for a
:= 0 to High(MsgArray
) do
124 if Cmd
= 'clearhistory' then
125 CommandHistory
:= nil;
127 if Cmd
= 'showhistory' then
128 if CommandHistory
<> nil then
131 for a
:= 0 to High(CommandHistory
) do
132 g_Console_Add(' '+CommandHistory
[a
]);
135 if Cmd
= 'commands' then
138 g_Console_Add('Commands list:');
139 for a
:= High(Commands
) downto 0 do
140 g_Console_Add(' '+Commands
[a
].Cmd
);
144 g_Console_Add(TimeToStr(Now
), True);
147 g_Console_Add(DateToStr(Now
), True);
150 if Length(P
) > 1 then
152 if P
[1] = 'ololo' then
157 for a
:= 1 to High(P
) do
159 g_Console_Add(b_Text_Format(s
), True);
167 if ConsoleHistory
<> nil then
169 if Length(P
) > 1 then
172 s
:= GameDir
+'/console.txt';
177 if IOResult
<> 0 then
179 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_WRITE
], [s
]));
184 for a
:= 0 to High(ConsoleHistory
) do
185 WriteLn(F
, ConsoleHistory
[a
]);
188 g_Console_Add(Format(_lc
[I_CONSOLE_DUMPED
], [s
]));
196 if Length(P
) > 1 then
198 s
:= GameDir
+'/'+P
[1];
203 if IOResult
<> 0 then
205 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
209 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
214 if IOResult
<> 0 then
216 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
220 if Pos('#', s
) <> 1 then // script comment
222 // prevents endless loops
224 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
225 if not RecursionLimitHit
then
226 g_Console_Process(s
, True);
230 if (RecursionDepth
= 0) and RecursionLimitHit
then
232 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
233 RecursionLimitHit
:= False;
240 g_Console_Add('exec <script file>');
243 if Cmd
= 'alias' then
245 // alias [alias_name] [commands]
246 if Length(P
) > 1 then
248 for a
:= 0 to High(Aliases
) do
249 if Aliases
[a
].Name
= P
[1] then
251 if Length(P
) > 2 then
252 Aliases
[a
].Commands
:= ParseAlias(P
[2])
254 for b
:= 0 to High(Aliases
[a
].Commands
) do
255 g_Console_Add(Aliases
[a
].Commands
[b
]);
258 SetLength(Aliases
, Length(Aliases
)+1);
260 Aliases
[a
].Name
:= P
[1];
261 if Length(P
) > 2 then
262 Aliases
[a
].Commands
:= ParseAlias(P
[2])
264 for b
:= 0 to High(Aliases
[a
].Commands
) do
265 g_Console_Add(Aliases
[a
].Commands
[b
]);
267 for a
:= 0 to High(Aliases
) do
268 if Aliases
[a
].Commands
<> nil then
269 g_Console_Add(Aliases
[a
].Name
);
275 if Length(P
) > 1 then
277 if Aliases
= nil then
279 for a
:= 0 to High(Aliases
) do
280 if Aliases
[a
].Name
= P
[1] then
282 if Aliases
[a
].Commands
<> nil then
284 // with this system proper endless loop detection seems either impossible
285 // or very dirty to implement, so let's have this instead
286 // prevents endless loops
287 for b
:= 0 to High(Aliases
[a
].Commands
) do
290 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
291 if not RecursionLimitHit
then
292 g_Console_Process(Aliases
[a
].Commands
[b
], True);
295 if (RecursionDepth
= 0) and RecursionLimitHit
then
297 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
298 RecursionLimitHit
:= False;
305 g_Console_Add('call <alias name>');
309 procedure WhitelistCommand(Cmd
: string);
313 SetLength(Whitelist
, Length(Whitelist
)+1);
314 a
:= High(Whitelist
);
318 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
);
322 SetLength(Commands
, Length(Commands
)+1);
324 Commands
[a
].Cmd
:= Cmd
;
325 Commands
[a
].Proc
:= Proc
;
328 procedure g_Console_Init();
332 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
333 Cons_Y
:= -(gScreenHeight
div 2);
334 gConsoleShow
:= False;
339 for a
:= 0 to High(MsgArray
) do
346 AddCommand('clear', ConsoleCommands
);
347 AddCommand('clearhistory', ConsoleCommands
);
348 AddCommand('showhistory', ConsoleCommands
);
349 AddCommand('commands', ConsoleCommands
);
350 AddCommand('time', ConsoleCommands
);
351 AddCommand('date', ConsoleCommands
);
352 AddCommand('echo', ConsoleCommands
);
353 AddCommand('dump', ConsoleCommands
);
354 AddCommand('exec', ConsoleCommands
);
355 AddCommand('alias', ConsoleCommands
);
356 AddCommand('call', ConsoleCommands
);
358 AddCommand('d_window', DebugCommands
);
359 AddCommand('d_sounds', DebugCommands
);
360 AddCommand('d_frames', DebugCommands
);
361 AddCommand('d_winmsg', DebugCommands
);
362 AddCommand('d_monoff', DebugCommands
);
363 AddCommand('d_botoff', DebugCommands
);
364 AddCommand('d_monster', DebugCommands
);
365 AddCommand('d_health', DebugCommands
);
366 AddCommand('d_player', DebugCommands
);
367 AddCommand('d_joy', DebugCommands
);
369 AddCommand('p1_name', GameCVars
);
370 AddCommand('p2_name', GameCVars
);
371 AddCommand('p1_color', GameCVars
);
372 AddCommand('p2_color', GameCVars
);
373 AddCommand('r_showfps', GameCVars
);
374 AddCommand('r_showtime', GameCVars
);
375 AddCommand('r_showscore', GameCVars
);
376 AddCommand('r_showlives', GameCVars
);
377 AddCommand('r_showstat', GameCVars
);
378 AddCommand('r_showkillmsg', GameCVars
);
379 AddCommand('r_showspect', GameCVars
);
380 AddCommand('r_showping', GameCVars
);
381 AddCommand('g_gamemode', GameCVars
);
382 AddCommand('g_friendlyfire', GameCVars
);
383 AddCommand('g_weaponstay', GameCVars
);
384 AddCommand('g_allow_exit', GameCVars
);
385 AddCommand('g_allow_monsters', GameCVars
);
386 AddCommand('g_bot_vsmonsters', GameCVars
);
387 AddCommand('g_bot_vsplayers', GameCVars
);
388 AddCommand('g_scorelimit', GameCVars
);
389 AddCommand('g_timelimit', GameCVars
);
390 AddCommand('g_maxlives', GameCVars
);
391 AddCommand('g_warmuptime', GameCVars
);
392 AddCommand('net_interp', GameCVars
);
393 AddCommand('net_forceplayerupdate', GameCVars
);
394 AddCommand('net_predictself', GameCVars
);
395 AddCommand('sv_name', GameCVars
);
396 AddCommand('sv_passwd', GameCVars
);
397 AddCommand('sv_maxplrs', GameCVars
);
398 AddCommand('sv_public', GameCVars
);
399 AddCommand('sv_intertime', GameCVars
);
401 AddCommand('quit', GameCommands
);
402 AddCommand('exit', GameCommands
);
403 AddCommand('pause', GameCommands
);
404 AddCommand('endgame', GameCommands
);
405 AddCommand('restart', GameCommands
);
406 AddCommand('addbot', GameCommands
);
407 AddCommand('bot_add', GameCommands
);
408 AddCommand('bot_addlist', GameCommands
);
409 AddCommand('bot_addred', GameCommands
);
410 AddCommand('bot_addblue', GameCommands
);
411 AddCommand('bot_removeall', GameCommands
);
412 AddCommand('chat', GameCommands
);
413 AddCommand('teamchat', GameCommands
);
414 AddCommand('game', GameCommands
);
415 AddCommand('host', GameCommands
);
416 AddCommand('map', GameCommands
);
417 AddCommand('nextmap', GameCommands
);
418 AddCommand('endmap', GameCommands
);
419 AddCommand('goodbye', GameCommands
);
420 AddCommand('suicide', GameCommands
);
421 AddCommand('spectate', GameCommands
);
422 AddCommand('ready', GameCommands
);
423 AddCommand('kick', GameCommands
);
424 AddCommand('kick_id', GameCommands
);
425 AddCommand('ban', GameCommands
);
426 AddCommand('permban', GameCommands
);
427 AddCommand('ban_id', GameCommands
);
428 AddCommand('permban_id', GameCommands
);
429 AddCommand('unban', GameCommands
);
430 AddCommand('connect', GameCommands
);
431 AddCommand('disconnect', GameCommands
);
432 AddCommand('reconnect', GameCommands
);
433 AddCommand('say', GameCommands
);
434 AddCommand('tell', GameCommands
);
435 AddCommand('overtime', GameCommands
);
436 AddCommand('rcon_password', GameCommands
);
437 AddCommand('rcon', GameCommands
);
438 AddCommand('callvote', GameCommands
);
439 AddCommand('vote', GameCommands
);
440 AddCommand('clientlist', GameCommands
);
441 AddCommand('event', GameCommands
);
443 WhitelistCommand('say');
444 WhitelistCommand('tell');
445 WhitelistCommand('overtime');
446 WhitelistCommand('ready');
447 WhitelistCommand('map');
448 WhitelistCommand('nextmap');
449 WhitelistCommand('endmap');
450 WhitelistCommand('restart');
451 WhitelistCommand('kick');
452 WhitelistCommand('ban');
454 WhitelistCommand('addbot');
455 WhitelistCommand('bot_add');
456 WhitelistCommand('bot_addred');
457 WhitelistCommand('bot_addblue');
458 WhitelistCommand('bot_removeall');
460 WhitelistCommand('g_gamemode');
461 WhitelistCommand('g_friendlyfire');
462 WhitelistCommand('g_weaponstay');
463 WhitelistCommand('g_allow_exit');
464 WhitelistCommand('g_allow_monsters');
465 WhitelistCommand('g_scorelimit');
466 WhitelistCommand('g_timelimit');
468 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
472 procedure g_Console_Update();
478 // Â ïðîöåññå îòêðûòèÿ:
479 if gConsoleShow
and (Cons_Y
< 0) then
481 Cons_Y
:= Cons_Y
+Step
;
484 // Â ïðîöåññå çàêðûòèÿ:
485 if (not gConsoleShow
) and
486 (Cons_Y
> -(gScreenHeight
div 2)) then
487 Cons_Y
:= Cons_Y
-Step
;
489 // Îêîí÷àòåëüíî îòêðûëàñü:
493 // Îêîí÷àòåëüíî çàêðûëàñü:
494 if Cons_Y
<= (-(gScreenHeight
div 2)) then
496 Cons_Y
:= -(gScreenHeight
div 2);
502 while a
<= High(MsgArray
) do
504 if MsgArray
[a
].Time
> 0 then
506 if MsgArray
[a
].Time
= 1 then
508 if a
< High(MsgArray
) then
510 for b
:= a
to High(MsgArray
)-1 do
511 MsgArray
[b
] := MsgArray
[b
+1];
513 MsgArray
[High(MsgArray
)].Time
:= 0;
519 Dec(MsgArray
[a
].Time
);
526 procedure g_Console_Draw();
528 CWidth
, CHeight
: Byte;
532 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
534 for a
:= 0 to High(MsgArray
) do
535 if MsgArray
[a
].Time
> 0 then
536 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
539 if not Cons_Shown
then
545 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
546 gStdFont
, 255, 255, 255, 1, True);
547 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
548 gStdFont
, 255, 255, 255, 1, True);
552 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
553 gStdFont
, 255, 255, 255, 1, True);
554 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
555 gStdFont
, 255, 255, 255, 1, True);
563 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
564 a
:= (gScreenWidth
- 2*mfW
) div 2;
565 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
566 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
567 _RGB(128, 0, 0), 2.0);
570 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
571 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
573 if ConsoleHistory
<> nil then
577 if Length(ConsoleHistory
) > ((gScreenHeight
div 2) div CHeight
)-1 then
578 b
:= Length(ConsoleHistory
)-((gScreenHeight
div 2) div CHeight
)+1;
580 b
:= Max(b
-Offset
, 0);
581 d
:= Max(High(ConsoleHistory
)-Offset
, 0);
584 for a
:= d
downto b
do
586 e_TextureFontPrintFmt(0, (gScreenHeight
div 2)-4-c
*CHeight
-Abs(Cons_Y
), ConsoleHistory
[a
],
592 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
595 procedure g_Console_Switch();
597 if gChatShow
then Exit
;
598 gConsoleShow
:= not gConsoleShow
;
602 procedure g_Console_Chat_Switch(Team
: Boolean = False);
604 if gConsoleShow
then Exit
;
605 if not g_Game_IsNet
then Exit
;
606 gChatShow
:= not gChatShow
;
614 procedure g_Console_Char(C
: Char);
616 if gChatShow
and (not gChatEnter
) then
618 Insert(C
, Line
, CPos
);
622 procedure Complete();
632 for i
:= 0 to High(Commands
) do
633 if LowerCase(Line
) = LowerCase(Copy(Commands
[i
].Cmd
, 0, Length(Line
))) then
635 SetLength(t
, Length(t
) + 1);
636 t
[Length(t
)-1] := Commands
[i
].Cmd
;
642 if Length(t
) = 1 then
645 CPos
:= Length(Line
)+1;
650 for i
:= 0 to High(t
) do
651 g_Console_Add(' '+t
[i
]);
655 procedure g_Console_Control(K
: Word);
659 if (Length(Line
) > 0) and (CPos
> 1) then
661 Delete(Line
, CPos
-1, 1);
665 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
666 Delete(Line
, CPos
, 1);
671 if CPos
<= Length(Line
) then
676 g_Console_Process(Line
)
680 if (Length(Line
) > 0) and g_Game_IsNet
then
684 if g_Game_IsClient
then
685 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
687 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
688 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
692 if g_Game_IsClient
then
693 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
695 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
703 gJustChatted
:= True;
707 if not gChatShow
then
710 if not gChatShow
then
711 if (CommandHistory
<> nil) and
712 (CmdIndex
< Length(CommandHistory
)) then
714 if CmdIndex
< Length(CommandHistory
)-1 then
715 CmdIndex
:= CmdIndex
+ 1;
716 Line
:= CommandHistory
[CmdIndex
];
717 CPos
:= Length(Line
) + 1;
720 if not gChatShow
then
721 if (CommandHistory
<> nil) and
722 (CmdIndex
<= Length(CommandHistory
)) then
725 CmdIndex
:= CmdIndex
- 1;
726 Line
:= CommandHistory
[CmdIndex
];
727 Cpos
:= Length(Line
) + 1;
730 if not gChatShow
then
731 IncMax(OffSet
, Length(ConsoleHistory
)-1);
733 if not gChatShow
then
738 CPos
:= Length(Line
) + 1;
742 function GetStr(var Str
: String): String;
748 for b
:= 1 to Length(Str
) do
749 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
751 Result
:= Copy(Str
, 2, b
-1);
758 for a
:= 1 to Length(Str
) do
759 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
761 Result
:= Copy(Str
, 1, a
);
768 function ParseString(Str
: String): SArray
;
779 SetLength(Result
, Length(Result
)+1);
780 Result
[High(Result
)] := GetStr(Str
);
784 procedure g_Console_Add(L
: String; Show
: Boolean = False);
788 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
789 while Pos(#10, L
) > 0 do
791 g_Console_Add(Copy(L
, 1, Pos(#10, L
) - 1), Show
);
792 Delete(L
, 1, Pos(#10, L
));
795 SetLength(ConsoleHistory
, Length(ConsoleHistory
)+1);
796 ConsoleHistory
[High(ConsoleHistory
)] := L
;
798 Show
:= Show
and gAllowConsoleMessages
;
800 if Show
and gShowMessages
then
802 for a
:= 0 to High(MsgArray
) do
811 for a
:= 0 to High(MsgArray
)-1 do
812 MsgArray
[a
] := MsgArray
[a
+1];
814 with MsgArray
[High(MsgArray
)] do
822 procedure g_Console_Clear();
824 ConsoleHistory
:= nil;
828 procedure AddToHistory(L
: String);
832 len
:= Length(CommandHistory
);
835 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
837 SetLength(CommandHistory
, len
+1);
838 CommandHistory
[len
] := L
;
841 CmdIndex
:= Length(CommandHistory
);
844 function g_Console_CommandBlacklisted(C
: String): Boolean;
856 Arr
:= ParseString(C
);
860 for i
:= 0 to High(Whitelist
) do
861 if Whitelist
[i
] = LowerCase(Arr
[0]) then
865 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
877 g_Console_Add('> '+L
);
882 Arr
:= ParseString(L
);
886 if Commands
= nil then
892 for i
:= 0 to High(Commands
) do
893 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
894 if @Commands
[i
].Proc
<> nil then
896 Commands
[i
].Proc(Arr
);
900 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));