Keelan Lightfoot 8 years ago
parent
commit
5e1829fbe0
5 changed files with 131 additions and 125 deletions
  1. 4
    5
      client.go
  2. 5
    7
      cmd/funmow/main.go
  3. 16
    11
      db.go
  4. 64
    75
      execution_context.go
  5. 42
    27
      object.go

+ 4
- 5
client.go View File

109
 				c.write("Bad username or password.\n")
109
 				c.write("Bad username or password.\n")
110
 				break
110
 				break
111
 			}
111
 			}
112
-			
113
 
112
 
114
 			c.playerID = player.ID
113
 			c.playerID = player.ID
115
 			c.authenticated = true
114
 			c.authenticated = true
134
 				c.write("That name is already taken.\n")
133
 				c.write("That name is already taken.\n")
135
 				break
134
 				break
136
 			}
135
 			}
137
-			
136
+
138
 			playerID, _ := c.db.CreatePlayer(strings.TrimSpace(fields[1]), strings.TrimSpace(fields[2]), nil)
137
 			playerID, _ := c.db.CreatePlayer(strings.TrimSpace(fields[1]), strings.TrimSpace(fields[2]), nil)
139
-			
138
+
140
 			_, found = c.db.Fetch(playerID)
139
 			_, found = c.db.Fetch(playerID)
141
 			if !found {
140
 			if !found {
142
 				c.write("I can't even.\n")
141
 				c.write("I can't even.\n")
143
 				break
142
 				break
144
 			}
143
 			}
145
-			
144
+
146
 			c.write("You have been created. Now you can connect!\n")
145
 			c.write("You have been created. Now you can connect!\n")
147
-			
146
+
148
 		} else {
147
 		} else {
149
 			c.write("What?\n")
148
 			c.write("What?\n")
150
 		}
149
 		}

+ 5
- 7
cmd/funmow/main.go View File

1
 package main
1
 package main
2
 
2
 
3
 import (
3
 import (
4
+	"flag"
4
 	"github.com/naleek/funmow"
5
 	"github.com/naleek/funmow"
5
 	"log"
6
 	"log"
6
 	"net"
7
 	"net"
7
-	"flag"
8
 )
8
 )
9
 
9
 
10
 const (
10
 const (
11
-	FunMOWVersion   = "0.2"
12
-	FunMOWDefaultDB = "funmow.db"
13
-	FunMOWDefaultListen    = ":4201"
11
+	FunMOWVersion       = "0.2"
12
+	FunMOWDefaultDB     = "funmow.db"
13
+	FunMOWDefaultListen = ":4201"
14
 )
14
 )
15
 
15
 
16
 func main() {
16
 func main() {
32
 		return
32
 		return
33
 	}
33
 	}
34
 
34
 
35
-
36
-
37
 	log.Print("Starting FunMOW Version ", FunMOWVersion)
35
 	log.Print("Starting FunMOW Version ", FunMOWVersion)
38
 
36
 
39
 	log.Print("Using database ", FunMOWDefaultDB)
37
 	log.Print("Using database ", FunMOWDefaultDB)
73
 
71
 
74
 	f := funmow.NewObjectFactory(db)
72
 	f := funmow.NewObjectFactory(db)
75
 
73
 
76
-	keelan, _ := db.CreatePlayer("keelan", "123", map[string]bool{"wizard":true})
74
+	keelan, _ := db.CreatePlayer("keelan", "123", map[string]bool{"wizard": true})
77
 	dan, _ := db.CreatePlayer("dan", "123", nil)
75
 	dan, _ := db.CreatePlayer("dan", "123", nil)
78
 
76
 
79
 	outside := f.NewObject()
77
 	outside := f.NewObject()

+ 16
- 11
db.go View File

4
 	"bytes"
4
 	"bytes"
5
 	"encoding/binary"
5
 	"encoding/binary"
6
 	"encoding/json"
6
 	"encoding/json"
7
+	"errors"
7
 	"fmt"
8
 	"fmt"
8
 	"github.com/boltdb/bolt"
9
 	"github.com/boltdb/bolt"
9
-	"strconv"
10
-	"errors"
11
 	"regexp"
10
 	"regexp"
11
+	"strconv"
12
 )
12
 )
13
 
13
 
14
 const (
14
 const (
19
 
19
 
20
 func NewDBRefFromHashRef(v string) (DBRef, bool) {
20
 func NewDBRefFromHashRef(v string) (DBRef, bool) {
21
 	var destInt int
21
 	var destInt int
22
-	
22
+
23
 	if matched, _ := regexp.MatchString(`^\pZ*#[0-9]+\pZ*?`, v); !matched {
23
 	if matched, _ := regexp.MatchString(`^\pZ*#[0-9]+\pZ*?`, v); !matched {
24
 		return 0, false
24
 		return 0, false
25
 	}
25
 	}
242
 func (s *DB) SetPlayer(name string, player PlayerMeta) error {
242
 func (s *DB) SetPlayer(name string, player PlayerMeta) error {
243
 
243
 
244
 	err := s.db.Update(func(tx *bolt.Tx) error {
244
 	err := s.db.Update(func(tx *bolt.Tx) error {
245
-		
245
+
246
 		buf, err := json.Marshal(player)
246
 		buf, err := json.Marshal(player)
247
 
247
 
248
-		if err != nil { return err }
249
-	
248
+		if err != nil {
249
+			return err
250
+		}
251
+
250
 		b := tx.Bucket([]byte("player"))
252
 		b := tx.Bucket([]byte("player"))
251
-		
253
+
252
 		return b.Put([]byte(name), buf)
254
 		return b.Put([]byte(name), buf)
253
 	})
255
 	})
254
 
256
 
259
 func (s *DB) GetPlayer(name string) (PlayerMeta, bool) {
261
 func (s *DB) GetPlayer(name string) (PlayerMeta, bool) {
260
 	var player PlayerMeta
262
 	var player PlayerMeta
261
 	found := false
263
 	found := false
262
-	
264
+
263
 	s.db.View(func(tx *bolt.Tx) error {
265
 	s.db.View(func(tx *bolt.Tx) error {
264
 		b := tx.Bucket([]byte("player"))
266
 		b := tx.Bucket([]byte("player"))
265
 		v := b.Get([]byte(name))
267
 		v := b.Get([]byte(name))
266
-		if v == nil { return nil }
268
+		if v == nil {
269
+			return nil
270
+		}
267
 		err := json.Unmarshal(v, &player)
271
 		err := json.Unmarshal(v, &player)
268
 		if err == nil {
272
 		if err == nil {
269
 			found = true
273
 			found = true
292
 			return errors.New("Can't find player")
296
 			return errors.New("Can't find player")
293
 		}
297
 		}
294
 		err := playerBucket.Delete([]byte(oldName))
298
 		err := playerBucket.Delete([]byte(oldName))
295
-		if err != nil { return err }
299
+		if err != nil {
300
+			return err
301
+		}
296
 		return playerBucket.Put([]byte(newName), buf)
302
 		return playerBucket.Put([]byte(newName), buf)
297
 	})
303
 	})
298
 }
304
 }
299
 
305
 
300
-
301
 func (s *DB) CreatePlayer(name string, password string, flags map[string]bool) (DBRef, error) {
306
 func (s *DB) CreatePlayer(name string, password string, flags map[string]bool) (DBRef, error) {
302
 
307
 
303
 	var playerID DBRef
308
 	var playerID DBRef

+ 64
- 75
execution_context.go View File

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

+ 42
- 27
object.go View File

13
 )
13
 )
14
 
14
 
15
 type PlayerMeta struct {
15
 type PlayerMeta struct {
16
-	ID          DBRef  `json:"id"`
17
-	Password    string `json:"password"`
16
+	ID       DBRef  `json:"id"`
17
+	Password string `json:"password"`
18
 }
18
 }
19
 
19
 
20
 type Object struct {
20
 type Object struct {
21
-
22
 	ID          DBRef             `json:"id"`
21
 	ID          DBRef             `json:"id"`
23
 	Type        string            `json:"type"`
22
 	Type        string            `json:"type"`
24
 	Owner       DBRef             `json:"owner"`
23
 	Owner       DBRef             `json:"owner"`
25
 	Next        DBRef             `json:"next"`
24
 	Next        DBRef             `json:"next"`
26
 	Name        string            `json:"name"`
25
 	Name        string            `json:"name"`
27
 	Description string            `json:"description"`
26
 	Description string            `json:"description"`
28
-	Flags		map[string]bool   `json:"flags"`
27
+	Flags       map[string]bool   `json:"flags"`
29
 	Properties  map[string]string `json:"properties"`
28
 	Properties  map[string]string `json:"properties"`
30
-	
31
-	db    *DB
32
-	
29
+
30
+	db *DB
33
 }
31
 }
34
 
32
 
35
 type ObjectFactory struct {
33
 type ObjectFactory struct {
147
 	r := make([]string, 0)
145
 	r := make([]string, 0)
148
 	children := o.db.GetChildren(o.ID)
146
 	children := o.db.GetChildren(o.ID)
149
 	for childID, linkType := range children {
147
 	for childID, linkType := range children {
150
-		if childID == exclude { continue }
151
-		if !(linkType == "player" || linkType == "thing") { continue }
148
+		if childID == exclude {
149
+			continue
150
+		}
151
+		if !(linkType == "player" || linkType == "thing") {
152
+			continue
153
+		}
152
 		o, found := o.db.Fetch(childID)
154
 		o, found := o.db.Fetch(childID)
153
-		if !found { continue }
154
-		if linkType == "player" && !o.GetFlag("online") { continue }
155
+		if !found {
156
+			continue
157
+		}
158
+		if linkType == "player" && !o.GetFlag("online") {
159
+			continue
160
+		}
155
 		r = append(r, o.DetailedName())
161
 		r = append(r, o.DetailedName())
156
 	}
162
 	}
157
 	sort.Strings(r)
163
 	sort.Strings(r)
162
 	r := make([]string, 0)
168
 	r := make([]string, 0)
163
 	children := o.db.GetChildren(o.ID)
169
 	children := o.db.GetChildren(o.ID)
164
 	for exitID, linkType := range children {
170
 	for exitID, linkType := range children {
165
-		if linkType != "exit" { continue }
171
+		if linkType != "exit" {
172
+			continue
173
+		}
166
 		exit, found := o.db.Fetch(exitID)
174
 		exit, found := o.db.Fetch(exitID)
167
-		if !found { continue }
175
+		if !found {
176
+			continue
177
+		}
168
 		aliases := strings.Split(exit.Name, ";")
178
 		aliases := strings.Split(exit.Name, ";")
169
 		r = append(r, aliases[0])
179
 		r = append(r, aliases[0])
170
 	}
180
 	}
171
-	
181
+
172
 	sort.Strings(r)
182
 	sort.Strings(r)
173
 	return r
183
 	return r
174
 }
184
 }
177
 	if o.Flags == nil {
187
 	if o.Flags == nil {
178
 		o.Flags = make(map[string]bool)
188
 		o.Flags = make(map[string]bool)
179
 	}
189
 	}
180
-	o.Flags[flag]=value
190
+	o.Flags[flag] = value
181
 }
191
 }
182
 
192
 
183
 func (o *Object) GetFlag(flag string) bool {
193
 func (o *Object) GetFlag(flag string) bool {
184
-	
185
-	if o.Flags == nil { return false }
194
+
195
+	if o.Flags == nil {
196
+		return false
197
+	}
186
 	value, ok := o.Flags[flag]
198
 	value, ok := o.Flags[flag]
187
-	if !ok { return false }
188
-	
199
+	if !ok {
200
+		return false
201
+	}
202
+
189
 	return value
203
 	return value
190
 }
204
 }
191
 
205
 
193
 	if o.Properties == nil {
207
 	if o.Properties == nil {
194
 		o.Properties = make(map[string]string)
208
 		o.Properties = make(map[string]string)
195
 	}
209
 	}
196
-	o.Properties[key]=value
210
+	o.Properties[key] = value
197
 }
211
 }
198
 
212
 
199
 func (o *Object) GetProp(key string) string {
213
 func (o *Object) GetProp(key string) string {
200
-	
201
-	if o.Properties == nil { return "" }
214
+
215
+	if o.Properties == nil {
216
+		return ""
217
+	}
202
 	value, ok := o.Properties[key]
218
 	value, ok := o.Properties[key]
203
-	if !ok { return "" }
204
-	
219
+	if !ok {
220
+		return ""
221
+	}
222
+
205
 	return value
223
 	return value
206
 }
224
 }
207
 
225
 
208
-
209
-
210
-
211
 type ObjectList []Object
226
 type ObjectList []Object
212
 
227
 
213
 func (l ObjectList) First() Object {
228
 func (l ObjectList) First() Object {