trunk
vilmibm 2022-12-21 22:38:15 -08:00
parent 57fd41dedc
commit 89e4c4b095
3 changed files with 40 additions and 18 deletions

View File

@ -249,8 +249,6 @@ func (s *gameWorldServer) Login(ctx context.Context, auth *proto.AuthInfo) (si *
si = &proto.SessionInfo{SessionID: sessionID}
// TODO actually put them in world
return
}
@ -276,8 +274,10 @@ func (s *gameWorldServer) HandleSay(sender *db.Object, msg string) error {
sendErrs := []error{}
// TODO figure out pointer shit
for _, h := range heard {
s.Gateway.VerbHandler(msg, *sender, h)
s.Gateway.VerbHandler("hears", msg, sender, &h)
// TODO once we have a script engine, deliver the HEARS event
for _, sess := range as {
if sess.AccountID == h.OwnerID {

View File

@ -1,16 +1,13 @@
package witch
import (
"log"
"github.com/vilmibm/hermeticum/server/db"
lua "github.com/yuin/gopher-lua"
)
func hasWrapper(obj db.Object) func(*lua.LState) int {
return func(ls *lua.LState) int {
lv := ls.ToTable(1)
log.Printf("%#v", lv)
//lv := ls.ToTable(1)
return 0
}
}
@ -26,17 +23,41 @@ func hearsWrapper(obj db.Object) func(*lua.LState) int {
}
func does(ls *lua.LState) int {
// TODO
// TODO how to feed events back into the server?
// it needs to behave like an event showing up in Commands stream
// this handler needs a reference to the gateway which has a channel for sending events that the server will see?
return 0
}
const addHandler = `
_addHandler = function(verb, pattern, cb)
_handlers[verb] = function(message)
f, l = string.find(message, pattern)
if f != nil
cb(message)
end
end
end
`
/*
string -> fn does not work because there might be multiple handlers for a given verb.
i can:
- have a list of handlers. call each one. it is the handler's
responsibility to decide if it's a match or not.
- store string -> map[string]fn. do the matching in Go.
handlers = {
"hear" = {
"*eat*" = cbfn0
"*slurp*" = cbfn1
}
"see" = {
"*fork*" = cbfn2
}
}
*/
func addHandler(ls *lua.LState) int {
verb := ls.ToString(1)
pattern := ls.ToString(2)
cb := ls.ToFunction(3)
handlers := ls.GetGlobal("_handlers").(*lua.LTable)
newHandler := ls.NewTable()
newHandler.RawSetString(pattern, cb)
handlerMap := handlers.RawGetString(verb).(*lua.LTable)
handlerMap.RawSetString(verb, newHandler)
return 0
}

View File

@ -73,6 +73,7 @@ func newScriptContext(obj db.Object) (*scriptContext, error) {
}
func (sc *scriptContext) Handle(ver, rest string, sender, target *db.Object) error {
// TODO call _handle function from the Lstate
return nil
}