author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 06 Aug 2019 23:33:08 +0200 | |
changeset 15324 | b761efebe3c4 |
parent 11046 | 47a8c19ecb60 |
child 15929 | 128ace913837 |
permissions | -rw-r--r-- |
4976 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10017
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
4976 | 17 |
*) |
18 |
||
4373 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
21 |
unit uCommands; |
|
22 |
||
23 |
interface |
|
24 |
||
25 |
var isDeveloperMode: boolean; |
|
7805 | 26 |
var isExternalSource: boolean; |
6898 | 27 |
type TCommandHandler = procedure (var params: shortstring); |
4373 | 28 |
|
29 |
procedure initModule; |
|
30 |
procedure freeModule; |
|
7409 | 31 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Rand: boolean); |
6898 | 32 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean); |
7805 | 33 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); inline; |
34 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource, ExternalSource: boolean); |
|
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
35 |
procedure ParseTeamCommand(s: shortstring); |
4373 | 36 |
procedure StopMessages(Message: Longword); |
37 |
||
38 |
implementation |
|
9301
c5d1c8259ef4
break uDebug and uCommand depedency loop by putting stuff in uIO
koda
parents:
9080
diff
changeset
|
39 |
uses uConsts, uVariables, uConsole, uUtils, SDLh; |
4373 | 40 |
|
41 |
type PVariable = ^TVariable; |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
42 |
TVariable = record |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
43 |
Next: PVariable; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
44 |
Name: string[15]; |
6898 | 45 |
Handler: TCommandHandler; |
7409 | 46 |
Trusted, Rand: boolean; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
47 |
end; |
4373 | 48 |
|
7850 | 49 |
var Variables: PVariable; |
4373 | 50 |
|
6898 | 51 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean); |
7407 | 52 |
begin |
53 |
RegisterVariable(Name, p, Trusted, false); |
|
54 |
end; |
|
9301
c5d1c8259ef4
break uDebug and uCommand depedency loop by putting stuff in uIO
koda
parents:
9080
diff
changeset
|
55 |
|
7409 | 56 |
procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Rand: boolean); |
9301
c5d1c8259ef4
break uDebug and uCommand depedency loop by putting stuff in uIO
koda
parents:
9080
diff
changeset
|
57 |
var value: PVariable; |
4373 | 58 |
begin |
59 |
New(value); |
|
9301
c5d1c8259ef4
break uDebug and uCommand depedency loop by putting stuff in uIO
koda
parents:
9080
diff
changeset
|
60 |
if value = nil then |
c5d1c8259ef4
break uDebug and uCommand depedency loop by putting stuff in uIO
koda
parents:
9080
diff
changeset
|
61 |
ParseCommand('fatal RegisterVariable: value = nil', true); |
c5d1c8259ef4
break uDebug and uCommand depedency loop by putting stuff in uIO
koda
parents:
9080
diff
changeset
|
62 |
|
4373 | 63 |
FillChar(value^, sizeof(TVariable), 0); |
64 |
value^.Name:= Name; |
|
65 |
value^.Handler:= p; |
|
66 |
value^.Trusted:= Trusted; |
|
7409 | 67 |
value^.Rand:= Rand; |
4373 | 68 |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
69 |
if Variables = nil then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
70 |
Variables:= value |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
71 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
72 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
73 |
value^.Next:= Variables; |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
74 |
Variables:= value |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
75 |
end; |
4373 | 76 |
end; |
77 |
||
78 |
||
7805 | 79 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); inline; |
80 |
begin |
|
81 |
ParseCommand(CmdStr, TrustedSource, false) |
|
82 |
end; |
|
83 |
||
84 |
procedure ParseCommand(CmdStr: shortstring; TrustedSource, ExternalSource: boolean); |
|
6992 | 85 |
var s: shortstring; |
4373 | 86 |
t: PVariable; |
87 |
c: char; |
|
88 |
begin |
|
7806 | 89 |
isExternalSource:= ExternalSource or ((CurrentTeam <> nil) and CurrentTeam^.ExtDriven); |
4373 | 90 |
//WriteLnToConsole(CmdStr); |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
91 |
if CmdStr[0]=#0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
92 |
exit; |
8498
eecadca7db50
Bring back full log strings for commands, just a bit sanitized
unc0rr
parents:
7850
diff
changeset
|
93 |
|
eecadca7db50
Bring back full log strings for commands, just a bit sanitized
unc0rr
parents:
7850
diff
changeset
|
94 |
AddFileLog('[Cmd] ' + sanitizeForLog(CmdStr)); |
eecadca7db50
Bring back full log strings for commands, just a bit sanitized
unc0rr
parents:
7850
diff
changeset
|
95 |
|
4373 | 96 |
c:= CmdStr[1]; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
97 |
if (c = '/') or (c = '$') then |
6898 | 98 |
Delete(CmdStr, 1, 1); |
4373 | 99 |
s:= ''; |
100 |
SplitBySpace(CmdStr, s); |
|
7407 | 101 |
|
4373 | 102 |
t:= Variables; |
103 |
while t <> nil do |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
104 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
105 |
if t^.Name = CmdStr then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
106 |
begin |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
107 |
if TrustedSource or t^.Trusted then |
7412
9e5aa3c8dc62
Ok. *these* should be safe with just this one extra check...
nemo
parents:
7409
diff
changeset
|
108 |
begin |
10017 | 109 |
if t^.Rand and (not CheckNoTeamOrHH) then |
7412
9e5aa3c8dc62
Ok. *these* should be safe with just this one extra check...
nemo
parents:
7409
diff
changeset
|
110 |
CheckSum:= CheckSum xor LongWord(SDLNet_Read32(@CmdStr)) xor LongWord(s[0]) xor GameTicks; |
6898 | 111 |
t^.Handler(s); |
7412
9e5aa3c8dc62
Ok. *these* should be safe with just this one extra check...
nemo
parents:
7409
diff
changeset
|
112 |
end; |
6898 | 113 |
exit |
114 |
end |
|
115 |
else |
|
116 |
t:= t^.Next |
|
117 |
end; |
|
4373 | 118 |
case c of |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
119 |
'$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"') |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
120 |
else |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
121 |
WriteLnToConsole(errmsgUnknownCommand + ': "/' + CmdStr + '"') end |
4373 | 122 |
end; |
123 |
||
6919
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
124 |
procedure ParseTeamCommand(s: shortstring); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
125 |
var Trusted: boolean; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
126 |
begin |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
127 |
Trusted:= (CurrentTeam <> nil) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
128 |
and (not CurrentTeam^.ExtDriven) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
129 |
and (CurrentHedgehog^.BotLevel = 0); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
130 |
ParseCommand(s, Trusted); |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
131 |
if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
132 |
ParseCommand('gencmd R', true) |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
133 |
end; |
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
134 |
|
bf7433e62b9c
in uTouch dont use bools to represent keystrokes, but issue ParseCommands
Xeli
parents:
6898
diff
changeset
|
135 |
|
4373 | 136 |
|
137 |
procedure StopMessages(Message: Longword); |
|
138 |
begin |
|
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
139 |
if (Message and gmLeft) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
140 |
ParseCommand('/-left', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
141 |
else if (Message and gmRight) <> 0 then |
10017 | 142 |
ParseCommand('/-right', true) |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
143 |
else if (Message and gmUp) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
144 |
ParseCommand('/-up', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
145 |
else if (Message and gmDown) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
146 |
ParseCommand('/-down', true) |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
147 |
else if (Message and gmAttack) <> 0 then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6450
diff
changeset
|
148 |
ParseCommand('/-attack', true) |
4373 | 149 |
end; |
150 |
||
151 |
procedure initModule; |
|
152 |
begin |
|
153 |
Variables:= nil; |
|
154 |
isDeveloperMode:= true; |
|
155 |
end; |
|
156 |
||
157 |
procedure freeModule; |
|
158 |
var t, tt: PVariable; |
|
159 |
begin |
|
160 |
tt:= Variables; |
|
161 |
Variables:= nil; |
|
162 |
while tt <> nil do |
|
163 |
begin |
|
164 |
t:= tt; |
|
165 |
tt:= tt^.Next; |
|
166 |
Dispose(t) |
|
167 |
end; |
|
168 |
end; |
|
169 |
||
4406
beb4de0af990
Increase teams to 8 to match the 8 colours, fix issue #108, reenable rope length modifier
nemo
parents:
4403
diff
changeset
|
170 |
end. |