|
@@ -37,6 +37,8 @@ func NewExecutionContext(actorID DBRef, e *EventDistributor, w *DB, outbound cha
|
37
|
37
|
if !found {
|
38
|
38
|
return nil
|
39
|
39
|
}
|
|
40
|
+
|
|
41
|
+
|
40
|
42
|
|
41
|
43
|
c.actor = actor
|
42
|
44
|
c.outbound = outbound
|
|
@@ -100,6 +102,11 @@ func (c *ExecutionContext) StartInboundChannel() chan PlayerEvent {
|
100
|
102
|
}
|
101
|
103
|
c.HandleEvent(event)
|
102
|
104
|
}
|
|
105
|
+ // mark player as offline
|
|
106
|
+ if c.actor.Type == "player" {
|
|
107
|
+ c.actor.SetFlag("online", "false")
|
|
108
|
+ c.actor.Commit()
|
|
109
|
+ }
|
103
|
110
|
// and finally we tell the event distributor to delete us.
|
104
|
111
|
c.outbound <- PlayerEvent{src: c.actor.ID, dst: c.actor.ID, messageType: EventTypeTeardownComplete}
|
105
|
112
|
}()
|
|
@@ -110,6 +117,14 @@ func (c *ExecutionContext) StartInboundChannel() chan PlayerEvent {
|
110
|
117
|
func (c *ExecutionContext) HandleEvent(m PlayerEvent) {
|
111
|
118
|
inside, _ := c.db.GetParent(c.actor.ID)
|
112
|
119
|
switch m.messageType {
|
|
120
|
+ case EventTypeLogin:
|
|
121
|
+ if c.actor.Type == "player" {
|
|
122
|
+ c.actor.SetFlag("online", "true")
|
|
123
|
+ c.actor.Commit()
|
|
124
|
+ inside, _ := c.db.GetParent(c.actor.ID)
|
|
125
|
+ c.system("Yay! %s has connected! Oh boy!", c.actor.Name)
|
|
126
|
+ c.oemit(inside, "You hear a rustling as %s awakens from a slumber.", c.actor.Name)
|
|
127
|
+ }
|
113
|
128
|
case EventTypeEmit:
|
114
|
129
|
fallthrough
|
115
|
130
|
case EventTypeOEmit:
|
|
@@ -123,7 +138,9 @@ func (c *ExecutionContext) HandleEvent(m PlayerEvent) {
|
123
|
138
|
if !found {
|
124
|
139
|
break
|
125
|
140
|
}
|
126
|
|
- c.output("In the distance, you hear %s bellow out \"%s\"", speaker.Name, m.message)
|
|
141
|
+ c.output("In the distance, you hear %s bellow out: \"%s\"", speaker.Name, m.message)
|
|
142
|
+ case EventTypeSystem:
|
|
143
|
+ c.output(m.message)
|
127
|
144
|
case EventTypePage:
|
128
|
145
|
speaker, found := c.db.Fetch(m.src)
|
129
|
146
|
if !found {
|
|
@@ -222,6 +239,9 @@ func (c *ExecutionContext) evaluateCommand(m PlayerEvent) {
|
222
|
239
|
c.destroyCmd(strings.TrimPrefix(message, "@destroy "))
|
223
|
240
|
case strings.HasPrefix(message, "@force "):
|
224
|
241
|
c.forceCmd(message)
|
|
242
|
+ case strings.HasPrefix(message, "@wizard "):
|
|
243
|
+ c.playerFlagCmd(message, "wizard")
|
|
244
|
+
|
225
|
245
|
default:
|
226
|
246
|
if !c.goCmd(message) {
|
227
|
247
|
c.output("What?\n")
|
|
@@ -335,28 +355,45 @@ func (c *ExecutionContext) forceCmd(input string) {
|
335
|
355
|
}
|
336
|
356
|
|
337
|
357
|
objectID, err := NewDBRefFromHashRef(objectName)
|
338
|
|
- wizard := false
|
|
358
|
+ wizard := c.actor.GetFlag("wizard","false") == "true"
|
339
|
359
|
if err == nil {
|
340
|
360
|
object, found := c.db.Fetch(objectID)
|
341
|
361
|
if !found {
|
342
|
362
|
c.output("I can't force what doesn't exist.")
|
343
|
363
|
}
|
344
|
|
- if object.Type == "thing" || (object.Type == "player" && wizard) {
|
345
|
|
- c.outbound <- PlayerEvent{src: c.actor.ID, dst: object.ID, message: command, messageType: EventTypeForce}
|
346
|
|
- } else {
|
|
364
|
+ if object.Type != "thing" && object.Type != "player" {
|
347
|
365
|
c.output("Some things just can't be forced.")
|
|
366
|
+ return
|
348
|
367
|
}
|
|
368
|
+ if object.Type == "player" && !wizard {
|
|
369
|
+ c.output("It's not nice to force others to do your bidding.")
|
|
370
|
+ return
|
|
371
|
+ }
|
|
372
|
+ if object.Owner != c.actor.ID && !wizard {
|
|
373
|
+ c.output("It's not nice to touch other people's things.")
|
|
374
|
+ return
|
|
375
|
+ }
|
|
376
|
+ c.outbound <- PlayerEvent{src: c.actor.ID, dst: object.ID, message: command, messageType: EventTypeForce}
|
|
377
|
+
|
349
|
378
|
} else {
|
350
|
379
|
|
351
|
380
|
object, matchType := room.MatchLinkNames(objectName, c.actor.ID).ExactlyOne()
|
352
|
381
|
|
353
|
382
|
switch matchType {
|
354
|
383
|
case MatchOne:
|
355
|
|
- if object.Type == "thing" || (object.Type == "player" && wizard) {
|
356
|
|
- c.outbound <- PlayerEvent{src: c.actor.ID, dst: object.ID, message: command, messageType: EventTypeForce}
|
357
|
|
- } else {
|
|
384
|
+ if object.Type != "thing" && object.Type != "player" {
|
358
|
385
|
c.output("Some things just can't be forced.")
|
|
386
|
+ return
|
359
|
387
|
}
|
|
388
|
+ if object.Type == "player" && !wizard {
|
|
389
|
+ c.output("It's not nice to force others to do your bidding.")
|
|
390
|
+ return
|
|
391
|
+ }
|
|
392
|
+ if object.Owner != c.actor.ID && !wizard {
|
|
393
|
+ c.output("It's not nice to touch other people's things.")
|
|
394
|
+ return
|
|
395
|
+ }
|
|
396
|
+ c.outbound <- PlayerEvent{src: c.actor.ID, dst: object.ID, message: command, messageType: EventTypeForce}
|
360
|
397
|
case MatchNone:
|
361
|
398
|
c.output("I don't see that here.")
|
362
|
399
|
case MatchMany:
|
|
@@ -408,6 +445,10 @@ func (c *ExecutionContext) getCmd(message string) {
|
408
|
445
|
c.output("You can't pick yourself up.")
|
409
|
446
|
return
|
410
|
447
|
}
|
|
448
|
+ if object.Type == "room" {
|
|
449
|
+ c.output("You can't carry a whole room, silly!")
|
|
450
|
+ return
|
|
451
|
+ }
|
411
|
452
|
err := c.actor.Contains(&object)
|
412
|
453
|
if err != nil {
|
413
|
454
|
return
|
|
@@ -464,6 +505,14 @@ func (c *ExecutionContext) enterCmd(message string) {
|
464
|
505
|
|
465
|
506
|
switch matchType {
|
466
|
507
|
case MatchOne:
|
|
508
|
+ if object.Type == "player" {
|
|
509
|
+ c.output("Maybe you should seek consent prior to entering another player.")
|
|
510
|
+ return
|
|
511
|
+ }
|
|
512
|
+ if object.Type == "exit" {
|
|
513
|
+ c.output("This s not how exits are meant to be used.")
|
|
514
|
+ return
|
|
515
|
+ }
|
467
|
516
|
if object.ID == c.actor.ID {
|
468
|
517
|
c.output("Entering yourself would be a bad idea.")
|
469
|
518
|
return
|
|
@@ -677,7 +726,6 @@ func (c *ExecutionContext) nameCmd(input string) {
|
677
|
726
|
candidate.Name = name
|
678
|
727
|
candidate.Commit()
|
679
|
728
|
c.output("Name set.")
|
680
|
|
- //c.actor.Refresh()
|
681
|
729
|
case MatchNone:
|
682
|
730
|
c.output("I don't see that here.")
|
683
|
731
|
case MatchMany:
|
|
@@ -686,6 +734,36 @@ func (c *ExecutionContext) nameCmd(input string) {
|
686
|
734
|
|
687
|
735
|
}
|
688
|
736
|
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+func (c *ExecutionContext) playerFlagCmd(input string, flag string) {
|
|
740
|
+ r, _ := regexp.Compile(`^@`+flag+`\pZ+([^=]*[^=\pZ]{1})\pZ*=\pZ*(.*)\pZ*$`)
|
|
741
|
+ params := r.FindStringSubmatch(input)
|
|
742
|
+ if params == nil {
|
|
743
|
+ return
|
|
744
|
+ }
|
|
745
|
+
|
|
746
|
+ playerName, value := params[1], params[2]
|
|
747
|
+
|
|
748
|
+ playerMeta,found := c.db.GetPlayer(playerName)
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+ if found {
|
|
752
|
+
|
|
753
|
+ player, found := c.db.Fetch(playerMeta.ID)
|
|
754
|
+
|
|
755
|
+ if !found {
|
|
756
|
+ return
|
|
757
|
+ }
|
|
758
|
+
|
|
759
|
+ player.SetFlag(flag, value)
|
|
760
|
+ player.Commit()
|
|
761
|
+ c.output("It is so.")
|
|
762
|
+ } else {
|
|
763
|
+ c.output("I don't know who that is.")
|
|
764
|
+ }
|
|
765
|
+}
|
|
766
|
+
|
689
|
767
|
func (c *ExecutionContext) descCmd(input string) {
|
690
|
768
|
|
691
|
769
|
r, _ := regexp.Compile(`^@desc\pZ+([^=]*[^=\pZ]{1})\pZ*=\pZ*(.*)\pZ*$`)
|
|
@@ -744,6 +822,21 @@ func (c *ExecutionContext) telCmd(destStr string) {
|
744
|
822
|
c.output("That doesn't exist.")
|
745
|
823
|
return
|
746
|
824
|
}
|
|
825
|
+
|
|
826
|
+ if newRoom.Type == "exit" {
|
|
827
|
+ c.output("As fun is it sounds, you're not going to teleport into an exit.")
|
|
828
|
+ return
|
|
829
|
+ }
|
|
830
|
+
|
|
831
|
+ if newRoom.Type == "player" {
|
|
832
|
+ c.output("Teleporting into other players is very impolite.")
|
|
833
|
+ return
|
|
834
|
+ }
|
|
835
|
+
|
|
836
|
+ if newRoom.ID == c.actor.ID {
|
|
837
|
+ c.output("Teleporting to yourself is generally considered dangerous.")
|
|
838
|
+ return
|
|
839
|
+ }
|
747
|
840
|
|
748
|
841
|
c.output("You feel an intense wooshing sensation.")
|
749
|
842
|
err = newRoom.Contains(&c.actor)
|
|
@@ -847,6 +940,20 @@ func (c *ExecutionContext) goCmd(dir string) bool {
|
847
|
940
|
|
848
|
941
|
}
|
849
|
942
|
|
|
943
|
+func (c *ExecutionContext) wall(format string, a ...interface{}) {
|
|
944
|
+
|
|
945
|
+ message := fmt.Sprintf(format, a...)
|
|
946
|
+ c.outbound <- PlayerEvent{src: c.actor.ID, message: message, messageType: EventTypeWall}
|
|
947
|
+
|
|
948
|
+}
|
|
949
|
+
|
|
950
|
+func (c *ExecutionContext) system(format string, a ...interface{}) {
|
|
951
|
+
|
|
952
|
+ message := fmt.Sprintf(format, a...)
|
|
953
|
+ c.outbound <- PlayerEvent{src: c.actor.ID, message: message, messageType: EventTypeSystem}
|
|
954
|
+
|
|
955
|
+}
|
|
956
|
+
|
850
|
957
|
func (c *ExecutionContext) oemit(audience DBRef, format string, a ...interface{}) {
|
851
|
958
|
|
852
|
959
|
message := fmt.Sprintf(format, a...)
|