]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/sandbox.qc
Rename more functions, and add server notification messages for database loading
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / sandbox.qc
1 float object_count;
2 .string object_clipboard;
3 .entity object_attach;
4 .string material;
5
6 .float touch_timer;
7 void sandbox_ObjectFunction_Touch()
8 {
9         // apply material impact effects
10
11         if(!self.material)
12                 return;
13         if(self.touch_timer > time)
14                 return; // don't execute each frame
15         self.touch_timer = time + 0.1;
16
17         // make particle count and sound volume depend on impact speed
18         float intensity;
19         intensity = vlen(self.velocity) + vlen(other.velocity);
20         if(intensity) // avoid divisions by 0
21                 intensity /= 2; // average the two velocities
22         if not(intensity >= autocvar_g_sandbox_object_material_velocity_min)
23                 return; // impact not strong enough to do anything
24         // now offset intensity and apply it to the effects
25         intensity -= autocvar_g_sandbox_object_material_velocity_min; // start from minimum velocity, not actual velocity
26         intensity = bound(0, intensity * autocvar_g_sandbox_object_material_velocity_factor, 1);
27
28         sound(self, CH_TRIGGER, strcat("object/impact_", self.material, "_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE * intensity, ATTN_NORM);
29         pointparticles(particleeffectnum(strcat("impact_", self.material)), self.origin, '0 0 0', ceil(intensity * 10)); // allow a count from 1 to 10
30 }
31
32 entity sandbox_ObjectEdit_Get()
33 {
34         // returns the traced entity if the player can edit it, and world if not
35         // attached objects are SOLID_NOT and don't risk getting traced
36
37         makevectors(self.v_angle);
38         WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self);
39
40         if(trace_ent.classname != "object")
41                 return world; // entity is not an object
42         if(!trace_ent.crypto_idfp)
43                 return trace_ent; // the player who spawned this object did not have an UID, so anyone can edit it
44         else if not(trace_ent.crypto_idfp != self.crypto_idfp && !autocvar_g_sandbox_editor_free)
45                 return trace_ent; // object does not belong to the player, and players can only edit their own objects on this server
46         return world;
47 }
48
49 void sandbox_ObjectEdit_Scale(entity e, float f)
50 {
51         e.scale = f;
52         if(e.scale)
53         {
54                 e.scale = bound(autocvar_g_sandbox_object_scale_min, e.scale, autocvar_g_sandbox_object_scale_max);
55                 setsize(e, e.mins * e.scale, e.maxs * e.scale); // adapt bounding box size to model size
56         }
57 }
58
59 .float old_movetype;
60 void sandbox_ObjectAttach_Set(entity e, entity parent, string s)
61 {
62         // attaches e to parent on string s
63
64         e.old_movetype = e.movetype; // persist this
65
66         e.movetype = MOVETYPE_FOLLOW;
67         e.solid = SOLID_NOT;
68         e.takedamage = DAMAGE_NO;
69
70         setattachment(e, parent, s);
71         e.owner = parent;
72 }
73
74 void sandbox_ObjectAttach_Remove(entity e)
75 {
76         // detaches any object attached to e
77
78         entity head;
79         for(head = world; (head = find(head, classname, "object")); )
80         {
81                 if(head.owner == e)
82                 {
83                         head.movetype = head.old_movetype; // revert to previous physics
84                         head.solid = SOLID_BBOX;
85                         head.takedamage = DAMAGE_AIM;
86
87                         setattachment(head, world, "");
88                         head.owner = world;
89
90                         // objects reset origin and angles when detached, so apply the parent's to prevent teleporting
91                         setorigin(head, e.origin);
92                         head.angles = e.angles;
93                 }
94         }
95 }
96
97 entity sandbox_ObjectSpawn(float database)
98 {
99         // spawn a new object with default properties
100
101         entity e;
102         e = spawn();
103         e.classname = "object";
104         e.takedamage = DAMAGE_AIM;
105         e.damageforcescale = 1;
106         e.solid = SOLID_BBOX; // SOLID_BSP would be best, but can lag the server badly
107         e.movetype = MOVETYPE_TOSS;
108         e.frame = 0;
109         e.skin = 0;
110         e.material = string_null;
111         e.touch = sandbox_ObjectFunction_Touch;
112
113         if(!database)
114         {
115                 // set the object's owner via player UID
116                 // if the player does not have an UID, the owner cannot be stored and his objects may be edited by anyone
117                 if(self.crypto_idfp != "")
118                         e.crypto_idfp = strzone(self.crypto_idfp);
119                 else
120                         print_to(self, "^1SANDBOX - WARNING: ^7You spawned an object, but lack a player UID. ^1Your objects are not secured and can be edited by any player!");
121
122                 // set origin and direction based on player position and view angle
123                 makevectors(self.v_angle);
124                 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
125                 setorigin(e, trace_endpos);
126                 e.angles_y = self.v_angle_y;
127         }
128
129         object_count += 1;
130         return e;
131 }
132
133 void sandbox_ObjectRemove(entity e)
134 {
135         sandbox_ObjectAttach_Remove(e); // detach child objects
136         if(e.material)
137         {
138                 strunzone(e.material);
139                 e.material = string_null;
140         }
141         if(e.crypto_idfp)
142         {
143                 strunzone(e.crypto_idfp);
144                 e.crypto_idfp = string_null;
145         }
146         remove(e);
147         e = world;
148
149         object_count -= 1;
150 }
151
152 string sandbox_ObjectPort_Save(entity e, float database)
153 {
154         // save object properties
155         string s;
156
157         s = strcat(e.model, " ");
158         s = strcat(s, ftos(e.skin), " ");
159         s = strcat(s, ftos(e.alpha), " ");
160         s = strcat(s, sprintf("\"%.9v\"", e.colormod), " ");
161         s = strcat(s, sprintf("\"%.9v\"", e.glowmod), " ");
162         s = strcat(s, ftos(e.frame), " ");
163         s = strcat(s, ftos(e.scale), " ");
164         s = strcat(s, ftos(e.movetype), " ");
165         s = strcat(s, ftos(e.damageforcescale), " ");
166         if(e.material)  s = strcat(s, e.material, " "); else    s = strcat(s, "- "); // none
167         if(database)
168         {
169                 if(e.crypto_idfp)       s = strcat(s, e.crypto_idfp, " ");      else    s = strcat(s, "- "); // none
170                 s = strcat(s, sprintf("\"%.9v\"", e.origin), " ");
171                 s = strcat(s, sprintf("\"%.9v\"", e.angles), " ");
172         }
173
174         return s;
175 }
176
177 void sandbox_ObjectPort_Load(entity e, string s, float database)
178 {
179         // load object properties
180         tokenize_console(s);
181
182         setmodel(e, argv(0));
183         e.skin = stof(argv(1));
184         e.alpha = stof(argv(2));
185         e.colormod = stov(argv(3));
186         e.glowmod = stov(argv(4));
187         e.frame = stof(argv(5));
188         sandbox_ObjectEdit_Scale(e, stof(argv(6)));
189         e.movetype = stof(argv(7));
190         e.damageforcescale = stof(argv(8));
191         if(e.material)  strunzone(e.material);  if(argv(9) != "-")      e.material = strzone(argv(9));  else    e.material = string_null;
192         if(database)
193         {
194                 if(e.crypto_idfp)       strunzone(e.crypto_idfp);       if(argv(10) != "-")     e.crypto_idfp = strzone(argv(10));      else    e.crypto_idfp = string_null;
195                 setorigin(e, stov(argv(11)));
196                 e.angles = stov(argv(12));
197         }
198 }
199
200 void sandbox_Database_Save()
201 {
202         // saves all objects to the database file
203         entity head;
204         string file_name;
205         float file_get;
206
207         file_name = strcat("sandbox/storage_", GetMapname(), ".txt");
208         file_get = fopen(file_name, FILE_WRITE);
209         fputs(file_get, strcat("// sandbox storage for map ", GetMapname(), ", containing a total of ", ftos(object_count), " objects\n"));
210         for(head = world; (head = find(head, classname, "object")); )
211         {
212                 // Unfortunately, attached objects cannot be persisted yet. That's because the parent is specified as an entity,
213                 // but only properties can be saved to this file, leaving no way to identify the owner once all objects are spawned
214                 // TODO: Find some way to fix this!
215                 if(head.owner != world)
216                         continue;
217
218                 // use a line for each object, listing all properties
219                 fputs(file_get, strcat(sandbox_ObjectPort_Save(head, TRUE), "\n"));
220         }
221         fclose(file_get);
222 }
223
224 void sandbox_Database_Load()
225 {
226         // loads all objects from the database file
227         string file_read, file_name;
228         float file_get;
229
230         file_name = strcat("sandbox/storage_", GetMapname(), ".txt");
231         file_get = fopen(file_name, FILE_READ);
232         if(file_get < 0)
233         {
234                 if(autocvar_g_sandbox_info > 0)
235                         print(strcat("^3SANDBOX - SERVER: ^7could not find storage file ^3", file_name, "^7, no objects were loaded\n"));
236         }
237         else
238         {
239                 for(;;)
240                 {
241                         file_read = fgets(file_get);
242                         if(!file_read)
243                                 break;
244                         if(substring(file_read, 0, 2) == "//")
245                                 continue;
246                         if(substring(file_read, 0, 1) == "#")
247                                 continue;
248
249                         entity e;
250                         e = sandbox_ObjectSpawn(TRUE);
251                         sandbox_ObjectPort_Load(e, file_read, TRUE);
252                 }
253                 if(autocvar_g_sandbox_info > 0)
254                         print(strcat("^3SANDBOX - SERVER: ^7successfully loaded storage file ^3", file_name, "\n"));
255         }
256 }
257
258 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
259 {
260         if(MUTATOR_RETURNVALUE) // command was already handled?
261                 return FALSE;
262         if(cmd_name == "g_sandbox")
263         {
264                 if(cmd_argc < 2)
265                 {
266                         print_to(self, "Sandbox mode is active. For usage information, type 'sandbox help'");
267                         return TRUE;
268                 }
269
270                 switch(argv(1))
271                 {
272                         entity e;
273                         float i;
274
275                         // ---------------- COMMAND: HELP ----------------
276                         case "help":
277                                 print_to(self, "You can use the following sandbox commands:");
278                                 print_to(self, "^7\"^2object_spawn ^3models/foo/bar.md3^7\" spawns a new object in front of the player, and gives it the specified model");
279                                 print_to(self, "^7\"^2object_remove^7\" removes the object the player is looking at. Players can only remove their own objects");
280                                 print_to(self, "^7\"^2object_duplicate ^3value^7\" duplicates the object. 'copy' copies the object, 'paste' puts it in front of the player");
281                                 print_to(self, "^7\"^2object_claim^7\" sets the player as the owner of the object, if he has the right to edit it");
282                                 print_to(self, "^7\"^2object_attach ^3property value^7\" attaches one object to another. Players can only attach their own objects");
283                                 print_to(self, "^7Attachment properties for ^2object_attach^7:");
284                                 print_to(self, "^3get ^7- selects the object you are facing as the object to be attached");
285                                 print_to(self, "^3set value ^7- attaches the previously selected object to the object you are facing, on the specified bone");
286                                 print_to(self, "^3remove ^7- detaches all objects from the object you are facing");
287                                 print_to(self, "^7\"^2object_edit ^3property value^7\" edits the given property of the object. Players can only edit their own objects");
288                                 print_to(self, "^7Object properties for ^2object_edit^7:");
289                                 print_to(self, "^3skin value ^7- changes the skin of the object");
290                                 print_to(self, "^3alpha value ^7- sets object transparency");
291                                 print_to(self, "^3colormod \"value_x value_y value_z\" ^7- main object color");
292                                 print_to(self, "^3glowmod \"value_x value_y value_z\" ^7- glow object color");
293                                 print_to(self, "^3frame value ^7- object animation frame, for self-animated models");
294                                 print_to(self, "^3scale value ^7- changes object scale. 0.5 is half size and 2 is double size");
295                                 print_to(self, "^3physics value ^7- object physics, 0 = static, 1 = movable, 2 = physical");
296                                 print_to(self, "^3force value ^7- amount of force applied to objects that are shot");
297                                 print_to(self, "^3material value ^7- sets the material of the object. Default materials are: metal, stone, wood, flesh");
298                                 print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
299                                 return TRUE;
300
301                         // ---------------- COMMAND: SPAWN OBJECT ----------------
302                         case "object_spawn":
303                                 if(object_count >= autocvar_g_sandbox_editor_maxobjects)
304                                 {
305                                         print_to(self, strcat("^1SANDBOX - WARNING: ^7Cannot spawn any more objects. Up to ^3", ftos(autocvar_g_sandbox_editor_maxobjects), " ^7objects may exist at a time"));
306                                         return TRUE;
307                                 }
308                                 if(cmd_argc < 3)
309                                 {
310                                         print_to(self, "^1SANDBOX - WARNING: ^7Attempted to spawn an object without specifying a model. Please specify the path to your model file after the 'object_spawn' command");
311                                         return TRUE;
312                                 }
313                                 else if not(fexists(argv(2)))
314                                 {
315                                         print_to(self, "^1SANDBOX - WARNING: ^7Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
316                                         return TRUE;
317                                 }
318
319                                 e = sandbox_ObjectSpawn(FALSE);
320                                 setmodel(e, argv(2));
321
322                                 if(autocvar_g_sandbox_info > 0)
323                                         print(strcat("^3SANDBOX - SERVER: ^7", self.netname, " spawned an object at origin ^3", vtos(e.origin), "\n"));
324                                 return TRUE;
325
326                         // ---------------- COMMAND: REMOVE OBJECT ----------------
327                         case "object_remove":
328                                 e = sandbox_ObjectEdit_Get();
329                                 if(e != world)
330                                 {
331                                         if(autocvar_g_sandbox_info > 0)
332                                                 print(strcat("^3SANDBOX - SERVER: ^7", self.netname, " removed an object at origin ^3", vtos(e.origin), "\n"));
333                                         sandbox_ObjectRemove(e);
334                                         return TRUE;
335                                 }
336
337                                 print_to(self, "^1SANDBOX - WARNING: ^7Object could not be removed. Make sure you are facing an object that you have edit rights over");
338                                 return TRUE;
339
340                         // ---------------- COMMAND: DUPLICATE OBJECT ----------------
341                         case "object_duplicate":
342                                 switch(argv(2))
343                                 {
344                                         case "copy":
345                                                 // copies customizable properties of the selected object to the clipboard
346                                                 e = sandbox_ObjectEdit_Get(); // you can only copy objects you can edit, so this works
347                                                 if(e != world)
348                                                 {
349                                                         if(self.object_clipboard)
350                                                                 strunzone(self.object_clipboard);
351                                                         self.object_clipboard = strzone(sandbox_ObjectPort_Save(e, FALSE));
352
353                                                         print_to(self, "^2SANDBOX - INFO: ^7Object copied to clipboard");
354                                                         return TRUE;
355                                                 }
356                                                 print_to(self, "^1SANDBOX - WARNING: ^7Object could not be copied. Make sure you are facing an object that you have edit rights over");
357                                                 return TRUE;
358
359                                         case "paste":
360                                                 // spawns a new object using the properties in the player's clipboard
361                                                 if(!self.object_clipboard) // no object in clipboard
362                                                 {
363                                                         print_to(self, "^1SANDBOX - WARNING: ^7No object in clipboard. You must copy an object before you can paste it");
364                                                         return TRUE;
365                                                 }
366                                                 if(object_count >= autocvar_g_sandbox_editor_maxobjects)
367                                                 {
368                                                         print_to(self, strcat("^1SANDBOX - WARNING: ^7Cannot spawn any more objects. Up to ^3", ftos(autocvar_g_sandbox_editor_maxobjects), " ^7objects may exist at a time"));
369                                                         return TRUE;
370                                                 }
371
372                                                 e = sandbox_ObjectSpawn(FALSE);
373                                                 sandbox_ObjectPort_Load(e, self.object_clipboard, FALSE);
374
375                                                 print_to(self, "^2SANDBOX - INFO: ^7Object pasted successfully");
376                                                 if(autocvar_g_sandbox_info > 0)
377                                                         print(strcat("^3SANDBOX - SERVER: ^7", self.netname, " pasted an object at origin ^3", vtos(e.origin), "\n"));
378                                                 return TRUE;
379                                 }
380                                 return TRUE;
381
382                         // ---------------- COMMAND: CLAIM OBJECT ----------------
383                         case "object_claim":
384                                 // if the player can edit an object but is not its owner, this can be used to claim that object
385                                 if(self.crypto_idfp == "")
386                                 {
387                                         print_to(self, "^1SANDBOX - WARNING: ^7You do not have a player UID, and cannot claim objects");
388                                         return TRUE;
389                                 }
390                                 e = sandbox_ObjectEdit_Get();
391                                 if(e != world)
392                                 {
393                                         if(e.crypto_idfp == self.crypto_idfp)
394                                         {
395                                                 print_to(self, "^2SANDBOX - INFO: ^7Object is already yours, nothing to claim");
396                                                 return TRUE;
397                                         }
398
399                                         if(e.crypto_idfp)
400                                                 strunzone(e.crypto_idfp);
401                                         e.crypto_idfp = self.crypto_idfp;
402                                         print_to(self, "^2SANDBOX - INFO: ^7Object claimed successfully");
403                                 }
404                                 print_to(self, "^1SANDBOX - WARNING: ^7Object could not be claimed. Make sure you are facing an object that you have edit rights over");
405                                 return TRUE;
406
407                         // ---------------- COMMAND: ATTACH OBJECT ----------------
408                         case "object_attach":
409                                 switch(argv(2))
410                                 {
411                                         case "get":
412                                                 // select e as the object as meant to be attached
413                                                 e = sandbox_ObjectEdit_Get();
414                                                 if(e != world)
415                                                 {
416                                                         self.object_attach = e;
417                                                         print_to(self, "^2SANDBOX - INFO: ^7Object selected for attachment");
418                                                         return TRUE;
419                                                 }
420                                                 print_to(self, "^1SANDBOX - WARNING: ^7Object could not be selected for attachment. Make sure you are facing an object that you have edit rights over");
421                                                 return TRUE;
422                                         case "set":
423                                                 if(self.object_attach == world)
424                                                 {
425                                                         print_to(self, "^1SANDBOX - WARNING: ^7No object selected for attachment. Please select an object to be attached first.");
426                                                         return TRUE;
427                                                 }
428
429                                                 // attaches the previously selected object to e
430                                                 e = sandbox_ObjectEdit_Get();
431                                                 if(e != world)
432                                                 {
433                                                         sandbox_ObjectAttach_Set(self.object_attach, e, argv(3));
434                                                         self.object_attach = world; // object was attached, no longer keep it scheduled for attachment
435                                                         print_to(self, "^2SANDBOX - INFO: ^7Object attached successfully");
436                                                         if(autocvar_g_sandbox_info > 1)
437                                                                 print(strcat("^3SANDBOX - SERVER: ^7", self.netname, " attached objects at origin ^3", vtos(e.origin), "\n"));
438                                                         return TRUE;
439                                                 }
440                                                 print_to(self, "^1SANDBOX - WARNING: ^7Object could not be attached to the parent. Make sure you are facing an object that you have edit rights over");
441                                                 return TRUE;
442                                         case "remove":
443                                                 // removes e if it was attached
444                                                 e = sandbox_ObjectEdit_Get();
445                                                 if(e != world)
446                                                 {
447                                                         sandbox_ObjectAttach_Remove(e);
448                                                         print_to(self, "^2SANDBOX - INFO: ^7Child objects detached successfully");
449                                                         if(autocvar_g_sandbox_info > 1)
450                                                                 print(strcat("^3SANDBOX - SERVER: ^7", self.netname, " detached objects at origin ^3", vtos(e.origin), "\n"));
451                                                         return TRUE;
452                                                 }
453                                                 print_to(self, "^1SANDBOX - WARNING: ^7Child objects could not be detached. Make sure you are facing an object that you have edit rights over");
454                                                 return TRUE;
455                                 }
456                                 return TRUE;
457
458                         // ---------------- COMMAND: EDIT OBJECT ----------------
459                         case "object_edit":
460                                 if(!argv(2))
461                                 {
462                                         print_to(self, "^1SANDBOX - WARNING: ^7Too few parameters. You must specify a property to edit");
463                                         return TRUE;
464                                 }
465
466                                 e = sandbox_ObjectEdit_Get();
467                                 if(e != world)
468                                 {
469                                         switch(argv(2))
470                                         {
471                                                 case "skin":
472                                                         e.skin = stof(argv(3));
473                                                         break;
474                                                 case "alpha":
475                                                         e.alpha = stof(argv(3));
476                                                         break;
477                                                 case "color_main":
478                                                         e.colormod = stov(argv(3));
479                                                         break;
480                                                 case "color_glow":
481                                                         e.glowmod = stov(argv(3));
482                                                         break;
483                                                 case "frame":
484                                                         e.frame = stof(argv(3));
485                                                         break;
486                                                 case "scale":
487                                                         sandbox_ObjectEdit_Scale(e, stof(argv(3)));
488                                                         break;
489                                                 case "physics":
490                                                         switch(argv(3))
491                                                         {
492                                                                 case "0": // static
493                                                                         e.movetype = MOVETYPE_NONE;
494                                                                         break;
495                                                                 case "1": // movable
496                                                                         e.movetype = MOVETYPE_TOSS;
497                                                                         break;
498                                                                 case "2": // physical
499                                                                         e.movetype = MOVETYPE_PHYSICS;
500                                                                         break;
501                                                                 default:
502                                                                         break;
503                                                         }
504                                                         break;
505                                                 case "force":
506                                                         e.damageforcescale = stof(argv(3));
507                                                         break;
508                                                 case "material":
509                                                         if(e.material)
510                                                                 strunzone(e.material);
511                                                         if(argv(3))
512                                                         {
513                                                                 for (i = 1; i <= 5; i++) // precache material sounds, 5 in total
514                                                                         precache_sound(strcat("object/impact_", argv(3), "_", ftos(i), ".ogg"));
515                                                                 e.material = strzone(argv(3));
516                                                         }
517                                                         else
518                                                                 e.material = string_null; // no material
519                                                         break;
520                                                 default:
521                                                         print_to(self, "^1SANDBOX - WARNING: ^7Invalid object property. For usage information, type 'sandbox help'");
522                                                         break;
523                                         }
524                                         if(autocvar_g_sandbox_info > 1)
525                                                 print(strcat("^3SANDBOX - SERVER: ^7", self.netname, " edited property ^3", argv(2), " ^7of an object at origin ^3", vtos(e.origin), "\n"));
526                                         return TRUE;
527                                 }
528
529                                 print_to(self, "^1SANDBOX - WARNING: ^7Object could not be edited. Make sure you are facing an object that you have edit rights over");
530                                 return TRUE;
531
532                         // ---------------- COMMAND: DEFAULT ----------------
533                         default:
534                                 print_to(self, "Invalid command. For usage information, type 'sandbox help'");
535                                 return TRUE;
536                 }
537         }
538         return FALSE;
539 }
540
541 MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
542 {
543         // if the player is close enough to their object, they can drag it
544
545         if(autocvar_sv_cheats)
546                 return FALSE; // cheat dragging is used instead
547
548         // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
549         // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
550         // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
551         // it goes out of range while slinging it around.
552
553         entity e;
554         float grab;
555
556         e = sandbox_ObjectEdit_Get();
557         if(e != world && vlen(e.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
558                 grab = TRUE;
559
560         if(Drag(e, grab)) // execute dragging
561                 return TRUE;
562
563         return FALSE;
564 }
565
566 MUTATOR_HOOKFUNCTION(sandbox_ClientDisconnect)
567 {
568         // unzone the player's clipboard if it's not empty
569         if(self.object_clipboard)
570         {
571                 strunzone(self.object_clipboard);
572                 self.object_clipboard = string_null;
573         }
574
575         return FALSE;
576 }
577
578 float autosave_time;
579 MUTATOR_HOOKFUNCTION(sandbox_StartFrame)
580 {
581         if(!autocvar_g_sandbox_storage_autosave)
582                 return FALSE;
583         if(time < autocvar_g_sandbox_storage_autosave)
584                 return FALSE;
585         autosave_time = time + autocvar_g_sandbox_storage_autosave;
586
587         sandbox_Database_Save();
588
589         return TRUE;
590 }
591
592 MUTATOR_DEFINITION(sandbox)
593 {
594         MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
595         MUTATOR_HOOK(SV_StartFrame, sandbox_StartFrame, CBC_ORDER_ANY);
596         MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);
597         MUTATOR_HOOK(ClientDisconnect, sandbox_ClientDisconnect, CBC_ORDER_ANY);
598
599         MUTATOR_ONADD
600         {
601                 autosave_time = time + autocvar_g_sandbox_storage_autosave; // don't save the first server frame
602                 if(autocvar_g_sandbox_storage_autoload)
603                         sandbox_Database_Load();
604         }
605
606         return FALSE;
607 }
608