PhotonServerPlugin How to use OnRaiseEvent ()
Options
hirakata
✭
tl:dr
Hello. I am a beginner.
I am creating online games with SelfHosted PhotonServer and Unity.
All the tests are in my PC.
I want to do POST from PhotonServer (via HTTP) to Apache HTTP Server using Plugin, but it will not work.
When calling RaiseEvent with Unity, I think Plugin will be called, but is my recognition incorrect?
Or what kind of code is missing?
I referred to the Plugins Manual and SDK samples.
Sample [Photon-OnPremise-Server-SDK \ src-server \ Plugins \ TestPlugins \ SyncAsyncHttpTestPlugin.cs]
Next, I added the following XML node to the file "Photon.LoadBalancing.dll.config" (Photon-OnPremise-Server-SDK \ deploy \ Loadbalancing \ GameServer \ bin)
Also, the following error appears in 'Log' of PhotonServer.
I tried google about the error that occurred, but I could not find anything.
In my code, it seems that the "Outbound HTTP Calls" section of the Plugins Manual is missing.
In that case, how should we incorporate OnHttpResponse () or PostJson ()?
What else should I add?
Thank you for reading.
Hello. I am a beginner.
I am creating online games with SelfHosted PhotonServer and Unity.
All the tests are in my PC.
I want to do POST from PhotonServer (via HTTP) to Apache HTTP Server using Plugin, but it will not work.
When calling RaiseEvent with Unity, I think Plugin will be called, but is my recognition incorrect?
Or what kind of code is missing?
Setting
First of all, I built a plugin and a factory and then built it.I referred to the Plugins Manual and SDK samples.
Sample [Photon-OnPremise-Server-SDK \ src-server \ Plugins \ TestPlugins \ SyncAsyncHttpTestPlugin.cs]
//Plugin Class. namespace Photon.Hive.Plugin { class PluginTest:PluginBase { public override string Name { get { return this.GetType().Name; } } public override void OnRaiseEvent(IRaiseEventCallInfo info) { if (info.Request.EvCode != 3) { var request = new HttpRequest { Async = info.Request.EvCode == 1, Url = "http://192.168.1.5/myphp.php", //LocalHost Callback = this.HttpRequestCallback, UserState = info, }; this.PluginHost.HttpRequest(request); } else { this.PluginHost.BroadcastEvent(ReciverGroup.All, 0, 0, info.Request.EvCode, null, 0); } } private void HttpRequestCallback(IHttpResponse response, object userState) { var info = (IRaiseEventCallInfo)userState; this.PluginHost.BroadcastEvent(ReciverGroup.All, 0, 0, info.Request.EvCode, null, 0); } } }
//Factory Class. using System.Collections.Generic; namespace Photon.Hive.Plugin { public class PluginFactory : Photon.Hive.Plugin.IPluginFactory { public IGamePlugin Create( IPluginHost host, string pluginName, // name of plugin requested by client Dictionary<string, string> config, // plugin settings out string errorMsg) { var plugin = new PluginTest(); if (plugin.SetupInstance(host, config, out errorMsg)) { return plugin; } return null; } } }Next, I placed the build dll in Photon-OnPremise-Server-SDK \ deploy \ Plugins \ PluginTest \ bin.
Next, I added the following XML node to the file "Photon.LoadBalancing.dll.config" (Photon-OnPremise-Server-SDK \ deploy \ Loadbalancing \ GameServer \ bin)
<PluginSettings Enabled="true"> <Plugins> <Plugin Name="PluginTest" AssemblyName="PluginTest.dll" Version="" Type="Photon.Hive.Plugin.PluginFactory" /> </Plugins> </PluginSettings>After setting up so far, if you run PhotonServer (LoadBalancing (MyCloud) - Start as application) and check the log, it seems that the dll you created can be read well.
//Log(part) 2018-12-10 18:44:06,279 [1] INFO Photon.Hive.Plugin.PluginManager - Plugin Type Photon.Hive.Plugin.PluginFactory from assembly PluginTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null was successfuly created 2018-12-10 18:44:06,303 [1] INFO Photon.Hive.Plugin.PluginManager - Plugin manager (version=1.0.15.11060) is setup. type=Photon.Hive.Plugin.PluginFactory;path=C:\MyPhoton\Photon-OnPremise-Server-SDK_v4-0-29-11263\deploy\Plugins\PluginTest\\bin\PluginTest.dll;version=1.0.15.11060Next I wrote the code to send and receive RaiseEvent with Unity.
using UnityEngine; public class PhotonManager : Photon.MonoBehaviour { private enum EEventType : byte { Hello = 1, } private void OnGUI() { GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString()); } void Awake() { PhotonNetwork.OnEventCall += OnRaiseEvent; } private void Start() { PhotonNetwork.autoJoinLobby = true; PhotonNetwork.ConnectUsingSettings("v2.0"); } //Auto Connection. void OnJoinedLobby() { Debug.Log("OnJoinedLobby"); string userId = UnityEngine.Random.Range(0, 100).ToString(); PhotonNetwork.AuthValues = new AuthenticationValues(); PhotonNetwork.AuthValues.UserId = userId; // connect RoomOptions roomOptions = new RoomOptions() { MaxPlayers = 20, IsOpen = true, IsVisible = true, }; PhotonNetwork.JoinOrCreateRoom("room1", roomOptions, null); } void OnJoinedRoom() { Debug.Log("OnJoinedRoom"); } //=========================================Raise========================================= //Raise Send Button Event. public void OnRaiseButton() { var option = new RaiseEventOptions() { CachingOption = EventCaching.DoNotCache, Receivers = ReceiverGroup.All, }; Debug.Log("Raise Send"); PhotonNetwork.RaiseEvent((byte)EEventType.Hello, "Hello!", true, option); } //Receive Raise. private void OnRaiseEvent(byte i_eventcode, object i_content, int i_senderid) { var eventType = (EEventType)i_eventcode; switch (eventType) { case EEventType.Hello: Debug.Log((string)i_content+" SenderId:"+i_senderid); break; default: Debug.Log("default"); break; } } //======================================================================================== }Finally, I set up the Apache side, I would like to access the following PHP file from PhotonServer via Apache.
<?php echo "Myphp Test"; ?>
Error that occurred
Launch Apache & Unity and Raise, the following Debug.Log will appear.
Raise Send
Operation 253 failed in a server-side plugin. Check the configuration in the Dashboard. Message from server-plugin: none of Photon.Hive.Plugin.RaiseEventCallInfo's method were called UnityEngine.Debug:LogError(Object) NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1625) ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[]) ExitGames.Client.Photon.TPeer:DispatchIncomingCommands() ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands() PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:161)
SenderId:-1
Also, the following error appears in 'Log' of PhotonServer.
ERROR Photon.Hive.HiveGame.HiveHostGame.Plugin - MissingCallProcessing for type:Photon.Hive.Plugin.RaiseEventCallInfo in Plugin:'Name:PluginTest, Version:1.0 AppId:C2A0-xxxxxxxx, AppVersion:'.
I tried google about the error that occurred, but I could not find anything.
In my code, it seems that the "Outbound HTTP Calls" section of the Plugins Manual is missing.
In that case, how should we incorporate OnHttpResponse () or PostJson ()?
What else should I add?
Thank you for reading.
0