Skip to content

trasa/watchmud-message

Repository files navigation

watchmud-message

messages definition for watchmud project

Installing the gRPC toolchain

You need Go 1.14 or better

$ go version

Then install gRPC

$ go get -u google.golang.org/grpc

Install ProtoBuf 3

Option 1: HomeBrew

brew install grpc

Option 2: From zip file

Install protoc plugin for Go

go get -u github.com/golang/protobuf/protoc-gen-go

Install type-registry plugin for Go

go get -u github.com/trasa/type-registry

Verify your path

Make sure that $GOPATH/bin is on your path.

Adding New Messages to watchmud (and the client)

Because I don't do this enough to recall which files to edit each time through.

Add Definition to message.proto

Very straightforward: create the message definition in message.proto and run make (or go generate) so that the go types are written.

You must add the message definition to GameMessage.inner and then define the messages themselves.

Messages should look something like:

message KillRequest {
    string target = 1;
}

message KillResponse {
    bool success = 1;
    string resultCode = 2;
}

Add Server Message Handler

Create a new handler in world package: world/h_kill.go

Add a handler:

package world
import (
	"github.com/trasa/watchmud/gameserver"
    "github.com/trasa/watchmud/message"
)

func (w *World) handleKill(msg *gameserver.HandlerParameter) {
	// TODO
    msg.Player.Send(message.KillResponse{Success:false, ResultCode:"TODO"})
}

Register the handler with the server: world/handlers.go Add the handler method to the world.handlerMap.

Add a Client Message Handler

TODO: make the client handler more dynamic than it is; right now setting up a new handler is too much work ...

Create a handler: h_kill.go

package main

import (
	"github.com/trasa/watchmud/message"
	"fmt"
)

func (c *Client) handleKillResponse(r *message.KillResponse) {
	// TODO
	fmt.Println("Response code should go here.")
}

Add the handler to handler.go and handleIncomingMessage:

switch msg.Inner.(type) {
     // ...
    case *message.GameMessage_KillResponse:
        c.handleKillResponse(msg.GetKillResponse())
     // ...

Add the message line translator

This turns the client string into a message. See message/translator.go

... And the rest is just implementing your feature.

About

messages definition for watchmud project

Resources

License

Stars

Watchers

Forks

Packages

No packages published