Step by step operations and events

Nyquest
edited July 2010 in Photon Server
Hello ppls..

I'm new to photon, but not new to the programming world. I am, however, completely self-taught (4 years now....).

I've read through the documentation for photon, and around here on the forums, done several searches for tutorials, guides, etc and etc, and still something is just not clicking with me.

I'm starting to better understand how photon (server side) works to handle events.. the trouble I'm having is, how exactly do I set up these custom operations. Reading around I got some good pointers from threads like THIS ONE for example, but again, something just is not clicking.

What I am interested in is, could someone possibly give a step by step guide on how to extend lite, for example.

To make this as basic as possible, the example should be something like:
(Using Unity and Photon Server SDK)
Client see's button 'button'
Client pushes 'button'
server takes call to MyLiteExtension
handles call to MyOperation.cs
returns MyEvent.cs to client
Client sees Label "Button Pushed" echoed from server.


This would help the photon community immensely I think since the documentation doesn't actually explain any of this.


Any help regarding this step by step procedure would be VERY appreciated!!

Comments

  • There are a few things missing:

    1. The client must talk to the corresponding application (sounds like you called it MyLiteExtension). By default it will talk to Lite and thus not work.

    2. Operations: They are two part. part one is the datacontainer implementation in MyOperation. The second and to me even more important part is the code that does the operation handling actually thats in LiteGame (or its extended) and gets routed there from the Dispatcher

    3. return MyEvent then again is easy (see SetProperties operation handling). Depending on what you do you can even use the operation response (see Join operation for this)

    4. The last step in the equation is that your local game code must handle either the eventaction or the operationresponse for the specific event id you used for MyEvent and alter the client label.


    All this is basically present in the dotnet client and/or the unity client. There though a lot goes directly through events cause if you don't alter anything on the server, which is also the case for your example, you don't want to use operations but events instead which are just relay forwarded by the server.
    Operations are for client requests where you want the server to process something, on which 0 or more clients then get informed in some way on something.
    Also the processing there is important, if you just want to set a permanent value on the game or actor, you would instead use the actor / game properties
  • Thanks for the clarifications.

    I guess the part I'm still struggling with is which files to edit to put in the event id's and how to determine what event id to use. I've tried to understand how this works through the unity3d demo for the 'lite' and for how to build an extension with 'litelobby' but I'm clearly missing something.

    For example, in the 'lite', under operations folder in the VS solution, it shows the operation enums, Join=90 for example.

    What I'm missing is where does Join get linked to the JoinOperation.cs, or doesn't it? I'm completely mixed up on how this is being input.

    I guess what I'm looking for is a breakdown on how to build something like litelobby (since I've read extensions are the way to go), and how to get the server to accept ones operations/events/etc.

    Thanks again for any help!
  • class LitePeer accepts the operationRequest and forwards it to the operationRequestDispatcher.
    There you will find a switch-case for the operationCode.
    Inside the HandleXYZoperation method is then the operation instance created, for instance inside HandleJoinOperation is a new JoinOperation created.
    To add your own operations override LitePeer.OnOperationRequest and use your own operation dispatcher or dispatch it right there.
  • That makes a lot more sense.

    So do I actually need to make use of the enums.cs file? I really know very little in regards to enumerations.

    Thanks again!
  • You don't have to use enums. They just make it easier to change codes if necessary.
  • Thanks,

    I'm getting closer, but still having some issues.
    Nyquest wrote:
    To make this as basic as possible, the example should be something like:
    (Using Unity and Photon Server SDK)
    Client see's button 'button'
    Client pushes 'button'
    server takes call to MyLiteExtension
    handles call to MyOperation.cs
    returns MyEvent.cs to client
    Client sees Label "Button Pushed" echoed from server.

    Don't suppose someone would be kind enough to make a mini-tut step by step version of the above eh? With Dreamora's corrections in the order of events of course (MyEvent.cs for example should not be used since this response should go to the peer only). I never thought I'd really have to have my hand held so much in this field after a few years of practice, but I guess networking at this level is still above me atm. I'm very intent on understanding it and learning it. I wont give up! I just need some basic lessons :/

    Thanks again!
  • Nyquest
    edited July 2010
    After fiddling some more, and re-reading the posts here, I want to double check some thoughts and see if I'm in the right train of thought.

    MyOperation.cs gathers the parameters sent by the client, which is then called from the OperationRequestDispatcher.cs to populate said parameters, but the actual functionality of the code is written in LiteGame.cs?

    The initial opening switch in OperationRequestDispatcher.cs determines which handle to use for the incoming operation, and if an enum is set, you can use the enum code # (like 110 for example) in place of the operation code on the client side to determine what function is being called?

    The on the client side, you create the hashtable to send the paramters to MyOperation.cs with the Peer.OpCustom(byte 110, myHashTable, isSentReliable)?

    Does this make sense? lol

    I will try it now and post my response/errors/etc and see if we can get it worked out with the push button method above. Once I get a working one, I will post the step by step process in some form of tutorial-ish manner that others can improve upon :)

    Thanks,


    Edit:
    minor correction. Looks like LiteGame.cs handles the game-room server-side operations (like joining the peer to the game itself).
    Essentially, I could do all the operation code I need in MyOperation.cs and whatever parameters I want to be passed back I can set at the end of the script, since the PopulateParameters() function should only pick up whatever parameters are set in MyOperation.cs correct?

    oi vei, the more I talk the more wrong I think I actually am :p
  • first part is basically right yeah.

    Reason for the functionality to be in litegame is that the operations commonly not global but related to the current game the player is in.
    Global ones would be implemented in the dispatcher or comparable.


    As for the code of the op: you always use a byte code. you can cast the value of enum (makes it truely unique and easy readable) or using many distinct consts if you want that. So your line there is right aside of the incorrect syntax (it will be peer.Op... and its (byte)110 ;) )
  • edited this top part out for how noob of a mistake it was :p

    dreamora wrote:
    Reason for the functionality to be in litegame is that the operations commonly not global but related to the current game the player is in.
    Global ones would be implemented in the dispatcher or comparable.
    Does this mean that if the code has no relevance to the game itself it does not need to be referenced in LiteGame.cs? Or would that give an error?

    eg- if the code is simply to pass some vars to the sql server, and then pass a completion code back to the player, it should not need to be mentioned at all in LiteGame.cs, yes?
  • dreamora
    dreamora
    edited July 2010
    Technically it should work when its not in there.
    That being said I couldn't think of anything aside of a login procedure to make sense outside of LiteGame at all and even the login can be handled in there technically without a problem

    as for your example: I'm pretty sure that it has some relevance to the game, otherwise there was no reason to fetch and pass the data around, was there?
  • Actually, it's for a registration procedure, in which has no relevance to the game at all since they are only submitting the data to the server and waiting for either approval of the registration, or an error (like Username already taken).

    I appreciate the help, I have not yet got any functions working, but I'm starting to get a far better grasp on the server-side functionality. I'm going to try and get some basic functions working and then I'll re-update this post or ask more questions as necessary. This is actually my first attempt doing networking of this sort.

    Thanks again! :)
  • dreamora wrote:
    ...I couldn't think of anything aside of a login procedure to make sense outside of LiteGame at all and even the login can be handled in there technically without a problem...

    Registration and authorization (login) are not room-relevant. They are the steps (or more drastically: barriers) to pass before you get into any room of a server.
    Highscores, friends lists and other community features also don't affect the room you're in. They simply don't interfere with anyone else you are playing with.