Extending Lite and LiteLobby with Custom App

edited December 2010 in Photon Server
Alright, I have a couple questions about using Lite and LiteLobby with a custom server app (built with the BlankServerSetup).

I would like to use the Lite and LiteLobby applications in my game as well as MyPhotonServer app.

I initially thought that I would have to implement Lite and LiteLobby into the custom server app, but then I remembered that you can open the same connection to the server with a different application name, right? When the Server starts up, it loads each application that you put in the xml config, and you can access the different apps via what you specify with Peer.Connect(ip,appname). Is that correct?

I was wondering if it would make sense to use MyPhotonServer application for custom operations, such as accessing a database, and then use Lite and LiteLobby for their respective functions?

For example, would this pseudocode make sense:
Peer.Connect(ip, "MyPhotonApp");
Login(user,pass); // therefore sending a Peer.OpCustom, and accessing the database on the server through the custom MyPhotonApp.
Peer.Disconnect(); // after receiving the response from server
Peer.Connect(ip,"LiteLobby");
// <execute LiteLobby Op commands>

Is it possible to connect to multiple applications on the same IP with the same Peer? (eg, hold a connection with LiteLobby while opening a new connection to MyPhotonApp)

Also, are LiteLobby and Lite meant to be used together as separate apps in the same game? (LiteLobby for the actual lobby menu, and Lite for the room gameplay) Or does LiteLobby cover Lite's functions as well?

Thanks!

Comments

  • You can't access two apps with the same peer at the same time.
    Also, Lite doesn't check your Login, so it wouldn't be very secure.
    LiteLobby is a Lite extension, basically a sample on how to integrate Lite into your app.
    It seems that for what you want do you should use the same approach: Reference the Lite project with your app and integrate your custom business logic.
  • I see. Well, it seems that LiteLobby would actually do good for my purpose by itself, if I simply integrate my custom app into its solution, instead of integrating LiteLobby and Lite into my custom solution.

    I opened up the LiteLobby and Lite solutions from the src-server files. I'll make a copy of those solutions, edit them to implement my custom logic, and then integrate the customized LiteLobby into the game.

    It makes sense to do it this way, right? I just want to be sure I'm on the right track.

    Thanks.
  • well, there will probably be a couple of updates on Lite and LiteLobby in the future - updating your code can be really hard if you change the existing lite/litelobby code. If you can use a separate project and reference lite/litelobby. The liteLobby project shows how to extend lite using inheritance, the same approach should work for extending litelobby.
  • Okay. I remember reading that about updates somewhere else, but wanted to make sure.

    There are a lot of classes in the Lite and LiteLobby apps, and I'm a little confused on which ones I need to inherit from so that I can customize what I need to, and leave the classes that I don't need to touch alone.

    Here's what I think I need:
    public class CustomApplication : LiteApplication //or LiteLobbyApplication?
    
    public class CustomPeer : LitePeer //or LiteLobbyPeer?
    
    public class OpRequestDispatcher : Lite.OperationRequestDispatcher //or LiteLobby.OperationRequestDispatcher?
    

    Then there are the LiteLobbyRoom and LiteLobbyGame classes, I can't tell if I'd need to inherit and customize those?

    Basically, I want to have it so that, if somewhere down the line, I want to add a different functionality for a particular purpose, I'll be able to with the inheritance.

    Also, would I inherit from the Lite classes, or the LiteLobby classes? (the LiteLobby classes all inherit from the Lite classes, right? So inheriting from the LiteLobby would make more sense?)

    In the game, there is an opening menu to login, then eventually a lobby scene, and then room creation/joining into a realtime match. -- Standard setup, I suppose.

    Thanks.
  • If you want the lobby functionality inherit from LiteLobby.
    Inherit the classes as you listed above, that looks good.
    You need to inherit from LiteLobbyGame etc only if you want to modify the business logic within a lite game (after everyone joined), e.g new operations or events in a game. It doesn't sound as if you need this at this point.
  • Alright, sounds good. I'll try this out and post back later if I run into any issues, thanks :)
  • JNMWIZKID,

    Did you get your project working? I am trying to do something similar to this. Would you mind sharing what you have so far?
  • Hi tito. I've been taking a break from coding recently, but I'll tell you what I know about this project so far--After setting up the blank server, you're going to want to look at the LiteLobby for an example of how to inherit with photon. (src-server folder, I believe) Depending on which package you want to inherit from (Litelobby in this case), you make a CustomPeer and an OperationDispatcher similar to what the LiteLobby looks like. What you need to do (I think, not entirely sure), is override the default Functions, then base.Function the basic lite and litelobby functions that you need to customize, and do some kind of if check on the incoming information to filter your custom commands, and the default commands. Here's an easy example to make the disconnect leave work correctly: (I don't remember the code exactly right now)
    public class CustomPeer : LiteLobbyPeer{
    
    public override void OnDisconnect(){
    base.OnDisconnect();
    }
    
    }
    

    To demonstrate what I'm trying to say with the 'if' to filter your custom information:
    //realistically, you'd use an OpDispatcher here, but:
    
    public override void OnOperationRequest(OperationRequest request){
    if(request.OpCode == 10){ //assuming you have a custom operation with opcode 10
    //handle custom operation
    }
    else{
    base.OnOperationRequest(request);
    }
    }
    
    
    I'm not even sure if the above code will work, wrote it on the spot, but that's the basic idea that I ran into (not sure if it's the right approach, still have more to experiment).

    Also, I'm running into some bugs right now with some of the default commands, but like I said, I've been taking a break recently.

    I'll get into this more some other time. Good luck :)
  • Thank you very much for the insight. I finally got a client and server communicating yesterday. Sending data back and forth. Got some help from Boris. What you wrote makes alot of sense.
  • Glad to have helped :)
Sign In or Register to comment.