func (eng *Engine) Do(obj **object.Object, msg *message.Message) { cmd := Commands[msg.Command] if cmd.function == nil { obj.Hear(message.MakeMessage("error", msg.Command+" is not a valid command!")) } else if obj.GetID() != object.DUMMY_ID || cmd.UseUnathenticated() { cmd.function(eng, obj, msg) } else { obj.Hear(message.MakeMessage("error", "You must be logged on to use "+msg.Command)) } }
func (eng *Engine) login(obj **object.Object, msg *message.Message) { player := eng.db.GetPlayer(msg.Data) if player == nil { obj.Hear(message.MakeMessage("error", "No player named %s exists!", msg.Data)) } else { writer := obj.GetWriter() player.SetWriter(writer) player.Hear(message.MakeMessage("result", "Successfully logged in as %s", player.GetAttr("name"))) (*obj) = player player.GetLocation().Emit(message.MakeMessage("emit", "%s has connected!", player.GetAttr("name"))) eng.look(obj, &message.Message{}) } }
func (eng *Engine) move(obj **object.Object, msg *message.Message) { location := obj.GetLocation() exit := location.FindInside("name", msg.Data) if exit != nil && exit.GetType() == object.EXIT { dest := exit.GetLink() location.Emit(message.MakeMessage("emit", "%s left through %s", obj.GetAttr("name"), exit.GetAttr("name"))) obj.Move(dest) dest.Emit(message.MakeMessage("emit", "%s arrived from %s", obj.GetAttr("name"), location.GetAttr("name"))) eng.look(obj, &message.Message{}) } else { obj.Hear(message.MakeMessage("error", "%s not found or not an exit!", msg.Data)) } }
func (eng *Engine) register(obj **object.Object, msg *message.Message) { player := eng.db.GetPlayer(msg.Data) if player != nil { obj.Hear(message.MakeMessage("error", "Player named %s already exists!", msg.Data)) } else { writer := obj.GetWriter() newPlayer := eng.db.CreateObject() newPlayer.SetWriter(writer) newPlayer.SetAttr("name", msg.Data) newPlayer.SetType(object.PLAYER) newPlayer.SetOwner(newPlayer) location := eng.db.GetObject(object.DEFAULT_LOCATION) newPlayer.SetHome(location) newPlayer.Move(location) newPlayer.Hear(message.MakeMessage("result", "Successfully registered as %s", msg.Data)) (*obj) = newPlayer newPlayer.GetLocation().Emit(message.MakeMessage("emit", "%s has connected!", newPlayer.GetAttr("name"))) eng.look(obj, &message.Message{}) } }
func (eng *Engine) pose(obj **object.Object, msg *message.Message) { obj.GetLocation().Emit(message.MakeMessage("emit", "%s %s", obj.GetAttr("name"), msg.Data)) }
func (eng *Engine) shutdown(obj **object.Object, msg *message.Message) { eng.wall(obj, message.MakeMessage("emit", "Server is shutting down now!")) eng.Shutdown() }