Commit 377f0c1f authored by Mo Firouz's avatar Mo Firouz
Browse files

Update Lua proto message name lookup. Merged #86

parent 82020752
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
hash: 26c638eb537a5d88ad12fffd9cb17d69b70548e20db7938623830c129947b1e6
updated: 2017-06-01T13:50:10.856331595+01:00
hash: 00c4318ad08f168ebf525164ff9fb486692a8f72905ef5d514bfe41bb006fb71
updated: 2017-06-29T10:26:44.307843698+01:00
imports:
- name: github.com/armon/go-metrics
  version: 97c69685293dce4c0a2d0b19535179bbc976e4d2
@@ -16,12 +16,17 @@ imports:
- name: github.com/go-yaml/yaml
  version: cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b
- name: github.com/gogo/protobuf
  version: 909568be09de550ed094403c2bf8a261b5bb730a
  version: 100ba4e885062801d56799d78530b73b178a78f3
  subpackages:
  - jsonpb
  - proto
  - sortkeys
  - types
- name: github.com/golang/protobuf
  version: 8ee79997227bf9b34611aee7946ae64735e6fd93
  subpackages:
  - proto
  - protoc-gen-go/descriptor
- name: github.com/gorhill/cronexpr
  version: a557574d6c024ed6e36acc8b610f5f211c91568a
- name: github.com/gorilla/context
@@ -51,7 +56,7 @@ imports:
- name: go.uber.org/atomic
  version: 4e336646b2ef9fc6e47be8e21594178f98e5ebcf
- name: go.uber.org/zap
  version: fab453050a7a08c35f31fc5fff6f2dbd962285ab
  version: 9cabc84638b70e564c3dab2766efcb1ded2aac9f
  subpackages:
  - buffer
  - internal/bufferpool
@@ -71,6 +76,14 @@ imports:
- name: gopkg.in/gorp.v1
  version: c87af80f3cc5036b55b83d77171e156791085e2e
testImports:
- name: github.com/davecgh/go-spew
  version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
  subpackages:
  - spew
- name: github.com/pmezard/go-difflib
  version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
  subpackages:
  - difflib
- name: github.com/stretchr/testify
  version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
  subpackages:
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ import:
  - bcrypt
- package: github.com/golang/protobuf
- package: github.com/gogo/protobuf
  version: ~0.3.0
  version: ~0.4.0
- package: github.com/gorilla/websocket
  version: ~1.0.0
- package: github.com/gorilla/mux
+2 −4
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import (
	"encoding/json"

	"fmt"
	"strings"

	"github.com/gogo/protobuf/jsonpb"
	"github.com/satori/go.uuid"
@@ -102,8 +101,7 @@ func RuntimeAfterHook(logger *zap.Logger, runtime *Runtime, jsonpbMarshaler *jso
}

func RuntimeBeforeHookAuthentication(runtime *Runtime, jsonpbMarshaler *jsonpb.Marshaler, jsonpbUnmarshaler *jsonpb.Unmarshaler, envelope *AuthenticateRequest) (*AuthenticateRequest, error) {
	messageType := strings.TrimPrefix(fmt.Sprintf("%T", envelope.Id), "*server.")
	messageType = strings.TrimSuffix(messageType, "_")
	messageType := RUNTIME_MESSAGES[fmt.Sprintf("%T", envelope.Id)]
	fn := runtime.GetRuntimeCallback(BEFORE, messageType)
	if fn == nil {
		return envelope, nil
@@ -142,7 +140,7 @@ func RuntimeBeforeHookAuthentication(runtime *Runtime, jsonpbMarshaler *jsonpb.M
}

func RuntimeAfterHookAuthentication(logger *zap.Logger, runtime *Runtime, jsonpbMarshaler *jsonpb.Marshaler, envelope *AuthenticateRequest, userId uuid.UUID, handle string, expiry int64) {
	messageType := strings.TrimPrefix(fmt.Sprintf("%T", envelope.Id), "*server")
	messageType := RUNTIME_MESSAGES[fmt.Sprintf("%T", envelope.Id)]
	fn := runtime.GetRuntimeCallback(AFTER, messageType)
	if fn == nil {
		return
+1 −3
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import (

	"nakama/pkg/social"

	"strings"

	"github.com/gogo/protobuf/jsonpb"
	"go.uber.org/zap"
)
@@ -73,7 +71,7 @@ func (p *pipeline) processRequest(logger *zap.Logger, session *session, original
	messageType := fmt.Sprintf("%T", originalEnvelope.Payload)
	logger.Debug("Received message", zap.String("type", messageType))

	messageType = strings.TrimPrefix(messageType, "*server.Envelope_")
	messageType = RUNTIME_MESSAGES[messageType]
	envelope, fnErr := RuntimeBeforeHook(p.runtime, p.jsonpbMarshaler, p.jsonpbUnmarshaler, messageType, originalEnvelope, session)
	if fnErr != nil {
		logger.Error("Runtime before function caused an error", zap.String("message", messageType), zap.Error(fnErr))
+4 −5
Original line number Diff line number Diff line
@@ -185,17 +185,16 @@ func (r *Runtime) NewStateThread() (*lua.LState, context.CancelFunc) {
}

func (r *Runtime) GetRuntimeCallback(e ExecutionMode, key string) *lua.LFunction {
	k := strings.ToLower(key)
	cp := r.vm.Context().Value(CALLBACKS).(*Callbacks)
	switch e {
	case HTTP:
		return cp.HTTP[k]
		return cp.HTTP[key]
	case RPC:
		return cp.RPC[k]
		return cp.RPC[key]
	case BEFORE:
		return cp.Before[k]
		return cp.Before[key]
	case AFTER:
		return cp.After[k]
		return cp.After[key]
	}

	return nil
Loading