I am working on my own version of mmo server.
I got the operation request and response communication working between client and server e.g. for a operation to enter the game world.
Now I am struggling with a simple Peer.SendMessage method. On the Unityclient side I receive the message but cannot read it. I get the following error:
ERROR: unexpected msgType 8
UnityEngine.Debug:Log(Object)
JYW.ThesisMMO.UnityClient.Assets.Scripts.Networking.ServerPeerListener:DebugReturn(DebugLevel, String) (at Assets/Scripts/Networking/ServerPeerListener.cs:15)
ExitGames.Client.Photon.<>c__DisplayClass2:b__0()
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:Service()
JYW.ThesisMMO.UnityClient.Assets.Scripts.Networking.Game:Update() (at Assets/Scripts/Networking/Game.cs:37)
What is msgType 8? I haven't found anything in the api docs.
I send the message after a client entered the game world. I send a message to all other clients which are already in the game world like this:
Server code:
Code from the game world:
private Channel<Message> m_MessageChannel = new Channel<Message>();
internal void AddEntity(PlayerEntity entity) {
log.DebugFormat("Adding entity with name: " + entity.Username);
m_Entities[entity.Username] = entity;
var newPlayerEvent = new NewPlayerEvent();
newPlayerEvent.Username = entity.Username;
newPlayerEvent.Position = entity.Position;
IEventData eventData = new EventData((byte)EventCode.NewPlayer, newPlayerEvent);
var sendParameters = new SendParameters { Unreliable = false, ChannelId = 0 };
var message = new Message(eventData, sendParameters);
m_MessageChannel.Publish(message);
}
Peer's op handler:
(SendMessage is subscribed to m_MessageChannel of the game world.)
private void SendMessage(Message message) {
m_Peer.SendMessage(message.eventData, message.sendParameters);
}
The message struct for IChannel:
namespace JYW.ThesisMMO.MMOServer {
using Photon.SocketServer;
internal struct Message {
internal Message(IEventData eventData, SendParameters sendParameters) {
this.eventData = eventData;
this.sendParameters = sendParameters;
}
internal IEventData eventData;
internal SendParameters sendParameters;
}
}
The data contract:
namespace JYW.ThesisMMO.MMOServer.Events {
using Common.Codes;
using Common.Types;
using Photon.SocketServer.Rpc;
class NewPlayerEvent {
[DataMember(Code = (byte)ParameterCode.Username)]
public string Username;
[DataMember(Code = (byte)ParameterCode.Position)]
public Vector Position;
}
}