how custom type in logic sever send data by client ?

Options
my project
are having problems:
2020-09-06 09:44:37,285 [16] ERROR Photon.Hive.HiveGame.HiveHostGame.Plugin - UnhandledException:'Name:PhotonPlugin, Version:1.0 AppId:440A-6127-B81C-3D99-E133-6DFE, AppVersion:'. Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Photon.SocketServer.Rpc.Protocols.GpBinaryByte.GpBinaryByteWriter.WriteCustomType(IBinaryWriter writer, CustomTypeInfo customTypeInfo, Object value) in h:\svncontent\photon-socketserver-sdk_cloud\src\Photon.SocketServer\Rpc\Protocols\GpBinaryByte\GpBinaryByteWriter.cs:line 561
at Photon.SocketServer.Rpc.Protocols.GpBinaryByte.GpBinaryByteWriter.Write(IBinaryWriter writer, Object value, Boolean setType, CustomTypeCache privateCustomTypeCache, Int32 depth) in h:\svncontent\photon-socketserver-sdk_cloud\src\Photon.SocketServer\Rpc\Protocols\GpBinaryByte\GpBinaryByteWriter.cs:line 291
at Photon.SocketServer.Rpc.Protocols.GpBinaryByte.GpBinaryByteWriter.WriteEventData(IBinaryWriter binaryWriter, IEventData eventData, CustomTypeCache privateCustomTypeCache) in h:\svncontent\photon-socketserver-sdk_cloud\src\Photon.SocketServer\Rpc\Protocols\GpBinaryByte\GpBinaryByteWriter.cs:line 79
at Photon.SocketServer.Rpc.Protocols.GpBinaryByte.GpBinaryByteProtocolV16.SerializeEventData(EventData eventData, CustomTypeCache privateCustomTypeCache) in h:\svncontent\photon-socketserver-sdk_cloud\src\Photon.SocketServer\Rpc\Protocols\GpBinaryByte\GpBinaryByteProtocolV16.cs:line 151
at Photon.SocketServer.ApplicationBase.BroadCastEvent[TPeer](IEventData eventData, IEnumerable`1 peers, SendParameters sendParameters) in h:\svncontent\photon-socketserver-sdk_cloud\src\Photon.SocketServer\ApplicationBase.cs:line 357
at Photon.Hive.HiveHostGame.BroadcastEventInternal(Byte evCode, Dictionary`2 data, Byte cacheOp, Boolean updateEventCache, Int32 senderActor, IEnumerable`1 actors, SendParameters sendParameters) in d:\dev\photon-socketserver-sdk_cloud\src-server\Hive\PhotonHive\HiveHostGame.cs:line 396
at Photon.Hive.Plugin.PluginBase.BroadcastEvent(Byte code, Dictionary`2 data) in d:\dev\photon-socketserver-sdk_cloud\src-server\HivePlugin\PluginBase.cs:line 594
at MobaOnline.MobaOnline.ScheduledEvent() in F:\Photon\Photon-OnPremise-Server-Plugin-SDK_v4-0-29-11263\src-server\Plugins\MobaOnline\MobaOnline.cs:line 76
at Photon.Hive.HiveHostGame.<>c__DisplayClass36.<GetTimerAction>b__35() in d:\dev\photon-socketserver-sdk_cloud\src-server\Hive\PhotonHive\HiveHostGame.cs:line 426


I have followed the instructions of the doc photon ,
logic sever:
public override bool SetupInstance(IPluginHost host, Dictionary<string, string> config, out string errorMsg)
{
host.TryRegisterType(typeof(PlayerInfos), (byte)'a', MyCustomType.SerializeCustomPluginType, MyCustomType.DeserializeCustomPluginType);

return base.SetupInstance(host, config, out errorMsg);
}
private void ScheduledEvent()
{
PlayerInfos playerInfos = new PlayerInfos();

playerInfos.HP = 111; playerInfos.MP = 100;


Dictionary<byte, object> dic_data = new Dictionary<byte, object>();
dic_data.Add(2, playerInfos);
BroadcastEvent(10, dic_data);
}

client :
private void Awake()
{
Protocol.TryRegisterType(typeof(PlayerController), (byte)'a', MyCustomType.Serialize, MyCustomType.Deserialize);
}


Can anyone help me solve this problem?

Comments

  • tuanvu
    Options
    this is my script custom data:
    class CustomPluginType
    {
    public int intField;
    public byte byteField ;
    public string stringField;
    }
    class MyCustomType
    {

    public static byte[] SerializeCustomPluginType(object o)
    {
    if (o == null)
    {
    return null;
    }
    CustomPluginType customObject = o as CustomPluginType;
    if (customObject == null) { return null; }
    using (var s = new MemoryStream())
    {
    using (var bw = new BinaryWriter(s))
    {
    bw.Write(customObject.intField);
    bw.Write(customObject.byteField);
    bw.Write(customObject.stringField);
    return s.ToArray();
    }
    }
    }
    public static object DeserializeCustomPluginType(byte[] bytes)
    {
    if (bytes == null)
    {
    return null;
    }
    CustomPluginType customObject = new CustomPluginType();
    using (var s = new MemoryStream(bytes))
    {
    using (var br = new BinaryReader(s))
    {
    customObject.intField = br.ReadInt32();
    customObject.byteField = br.ReadByte();
    customObject.stringField = br.ReadString();
    }
    }
    return customObject;
    }

    }
  • chvetsov
    Options
    hi, @tuanvu

    could you create very basic project with what you do and send it us on developer@photonengine.com ?

    best,
    ilya