Sending messages to the server

edited July 2010 in Photon Server
I am trying to learn Photon and I am finding it pretty hard to do so. There isn't alot of documentation and what there is I am not finding to helpful. For a small project in Learning Server side programming with Photon I thought I would send a message from the client to the server and when the server recieves the message have it print out some text to the debug file.

I use peer.OpCustom(110,values,true); in the client. 110 is the number assigned in Photon.MMODemo.Common OperationCode.cs: TestOperation = 110

I then have a method named TestOperation in Photon.MMODemo.Client.DotNet Operations.cs:
public static void TestOperation(Game game, string message)
        {
            var data = new Hashtable();
            data["Message"] = message;
            game.SendOperation(OperationCode.TestOperation, data, true, Settings.ItemChannel);
            System.Console.Write("Test message");
            game.DebugReturn("test");
        }

So now from here what else do I need to do in order to get this to work?

Comments

  • Operations.cs is not the class where all operations are defined. Instead, it's a base class to extend. RaiseEventOperation.cs is one example for that.
    So you create your own class of operation and assign it the code 110. All operations are piped through the LitePeer to OperationRequestDispatcher.DispatchOperationRequest(). The code that's there can be extended to handle your code 110 and create an operation from it. As you just log, you could execute this immediately. Add your TestOperation to the dispatcher class and call it.
  • I am trying to learn Photon and I am finding it pretty hard to do so. There isn't a lot of documentation and what there is I am not finding to helpful.

    I have to agree with you, understand photon is certainly a learning curve and it really depends on your on your debug skills and previous network server side programming knowledge.

    Im learning Photon for around 2 weeks already and 90% of the time I spend tracing back function calls and events to try to understand what happens when and how.
    You can see me bothering the dev team in some posts like this one:
    viewtopic.php?f=5&t=69

    I have no previous knowledge of network programming but ive checked around other servers on the net and photon is in a way more complex the others that Ive seen, but I like it as I know I will use many of its built in functionalities

    Im also not learning much from the help file that comes with the server, it looks like to be built from the source code of the server somehow. Its good that I can see all the methods and properties but there is no examples.
    Im posting many questions here on the forums because im sure more ppl will come here and have the same doubts and i think this will help them for now.

    I guess that I can say that im my opinion learning photon is hard and takes a lot of time.
    I dont mean to be giving out to exit games or to the dev team, god no by no means, I guess im just trying to give a client feedback.
    I would love to have examples and more documentation to understand the architecture a bit better, I say that because there is a lot that happens for one event to happen.

    Would be nice to see things explained in steps of the behind the scenes of at least the most common things that happens in a game, like what happens, and where, when a player joins the server, when it enters a world, also some how-to's: how to extend a class and what it will need to communicate properly etc...
    I think those kind of situations are quite common in most games and would be nice as they would give some ideas to better understand the server when one tries to use it for the first few times.

    I think Photon is great, its the right choice for me for my future games.
    I wonder what helped other developers when they made their games with this serve, for example for the games Paradise Paintball, Pig Tanks, World Golf and Freaky creatures.

    DId those ppl had previous knowledge of the server, or at least network programming in general?
    Its so hard to find information about network programming on the internet.
  • BorisBoris ✭✭
    @Tobias: it seems that mmointeractive extends the mmo demo, and not lite.
    @MmoInteractive: Ignoring Tobias Post the MmoPeer is itself the first operation handler for peers. There is a switch-case on operationrequest.operationcode in that class.
    @Zoultrex: Thanks for the feedback. We are trying to make it as easy as possible, but obviously there is still room for improvement. Keep posting questions, so we know what to work on.
  • Ok what am I doing wrong here now? I am trying to send variables to the server:
    var login = new Hashtable()
                    {
                        {(byte)ParameterCode.Username, "James"},
                        {(byte)ParameterCode.Password, "jamesp"}
                    };
            peer.OpCustom((byte)OperationCode.TestOperation, login, true);
    

    This code right here results in the following error:

    System.InvalidCastException: Cannot cast from source type to destination type.

    at ExitGames.Client.Protocol.serializeParameters (System.Collections.Hashtable _parameters, Boolean useDummy, Byte opCode, Int16 invocID, System.Byte[] header) [0x00000]

    at ExitGames.Client.Photon.NConnect.serialiseOperation (System.Collections.Hashtable parameters, Byte opc) [0x00000]

    at ExitGames.Client.Photon.EnetPeer.sendOperation (System.Collections.Hashtable parameters, Byte opCode, Boolean sendReliable, Byte channelId) [0x00000]

    at ExitGames.Client.Photon.PhotonPeer.OpCustom (Byte customOpCode, System.Collections.Hashtable customOpParameters, Boolean sendReliable, Byte channelId) [0x00000]

    at ExitGames.Client.Photon.PhotonPeer.OpCustom (Byte customOpCode, System.Collections.Hashtable customOpParameters, Boolean sendReliable) [0x00000]

    at MmoEngine.OnConnect (Photon.MmoDemo.Client.Game game) [0x00000]

    at Photon.MmoDemo.Client.Game.SetConnected () [0x00000]

    at Photon.MmoDemo.Client.GameStateStrategies.WaitingForConnect.OnPeerStatusCallback (Photon.MmoDemo.Client.Game game, ReturnCode returnCode) [0x00000]

    at Photon.MmoDemo.Client.Game.PeerStatusCallback (Int32 returnCode) [0x00000]
    UnityEngine.Debug:Log(Object)
    MmoEngine:LogError(Game, Exception)
    Photon.MmoDemo.Client.Game:PeerStatusCallback(Int32)
    ExitGames.Client.Photon.PeerBase:InitCallback()
    ExitGames.Client.Photon.NConnect:deserializeNeutron(Byte[])
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.EnetPeer:Service()
    ExitGames.Client.Photon.PhotonPeer:Service()
    Photon.MmoDemo.Client.GameStateStrategies.WaitingForConnect:OnUpdate(Game)
    Photon.MmoDemo.Client.Game:Update()
    MmoEngine:Update()
  • BorisBoris ✭✭
    strange, the code looks correct. Are you sure you did really cast all parameter keys to byte?
  • That is a copy and paste from my client code. So yes I am sure I did. and then in Parametercode.cs I added the password one and gave it a value of 112:

    Password = 112

    Username was already in there so that is set correctly.
  • BorisBoris ✭✭
    serializeParameters casts the hashtable keys to byte, there are no other casts.
    Since you put only bytes in there I am very surprised that it's supposed to cause this error.
    Did you try removing the operation call and check if it the error then vanishes?
  • BorisBoris ✭✭
    public static void TestOperation(Game game, string message)
            {
                var data = new Hashtable();
                data["Message"] = message;
                game.SendOperation(OperationCode.TestOperation, data, true, Settings.ItemChannel);
                System.Console.Write("Test message");
                game.DebugReturn("test");
            }
    
    I do expect an InvalidCastException from this code.
  • I got it working heres what I now have:

    Hashtable login = new Hashtable();
    login.Add((byte)ParameterCode.Username, "James");
    login.Add((byte)ParameterCode.Password, "jamesp");

    peer.OpCustom((byte)OperationCode.TestOperation, login, true);
  • BorisBoris ✭✭
    var login = new Hashtable()
                    {
                        {(byte)ParameterCode.Username, "James"},
                        {(byte)ParameterCode.Password, "jamesp"}
                    };
    
    I wonder if these redundant parentheses in "Hashtable()" have anything to do with it.. maybe a mono bug?
  • Not sure. With out the parentheses Unity was giving me some errors which is why I added them.
  • You need the parenthesis there for .Net 2 / unity (not using them is a functionality of .NET 3 or even 3.5 where anonymous objects etc were introduced, at least as far as I know)

    new Hashtable() is a constructor that creates the object for you.
    { ... } then fills it with init data.

    that being said: as long as you don't use js in unity you can't use it this way anyway out of my experience, you would have
    Hashtable login = new Hashtable();
    login.Add( ... );
    login.Add( ... );
    
  • Ok What does this error mean?
    Unity: unexpected operation error OperationNotSupported from operation NpcClicked in state WorldEntered
    UnityEngine.Debug:Log(Object)
    MmoEngine:LogError(Game, String)
    Photon.MmoDemo.Client.Game:OnUnexpectedOperationError(OperationCode, ErrorCode, String, Hashtable)
    Photon.MmoDemo.Client.GameStateStrategies.WorldEntered:OnOperationReturn(Game, OperationCode, ReturnCode, Hashtable)
    Photon.MmoDemo.Client.Game:OperationResult(Byte, Int32, Hashtable, Int16)
    ExitGames.Client.Photon.NConnect:deserializeNeutron(Byte[])
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.EnetPeer:Service()
    ExitGames.Client.Photon.PhotonPeer:Service()
    Photon.MmoDemo.Client.GameStateStrategies.WorldEntered:OnUpdate(Game)
    Photon.MmoDemo.Client.Game:Update()
    MmoEngine:Update()
    

    I am trying to get it setup so that when a player clicks on a npc a dialog box comes up. When the npc is clicked on it will send a message to the server saying the npc was clicked on then the server will send back a response containing what the NPC should say. Once the client gets the response the dialog will open containing what the npc says.

    The message is never being sent to the server. I have it setup exactly like my other messages that successfully get sent to the server so I don't understand why it's now not working.
  • BorisBoris ✭✭
    "OperationNotSupported" is the response from the server.
    It means that you aren't dispatching your custom operation.
    Check MmoActor.OnOperationRequest, there is a switch-case on operationRequest.OperationCode.
    Add your server logic here.
Sign In or Register to comment.