|
@@ -38,8 +38,6 @@ func NewExecutionContext(actorID DBRef, e *EventDistributor, w *DB, outbound cha
|
38
|
38
|
if !found {
|
39
|
39
|
return nil
|
40
|
40
|
}
|
41
|
|
-
|
42
|
|
-
|
43
|
41
|
|
44
|
42
|
c.actor = actor
|
45
|
43
|
c.outbound = outbound
|
|
@@ -121,8 +119,7 @@ func (c *ExecutionContext) HandleEvent(m PlayerEvent) {
|
121
|
119
|
if found {
|
122
|
120
|
c.context, _ = c.db.Fetch(contextID)
|
123
|
121
|
}
|
124
|
|
-
|
125
|
|
-
|
|
122
|
+
|
126
|
123
|
switch m.messageType {
|
127
|
124
|
case EventTypeLogin:
|
128
|
125
|
if c.actor.Type == "player" {
|
|
@@ -250,8 +247,7 @@ func (c *ExecutionContext) evaluateCommand(m PlayerEvent) {
|
250
|
247
|
c.destroyCmd(strings.TrimPrefix(message, "@destroy "))
|
251
|
248
|
case strings.HasPrefix(message, "@force "):
|
252
|
249
|
c.forceCmd(message)
|
253
|
|
-
|
254
|
|
-
|
|
250
|
+
|
255
|
251
|
default:
|
256
|
252
|
if !c.goCmd(message) {
|
257
|
253
|
c.output("What?\n")
|
|
@@ -264,7 +260,7 @@ func (c *ExecutionContext) lookCmd(target string) {
|
264
|
260
|
|
265
|
261
|
if len(target) > 0 {
|
266
|
262
|
object, found := c.MatchFirst(c.context.ID, target, false, false)
|
267
|
|
- if (!found) {
|
|
263
|
+ if !found {
|
268
|
264
|
c.output("I don't see that here.")
|
269
|
265
|
return
|
270
|
266
|
}
|
|
@@ -273,11 +269,11 @@ func (c *ExecutionContext) lookCmd(target string) {
|
273
|
269
|
c.output("%s\n%s", c.context.DetailedName(), c.context.Description)
|
274
|
270
|
contents := c.context.GetContents(c.actor.ID)
|
275
|
271
|
if len(contents) > 0 {
|
276
|
|
- c.output("Contents:\n"+strings.Join(contents,"\n"))
|
|
272
|
+ c.output("Contents:\n" + strings.Join(contents, "\n"))
|
277
|
273
|
}
|
278
|
274
|
exits := c.context.GetExits()
|
279
|
275
|
if len(exits) > 0 {
|
280
|
|
- c.output("Obvious Exits:\n"+strings.Join(exits," "))
|
|
276
|
+ c.output("Obvious Exits:\n" + strings.Join(exits, " "))
|
281
|
277
|
}
|
282
|
278
|
}
|
283
|
279
|
|
|
@@ -295,11 +291,11 @@ func (c *ExecutionContext) objectName(id DBRef) string {
|
295
|
291
|
func (c *ExecutionContext) examineCmd(objectName string) {
|
296
|
292
|
|
297
|
293
|
object, found := c.MatchFirst(c.context.ID, objectName, true, true)
|
298
|
|
- if (!found) {
|
|
294
|
+ if !found {
|
299
|
295
|
c.output("I don't see that here.")
|
300
|
296
|
return
|
301
|
297
|
}
|
302
|
|
-
|
|
298
|
+
|
303
|
299
|
c.output("%s", object.DetailedName())
|
304
|
300
|
c.output("ID: %d", object.ID)
|
305
|
301
|
c.output("Type: %s", object.Type)
|
|
@@ -313,31 +309,27 @@ func (c *ExecutionContext) examineCmd(objectName string) {
|
313
|
309
|
if len(contents) > 0 {
|
314
|
310
|
c.output("Contents:\n %s", strings.Join(contents, "\n "))
|
315
|
311
|
}
|
316
|
|
-
|
|
312
|
+
|
317
|
313
|
exits := object.GetExits()
|
318
|
314
|
if len(exits) > 0 {
|
319
|
315
|
c.output("Exits:\n %s", strings.Join(exits, "\n "))
|
320
|
316
|
}
|
321
|
|
-
|
322
|
|
-
|
323
|
|
-
|
324
|
|
- flags := make([]string, 0, len(object.Flags))
|
325
|
|
- for k, v := range object.Flags {
|
326
|
|
- if v {
|
327
|
|
- flags = append(flags, k)
|
328
|
|
- }
|
329
|
|
- }
|
330
|
|
- c.output("Flags:\n%s", strings.Join(flags, ", "))
|
331
|
|
-
|
332
|
|
- properties := make([]string, 0, len(object.Properties))
|
333
|
|
- for k, v := range object.Properties {
|
334
|
|
- properties = append(properties, fmt.Sprintf("%s: \"%s\"", k, v))
|
335
|
|
- }
|
336
|
|
- c.output("Properties:\n%s", strings.Join(properties, ", "))
|
337
|
317
|
|
338
|
|
-}
|
|
318
|
+ flags := make([]string, 0, len(object.Flags))
|
|
319
|
+ for k, v := range object.Flags {
|
|
320
|
+ if v {
|
|
321
|
+ flags = append(flags, k)
|
|
322
|
+ }
|
|
323
|
+ }
|
|
324
|
+ c.output("Flags:\n%s", strings.Join(flags, ", "))
|
339
|
325
|
|
|
326
|
+ properties := make([]string, 0, len(object.Properties))
|
|
327
|
+ for k, v := range object.Properties {
|
|
328
|
+ properties = append(properties, fmt.Sprintf("%s: \"%s\"", k, v))
|
|
329
|
+ }
|
|
330
|
+ c.output("Properties:\n%s", strings.Join(properties, ", "))
|
340
|
331
|
|
|
332
|
+}
|
341
|
333
|
|
342
|
334
|
func (c *ExecutionContext) forceCmd(input string) {
|
343
|
335
|
|
|
@@ -352,7 +344,7 @@ func (c *ExecutionContext) forceCmd(input string) {
|
352
|
344
|
wizard := c.actor.GetFlag("wizard")
|
353
|
345
|
|
354
|
346
|
object, found := c.MatchFirst(c.context.ID, objectName, true, false)
|
355
|
|
- if (!found) {
|
|
347
|
+ if !found {
|
356
|
348
|
c.output("I don't see that here.")
|
357
|
349
|
return
|
358
|
350
|
}
|
|
@@ -363,11 +355,11 @@ func (c *ExecutionContext) forceCmd(input string) {
|
363
|
355
|
if object.Type == "player" && !wizard {
|
364
|
356
|
c.output("It's not nice to force others to do your bidding.")
|
365
|
357
|
return
|
366
|
|
- }
|
|
358
|
+ }
|
367
|
359
|
if object.Owner != c.actor.ID && !wizard {
|
368
|
360
|
c.output("It's not nice to touch other people's things.")
|
369
|
361
|
return
|
370
|
|
- }
|
|
362
|
+ }
|
371
|
363
|
c.outbound <- PlayerEvent{src: c.actor.ID, dst: object.ID, message: command, messageType: EventTypeForce}
|
372
|
364
|
|
373
|
365
|
}
|
|
@@ -398,13 +390,13 @@ func (c *ExecutionContext) inventoryCmd() {
|
398
|
390
|
}
|
399
|
391
|
|
400
|
392
|
func (c *ExecutionContext) getCmd(objectName string) {
|
401
|
|
-
|
|
393
|
+
|
402
|
394
|
object, found := c.MatchFirst(c.context.ID, objectName, false, false)
|
403
|
|
- if (!found) {
|
|
395
|
+ if !found {
|
404
|
396
|
c.output("I don't see that here.")
|
405
|
397
|
return
|
406
|
398
|
}
|
407
|
|
-
|
|
399
|
+
|
408
|
400
|
if object.ID == c.actor.ID {
|
409
|
401
|
c.output("You can't pick yourself up.")
|
410
|
402
|
return
|
|
@@ -422,7 +414,6 @@ func (c *ExecutionContext) getCmd(objectName string) {
|
422
|
414
|
c.pemit(object.ID, "%s picked you up.", c.actor.Name)
|
423
|
415
|
c.oemit(c.context.ID, "%s picks up %s.", c.actor.Name, object.Name)
|
424
|
416
|
|
425
|
|
-
|
426
|
417
|
}
|
427
|
418
|
|
428
|
419
|
func (c *ExecutionContext) putCmd(input string) {
|
|
@@ -433,10 +424,9 @@ func (c *ExecutionContext) giveCmd(input string) {
|
433
|
424
|
c.xferCmd(input, "give", "to")
|
434
|
425
|
}
|
435
|
426
|
|
436
|
|
-
|
437
|
427
|
func (c *ExecutionContext) xferCmd(input string, verb string, preposition string) {
|
438
|
428
|
|
439
|
|
- r, _ := regexp.Compile(`^`+verb+`\pZ+([^=]*[^=\pZ]{1})\pZ*`+preposition+`\pZ*(.*)\pZ*$`)
|
|
429
|
+ r, _ := regexp.Compile(`^` + verb + `\pZ+([^=]*[^=\pZ]{1})\pZ*` + preposition + `\pZ*(.*)\pZ*$`)
|
440
|
430
|
|
441
|
431
|
params := r.FindStringSubmatch(input)
|
442
|
432
|
if params == nil {
|
|
@@ -446,13 +436,13 @@ func (c *ExecutionContext) xferCmd(input string, verb string, preposition string
|
446
|
436
|
objectName, receiverName := params[1], params[2]
|
447
|
437
|
|
448
|
438
|
object, found := c.MatchFirst(c.actor.ID, objectName, false, false)
|
449
|
|
- if (!found) {
|
450
|
|
- c.output("You can't "+verb+" what you don't have.")
|
|
439
|
+ if !found {
|
|
440
|
+ c.output("You can't " + verb + " what you don't have.")
|
451
|
441
|
return
|
452
|
442
|
}
|
453
|
443
|
receiver, found := c.MatchFirst(c.context.ID, receiverName, false, false)
|
454
|
|
- if (!found) {
|
455
|
|
- c.output("I cant find who or what you want to "+verb+" this "+preposition+".")
|
|
444
|
+ if !found {
|
|
445
|
+ c.output("I cant find who or what you want to " + verb + " this " + preposition + ".")
|
456
|
446
|
return
|
457
|
447
|
}
|
458
|
448
|
|
|
@@ -460,16 +450,16 @@ func (c *ExecutionContext) xferCmd(input string, verb string, preposition string
|
460
|
450
|
if err != nil {
|
461
|
451
|
return
|
462
|
452
|
}
|
463
|
|
-
|
|
453
|
+
|
464
|
454
|
c.output("You "+verb+" %s "+preposition+" %s.", object.Name, receiver.Name)
|
465
|
455
|
c.pemit(object.ID, "%s "+verb+"s you "+preposition+" %s.", c.actor.Name, receiver.Name)
|
466
|
|
-
|
467
|
|
- if (verb == "give") {
|
|
456
|
+
|
|
457
|
+ if verb == "give" {
|
468
|
458
|
c.pemit(receiver.ID, "%s gives you %s.", c.actor.Name, object.Name)
|
469
|
459
|
} else {
|
470
|
460
|
c.pemit(receiver.ID, "%s puts %s into you.", c.actor.Name, object.Name)
|
471
|
461
|
}
|
472
|
|
-
|
|
462
|
+
|
473
|
463
|
}
|
474
|
464
|
|
475
|
465
|
func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, globalDBRefMatch bool, playerNameMatch bool) (Object, bool) {
|
|
@@ -479,8 +469,8 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, globalDBR
|
479
|
469
|
}
|
480
|
470
|
if matchName == "me" {
|
481
|
471
|
return c.actor, true
|
482
|
|
- }
|
483
|
|
-
|
|
472
|
+ }
|
|
473
|
+
|
484
|
474
|
if globalDBRefMatch {
|
485
|
475
|
ref, valid := NewDBRefFromHashRef(matchName)
|
486
|
476
|
if valid {
|
|
@@ -490,7 +480,7 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, globalDBR
|
490
|
480
|
}
|
491
|
481
|
}
|
492
|
482
|
}
|
493
|
|
-
|
|
483
|
+
|
494
|
484
|
if playerNameMatch {
|
495
|
485
|
playerMeta, foundMeta := c.db.GetPlayer(matchName)
|
496
|
486
|
if foundMeta {
|
|
@@ -513,17 +503,17 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, globalDBR
|
513
|
503
|
}
|
514
|
504
|
}
|
515
|
505
|
return Object{}, false
|
516
|
|
-
|
|
506
|
+
|
517
|
507
|
}
|
518
|
508
|
|
519
|
509
|
func (c *ExecutionContext) dropCmd(objectName string) {
|
520
|
510
|
|
521
|
511
|
object, found := c.MatchFirst(c.actor.ID, objectName, false, false)
|
522
|
|
- if (!found) {
|
|
512
|
+ if !found {
|
523
|
513
|
c.output("You're not carrying that.")
|
524
|
514
|
return
|
525
|
515
|
}
|
526
|
|
-
|
|
516
|
+
|
527
|
517
|
err := c.context.Contains(&object)
|
528
|
518
|
if err != nil {
|
529
|
519
|
return
|
|
@@ -538,11 +528,11 @@ func (c *ExecutionContext) dropCmd(objectName string) {
|
538
|
528
|
func (c *ExecutionContext) enterCmd(objectName string) {
|
539
|
529
|
|
540
|
530
|
object, found := c.MatchFirst(c.context.ID, objectName, false, false)
|
541
|
|
- if (!found) {
|
|
531
|
+ if !found {
|
542
|
532
|
c.output("I don't see that here.")
|
543
|
533
|
return
|
544
|
534
|
}
|
545
|
|
-
|
|
535
|
+
|
546
|
536
|
if object.Type == "player" {
|
547
|
537
|
c.output("Maybe you should seek consent prior to entering another player.")
|
548
|
538
|
return
|
|
@@ -555,7 +545,7 @@ func (c *ExecutionContext) enterCmd(objectName string) {
|
555
|
545
|
c.output("Entering yourself would be a bad idea.")
|
556
|
546
|
return
|
557
|
547
|
}
|
558
|
|
-
|
|
548
|
+
|
559
|
549
|
err := object.Contains(&c.actor)
|
560
|
550
|
if err != nil {
|
561
|
551
|
return
|
|
@@ -563,7 +553,7 @@ func (c *ExecutionContext) enterCmd(objectName string) {
|
563
|
553
|
c.output("You climb into %s.", object.Name)
|
564
|
554
|
c.oemit(c.context.ID, "%s climbs into %s.", c.actor.Name, object.Name)
|
565
|
555
|
c.oemit(object.ID, "%s squeezes into %s with you.", c.actor.Name, object.Name)
|
566
|
|
-
|
|
556
|
+
|
567
|
557
|
}
|
568
|
558
|
|
569
|
559
|
func (c *ExecutionContext) leaveCmd() {
|
|
@@ -575,10 +565,14 @@ func (c *ExecutionContext) leaveCmd() {
|
575
|
565
|
}
|
576
|
566
|
|
577
|
567
|
container, found := c.db.Fetch(outerObjectID)
|
578
|
|
- if !found { return }
|
|
568
|
+ if !found {
|
|
569
|
+ return
|
|
570
|
+ }
|
579
|
571
|
|
580
|
572
|
err := container.Contains(&c.actor)
|
581
|
|
- if err != nil { return }
|
|
573
|
+ if err != nil {
|
|
574
|
+ return
|
|
575
|
+ }
|
582
|
576
|
|
583
|
577
|
c.output("You climb out of %s.", c.context.Name)
|
584
|
578
|
c.oemit(c.context.ID, "%s climbs out of %s.", c.actor.Name, c.context.Name)
|
|
@@ -710,7 +704,6 @@ func (c *ExecutionContext) digCmd(input string) {
|
710
|
704
|
|
711
|
705
|
}
|
712
|
706
|
|
713
|
|
-
|
714
|
707
|
func (c *ExecutionContext) nameCmd(input string) {
|
715
|
708
|
|
716
|
709
|
r, _ := regexp.Compile(`^@name\pZ+([^=]*[^=\pZ]{1})\pZ*=\pZ*(.*)\pZ*$`)
|
|
@@ -751,8 +744,6 @@ func (c *ExecutionContext) nameCmd(input string) {
|
751
|
744
|
|
752
|
745
|
}
|
753
|
746
|
|
754
|
|
-
|
755
|
|
-
|
756
|
747
|
func (c *ExecutionContext) setCmd(input string) {
|
757
|
748
|
r, _ := regexp.Compile(`^@set\pZ+([^=]*[^=\pZ]{1})\pZ*=\pZ*(!)?(.*)\pZ*$`)
|
758
|
749
|
params := r.FindStringSubmatch(input)
|
|
@@ -760,20 +751,19 @@ func (c *ExecutionContext) setCmd(input string) {
|
760
|
751
|
return
|
761
|
752
|
}
|
762
|
753
|
|
763
|
|
- objectName, value, flag := params[1], params[2]!="!", params[3]
|
|
754
|
+ objectName, value, flag := params[1], params[2] != "!", params[3]
|
764
|
755
|
|
765
|
756
|
object, found := c.MatchFirst(c.context.ID, objectName, true, true)
|
766
|
|
- if (!found) {
|
|
757
|
+ if !found {
|
767
|
758
|
c.output("I don't know what that is")
|
768
|
759
|
return
|
769
|
760
|
}
|
770
|
|
-
|
771
|
|
-
|
|
761
|
+
|
772
|
762
|
object.SetFlag(flag, value)
|
773
|
763
|
object.Commit()
|
774
|
|
-
|
|
764
|
+
|
775
|
765
|
c.output("It is so.")
|
776
|
|
-
|
|
766
|
+
|
777
|
767
|
}
|
778
|
768
|
|
779
|
769
|
func (c *ExecutionContext) descCmd(input string) {
|
|
@@ -803,19 +793,19 @@ func (c *ExecutionContext) telCmd(destStr string) {
|
803
|
793
|
|
804
|
794
|
var dest Object
|
805
|
795
|
var found bool
|
806
|
|
-
|
|
796
|
+
|
807
|
797
|
dest, found = c.MatchFirst(c.context.ID, destStr, true, false)
|
808
|
|
-
|
|
798
|
+
|
809
|
799
|
if !found {
|
810
|
800
|
c.output("Invalid destination.")
|
811
|
801
|
return
|
812
|
802
|
}
|
813
|
|
-
|
|
803
|
+
|
814
|
804
|
if dest.Type == "exit" {
|
815
|
805
|
c.output("As fun is it sounds, you're not going to teleport into an exit.")
|
816
|
806
|
return
|
817
|
807
|
}
|
818
|
|
-
|
|
808
|
+
|
819
|
809
|
if dest.Type == "player" {
|
820
|
810
|
c.output("Teleporting into players is very impolite.")
|
821
|
811
|
return
|
|
@@ -824,7 +814,7 @@ func (c *ExecutionContext) telCmd(destStr string) {
|
824
|
814
|
if dest.Owner != c.actor.ID && !dest.GetFlag("jump_ok") {
|
825
|
815
|
c.output("You're not allowed to do that.")
|
826
|
816
|
}
|
827
|
|
-
|
|
817
|
+
|
828
|
818
|
c.output("You feel an intense wooshing sensation.")
|
829
|
819
|
c.oemit(c.context.ID, "%s teleports out of the room.", c.actor.Name)
|
830
|
820
|
c.oemit(dest.ID, "%s teleports in to the room.", c.actor.Name)
|
|
@@ -833,7 +823,6 @@ func (c *ExecutionContext) telCmd(destStr string) {
|
833
|
823
|
if err != nil {
|
834
|
824
|
return
|
835
|
825
|
}
|
836
|
|
-
|
837
|
826
|
|
838
|
827
|
c.actor.Refresh()
|
839
|
828
|
c.lookCmd("")
|
|
@@ -856,11 +845,11 @@ func (c *ExecutionContext) dumpCmd(refStr string) {
|
856
|
845
|
func (c *ExecutionContext) destroyCmd(target string) {
|
857
|
846
|
|
858
|
847
|
object, found := c.MatchFirst(c.actor.ID, target, true, false)
|
859
|
|
- if (!found) {
|
|
848
|
+ if !found {
|
860
|
849
|
c.output("I don't see that here.")
|
861
|
850
|
return
|
862
|
851
|
}
|
863
|
|
-
|
|
852
|
+
|
864
|
853
|
if object.ID == c.actor.ID {
|
865
|
854
|
c.output("There are alternatives to suicide.")
|
866
|
855
|
return
|