WIP on look handler
parent
9b7e92c118
commit
f4934e28f3
|
@ -109,7 +109,7 @@ func (s *gameWorldServer) verbHandler(verb, rest string, sender, target db.Objec
|
|||
sid, _ := s.db.SessionIDForAvatar(target)
|
||||
serverAPI := witch.ServerAPI{
|
||||
Show: func(_ int, _ string) {},
|
||||
Tell: func(_ int, _ string) {},
|
||||
Tell: func(_ int, _ string) { log.Println("stub tell called") },
|
||||
DB: func() db.DB {
|
||||
return s.db
|
||||
},
|
||||
|
@ -137,6 +137,7 @@ func (s *gameWorldServer) verbHandler(verb, rest string, sender, target db.Objec
|
|||
send(&cm)
|
||||
}
|
||||
serverAPI.Tell = func(senderID int, msg string) {
|
||||
log.Printf("Tell %s %d %s", sid, senderID, msg)
|
||||
cm := proto.ClientMessage{
|
||||
Type: proto.ClientMessage_OVERHEARD,
|
||||
Text: msg,
|
||||
|
@ -239,6 +240,10 @@ func (s *gameWorldServer) Commands(stream proto.GameWorld_CommandsServer) error
|
|||
return s.HandleError(send, err)
|
||||
}
|
||||
|
||||
for _, obj := range affected {
|
||||
log.Printf("%s heard %s from %d", obj.Data["name"], cmd.Verb, avatar.ID)
|
||||
}
|
||||
|
||||
for _, o = range affected {
|
||||
if err = s.verbHandler(cmd.Verb, cmd.Rest, *avatar, o); err != nil {
|
||||
log.Printf("error handling verb %s for object %d: %s", cmd.Verb, o.ID, err)
|
||||
|
|
|
@ -113,9 +113,11 @@ func (db *pgDB) Ensure() error {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO for some reason, when the seen() callback runs for foyer we're calling the stub Tell instead of the sid-closured Tell. figure out why.
|
||||
|
||||
roomScript := `
|
||||
seen(function()
|
||||
tellSender(my("description"))
|
||||
tellMe(my("description"))
|
||||
end)
|
||||
`
|
||||
|
||||
|
@ -426,7 +428,8 @@ func (db *pgDB) Earshot(obj Object) ([]Object, error) {
|
|||
WHERE id IN (
|
||||
SELECT contained FROM contains
|
||||
WHERE container = (
|
||||
SELECT container FROM contains WHERE contained = $1 LIMIT 1))`
|
||||
SELECT container FROM contains WHERE contained = $1 LIMIT 1))
|
||||
OR id = (SELECT container FROM contains WHERE contained = $1 LIMIT 1)`
|
||||
rows, err := db.pool.Query(context.Background(), stmt, obj.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -12,18 +12,18 @@ func witchHas(l *lua.LState) int {
|
|||
// TODO provides
|
||||
|
||||
func witchHears(l *lua.LState) int {
|
||||
return addHandler(l, "say")
|
||||
return addPatternHandler(l, "say")
|
||||
}
|
||||
|
||||
func witchSees(l *lua.LState) int {
|
||||
return addHandler(l, "emote")
|
||||
return addPatternHandler(l, "emote")
|
||||
}
|
||||
|
||||
func witchGo(l *lua.LState) int {
|
||||
// TODO get the handler map
|
||||
// - check if handler map has a Go handler already, exit early if so
|
||||
// TODO register this object as an exit in DB
|
||||
return addHandler(l, "go")
|
||||
return addPatternHandler(l, "go")
|
||||
}
|
||||
|
||||
func witchSeen(l *lua.LState) int {
|
||||
|
@ -45,8 +45,29 @@ func witchDoes(ls *lua.LState) int {
|
|||
}
|
||||
|
||||
func addHandler(l *lua.LState, verb string) int {
|
||||
pattern := l.ToString(1)
|
||||
cb := l.ToFunction(2)
|
||||
pattern := ".*"
|
||||
cb := l.ToFunction(1)
|
||||
|
||||
//log.Printf("adding handler: %s %s %#v", verb, pattern, cb)
|
||||
|
||||
handlers := l.GetGlobal("_handlers").(*lua.LTable)
|
||||
|
||||
verbHandlers, ok := handlers.RawGetString(verb).(*lua.LTable)
|
||||
if !ok {
|
||||
verbHandlers = l.NewTable()
|
||||
handlers.RawSetString(verb, verbHandlers)
|
||||
}
|
||||
|
||||
verbHandlers.RawSetString(pattern, cb)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func addPatternHandler(l *lua.LState, verb string) int {
|
||||
pattern := l.ToString(1)
|
||||
cb := l.ToFunction(2)
|
||||
|
||||
//log.Printf("adding handler: %s %s %#v", verb, string(pattern), cb)
|
||||
|
||||
handlers := l.GetGlobal("_handlers").(*lua.LTable)
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ func NewScriptContext(sAPI ServerAPI) (*ScriptContext, error) {
|
|||
l.SetGlobal("tellMe", l.NewFunction(func(l *lua.LState) int {
|
||||
sender := l.GetGlobal("sender").(*lua.LTable)
|
||||
senderID := int(lua.LVAsNumber(sender.RawGetString("ID")))
|
||||
log.Printf("tellMe: %d %s", senderID, l.ToString(1))
|
||||
sc.serverAPI.Tell(senderID, l.ToString(1))
|
||||
return 0
|
||||
}))
|
||||
|
@ -109,7 +110,7 @@ func NewScriptContext(sAPI ServerAPI) (*ScriptContext, error) {
|
|||
}))
|
||||
|
||||
// TODO check execute permission and bail out potentially
|
||||
log.Printf("%#v", vc)
|
||||
//log.Printf("%#v", vc)
|
||||
|
||||
senderT := l.NewTable()
|
||||
senderT.RawSetString("name", lua.LString(vc.Sender.Data["name"]))
|
||||
|
|
Loading…
Reference in New Issue