Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

Network Message Interpreters

Brent Farris edited this page Apr 12, 2020 · 7 revisions
Directory Previous Next
Directory Network Messages Message Pools

Messages go hand-in-hand with Message Interpreters, for this, you should read up on Network Messages before reviewing this document. That being said, without an interpreter, the Message isn't exactly useful.

Creating an interpreter

When you create any Network Messages you'll notice that the dialog box (seen below) has 3 checkboxes that are directly related to the behavior of the interpreter. When you click on the Create button not only will a message be created, but so will an interpreter. Where the message class will be suffixed with the word Message, the interpreter class will be suffixed with the word Interpreter.

image

Interpret on server: If this checkbox is enabled, then this message is allowed to be interpreted on the server. This means if a client sends this message to the server, it will execute its behavior. If you do not check this box, then the server will ignore this message if it is received.

Interpret on client: If this checkbox is enabled, then this message is allowed to be interpreted on the client. This means if a server sends this message to the client, it will execute its behavior. If you do not check this box, then the client will ignore this message if it is received.

Singleton Interpreter: This is the default and probably isn't something you would want to turn off unless you are an advanced developer in need of creating new instances of this interpreter for the message to be read by. By turning this on, you will still be able to new up the class (for unit tests and any other reasons), so don't worry.

Interpreting a message

The message interpreter will be automatically setup based on the check boxes you selected in the dialog box. The most important thing to take note of here is the Interpret method. Here you will see that there has been a couple of lines auto generated, the more important one being the message being casted to the expected type. From here, you have access to the rest of both your engine and to Forge. You can access Forge through the INetworkMediator netMediator argument, you can identify who sent the message with the EndPoint sender argument, and lastly, you can get to your code (if needed) through the netMediator by accessing the netMediator.EngineProxy member. If you have just setup Forge without modifications, this will return the ForgeEngineFacade class (a class you can alter to what you need or completely replace). Something you'll probably want to do is do some further reading on the Engine Facade.

At this point, you have everything you need to know what message came in, who sent the message, how to reply to the message (if needed) using the netMediator, and access to the rest of your game code through the engine facade. For some examples of how to use the message interpreters, check out the example docs for things like Chat Example, Spawning Example, and Complex Example.

Message interpreter template files

The template system in Forge Alloy is much less a system and much more a file selection and modifying it's contents. The file templates can be located in the Assets/ForgeNetworking/Editor/Resources/ForgeNetworking/Templates folder. As it relates to Messages, you'll see a MessageInterpreterTemplate.txt file and a MessageInterpreterTemplateSingleton.txt. Based on if you select for the interpreter to be a singleton or not will select which of the two templates to use.


Directory Previous Next
Directory Network Messages Message Pools

Home

Getting Started
Network Contract Wizard (NCW)
Network Object
Remote Procedure Calls (RPCs)
Unity Integration
Basic Network Samples
Scene Navigation
NetWorker
Master Server
Web Server
Netcoding Design Patterns
Troubleshooting
Miscellaneous
Forge Networking Alloy
Steamworks
Clone this wiki locally