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
, conbuf
;
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
;
69 conSkipLines
: Integer = 0;
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;
121 for a
:= 0 to High(MsgArray
) do
129 if Cmd
= 'clearhistory' then
130 CommandHistory
:= nil;
132 if Cmd
= 'showhistory' then
133 if CommandHistory
<> nil then
136 for a
:= 0 to High(CommandHistory
) do
137 g_Console_Add(' '+CommandHistory
[a
]);
140 if Cmd
= 'commands' then
143 g_Console_Add('Commands list:');
144 for a
:= High(Commands
) downto 0 do
145 g_Console_Add(' '+Commands
[a
].Cmd
);
149 g_Console_Add(TimeToStr(Now
), True);
152 g_Console_Add(DateToStr(Now
), True);
155 if Length(P
) > 1 then
157 if P
[1] = 'ololo' then
162 for a
:= 1 to High(P
) do
164 g_Console_Add(b_Text_Format(s
), True);
173 if ConsoleHistory <> nil then
175 if Length(P) > 1 then
178 s := GameDir+'/console.txt';
183 if IOResult <> 0 then
185 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [s]));
190 for a := 0 to High(ConsoleHistory) do
191 WriteLn(F, ConsoleHistory[a]);
194 g_Console_Add(Format(_lc[I_CONSOLE_DUMPED], [s]));
203 if Length(P
) > 1 then
205 s
:= GameDir
+'/'+P
[1];
210 if IOResult
<> 0 then
212 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
216 g_Console_Add(Format(_lc
[I_CONSOLE_EXEC
], [s
]));
221 if IOResult
<> 0 then
223 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_READ
], [s
]));
227 if Pos('#', s
) <> 1 then // script comment
229 // prevents endless loops
231 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
232 if not RecursionLimitHit
then
233 g_Console_Process(s
, True);
237 if (RecursionDepth
= 0) and RecursionLimitHit
then
239 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
240 RecursionLimitHit
:= False;
247 g_Console_Add('exec <script file>');
250 if Cmd
= 'alias' then
252 // alias [alias_name] [commands]
253 if Length(P
) > 1 then
255 for a
:= 0 to High(Aliases
) do
256 if Aliases
[a
].Name
= P
[1] then
258 if Length(P
) > 2 then
259 Aliases
[a
].Commands
:= ParseAlias(P
[2])
261 for b
:= 0 to High(Aliases
[a
].Commands
) do
262 g_Console_Add(Aliases
[a
].Commands
[b
]);
265 SetLength(Aliases
, Length(Aliases
)+1);
267 Aliases
[a
].Name
:= P
[1];
268 if Length(P
) > 2 then
269 Aliases
[a
].Commands
:= ParseAlias(P
[2])
271 for b
:= 0 to High(Aliases
[a
].Commands
) do
272 g_Console_Add(Aliases
[a
].Commands
[b
]);
274 for a
:= 0 to High(Aliases
) do
275 if Aliases
[a
].Commands
<> nil then
276 g_Console_Add(Aliases
[a
].Name
);
282 if Length(P
) > 1 then
284 if Aliases
= nil then
286 for a
:= 0 to High(Aliases
) do
287 if Aliases
[a
].Name
= P
[1] then
289 if Aliases
[a
].Commands
<> nil then
291 // with this system proper endless loop detection seems either impossible
292 // or very dirty to implement, so let's have this instead
293 // prevents endless loops
294 for b
:= 0 to High(Aliases
[a
].Commands
) do
297 RecursionLimitHit
:= (RecursionDepth
> MaxScriptRecursion
) or RecursionLimitHit
;
298 if not RecursionLimitHit
then
299 g_Console_Process(Aliases
[a
].Commands
[b
], True);
302 if (RecursionDepth
= 0) and RecursionLimitHit
then
304 g_Console_Add(Format(_lc
[I_CONSOLE_ERROR_CALL
], [s
]));
305 RecursionLimitHit
:= False;
312 g_Console_Add('call <alias name>');
316 procedure WhitelistCommand(Cmd
: string);
320 SetLength(Whitelist
, Length(Whitelist
)+1);
321 a
:= High(Whitelist
);
325 procedure AddCommand(Cmd
: String; Proc
: TCmdProc
);
329 SetLength(Commands
, Length(Commands
)+1);
331 Commands
[a
].Cmd
:= Cmd
;
332 Commands
[a
].Proc
:= Proc
;
335 procedure g_Console_Init();
339 g_Texture_CreateWAD(ID
, GameWAD
+':TEXTURES\CONSOLE');
340 Cons_Y
:= -(gScreenHeight
div 2);
341 gConsoleShow
:= False;
346 for a
:= 0 to High(MsgArray
) do
353 AddCommand('clear', ConsoleCommands
);
354 AddCommand('clearhistory', ConsoleCommands
);
355 AddCommand('showhistory', ConsoleCommands
);
356 AddCommand('commands', ConsoleCommands
);
357 AddCommand('time', ConsoleCommands
);
358 AddCommand('date', ConsoleCommands
);
359 AddCommand('echo', ConsoleCommands
);
360 AddCommand('dump', ConsoleCommands
);
361 AddCommand('exec', ConsoleCommands
);
362 AddCommand('alias', ConsoleCommands
);
363 AddCommand('call', ConsoleCommands
);
365 AddCommand('d_window', DebugCommands
);
366 AddCommand('d_sounds', DebugCommands
);
367 AddCommand('d_frames', DebugCommands
);
368 AddCommand('d_winmsg', DebugCommands
);
369 AddCommand('d_monoff', DebugCommands
);
370 AddCommand('d_botoff', DebugCommands
);
371 AddCommand('d_monster', DebugCommands
);
372 AddCommand('d_health', DebugCommands
);
373 AddCommand('d_player', DebugCommands
);
374 AddCommand('d_joy', DebugCommands
);
376 AddCommand('p1_name', GameCVars
);
377 AddCommand('p2_name', GameCVars
);
378 AddCommand('p1_color', GameCVars
);
379 AddCommand('p2_color', GameCVars
);
380 AddCommand('r_showfps', GameCVars
);
381 AddCommand('r_showtime', GameCVars
);
382 AddCommand('r_showscore', GameCVars
);
383 AddCommand('r_showlives', GameCVars
);
384 AddCommand('r_showstat', GameCVars
);
385 AddCommand('r_showkillmsg', GameCVars
);
386 AddCommand('r_showspect', GameCVars
);
387 AddCommand('r_showping', GameCVars
);
388 AddCommand('g_gamemode', GameCVars
);
389 AddCommand('g_friendlyfire', GameCVars
);
390 AddCommand('g_weaponstay', GameCVars
);
391 AddCommand('g_allow_exit', GameCVars
);
392 AddCommand('g_allow_monsters', GameCVars
);
393 AddCommand('g_bot_vsmonsters', GameCVars
);
394 AddCommand('g_bot_vsplayers', GameCVars
);
395 AddCommand('g_scorelimit', GameCVars
);
396 AddCommand('g_timelimit', GameCVars
);
397 AddCommand('g_maxlives', GameCVars
);
398 AddCommand('g_warmuptime', GameCVars
);
399 AddCommand('net_interp', GameCVars
);
400 AddCommand('net_forceplayerupdate', GameCVars
);
401 AddCommand('net_predictself', GameCVars
);
402 AddCommand('sv_name', GameCVars
);
403 AddCommand('sv_passwd', GameCVars
);
404 AddCommand('sv_maxplrs', GameCVars
);
405 AddCommand('sv_public', GameCVars
);
406 AddCommand('sv_intertime', GameCVars
);
408 AddCommand('quit', GameCommands
);
409 AddCommand('exit', GameCommands
);
410 AddCommand('pause', GameCommands
);
411 AddCommand('endgame', GameCommands
);
412 AddCommand('restart', GameCommands
);
413 AddCommand('addbot', GameCommands
);
414 AddCommand('bot_add', GameCommands
);
415 AddCommand('bot_addlist', GameCommands
);
416 AddCommand('bot_addred', GameCommands
);
417 AddCommand('bot_addblue', GameCommands
);
418 AddCommand('bot_removeall', GameCommands
);
419 AddCommand('chat', GameCommands
);
420 AddCommand('teamchat', GameCommands
);
421 AddCommand('game', GameCommands
);
422 AddCommand('host', GameCommands
);
423 AddCommand('map', GameCommands
);
424 AddCommand('nextmap', GameCommands
);
425 AddCommand('endmap', GameCommands
);
426 AddCommand('goodbye', GameCommands
);
427 AddCommand('suicide', GameCommands
);
428 AddCommand('spectate', GameCommands
);
429 AddCommand('ready', GameCommands
);
430 AddCommand('kick', GameCommands
);
431 AddCommand('kick_id', GameCommands
);
432 AddCommand('ban', GameCommands
);
433 AddCommand('permban', GameCommands
);
434 AddCommand('ban_id', GameCommands
);
435 AddCommand('permban_id', GameCommands
);
436 AddCommand('unban', GameCommands
);
437 AddCommand('connect', GameCommands
);
438 AddCommand('disconnect', GameCommands
);
439 AddCommand('reconnect', GameCommands
);
440 AddCommand('say', GameCommands
);
441 AddCommand('tell', GameCommands
);
442 AddCommand('overtime', GameCommands
);
443 AddCommand('rcon_password', GameCommands
);
444 AddCommand('rcon', GameCommands
);
445 AddCommand('callvote', GameCommands
);
446 AddCommand('vote', GameCommands
);
447 AddCommand('clientlist', GameCommands
);
448 AddCommand('event', GameCommands
);
450 AddCommand('god', GameCheats
);
451 AddCommand('notarget', GameCheats
);
452 AddCommand('give', GameCheats
); // "exit" too ;-)
453 AddCommand('open', GameCheats
);
454 AddCommand('fly', GameCheats
);
455 AddCommand('noclip', GameCheats
);
456 AddCommand('speedy', GameCheats
);
457 AddCommand('jumpy', GameCheats
);
458 AddCommand('noreload', GameCheats
);
459 AddCommand('aimline', GameCheats
);
460 AddCommand('automap', GameCheats
);
462 WhitelistCommand('say');
463 WhitelistCommand('tell');
464 WhitelistCommand('overtime');
465 WhitelistCommand('ready');
466 WhitelistCommand('map');
467 WhitelistCommand('nextmap');
468 WhitelistCommand('endmap');
469 WhitelistCommand('restart');
470 WhitelistCommand('kick');
471 WhitelistCommand('ban');
473 WhitelistCommand('addbot');
474 WhitelistCommand('bot_add');
475 WhitelistCommand('bot_addred');
476 WhitelistCommand('bot_addblue');
477 WhitelistCommand('bot_removeall');
479 WhitelistCommand('g_gamemode');
480 WhitelistCommand('g_friendlyfire');
481 WhitelistCommand('g_weaponstay');
482 WhitelistCommand('g_allow_exit');
483 WhitelistCommand('g_allow_monsters');
484 WhitelistCommand('g_scorelimit');
485 WhitelistCommand('g_timelimit');
487 g_Console_Add(Format(_lc
[I_CONSOLE_WELCOME
], [GAME_VERSION
]));
491 procedure g_Console_Update();
497 // Â ïðîöåññå îòêðûòèÿ:
498 if gConsoleShow
and (Cons_Y
< 0) then
500 Cons_Y
:= Cons_Y
+Step
;
503 // Â ïðîöåññå çàêðûòèÿ:
504 if (not gConsoleShow
) and
505 (Cons_Y
> -(gScreenHeight
div 2)) then
506 Cons_Y
:= Cons_Y
-Step
;
508 // Îêîí÷àòåëüíî îòêðûëàñü:
512 // Îêîí÷àòåëüíî çàêðûëàñü:
513 if Cons_Y
<= (-(gScreenHeight
div 2)) then
515 Cons_Y
:= -(gScreenHeight
div 2);
521 while a
<= High(MsgArray
) do
523 if MsgArray
[a
].Time
> 0 then
525 if MsgArray
[a
].Time
= 1 then
527 if a
< High(MsgArray
) then
529 for b
:= a
to High(MsgArray
)-1 do
530 MsgArray
[b
] := MsgArray
[b
+1];
532 MsgArray
[High(MsgArray
)].Time
:= 0;
538 Dec(MsgArray
[a
].Time
);
546 procedure drawConsoleText ();
548 CWidth
, CHeight
: Byte;
553 procedure putLine (sp
, ep
: LongWord);
562 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
563 if wdt
+cw
> gScreenWidth
-8 then break
;
564 //e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False);
568 if p
<> ep
then putLine(p
, ep
); // do rest of the line first
569 // now print our part
577 cw
:= e_TextureFontCharWidth(cbufAt(p
), gStdFont
);
578 e_TextureFontPrintCharEx(wdt
, ty
, cbufAt(p
), gStdFont
);
591 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
592 ty
:= (gScreenHeight
div 2)-4-2*CHeight
-Abs(Cons_Y
);
593 skip
:= conSkipLines
;
594 cbufLastLine(sp
, ep
);
597 if ty
+CHeight
<= 0 then break
;
598 until not cbufLineUp(sp
, ep
);
601 procedure g_Console_Draw();
603 CWidth
, CHeight
: Byte;
607 e_TextureFontGetSize(gStdFont
, CWidth
, CHeight
);
609 for a
:= 0 to High(MsgArray
) do
610 if MsgArray
[a
].Time
> 0 then
611 e_TextureFontPrintFmt(0, CHeight
*a
, MsgArray
[a
].Msg
,
614 if not Cons_Shown
then
620 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say team> ' + Line
,
621 gStdFont
, 255, 255, 255, 1, True);
622 e_TextureFontPrintEx((CPos
+ 9)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
623 gStdFont
, 255, 255, 255, 1, True);
627 e_TextureFontPrintEx(0, gScreenHeight
- CHeight
- 1, 'say> ' + Line
,
628 gStdFont
, 255, 255, 255, 1, True);
629 e_TextureFontPrintEx((CPos
+ 4)*CWidth
, gScreenHeight
- CHeight
- 1, '_',
630 gStdFont
, 255, 255, 255, 1, True);
638 e_CharFont_GetSize(gMenuFont
, DEBUG_STRING
, mfW
, mfH
);
639 a
:= (gScreenWidth
- 2*mfW
) div 2;
640 b
:= Cons_Y
+ ((gScreenHeight
div 2) - 2*mfH
) div 2;
641 e_CharFont_PrintEx(gMenuFont
, a
div 2, b
div 2, DEBUG_STRING
,
642 _RGB(128, 0, 0), 2.0);
645 e_DrawSize(ID
, 0, Cons_Y
, Alpha
, False, False, gScreenWidth
, gScreenHeight
div 2);
646 e_TextureFontPrint(0, Cons_Y
+(gScreenHeight
div 2)-CHeight
-4, '> '+Line
, gStdFont
);
650 if ConsoleHistory <> nil then
654 if Length(ConsoleHistory) > ((gScreenHeight div 2) div CHeight)-1 then
655 b := Length(ConsoleHistory)-((gScreenHeight div 2) div CHeight)+1;
657 b := Max(b-Offset, 0);
658 d := Max(High(ConsoleHistory)-Offset, 0);
661 for a := d downto b do
663 e_TextureFontPrintFmt(0, (gScreenHeight div 2)-4-c*CHeight-Abs(Cons_Y), ConsoleHistory[a],
670 e_TextureFontPrint((CPos
+1)*CWidth
, Cons_Y
+(gScreenHeight
div 2)-21, '_', gStdFont
);
673 procedure g_Console_Switch();
675 if gChatShow
then Exit
;
676 gConsoleShow
:= not gConsoleShow
;
680 procedure g_Console_Chat_Switch(Team
: Boolean = False);
682 if gConsoleShow
then Exit
;
683 if not g_Game_IsNet
then Exit
;
684 gChatShow
:= not gChatShow
;
692 procedure g_Console_Char(C
: Char);
694 if gChatShow
and (not gChatEnter
) then
696 Insert(C
, Line
, CPos
);
700 procedure Complete();
710 for i
:= 0 to High(Commands
) do
711 if LowerCase(Line
) = LowerCase(Copy(Commands
[i
].Cmd
, 0, Length(Line
))) then
713 SetLength(t
, Length(t
) + 1);
714 t
[Length(t
)-1] := Commands
[i
].Cmd
;
720 if Length(t
) = 1 then
723 CPos
:= Length(Line
)+1;
728 for i
:= 0 to High(t
) do
729 g_Console_Add(' '+t
[i
]);
733 procedure g_Console_Control(K
: Word);
737 if (Length(Line
) > 0) and (CPos
> 1) then
739 Delete(Line
, CPos
-1, 1);
743 if (Length(Line
) > 0) and (CPos
<= Length(Line
)) then
744 Delete(Line
, CPos
, 1);
748 IK_RIGHT
, IK_KPRIGHT
:
749 if CPos
<= Length(Line
) then
751 IK_RETURN
, IK_KPRETURN
:
754 g_Console_Process(Line
)
758 if (Length(Line
) > 0) and g_Game_IsNet
then
762 if g_Game_IsClient
then
763 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_TEAM
)
765 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
766 NET_CHAT_TEAM
, gPlayer1Settings
.Team
);
770 if g_Game_IsClient
then
771 MC_SEND_Chat(b_Text_Format(Line
), NET_CHAT_PLAYER
)
773 MH_SEND_Chat('[' + gPlayer1Settings
.Name
+ ']: ' + b_Text_Format(Line
),
781 gJustChatted
:= True;
785 if not gChatShow
then
788 if not gChatShow
then
789 if (CommandHistory
<> nil) and
790 (CmdIndex
< Length(CommandHistory
)) then
792 if CmdIndex
< Length(CommandHistory
)-1 then
793 CmdIndex
:= CmdIndex
+ 1;
794 Line
:= CommandHistory
[CmdIndex
];
795 CPos
:= Length(Line
) + 1;
798 if not gChatShow
then
799 if (CommandHistory
<> nil) and
800 (CmdIndex
<= Length(CommandHistory
)) then
803 CmdIndex
:= CmdIndex
- 1;
804 Line
:= CommandHistory
[CmdIndex
];
805 Cpos
:= Length(Line
) + 1;
807 IK_PAGEUP
, IK_KPPAGEUP
: // PgUp
808 if not gChatShow
then Inc(conSkipLines
);
809 IK_PAGEDN
, IK_KPPAGEDN
: // PgDown
810 if not gChatShow
and (conSkipLines
> 0) then Dec(conSkipLines
);
814 CPos
:= Length(Line
) + 1;
818 function GetStr(var Str
: String): String;
825 for b
:= 1 to Length(Str
) do
826 if (b
= Length(Str
)) or (Str
[b
+1] = '"') then
828 Result
:= Copy(Str
, 2, b
-1);
835 for a
:= 1 to Length(Str
) do
836 if (a
= Length(Str
)) or (Str
[a
+1] = ' ') then
838 Result
:= Copy(Str
, 1, a
);
845 function ParseString(Str
: String): SArray
;
856 SetLength(Result
, Length(Result
)+1);
857 Result
[High(Result
)] := GetStr(Str
);
861 procedure g_Console_Add(L
: String; Show
: Boolean = False);
865 // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
867 while Pos(#10, L) > 0 do
869 g_Console_Add(Copy(L, 1, Pos(#10, L) - 1), Show);
870 Delete(L, 1, Pos(#10, L));
874 //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
875 //ConsoleHistory[High(ConsoleHistory)] := L;
878 if (length(L
) = 0) or ((L
[length(L
)] <> #10) and (L
[length(L
)] <> #13)) then cbufPut(#10);
881 Show := Show and gAllowConsoleMessages;
883 if Show and gShowMessages then
885 for a := 0 to High(MsgArray) do
894 for a := 0 to High(MsgArray)-1 do
895 MsgArray[a] := MsgArray[a+1];
897 with MsgArray[High(MsgArray)] do
905 e_WriteLog('CON: ' + L, MSG_NOTIFY);
910 procedure g_Console_Clear();
912 //ConsoleHistory := nil;
917 procedure AddToHistory(L
: String);
921 len
:= Length(CommandHistory
);
924 (LowerCase(CommandHistory
[len
-1]) <> LowerCase(L
)) then
926 SetLength(CommandHistory
, len
+1);
927 CommandHistory
[len
] := L
;
930 CmdIndex
:= Length(CommandHistory
);
933 function g_Console_CommandBlacklisted(C
: String): Boolean;
945 Arr
:= ParseString(C
);
949 for i
:= 0 to High(Whitelist
) do
950 if Whitelist
[i
] = LowerCase(Arr
[0]) then
954 procedure g_Console_Process(L
: String; Quiet
: Boolean = False);
964 if L
= 'goobers' then
969 g_Console_Add('Your memory serves you well.');
975 g_Console_Add('> '+L
);
980 Arr
:= ParseString(L
);
984 if Commands
= nil then
990 for i
:= 0 to High(Commands
) do
991 if Commands
[i
].Cmd
= LowerCase(Arr
[0]) then
992 if @Commands
[i
].Proc
<> nil then
994 Commands
[i
].Proc(Arr
);
998 g_Console_Add(Format(_lc
[I_CONSOLE_UNKNOWN
], [Arr
[0]]));