Keelan Lightfoot пре 8 година
родитељ
комит
9895e6434d
4 измењених фајлова са 56 додато и 30 уклоњено
  1. 13
    0
      cmd/funmow/main.go
  2. 2
    11
      db.go
  3. 35
    19
      execution_context.go
  4. 6
    0
      object.go

+ 13
- 0
cmd/funmow/main.go Прегледај датотеку

@@ -43,6 +43,7 @@ func main() {
43 43
 	if seed {
44 44
 		log.Print("Seeding database...")
45 45
 		seedDB(db)
46
+		return
46 47
 	}
47 48
 
48 49
 	log.Print("Listening for connections on ", listen)
@@ -71,6 +72,18 @@ func seedDB(db *funmow.DB) {
71 72
 
72 73
 	f := funmow.NewObjectFactory(db)
73 74
 
75
+	limbo := f.NewRawObject()
76
+	limbo.Type = "room"
77
+	limbo.Name = "Limbo"
78
+	limbo.Description = "There's very little to see here."
79
+	limbo.Owner = 1
80
+	limbo.SetFlag("jumk_ok", true)
81
+	limbo.ID = 0
82
+	err := limbo.Commit()
83
+	if err != nil {
84
+		log.Fatal(err)
85
+	}
86
+
74 87
 	keelan, _ := db.CreatePlayer("keelan", "123", map[string]bool{"wizard": true})
75 88
 	dan, _ := db.CreatePlayer("dan", "123", nil)
76 89
 

+ 2
- 11
db.go Прегледај датотеку

@@ -102,7 +102,7 @@ func (s *DB) Open() error {
102 102
 	}
103 103
 	return s.db.Update(func(tx *bolt.Tx) error {
104 104
 		var err error
105
-		objectBucket, err := tx.CreateBucketIfNotExists([]byte("object"))
105
+		_, err = tx.CreateBucketIfNotExists([]byte("object"))
106 106
 		if err != nil {
107 107
 			return fmt.Errorf("create bucket: %s", err)
108 108
 		}
@@ -122,15 +122,6 @@ func (s *DB) Open() error {
122 122
 			return fmt.Errorf("create bucket: %s", err)
123 123
 		}
124 124
 
125
-		// make sure we have a limbo
126
-		if _, found := s.txRetrieveObject(objectBucket, 0); !found {
127
-			limbo := Object{Name: "Limbo", Description: "There's very little to see here.", ID: 0}
128
-			err = s.txStoreObject(objectBucket, limbo, 0)
129
-			if err != nil {
130
-				return err
131
-			}
132
-		}
133
-
134 125
 		return nil
135 126
 	})
136 127
 }
@@ -380,7 +371,7 @@ func (s *DB) RetrieveObject(id DBRef) (Object, bool) {
380 371
 	s.db.View(func(tx *bolt.Tx) error {
381 372
 		b := tx.Bucket([]byte("object"))
382 373
 		o, f = s.txRetrieveObject(b, id)
383
-		return nil
374
+		return nil	
384 375
 	})
385 376
 	return o, f
386 377
 

+ 35
- 19
execution_context.go Прегледај датотеку

@@ -544,15 +544,24 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, matchType
544 544
 		}
545 545
 	}
546 546
 
547
-	if matchType & MatchGlobalDBRef != 0 {
548
-		ref, valid := NewDBRefFromHashRef(matchName)
549
-		if valid {
550
-			o, found := c.db.Fetch(ref)
551
-			if found && wanted[o.Type] {
547
+	ref, valid := NewDBRefFromHashRef(matchName)
548
+	
549
+	if valid {
550
+		o, found := c.db.Fetch(ref)
551
+		if found && wanted[o.Type] {
552
+			container, _ := c.db.GetParent(o.ID)
553
+			if container == context && matchType & MatchContext != 0 {
554
+				return o, true
555
+			}
556
+			if container == c.actor.ID && matchType & MatchInventory != 0 {
557
+				return o, true
558
+			}
559
+			if matchType & MatchGlobalDBRef != 0 {
552 560
 				return o, true
553 561
 			}
554 562
 		}
555 563
 	}
564
+	
556 565
 
557 566
 	if  wanted["player"] && matchType & MatchGlobalPlayer != 0 {
558 567
 		o, found := c.MatchPlayerName(matchName)
@@ -573,10 +582,9 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, matchType
573 582
 						}
574 583
 					}
575 584
 				}
576
-				_, refValid := NewDBRefFromHashRef(matchName)
577 585
 				lowerObjectName := strings.ToLower(o.Name)
578 586
 				lowerMatchName := strings.ToLower(matchName)
579
-				if strings.HasPrefix(lowerObjectName, lowerMatchName) || refValid {
587
+				if strings.HasPrefix(lowerObjectName, lowerMatchName) {
580 588
 					return o, true
581 589
 				}
582 590
 			}
@@ -587,10 +595,9 @@ func (c *ExecutionContext) MatchFirst(context DBRef, matchName string, matchType
587 595
 		for childID, _ := range c.db.GetChildren(c.actor.ID) {
588 596
 			o, found := c.db.Fetch(childID)
589 597
 			if found && wanted[o.Type] {
590
-				_, refValid := NewDBRefFromHashRef(matchName)
591 598
 				lowerObjectName := strings.ToLower(o.Name)
592 599
 				lowerMatchName := strings.ToLower(matchName)
593
-				if strings.HasPrefix(lowerObjectName, lowerMatchName) || refValid {
600
+				if strings.HasPrefix(lowerObjectName, lowerMatchName) {
594 601
 					return o, true
595 602
 				}
596 603
 			}
@@ -838,7 +845,8 @@ func (c *ExecutionContext) nameCmd(input string) {
838 845
 
839 846
 	searchName, newName := params[1], params[2]
840 847
 
841
-	candidate, found := c.MatchFirst(c.context.ID, searchName, MatchContext|MatchGlobalDBRef|MatchExitAliases|MatchInventory|MatchRelative|MatchStuffTypes)
848
+	candidate, found := c.MatchFirst(c.context.ID, searchName, MatchContext|MatchInventory|MatchRelative|MatchGlobalDBRef|MatchExitAliases|MatchAnyType)
849
+
842 850
 	if !found {
843 851
 		c.output("I don't see that here.")
844 852
 		return
@@ -879,13 +887,13 @@ func (c *ExecutionContext) descCmd(input string) {
879 887
 
880 888
 	objectName, description := params[1], params[2]
881 889
 
882
-	object, found := c.MatchFirst(c.context.ID, objectName, MatchContext|MatchGlobalDBRef|MatchExitAliases|MatchInventory|MatchRelative|MatchStuffTypes)
890
+
891
+	object, found := c.MatchFirst(c.context.ID, objectName, MatchContext|MatchInventory|MatchRelative|MatchGlobalDBRef|MatchExitAliases|MatchAnyType)
883 892
 	if !found {
884 893
 		c.output("I don't see that here.")
885 894
 		return
886 895
 	}
887 896
 
888
-	fmt.Println(object)
889 897
 	object.Description = description
890 898
 	object.Commit()
891 899
 
@@ -902,7 +910,7 @@ func (c *ExecutionContext) setCmd(input string) {
902 910
 
903 911
 	objectName, value, flag := params[1], params[2] != "!", params[3]
904 912
 
905
-	object, found := c.MatchFirst(c.context.ID, objectName, MatchContext|MatchGlobalDBRef|MatchExitAliases|MatchInventory|MatchRelative|MatchStuffTypes|MatchGlobalPlayer)
913
+	object, found := c.MatchFirst(c.context.ID, objectName, MatchContext|MatchInventory|MatchRelative|MatchGlobalDBRef|MatchExitAliases|MatchAnyType)
906 914
 	if !found {
907 915
 		c.output("I don't know what that is")
908 916
 		return
@@ -926,7 +934,8 @@ func (c *ExecutionContext) colorCmd(input string) {
926 934
 
927 935
 	objectName, value := params[1], params[2]
928 936
 
929
-	object, found := c.MatchFirst(c.context.ID, objectName, MatchContext|MatchGlobalDBRef|MatchExitAliases|MatchInventory|MatchRelative|MatchStuffTypes)
937
+	object, found := c.MatchFirst(c.context.ID, objectName, MatchContext|MatchInventory|MatchRelative|MatchGlobalDBRef|MatchExitAliases|MatchAnyType)
938
+
930 939
 	if !found {
931 940
 		c.output("I don't know what that is")
932 941
 		return
@@ -953,8 +962,9 @@ func (c *ExecutionContext) telCmd(destStr string) {
953 962
 		return
954 963
 	}
955 964
 
956
-	if dest.Owner != c.actor.ID && !dest.GetFlag("jump_ok") {
965
+	if dest.Owner != c.actor.ID && !dest.GetFlag("jump_ok") && !c.actor.GetFlag("wizard") {
957 966
 		c.output("You're not allowed to do that.")
967
+		return
958 968
 	}
959 969
 
960 970
 	c.output("You feel an intense wooshing sensation.")
@@ -966,14 +976,13 @@ func (c *ExecutionContext) telCmd(destStr string) {
966 976
 		return
967 977
 	}
968 978
 
969
-	c.actor.Refresh()
970
-	c.lookCmd("")
979
+	c.command("look")
971 980
 
972 981
 }
973 982
 
974
-func (c *ExecutionContext) dumpCmd(refStr string) {
983
+func (c *ExecutionContext) dumpCmd(input string) {
975 984
 
976
-	object, found := c.MatchFirst(c.context.ID, refStr, MatchContext|MatchGlobalDBRef|MatchGlobalPlayer|MatchExitAliases|MatchInventory|MatchRelative|MatchStuffTypes)
985
+	object, found := c.MatchFirst(c.context.ID, input, MatchContext|MatchInventory|MatchRelative|MatchGlobalDBRef|MatchGlobalPlayer|MatchExitAliases|MatchAnyType)
977 986
 
978 987
 	if !found {
979 988
 		c.output("I can't find that.")
@@ -1040,6 +1049,13 @@ func (c *ExecutionContext) goCmd(dir string) bool {
1040 1049
 
1041 1050
 }
1042 1051
 
1052
+func (c *ExecutionContext) command(format string, a ...interface{}) {
1053
+
1054
+	command := fmt.Sprintf(format, a...)
1055
+	c.outbound <- PlayerEvent{src: c.actor.ID, dst: c.actor.ID, message: command, messageType: EventTypeCommand}
1056
+
1057
+}
1058
+
1043 1059
 func (c *ExecutionContext) wall(format string, a ...interface{}) {
1044 1060
 
1045 1061
 	message := fmt.Sprintf(format, a...)

+ 6
- 0
object.go Прегледај датотеку

@@ -46,6 +46,12 @@ func (f *ObjectFactory) NewObject() Object {
46 46
 	return o
47 47
 }
48 48
 
49
+func (f *ObjectFactory) NewRawObject() Object {
50
+	o := Object{}
51
+	o.db = f.db
52
+	return o
53
+}
54
+
49 55
 func (f *ObjectFactory) NewExit(name string, next DBRef, owner DBRef) Object {
50 56
 	o := Object{
51 57
 		Type:  "exit",