Begin with loadBalancing

Options
vmarquis
vmarquis
edited July 2014 in Photon Server
Hello

I'm a French devoloppeur and this is my first steep whith Photon

After read the tutorial I decide to use Photon LoadBalancing.

The First thing i have to do is to implement an Operation on the master server to return some information from the database to the client.
After I have to implement a personnal logic for create and joinning game (it's a poker poker game, so the client join a game with a particular cave and a new game is create when there's no place in the existing). And finally implement the game logic in the game server.

Is the good way is to extents the load balancing in a new projet or to modifiy the exiting project.

Best regards

Comments

  • Hey, welcome to Photon! :)

    I would extend loadbalancing in a new project, then you have a clean separation between "our" code and "your" code, and it easier to update to new Photon versions later on.
  • vmarquis
    Options
    Thank Nicole
  • vmarquis
    Options
    Ok I have extends LoadBalancing this way
    namespace PokerLoadBalancing.MasterServer
    {
        class MasterApplication : Photon.LoadBalancing.MasterServer.MasterApplication
        {
            #region Constants and Fields
    
            /// <summary>
            ///   An <see cref = "ILog" /> instance used to log messages to the log4net framework.
            /// </summary>
            private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
    
            #endregion
    
            #region Methods
    
            protected override PeerBase CreatePeer(InitRequest initRequest)
            {
                if (this.IsGameServerPeer(initRequest))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Received init request from game server");
                    }
                    
                    return new Photon.LoadBalancing.MasterServer.GameServer.IncomingGameServerPeer(initRequest, this);
                }
    
                if (this.LocalNodeId == this.MasterNodeId)
                {
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Received init request from game client on leader node");
                    }
    
                    return new PokerMasterClientPeer(initRequest, this.DefaultApplication);
                }
    
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Received init request from game client on slave node");
                }
    
                return new RedirectedClientPeer(initRequest.Protocol, initRequest.PhotonPeer);
            }
    
            #endregion
        }
    }
    

    and implement a PokerMasterClientPeer for handeling the operations I need
    But when I try to run it with my client it don't work, I have nothing in the log.
    My configuration file for this is
    <Applications Default="Master">		
    			<Application
    				Name="Master"
    				BaseDirectory="LoadBalancing\Master"
    				Assembly="PokerLoadBalancing"
    				Type="PokerLoadBalancing.MasterServer.MasterApplication"
    				ForceAutoRestart="true"
    				WatchFiles="dll;config"
    				ExcludeFiles="log4net.config"
    				>
    			</Application>
    
    and I'm sure the client work because when I run the defaut loadBalancing application there's what I expect in the log's
    2014-07-19 10:24:00,823 [11] DEBUG Photon.LoadBalancing.MasterServer.MasterApplication [(null)] - Received init request from game client on leader node
    
    
    2014-07-19 10:24:00,969 [10] DEBUG Photon.LoadBalancing.MasterServer.MasterClientPeer [(null)] - OnOperationRequest: pid=0, op=199
    
    
    Do I miss something I have to implement in my server?


    Best regards
  • vmarquis
    Options
    I have foun'd in the PhotonCLR.log that my application is stop by photon just after starting, I try to understabd why
    2014-07-21 10:08:04,336 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - CreateAppDomain: name = 'Master' , assemblyName = 'PokerLoadBalancing'
    2014-07-21 10:08:04,341 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   ApplicationBase = 'C:\Photon\deploy'
    2014-07-21 10:08:04,346 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   PrivateBinPath = 'C:\Photon\deploy\LoadBalancing\Master\bin;bin_Win64;Shared;'
    2014-07-21 10:08:04,351 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   ConfigurationFile = ''
    2014-07-21 10:08:04,355 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   CachePath = 'C:\Photon\deploy\LoadBalancing\Master\bin\Cache'
    2014-07-21 10:08:04,753 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   ApplicationPath = 'C:\Photon\deploy\LoadBalancing\Master'
    2014-07-21 10:08:04,756 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   BinaryPath = 'C:\Photon\deploy\LoadBalancing\Master\bin'
    2014-07-21 10:08:04,759 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   ApplicationRootPath = 'C:\Photon\deploy'
    2014-07-21 10:08:04,762 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager -   UnmanagedLogPath = 'C:\Photon\deploy\bin_Win64\log'
    2014-07-21 10:08:04,842 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - AssemblyLoadEvent: PokerLoadBalancing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null from file:///C:/Photon/deploy/LoadBalancing/Master/bin/PokerLoadBalancing.DLL
    2014-07-21 10:08:04,845 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - Photon SDK:3.4.22.6309
    2014-07-21 10:08:05,003 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - AssemblyLoadEvent: Photon.LoadBalancing, Version=3.4.22.6309, Culture=neutral, PublicKeyToken=null from file:///C:/Photon/deploy/LoadBalancing/Master/bin/Photon.LoadBalancing.DLL
    2014-07-21 10:08:05,033 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - AssemblyLoadEvent: Photon.SocketServer, Version=3.4.22.6309, Culture=neutral, PublicKeyToken=48c2fa3b6988090e from file:///C:/Photon/deploy/LoadBalancing/Master/bin/Photon.SocketServer.DLL
    2014-07-21 10:08:05,057 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - AssemblyLoadEvent: ExitGamesLibs, Version=1.0.1.0, Culture=neutral, PublicKeyToken=eac0edd9746a4aa0 from file:///C:/Photon/deploy/LoadBalancing/Master/bin/ExitGamesLibs.DLL
    2014-07-21 10:08:05,069 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - AssemblyLoadEvent: System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 from file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
    2014-07-21 10:08:05,074 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - Starting: name = 'Master', assemblyName = 'PokerLoadBalancing', typeName = 'PokerLoadBalancing.MasterServer.MasterApplication'
    2014-07-21 10:08:05,078 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - PhotonRunning: ApplicationName = 'Master', DomainId='6' -- calling Application.Setup
    2014-07-21 10:08:05,088 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - AssemblyLoadEvent: ExitGames.Logging.Log4Net, Version=1.0.1.0, Culture=neutral, PublicKeyToken=eac0edd9746a4aa0 from file:///C:/Photon/deploy/LoadBalancing/Master/bin/ExitGames.Logging.Log4Net.DLL
    2014-07-21 10:08:05,151 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - AssemblyLoadEvent: System.resources, Version=2.0.0.0, Culture=fr, PublicKeyToken=b77a5c561934e089 from file:///C:/WINDOWS/assembly/GAC_MSIL/System.resources/2.0.0.0_fr_b77a5c561934e089/System.resources.dll
    2014-07-21 10:08:05,742 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - RequestStop: ApplicationName = 'Master', DomainId='2' -- calling Application.OnStopRequested()
    2014-07-21 10:08:05,761 [ 6] INFO  PhotonHostRuntime.PhotonDomainManager - Stop: ApplicationName = 'Master', DomainId='2' -- calling Application.TearDown()
    
    
  • vmarquis
    Options
    Ok I have found why my application is stop it was because I have no PokerLoadBalancing.dll.config.
    So this matter is solve but I still have no log of the CreatePeer methode I have override.
    In my log I have
    2014-07-21 11:10:16,423 [12] DEBUG Photon.LoadBalancing.MasterServer.MasterClientPeer [(null)] - OnOperationRequest: pid=0, op=230
    2014-07-21 11:10:16,451 [11] DEBUG Photon.LoadBalancing.MasterServer.MasterClientPeer [(null)] - OnOperationRequest: pid=0, op=229
    2014-07-21 11:10:16,457 [11] DEBUG Photon.LoadBalancing.MasterServer.MasterClientPeer [(null)] - Joined lobby: , 0
    
    
    When I play
    this.connectToMaster(this.appId, "1.0", android_id
    
    in my client

    I have nothing in my log when I play
    public boolean opPlayerLogin()
        {
    
    
    
            PokerPlayer player=this.getPlayer();
            if (this.loadBalancingPeer.getDebugOut().atLeast(DebugLevel.INFO))
            {
                this.loadBalancingPeer.getListener().debugReturn(DebugLevel.INFO, "OpJoinRoom()");
            }
    
            if (player.getLoginMode().getId()==0||(player.getLoginId()==null)||player.getLoginId().length()==0)
            {
                this.loadBalancingPeer.getListener().debugReturn(DebugLevel.INFO, "LoginInvalide");
                return false;
            }
            TypedHashMap<Byte, Object> op = new TypedHashMap<Byte, Object>(Byte.class, Object.class);
    
            op.put(PokerParameterCode.LoginId,player.getLoginId());
            op.put(PokerParameterCode.LoginMode, player.getLoginMode().getId());
            return this.loadBalancingPeer.opCustom(OperationCode.Login, op, true);
        }
    


    I expected to have Received init request from game client on leader node when I play connectToMaster don't understand why I have'nt

    Best regards
  • Hey,

    for the logs:
    - please make sure that you copy the "log4net.config" and "log4net.dll" into your output directory
    - check the log4net.config: is the log level set to "DEBUG" for the classes from which you expect some logging?

    More info on log configuration here:
    http://logging.apache.org/log4net/relea ... ation.html
  • vmarquis
    Options
    Thank Nicole I add
    <logger name="PokerLoadBalancing.MasterServer" additivity="false">
    		<level value="DEBUG" />
    		<appender-ref ref="LogFileAppender" />
    	</logger>
    
    In log4net.config and now it's OK
  • vmarquis
    Options
    Hello

    Ok so my connection with the server work, I handle properly my custum op and interface with my data base.

    Now I need to change the rules for selecting a room (in my poker app you chose a bind and your automatic go to a room with the good bind).

    I see that ExecuteOperation on AppLobby is virtual, it's look good so I do my own implentation.

    The matter is that the AppLobby is access by
    this.Application.LobbyFactory.GetOrCreateAppLobby(joinPokerGameRequest.LobbyName, (AppLobbyType)joinPokerGameRequest.LobbyType, out lobby))
    

    Do I need to extends ApplicationGame, LobbyFactory and may be other or is there a better way?

    Best regards