Photon server for unity

hi.i'm new on photon for unity.i have a Game project that i have to set the logic for that game in server side and the server handle that logic, not Client.so i switched from PUN to Photon server and now i have these questions:

1-is it possible to make methods with photon server?or develop the photon server??if yes,please link some documentation except yours.i just found one 5 minute video in your site that show how to run photon loadbalancing.and 3 or maybe 4 about photon server setup for unity in youtube.

2-should i have to use PUN for unity??for connecting to photon server.i think i have to.because i had try that.just for sure i asked;

3-i am using Unity for my project.so i have read these articles that show unity security is in low level.
https://www.alanzucconi.com/2015/09/02/a-practical-tutorial-to-hack-and-protect-unity-games/
http://devxdevelopment.com/
so how can i for example handle my game logic in server that no one can't see or reach that even they changed my unity project source code??(this is my main question)

Comments

  • hi, @Aidin0181

    1. to develop server logic we recommend server side plugins. https://doc.photonengine.com/en-us/onpremise/current/plugins/manual
    2. for client side you may use client lib of your choice. PUN of course too.

    best,
    ilya
  • JohnTube
    JohnTube ✭✭✭✭✭
    hi @Aidin0181

    check my comment here.
    do not open multiple support channels next time, you sent an email, asked questions on another forum thread and started a new thread. we can't help you this way.
  • hi john.sry for my spam.i just needed a quick answer.so i tought maby caus of that post i commented there is old,u are not answering.
  • sooooooooo now i have these questions.
    i have used plugin for my server.now i need to know how to send data from server to unity clients or vise versa.i have read somethings in plugin manual page that said i can send event from plugin by using IPluginHost.BroadcastEvent() method.ok that's cool.but how to receive these events sent from plugin?????
  • Aidin0181
    Aidin0181
    edited March 2018
    so i can send message from unity client by calling photonetwork.raiseevet method.and in server i can handle that message on OnRaisedEvent method.now i want to know how to send message or data from server to client and how to receive that message from unity client.
    i think this forum is becoming my note pad (memory) :smile:

  • Aidin0181
    Aidin0181
    edited March 2018
    ok so i got the main idea to send message from plugin to client.but here is the problem.

    from my plugin i used your plugin documentation.
     public override void OnRaiseEvent(IRaiseEventCallInfo info)
            {
                info.Continue();
                if (info.Request.EvCode == 1)
                {
                    PluginHost.LogDebug(info.Request.Data);
                }
                this.RaiseEvent(1, "hello unityyyyyyyyyyyyyyy");
    
            }
            public void RaiseEvent(byte eventCode, object eventData,
                byte receiverGroup = ReciverGroup.All,
                int senderActorNumber = 0,
                byte cachingOption = CacheOperations.DoNotCache,
                byte interestGroup = 0,
                SendParameters sendParams = default(SendParameters))
            {
                Dictionary<byte, object> parameters = new Dictionary<byte, object>();
                parameters.Add(254, eventData);
                parameters.Add(245, senderActorNumber);
                PluginHost.BroadcastEvent(receiverGroup, senderActorNumber, interestGroup, eventCode, parameters, cachingOption, sendParams);
            }


    and from my unity client

        void Awake()
        {
            PhotonNetwork.ConnectUsingSettings("1.5");
            PhotonNetwork.OnEventCall += this.OnEvent;
        }
    
    
        //The void where I receive the events
        private void OnEvent(byte eventcode, object content, int senderid)
        {
            Debug.Log("onEvent");
            Debug.Log(eventcode);
            Debug.Log(content);
            Debug.Log(senderid);
        }
    

    soooooooooo.i can get the eventcode that is 1.
    but i cant get the eventContent(null received).
    and the senderid will be -1 . so it must be 0.
    i dont know............

    anyway these logs out put could be appear when i used default pluginbase broadcaseEvent method.

    when i used your method that add 254 byte to eventContent and 245 to senderActorNum i will get this error from unity .

    InvalidCastException: Cannot cast from source type to destination type.
    NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2378)
    ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff)
    ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
    ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
    PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:153)

    and after a while search in your forum i got nothing :neutral:


    can u help me plz?

    tnx
  • Aidin0181
    Aidin0181
    edited March 2018
    ok.so this is so funny.becaus when i change my raiseEvent content sent from my plugin (change it to int(10)) i worked.but....but.....in my unity when i logged those event i got the eventcode correctly however the content and senderid place changed! soooooooooooooooo wiiiiiiiiiiiiiierd!

    event code : 1 content : 0 sender id : 10

    see???
    it should actually be like this :smile:
    event code : 1 content : 10 sender id : 0

    plz help me if i'm wrong?
  • Aidin0181
    Aidin0181
    edited March 2018
    thank u for answering.is there anybody there?i don't want realtime support.but i have expect you answer me after 2day day. :neutral:
  • Aidin0181
    Aidin0181
    edited March 2018
    i think you should hire me for resolving your framework BUGs.

    in this method
    public void RaiseEvent(byte eventCode, object eventData, 
        byte receiverGroup = ReciverGroup.All, 
        int senderActorNumber = 0, 
        byte cachingOption = CacheOperations.DoNotCache, 
        byte interestGroup = 0, 
        SendParameters sendParams = default(SendParameters))
    {
        Dictionary<byte, object> parameters = new Dictionary<byte, object>();
        parameters.Add(254, eventData);
        parameters.Add(245, senderActorNumber);
        PluginHost.BroadcastEvent(receiverGroup, senderActorNumber, interestGroup, eventCode, parameters, cachingOption, sendParams);
    }
    u should actually change the second or first parameters.add parameters.
    something like this.
        parameters.Add(254, senderActorNumber);
        parameters.Add(245, eventData);
    
    or u will get the wrong result like mine :

    event code : 1 content : 0 sender id : 10

    see???
    it should actually be like this :smile:

    event code : 1 content : 10 sender id : 0

    Thank You for your attention.if u have some time read what i said.
  • Hey, thanks for adding the details.
    Please note
    a) we usually do not answer forum questions on weekends
    b) it would make it easier to read your code, if you could format it as code blocks :wink:
  • Aidin0181
    Aidin0181
    edited March 2018
    okay.this code belongs to your plugin manual page of your web site.

    public void RaiseEvent(byte eventCode, object eventData, byte receiverGroup = ReciverGroup.All, int senderActorNumber = 0, byte cachingOption = CacheOperations.DoNotCache, byte interestGroup = 0, SendParameters sendParams = default(SendParameters)) { Dictionary<byte, object> parameters = new Dictionary<byte, object>(); parameters.Add(254, eventData); parameters.Add(245, senderActorNumber); PluginHost.BroadcastEvent(receiverGroup, senderActorNumber, interestGroup, eventCode, parameters, cachingOption, sendParams); }
    page source : https://doc.photonengine.com/en-us/onpremise/current/plugins/manual

    so in unity when u log this event data u actually get the sender id and vise versa.

    :smile: u have 2 change those values.i hope i could transfer my information to you.

    and i didn't cache you about code block. :blush:



  • I formatted the code blocks in your answers for you, have a look. You can do that with the formatting controls.

    We will have a look and try to get you an answer today.
  • JohnTube
    JohnTube ✭✭✭✭✭
    hi @Aidin0181 thank you for you time and your report.
    we will update the docs with your fix.
    the good thing is that you are now more familiar with how Photon works.
    sorry for the inconvenience.
  • Aidin0181
    Aidin0181
    edited March 2018
    hi @Markus

    thank you for formatting.i will use it on my next comment.
  • hi @JohnTube

    i thought that i was wrong.because with your big company it's impossible to someone wont work with unity and your server SDK and.... wont use your plugin.maybe it's new.but anyway i'm glad to find that issue and i hope don't get in trouble with these issues again.because for this little tiny problem i was searching about 2 days.and no one mentioned that.and if u perform a course or tutorial about your framework not like CJR gaming like unity company about creating games and use the app features your clients will be familiar with your framework sooner(sooooooooooooooooooooneeeeeeeeeeeeer).

    sry :D
  • how does photon handle authenticating???i'm looking at gameserver app for loadbalancing, so clients can join the gameserver directly but is it possible for clients to give operations from gameserver like when they are in master????i mean i configured master server for authenticating clients.so if clients can join gameserver directly what is the benefit of using master server???and how can disable the directly join for gameserver.i mean clinets must first connect to master server then from master server connect to gameserver.
  • how does this piece of code works?????
     protected virtual void HandleAuthenticateOperation(OperationRequest operationRequest, SendParameters sendParameters)
            {
                var request = new AuthenticateRequest(this.Protocol, operationRequest);
                if (this.ValidateOperation(request, sendParameters) == false)
                {
                    return;
                }
    
                if (!string.IsNullOrEmpty(request.Token)
                    )
                {
                    var response = this.HandleAuthenticateTokenRequest(request);
    
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat(
                            "HandleAuthenticateRequest - Token Authentication done. Result: {0}; msg={1}",
                            response.ReturnCode,
                            response.DebugMessage); 
                    }
    
                    this.SendOperationResponse(response, sendParameters);
                    return;
                }
                else
                {
                    this.Disconnect();
                    return;
                }
            }
    i mean for authenticating client in gameserver it use a request.Token .i want to know how does this token will be set?????can client use his token????i disabled authentication type of token from client.so when clients directly connect to gameserver then wont be authenticate and will be disconnect.and i dont know how is it possible for master servers.i mean from master server it will generate a token for connecting to game server and game server will check this token????i dont know.something is wired with this token.
    plz Help me in this case.Tnx
  • i think clients will be get a Token in master server when they will authenticate(i can see the log out put of authenticating in master).so with this token they can connect to game server.and game server will check for token is empty or null and then let client to connect to game server.

    am i saying Right?
  • yes, you are right. you did good work

    best,
    ilya
  • hi again chvetsov.
    thanks for reply.
    i have a project in unity.in my project i have a Register system.so clients for logging in to game server they have to first register.i have some problem here.i can connect to game server directly(in port 5056).and photon loadbalancing will recognize me.and i can give this game server a token.(consider any one can have photon sdk and watch the source code).so game server will let me connect with this token.but i cant get receive those operation response from game server.and my project will let client authenticate in master and let them authenticate as anonymouse user(guest user).in game server i use plugin for each game creation.and in plugin i use User_ID that configured in master server authentication.so for security reason,everyone can connect to game server with any User_ID as anonymouse.and edit that User_ID setting in game server(i'm considering that the clinets can send and receive operations when they directly connect to game server, i didn't try that but i could set the client token with some function in PUN that i cant remember that right now.anyway i'm not gonna mess a alot with photonloadbalancing).for this and one plugin per roomcreation(client's cant connect to multi room) i am connecting client's directly to game server and in game server i have to check again the client Username and password for authentication.as u can see the security is the first point of my project.so....can u guide me a way to handle this better??

    and i read your post in this article

    http://forum.photonengine.com/discussion/comment/34019/#Comment_34019

    and i should tell u that i'm done with networking as i am working alone. :smile:
    i'm not gonna try another photon sdk.because it cost me a lot of time.for this reason if i have to handle networking for my projects i will use my own server or use my customPhotonFramework.
    i mean it will make me so upset when i see your framework and at last i have these problem(multi gaming or authentication security).i'm not saying that your photon is bad.it's so much and so much good as no one need to code some basic networking.but here are the problems with your photon.i'm just saying my Opinion.
  • Aidin0181
    Aidin0181
    edited April 2018
    and another security issue for photon is that anyone can see your DLL's source code.for example: Photon3Unity3d.dll(that this dll contains all functionality for connecting and sending event or operations) .a lot of good decompiler are in internet.for example ILSpy.
    but for For plugins the client's cant do anything as they can just sending event and the hole data can be check in plugins.
  • hi, @Aidin0181

    in settings for master and GS you may find encryption key, which is used to encrypt token. your personal encryption key will protect your GS from unknown tokens. it will not be able to decrypt them.

    our loadbalancing code may still contain some legacy code to support very old clients, you may remove/disable it to get rid of your concerns.

    if i missed some questions, please reask

    best,
    ilya
  • Ok chvetsov,

    i'm ok with encryption.but what can i do with multi gameing?? i mean it is very important to clients can join multi Room in same time.i can see the loadbalancing will send the evenCodes for Creating,Joining or Leaving rooms(227,226,254) . so for connecting clients to game server the master server will send for example event code 227 with datacontract of createGameResponse.
    
     protected virtual OperationResponse HandleCreateGame(MasterClientPeer peer, OperationRequest operationRequest)
            {
                // validate the operation request
                OperationResponse response;
                var operation = new CreateGameRequest(peer.Protocol, operationRequest);
                if (OperationHelper.ValidateOperation(operation, log, out response) == false)
                {
                    return response;
                }
    
                // if no gameId is specified by the client generate a unique id 
                if (string.IsNullOrEmpty(operation.GameId))
                {
                    operation.GameId = Guid.NewGuid().ToString();
                }
               
                // try to create game
                GameState gameState;
                bool gameCreated;
                if (!this.TryCreateGame(operation, operation.GameId, false, operation.GameProperties, out gameCreated, out gameState, out response))
                {
                    return response;
                }
    
                // add peer to game
                gameState.AddPeer(peer);
    
                this.ScheduleCheckJoinTimeOuts();
                log.DebugFormat("on AppLobby for creating room");
                // publish operation response
                var createGameResponse = this.GetCreateGameResponse(peer, gameState);
    
                return new OperationResponse(operationRequest.OperationCode , createGameResponse);
            }
    and this blow code is not full , i just show the important of codes when creating room.i just debugged the load balancing and follow the Codes.
    protected virtual void ExecuteOperation(MasterClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters)
            {
                  switch ((OperationCode)operationRequest.OperationCode)
                     {
                            OperationResponse response;
                                case OperationCode.CreateGame:
                                    response = this.HandleCreateGame(peer, operationRequest);
                      }
    
                peer.SendOperationResponse(response, sendParameters);
             }
    
    so here when peer.SendOperationResponse(response, sendParameters); will be executed by masterPeer that inherited of Peer that inherited of PeerBase.the PeerBase send this OperationRespone to ApplicationBase i think.just watch the Logs:
    
    2018-04-10 14:55:18,670 [14] DEBUG Photon.SocketServer.PeerBase - SentOpResponse: Peer=T:MasterClientPeer,ConnId:0,ip:127.0.0.1:49275, opCode=227, return=0, ChannelId=0 result=Ok size=36 bytes
    2018-04-10 14:55:18,690 [16] DEBUG Photon.SocketServer.ApplicationBase - OnDisconnect - ConnID=0 reasonCode=ClientDisconnect
    2018-04-10 14:55:18,716 [13] DEBUG Photon.SocketServer.PeerBase - Connection state changed from Connected to Disconnected: peer=T:MasterClientPeer,ConnId:0,ip:127.0.0.1:0
    2018-04-10 14:55:18,729 [13] DEBUG Photon.LoadBalancing.MasterServer.MasterClientPeer - Disconnect: pid=0: reason=ClientDisconnect, detail=
    2018-04-10 14:55:18,742 [13] DEBUG Photon.SocketServer.PeerBase - Connection state changed from Disconnected to Disposed: peer=T:MasterClientPeer,ConnId:0,ip:127.0.0.1:0
    and here i cant do anything.becaus the PeerBase is a source code that u have written for this perpose.
    so if u can help me with this issue to not disconnect from master server i will adore you . :smile:
  • i'm not gonna use this way that quickly disconnect client from room and connect him to another room.
    i don'n want this way.i just want to client wont be disconnected when entering Room.
  • well. i just may say that this is not supported by us. client can be in just one room. You need to modify our code to get it working your way. and i can not help you here. because of lack of time

    best,
    ilya
  • :(((((((((((((((((((((((((((((((((((((((((((