|
@@ -8,19 +8,18 @@ import (
|
8
|
8
|
)
|
9
|
9
|
|
10
|
10
|
const (
|
11
|
|
- MatchContext = 1 << iota
|
12
|
|
- MatchGlobalDBRef = 1 << iota
|
13
|
|
- MatchGlobalPlayer = 1 << iota
|
14
|
|
- MatchInventory = 1 << iota
|
15
|
|
- MatchRelative = 1 << iota
|
16
|
|
- MatchExitAliases = 1 << iota
|
17
|
|
- MatchExitType = 1 << iota
|
18
|
|
- MatchRoomType = 1 << iota
|
19
|
|
- MatchPlayerType = 1 << iota
|
20
|
|
- MatchThingType = 1 << iota
|
21
|
|
- MatchAnyType = MatchExitType|MatchRoomType|MatchPlayerType|MatchThingType
|
22
|
|
- MatchStuffTypes = MatchExitType|MatchRoomType|MatchThingType
|
23
|
|
-
|
|
11
|
+ MatchContext = 1 << iota
|
|
12
|
+ MatchGlobalDBRef = 1 << iota
|
|
13
|
+ MatchGlobalPlayer = 1 << iota
|
|
14
|
+ MatchInventory = 1 << iota
|
|
15
|
+ MatchRelative = 1 << iota
|
|
16
|
+ MatchExitAliases = 1 << iota
|
|
17
|
+ MatchExitType = 1 << iota
|
|
18
|
+ MatchRoomType = 1 << iota
|
|
19
|
+ MatchPlayerType = 1 << iota
|
|
20
|
+ MatchThingType = 1 << iota
|
|
21
|
+ MatchAnyType = MatchExitType | MatchRoomType | MatchPlayerType | MatchThingType
|
|
22
|
+ MatchStuffTypes = MatchExitType | MatchRoomType | MatchThingType
|
24
|
23
|
)
|
25
|
24
|
|
26
|
25
|
type ExecutionContext struct {
|
|
@@ -291,11 +290,11 @@ func (c *ExecutionContext) lookCmd(target string) {
|
291
|
290
|
c.output("%s\n%s", object.DetailedName(), object.Description)
|
292
|
291
|
} else {
|
293
|
292
|
c.output("%s\n%s", c.context.DetailedName(), c.context.Description)
|
294
|
|
- contents := c.context.GetContents(c.actor.ID)
|
|
293
|
+ contents := c.context.GetContents(c.actor.ID, false)
|
295
|
294
|
if len(contents) > 0 {
|
296
|
295
|
c.output("Contents:\n" + strings.Join(contents, "\n"))
|
297
|
296
|
}
|
298
|
|
- exits := c.context.GetExits(true)
|
|
297
|
+ exits := c.context.GetExits(true, false)
|
299
|
298
|
if len(exits) > 0 {
|
300
|
299
|
c.output("Obvious Exits:\n" + strings.Join(exits, " "))
|
301
|
300
|
}
|
|
@@ -330,12 +329,12 @@ func (c *ExecutionContext) examineCmd(objectName string) {
|
330
|
329
|
c.output("Owner: %s", c.objectName(object.Owner))
|
331
|
330
|
c.output("Location: %s", c.objectName(containerID))
|
332
|
331
|
|
333
|
|
- contents := object.GetContents(0)
|
|
332
|
+ contents := object.GetContents(0, true)
|
334
|
333
|
if len(contents) > 0 {
|
335
|
334
|
c.output("Contains:\n%s", strings.Join(contents, "\n"))
|
336
|
335
|
}
|
337
|
336
|
|
338
|
|
- exits := object.GetExits(false)
|
|
337
|
+ exits := object.GetExits(false, true)
|
339
|
338
|
if len(exits) > 0 {
|
340
|
339
|
c.output("Exits:\n%s", strings.Join(exits, "\n"))
|
341
|
340
|
}
|
|
@@ -414,15 +413,15 @@ func (c *ExecutionContext) pageCmd(input string) {
|
414
|
413
|
c.output("That player appears to be offline.")
|
415
|
414
|
return
|
416
|
415
|
}
|
417
|
|
-
|
|
416
|
+
|
418
|
417
|
c.output(`You paged %s with "%s".`, candidate.ColorName(), message)
|
419
|
418
|
c.outbound <- PlayerEvent{src: c.actor.ID, dst: candidate.ID, message: message, messageType: EventTypePage}
|
420
|
|
-
|
|
419
|
+
|
421
|
420
|
}
|
422
|
421
|
|
423
|
422
|
func (c *ExecutionContext) inventoryCmd() {
|
424
|
423
|
|
425
|
|
- inventory := c.actor.GetContents(0)
|
|
424
|
+ inventory := c.actor.GetContents(0, true)
|
426
|
425
|
|
427
|
426
|
if len(inventory) > 0 {
|
428
|
427
|
c.output("Inventory:\n %s", strings.Join(inventory, "\n "))
|
|
@@ -451,7 +450,7 @@ func (c *ExecutionContext) getCmd(objectName string) {
|
451
|
450
|
c.output("You can't pick yourself up.")
|
452
|
451
|
return
|
453
|
452
|
}
|
454
|
|
-
|
|
453
|
+
|
455
|
454
|
err := c.actor.Contains(&object)
|
456
|
455
|
if err != nil {
|
457
|
456
|
return
|
|
@@ -521,22 +520,22 @@ func (c *ExecutionContext) MatchPlayerName(matchName string) (Object, bool) {
|
521
|
520
|
}
|
522
|
521
|
|
523
|
522
|
func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, matchType int) (Object, bool) {
|
524
|
|
-
|
|
523
|
+
|
525
|
524
|
wanted := map[string]bool{
|
526
|
|
- "player": matchType & MatchPlayerType != 0,
|
527
|
|
- "exit": matchType & MatchExitType != 0,
|
528
|
|
- "room": matchType & MatchRoomType != 0,
|
529
|
|
- "thing": matchType & MatchThingType != 0,
|
|
525
|
+ "player": matchType&MatchPlayerType != 0,
|
|
526
|
+ "exit": matchType&MatchExitType != 0,
|
|
527
|
+ "room": matchType&MatchRoomType != 0,
|
|
528
|
+ "thing": matchType&MatchThingType != 0,
|
530
|
529
|
}
|
531
|
|
-
|
532
|
|
- if matchType & MatchRelative != 0 {
|
|
530
|
+
|
|
531
|
+ if matchType&MatchRelative != 0 {
|
533
|
532
|
if matchName == "here" {
|
534
|
533
|
o, found := c.db.Fetch(context)
|
535
|
534
|
if found && wanted[o.Type] {
|
536
|
535
|
return o, true
|
537
|
536
|
}
|
538
|
537
|
}
|
539
|
|
-
|
|
538
|
+
|
540
|
539
|
if matchName == "me" {
|
541
|
540
|
if wanted[c.actor.Type] {
|
542
|
541
|
return c.actor, true
|
|
@@ -545,36 +544,35 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, matchType
|
545
|
544
|
}
|
546
|
545
|
|
547
|
546
|
ref, valid := NewDBRefFromHashRef(matchName)
|
548
|
|
-
|
|
547
|
+
|
549
|
548
|
if valid {
|
550
|
549
|
o, found := c.db.Fetch(ref)
|
551
|
550
|
if found && wanted[o.Type] {
|
552
|
551
|
container, _ := c.db.GetParent(o.ID)
|
553
|
|
- if container == context && matchType & MatchContext != 0 {
|
|
552
|
+ if container == context && matchType&MatchContext != 0 {
|
554
|
553
|
return o, true
|
555
|
554
|
}
|
556
|
|
- if container == c.actor.ID && matchType & MatchInventory != 0 {
|
|
555
|
+ if container == c.actor.ID && matchType&MatchInventory != 0 {
|
557
|
556
|
return o, true
|
558
|
557
|
}
|
559
|
|
- if matchType & MatchGlobalDBRef != 0 {
|
|
558
|
+ if matchType&MatchGlobalDBRef != 0 {
|
560
|
559
|
return o, true
|
561
|
560
|
}
|
562
|
561
|
}
|
563
|
562
|
}
|
564
|
|
-
|
565
|
563
|
|
566
|
|
- if wanted["player"] && matchType & MatchGlobalPlayer != 0 {
|
|
564
|
+ if wanted["player"] && matchType&MatchGlobalPlayer != 0 {
|
567
|
565
|
o, found := c.MatchPlayerName(matchName)
|
568
|
566
|
if found {
|
569
|
567
|
return o, true
|
570
|
568
|
}
|
571
|
569
|
}
|
572
|
570
|
|
573
|
|
- if matchType & MatchContext != 0 {
|
|
571
|
+ if matchType&MatchContext != 0 {
|
574
|
572
|
for childID, _ := range c.db.GetChildren(context) {
|
575
|
573
|
o, found := c.db.Fetch(childID)
|
576
|
574
|
if found && wanted[o.Type] {
|
577
|
|
- if o.Type == "exit" && matchType & MatchExitAliases != 0 {
|
|
575
|
+ if o.Type == "exit" && matchType&MatchExitAliases != 0 {
|
578
|
576
|
aliases := strings.Split(o.Name, ";")
|
579
|
577
|
for _, v := range aliases {
|
580
|
578
|
if strings.EqualFold(v, matchName) {
|
|
@@ -590,8 +588,8 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, matchType
|
590
|
588
|
}
|
591
|
589
|
}
|
592
|
590
|
}
|
593
|
|
-
|
594
|
|
- if matchType & MatchInventory != 0 {
|
|
591
|
+
|
|
592
|
+ if matchType&MatchInventory != 0 {
|
595
|
593
|
for childID, _ := range c.db.GetChildren(c.actor.ID) {
|
596
|
594
|
o, found := c.db.Fetch(childID)
|
597
|
595
|
if found && wanted[o.Type] {
|
|
@@ -603,7 +601,7 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, matchType
|
603
|
601
|
}
|
604
|
602
|
}
|
605
|
603
|
}
|
606
|
|
-
|
|
604
|
+
|
607
|
605
|
return Object{}, false
|
608
|
606
|
|
609
|
607
|
}
|
|
@@ -648,6 +646,11 @@ func (c *ExecutionContext) enterCmd(objectName string) {
|
648
|
646
|
return
|
649
|
647
|
}
|
650
|
648
|
|
|
649
|
+ if !object.GetFlag("enter_ok") && !c.actor.GetFlag("wizard") {
|
|
650
|
+ c.output("You're not allowed to do that.")
|
|
651
|
+ return
|
|
652
|
+ }
|
|
653
|
+
|
651
|
654
|
err := object.Contains(&c.actor)
|
652
|
655
|
if err != nil {
|
653
|
656
|
return
|
|
@@ -812,27 +815,27 @@ func (c *ExecutionContext) passwordCmd(input string) {
|
812
|
815
|
c.output("Only players can have passwords.")
|
813
|
816
|
return
|
814
|
817
|
}
|
815
|
|
-
|
|
818
|
+
|
816
|
819
|
r, _ := regexp.Compile(`^@password\pZ+([^\pZ]+)\pZ*=\pZ*([^\pZ]+)\pZ*$`)
|
817
|
820
|
params := r.FindStringSubmatch(input)
|
818
|
821
|
if params == nil {
|
819
|
822
|
return
|
820
|
823
|
}
|
821
|
|
-
|
|
824
|
+
|
822
|
825
|
oldPassword, newPassword := params[1], params[2]
|
823
|
826
|
|
824
|
827
|
if len(oldPassword) == 0 || len(newPassword) == 0 {
|
825
|
828
|
c.output("Password can't be blank.")
|
826
|
829
|
return
|
827
|
830
|
}
|
828
|
|
-
|
|
831
|
+
|
829
|
832
|
changed := c.db.SetPlayerPassword(c.actor.Name, oldPassword, newPassword)
|
830
|
833
|
if changed {
|
831
|
834
|
c.output("Password updated.")
|
832
|
835
|
} else {
|
833
|
836
|
c.output("Old password is wrong.")
|
834
|
837
|
}
|
835
|
|
-
|
|
838
|
+
|
836
|
839
|
}
|
837
|
840
|
|
838
|
841
|
func (c *ExecutionContext) nameCmd(input string) {
|
|
@@ -878,7 +881,6 @@ func (c *ExecutionContext) nameCmd(input string) {
|
878
|
881
|
|
879
|
882
|
func (c *ExecutionContext) descCmd(input string) {
|
880
|
883
|
|
881
|
|
-
|
882
|
884
|
r, _ := regexp.Compile(`^@desc\pZ+([^=]*[^=\pZ]{1})\pZ*=\pZ*(.*)\pZ*$`)
|
883
|
885
|
params := r.FindStringSubmatch(input)
|
884
|
886
|
if params == nil {
|
|
@@ -887,7 +889,6 @@ func (c *ExecutionContext) descCmd(input string) {
|
887
|
889
|
|
888
|
890
|
objectName, description := params[1], params[2]
|
889
|
891
|
|
890
|
|
-
|
891
|
892
|
object, found := c.MatchFirst(c.context.ID, objectName, MatchContext|MatchInventory|MatchRelative|MatchGlobalDBRef|MatchExitAliases|MatchAnyType)
|
892
|
893
|
if !found {
|
893
|
894
|
c.output("I don't see that here.")
|
|
@@ -916,6 +917,11 @@ func (c *ExecutionContext) setCmd(input string) {
|
916
|
917
|
return
|
917
|
918
|
}
|
918
|
919
|
|
|
920
|
+ if object.Owner != c.actor.ID && !c.actor.GetFlag("wizard") {
|
|
921
|
+ c.output("You're not allowed to do that.")
|
|
922
|
+ return
|
|
923
|
+ }
|
|
924
|
+
|
919
|
925
|
object.SetFlag(flag, value)
|
920
|
926
|
object.Commit()
|
921
|
927
|
|
|
@@ -923,7 +929,6 @@ func (c *ExecutionContext) setCmd(input string) {
|
923
|
929
|
|
924
|
930
|
}
|
925
|
931
|
|
926
|
|
-
|
927
|
932
|
func (c *ExecutionContext) colorCmd(input string) {
|
928
|
933
|
|
929
|
934
|
r, _ := regexp.Compile(`^@color\pZ+([^=]*[^=\pZ]{1})\pZ*=\pZ*([^\pZ]*)\pZ*$`)
|
|
@@ -941,6 +946,11 @@ func (c *ExecutionContext) colorCmd(input string) {
|
941
|
946
|
return
|
942
|
947
|
}
|
943
|
948
|
|
|
949
|
+ if object.Owner != c.actor.ID && !c.actor.GetFlag("wizard") {
|
|
950
|
+ c.output("You're not allowed to do that.")
|
|
951
|
+ return
|
|
952
|
+ }
|
|
953
|
+
|
944
|
954
|
object.SetProp("color", value)
|
945
|
955
|
object.Commit()
|
946
|
956
|
|
|
@@ -948,8 +958,6 @@ func (c *ExecutionContext) colorCmd(input string) {
|
948
|
958
|
|
949
|
959
|
}
|
950
|
960
|
|
951
|
|
-
|
952
|
|
-
|
953
|
961
|
func (c *ExecutionContext) telCmd(destStr string) {
|
954
|
962
|
|
955
|
963
|
var dest Object
|
|
@@ -1009,6 +1017,12 @@ func (c *ExecutionContext) destroyCmd(target string) {
|
1009
|
1017
|
c.output("I didn't think homicide was your thing.")
|
1010
|
1018
|
return
|
1011
|
1019
|
}
|
|
1020
|
+
|
|
1021
|
+ if object.Owner != c.actor.ID && !c.actor.GetFlag("wizard") {
|
|
1022
|
+ c.output("You're not allowed to do that.")
|
|
1023
|
+ return
|
|
1024
|
+ }
|
|
1025
|
+
|
1012
|
1026
|
name := object.DetailedName()
|
1013
|
1027
|
err := object.Delete()
|
1014
|
1028
|
if err == nil {
|
|
@@ -1020,11 +1034,11 @@ func (c *ExecutionContext) destroyCmd(target string) {
|
1020
|
1034
|
func (c *ExecutionContext) goCmd(dir string) bool {
|
1021
|
1035
|
|
1022
|
1036
|
exit, found := c.MatchFirst(c.context.ID, dir, MatchContext|MatchExitType|MatchExitAliases)
|
1023
|
|
-
|
|
1037
|
+
|
1024
|
1038
|
if !found {
|
1025
|
1039
|
return false
|
1026
|
1040
|
}
|
1027
|
|
-
|
|
1041
|
+
|
1028
|
1042
|
if !exit.Next.Valid() {
|
1029
|
1043
|
return false
|
1030
|
1044
|
}
|
|
@@ -1043,8 +1057,7 @@ func (c *ExecutionContext) goCmd(dir string) bool {
|
1043
|
1057
|
c.oemit(c.context.ID, "%s leaves the room.", c.actor.ColorName())
|
1044
|
1058
|
c.oemit(newRoom.ID, "%s enters the room.", c.actor.ColorName())
|
1045
|
1059
|
return true
|
1046
|
|
-
|
1047
|
|
-
|
|
1060
|
+
|
1048
|
1061
|
return false
|
1049
|
1062
|
|
1050
|
1063
|
}
|