-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser.c
344 lines (285 loc) · 7.16 KB
/
user.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/* user.c - the user body object
Copyright (C) 1994-2000 Annihilator <annihilator@muds.net>
This program is a part of ES2 mudlib. Permission is granted to use,
modify, copy or distribute this program provided this copyright notice
remains intact and subject to the restriction that this program MAY
NOT be used in any way for monetary gain.
Details of terms and conditions is available in the Copyright.ES2 file.
If you don't receive this file along with this program, write to the
primary author of ES2 mudlib: Annihilator <annihilator@muds.net>
*/
#include <ansi.h>
#include <origin.h>
#include <user.h>
#include <action.h>
inherit CHARACTER;
inherit F_AUTOLOAD;
inherit F_EDIT;
inherit F_SAVE;
inherit F_MORE;
inherit F_FLAG;
// private prototypes
private void user_dump(int type);
// variables
static object my_link;
static int last_age_set, handle;
// implementations
void
create()
{
object ob;
// Let LOGIN_D export proper uid to us.
seteuid(0);
if( clonep(this_object()) )
set_name("無名氏", "noname");
}
private int
move_or_destruct( object dest )
{
if( dest ) move(dest);
else {
message("system", "一陣時空的扭曲將你傳送到另一個地方....\n", this_object());
set_temp("last_location", base_name(environment()));
move(VOID_OB);
}
}
private void
reset()
{
// To prevent the master copy of user object error out by security
// violation.
if( !userp(this_object()) ) return;
gain_score("survive", (int)query("age") / 2 + 1 );
}
int set_link(object link)
{
if( origin()==ORIGIN_CALL_OTHER
&& (geteuid(previous_object()) != ROOT_UID)
&& (geteuid(previous_object()) != geteuid(this_object())) )
return 0;
my_link = link;
return 1;
}
object link() { return my_link; }
void terminal_type(string term_type)
{
set_temp("terminal_type", term_type);
message("system", "終端機型態設定為 " + term_type + "。\n", this_object());
}
// This is used by F_SAVE to determine the filename to save our data.
string query_save_file()
{
string id;
id = geteuid();
if( !id ) id = getuid();
return user_data(id);
}
int save()
{
int res;
if( objectp(my_link) ) my_link->save();
save_autoload();
res = ::save();
clean_up_autoload(); // To save memory
return res;
}
// This function updates player's age, called by heart_beat()
private void
heart_beat()
{
::heart_beat();
if( !this_object() ) return;
// Make us older. Note this should not rely on fixed period between
// each call to heart_beat bcz heart_beat could be stoped for various
// reason. - Annihilator
if( !last_age_set ) last_age_set = time();
add("time_aged", time() - last_age_set);
last_age_set = time();
if( (int)query("time_aged") >= 86400 ) {
add("age", 1);
delete("time_aged");
}
if( objectp(my_link) ) my_link->update_age();
// if( interactive(this_object())
// && query_idle(this_object()) >= IDLE_TIMEOUT )
// user_dump(DUMP_IDLE);
}
void
setup()
{
if( ! query("id") ) set("id", getuid());
::setup();
/* 以下是讓 F_STATISTIC 檢查這個使用者是否在上次 quit 之前已經死亡,但
* 還沒有被 heart_beat 抓到( 俗稱 quit 大法 )
*/
damage_stat("gin", 0);
damage_stat("kee", 0);
damage_stat("sen", 0);
damage_stat("HP", 0);
restore_autoload();
restore_condition();
}
private void
user_dump(int type)
{
switch(type)
{
case DUMP_NET_DEAD:
// change cmd: quit to quit ! -Dragoon
command("quit !");
break;
case DUMP_IDLE:
// wiz don't get kicked out (Elon 10-17-95)
if (wizardp(this_object())) return;
tell_object( this_object(), "對不起﹐您已經發呆超過 "
+ IDLE_TIMEOUT/60 + " 分鐘了﹐請下次再來。\n");
tell_room( environment(), "一陣風吹來﹐將發呆中的" + query("name")
+ "化為一堆飛灰﹐消失了。\n", ({this_object()}));
// change cmd: quit to quit ! -Dragoon
command("quit !");
break;
default:
return;
}
}
/* net_dead()
*
* 當使用者斷線時,driver 會呼叫這個函數。
*/
private void
net_dead()
{
set_heart_beat(0);
if( objectp(my_link) ) {
my_link->save();
destruct(my_link);
}
// Stop fighting, we'll be back soon.
remove_all_enemy();
if( environment() )
set_temp("last_location", base_name(environment()) );
if( is_busy() ) interrupt(this_object(), INTR_LINKDEAD);
if( userp(this_object()) ) {
handle = call_out((: user_dump :), NET_DEAD_TIMEOUT, DUMP_NET_DEAD);
// tell room what happen to this player -dragoon
tell_room(environment(), "時空一陣波動, " + query("name") +
"瞬間由這個世界消失...\n");
LOGIN_D->net_dead(this_object());
} else
command("quit");
}
// reconnect: called by the LOGIN_D when a netdead player reconnects.
void
reconnect()
{
string last_loc;
if( geteuid(previous_object()) != ROOT_UID )
error("Permission denied.\n");
set_heart_beat(1);
remove_call_out(handle);
tell_object(this_object(), "重新連線完畢。\n");
if( stringp(last_loc = query_temp("last_location")) )
move(last_loc);
}
static string last_cmd;
static int last_cmd_time;
static int last_cmd_count;
string
process_input(string str)
{
#ifdef MAX_COMMAND_PER_SECOND
if( last_cmd_time == time() ) {
last_cmd_count++;
if( last_cmd_count > MAX_COMMAND_PER_SECOND ) return "";
if( last_cmd_count == MAX_COMMAND_PER_SECOND ) {
write("\r你下指令的速度太快了,你所控制的人物無法執行這麼多命令。\n");
return "";
}
} else {
last_cmd_time = time();
last_cmd_count = 1;
}
#endif /* MAX_COMMAND_PER_SECOND */
if( str[0..1]=="!!" )
return last_cmd + str[2..];
if( objectp(my_link) )
return last_cmd = my_link->process_alias(str);
return 0;
}
void
lose_fight(object opponent)
{
::lose_fight(opponent);
tell_object(this_object(), "這一招你無法招架,輸掉了這場比試。\n");
}
void
win_fight(object opponent)
{
tell_object(this_object(), opponent->name() + "招架不住,你贏了這場比試。\n");
// add to test -Dragoon
remove_all_enemy();
}
/***********************************************************************
USER DATA PROTECTIONS
***********************************************************************/
nomask mixed
set(string prop, mixed data)
{
USER_PROTECT();
return ::set(prop, data);
}
nomask mixed
add(string prop, mixed data)
{
USER_PROTECT();
return ::add(prop, data);
}
nomask void
delete(string prop)
{
USER_PROTECT();
::delete(prop);
}
nomask varargs mixed
query(string prop, int raw)
{
mixed v = ::query(prop, raw);
if( mapp(v) || arrayp(v) ) USER_PROTECT();
return v;
}
nomask void
set_skill(string skill, int amount)
{
USER_PROTECT();
::set_skill(skill, amount);
}
nomask void
advance_skill(string skill, int amount)
{
USER_PROTECT();
::advance_skill(skill, amount);
}
nomask void
set_learn(string skill, int lrn)
{
USER_PROTECT();
::set_learn(skill, lrn);
}
nomask void
improve_skill(string skill, int amount)
{
USER_PROTECT();
::improve_skill(skill, amount);
}
nomask int
set_attr(string what, int value)
{
USER_PROTECT();
return ::set_attr(what, value);
}
nomask int
set_stat_maximum(string what, int val)
{
USER_PROTECT();
return ::set_stat_maximum(what, val);
}