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} si = &proto.SessionInfo{SessionID: sessionID}
// TODO actually put them in world
return return
} }
@ -276,8 +274,10 @@ func (s *gameWorldServer) HandleSay(sender *db.Object, msg string) error {
sendErrs := []error{} sendErrs := []error{}
// TODO figure out pointer shit
for _, h := range heard { 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 // TODO once we have a script engine, deliver the HEARS event
for _, sess := range as { for _, sess := range as {
if sess.AccountID == h.OwnerID { if sess.AccountID == h.OwnerID {

View File

@ -1,16 +1,13 @@
package witch package witch
import ( import (
"log"
"github.com/vilmibm/hermeticum/server/db" "github.com/vilmibm/hermeticum/server/db"
lua "github.com/yuin/gopher-lua" lua "github.com/yuin/gopher-lua"
) )
func hasWrapper(obj db.Object) func(*lua.LState) int { func hasWrapper(obj db.Object) func(*lua.LState) int {
return func(ls *lua.LState) int { return func(ls *lua.LState) int {
lv := ls.ToTable(1) //lv := ls.ToTable(1)
log.Printf("%#v", lv)
return 0 return 0
} }
} }
@ -26,17 +23,41 @@ func hearsWrapper(obj db.Object) func(*lua.LState) int {
} }
func does(ls *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 return 0
} }
const addHandler = ` /*
_addHandler = function(verb, pattern, cb) string -> fn does not work because there might be multiple handlers for a given verb.
_handlers[verb] = function(message)
f, l = string.find(message, pattern) i can:
if f != nil - have a list of handlers. call each one. it is the handler's
cb(message) responsibility to decide if it's a match or not.
end - store string -> map[string]fn. do the matching in Go.
end
end 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 { func (sc *scriptContext) Handle(ver, rest string, sender, target *db.Object) error {
// TODO call _handle function from the Lstate // TODO call _handle function from the Lstate
return nil return nil
} }