Esempio n. 1
0
        void HandleRequestSpawnStart(InsightNetworkMessage netMsg)
        {
            RequestSpawnStartMsg message = netMsg.ReadMessage <RequestSpawnStartMsg>();

            //Try to start the new process
            if (!InternalStartNewProcess(message))
            {
                netMsg.Reply((short)MsgId.Error, new ErrorMsg()
                {
                    Text = "[ProcessSpawner] - Spawn failed"
                });
            }

            if (netMsg.callbackId != 0)
            {
                netMsg.Reply((short)MsgId.RequestSpawnStart, new RequestSpawnStartMsg()
                {
                    //If the UniqueID is not provided in the MSG it is generated by the spawner
                    //Should that be passed back and used here?

                    SceneName      = message.SceneName,
                    NetworkAddress = SpawnerNetworkAddress,
                    UniqueID       = message.UniqueID
                });
            }
        }
Esempio n. 2
0
        void CreateMatch()
        {
            //Used to track completion of requested spawn
            string uniqueID = Guid.NewGuid().ToString();

            //Specify the match details
            RequestSpawnStartMsg requestSpawnStart = new RequestSpawnStartMsg()
            {
                //This should not be hard coded. Where should it go?
                SceneName = "SuperAwesomeGame",
                UniqueID  = uniqueID
            };

            List <UserContainer> matchUsers = new List <UserContainer>();

            //This should check to make sure that the max players is not higher than the number in queue
            //Add the players from the queue into this match:
            for (int i = playerQueue.Count - 1; i >= 0; i--)
            {
                matchUsers.Add(playerQueue[i]);
                playerQueue.RemoveAt(i);
            }

            matchList.Add(new MatchContainer(this, requestSpawnStart, matchUsers));
        }
Esempio n. 3
0
 public MatchContainer(ServerMatchMaking MatchModule, RequestSpawnStartMsg MatchProperties, List <UserContainer> MatchUsers)
 {
     matchModule     = MatchModule;
     matchProperties = MatchProperties;
     matchModule.gameManager.RequestGameSpawnStart(matchProperties);
     matchUsers     = MatchUsers;
     matchStartTime = DateTime.UtcNow;
 }
Esempio n. 4
0
        bool InternalStartNewProcess(RequestSpawnStartMsg spawnProperties)
        {
            int thisPort = GetPort();

            if (thisPort == -1)
            {
                return(false);
            }

            //If a UniqueID was not provided add one for GameResitration
            if (string.IsNullOrEmpty(spawnProperties.UniqueID))
            {
                spawnProperties.UniqueID = Guid.NewGuid().ToString();

                Debug.LogWarning("[ProcessSpawner] - UniqueID was not provided for spawn. Generating: " + spawnProperties.UniqueID);
            }

            Process p = new Process();

            // Put the process path and the process name together. We use
            // Path.Combine for this, which will include correct directory
            // seperators on the OS we're running on (ie. C:\Game\ or /Game/ )
            p.StartInfo.FileName = System.IO.Path.Combine(ProcessPath, ProcessName);
            //Args to pass: Port, Scene, UniqueID...
            p.StartInfo.Arguments = ArgsString() +
                                    " -NetworkAddress " + SpawnerNetworkAddress +
                                    " -NetworkPort " + (StartingNetworkPort + thisPort * allocatedPorts) +
                                    " -SceneName " + spawnProperties.SceneName +
                                    " -UniqueID " + spawnProperties.UniqueID; //What to do if the UniqueID or any other value is null??

            if (p.Start())
            {
                Debug.Log("[ProcessSpawner]: spawning: " + p.StartInfo.FileName + "; args=" + p.StartInfo.Arguments);
            }
            else
            {
                Debug.LogError("[ProcessSpawner] - Process Creation Failed.");
                return(false);
            }

            //Update the collection with newly started process
            spawnerProcesses[thisPort] = new RunningProcessContainer()
            {
                process = p, pid = p.Id, uniqueID = spawnProperties.UniqueID
            };

            //If registered to a master. Notify it of the current thread utilization
            if (client != null)
            {
                client.Send(new SpawnerStatusMsg()
                {
                    CurrentThreads = GetRunningProcessCount()
                });
            }

            return(true);
        }
Esempio n. 5
0
 protected RequestSpawnStartMsg(RequestSpawnStartMsg _original)
 {
     gameUniqueId   = _original.gameUniqueId;
     networkAddress = _original.networkAddress;
     networkPort    = _original.networkPort;
     gameName       = _original.gameName;
     minPlayers     = _original.minPlayers;
     maxPlayers     = _original.maxPlayers;
 }
Esempio n. 6
0
        bool InternalStartNewProcess(RequestSpawnStartMsg spawnProperties)
        {
            if (spawnerProcesses.Count >= MaximumProcesses)
            {
                UnityEngine.Debug.LogError("[ProcessSpawner] - Maximum Process Count Reached");
                return(false);
            }

            //If a UniqueID was not provided add one for GameResitration
            if (string.IsNullOrEmpty(spawnProperties.UniqueID))
            {
                spawnProperties.UniqueID = Guid.NewGuid().ToString();

                UnityEngine.Debug.LogWarning("[ProcessSpawner] - UniqueID was not provided for spawn. Generating: " + spawnProperties.UniqueID);
            }

            Process p = new Process();

            p.StartInfo.FileName = ProcessPath + ProcessName;
            //Args to pass: Port, Scene, UniqueID...
            p.StartInfo.Arguments = ArgsString() +
                                    " -NetworkAddress " + SpawnerNetworkAddress +
                                    " -NetworkPort " + (StartingNetworkPort + _portCounter) +
                                    " -SceneName " + spawnProperties.SceneName +
                                    " -UniqueID " + spawnProperties.UniqueID; //What to do if the UniqueID or any other value is null??

            if (p.Start())
            {
                print("[ProcessSpawner]: spawning: " + p.StartInfo.FileName + "; args=" + p.StartInfo.Arguments);

                //Increment port after sucessful spawn.
                _portCounter++;

                //If registered to a master. Notify it of the current thread utilization
                if (client != null)
                {
                    client.Send((short)MsgId.SpawnerStatus, new SpawnerStatusMsg()
                    {
                        CurrentThreads = spawnerProcesses.Count
                    });
                }

                spawnerProcesses.Add(new RunningProcessStruct()
                {
                    process = p, pid = p.Id, uniqueID = spawnProperties.UniqueID
                });
                return(true);
            }
            else
            {
                UnityEngine.Debug.LogError("[ProcessSpawner] - Process Createion Failed.");
                return(false);
            }
        }
Esempio n. 7
0
        bool InternalStartNewProcess(RequestSpawnStartMsg spawnProperties)
        {
            int thisPort = GetPort();

            if (thisPort == -1)
            {
                return(false);
            }

            //If a UniqueID was not provided add one for GameResitration
            if (string.IsNullOrEmpty(spawnProperties.UniqueID))
            {
                spawnProperties.UniqueID = Guid.NewGuid().ToString();

                logger.LogWarning("[ProcessSpawner] - UniqueID was not provided for spawn. Generating: " + spawnProperties.UniqueID);
            }

            Process p = new Process();

            p.StartInfo.FileName = ProcessPath + ProcessName;
            //Args to pass: Port, Scene, UniqueID...
            p.StartInfo.Arguments = ArgsString() +
                                    " -NetworkAddress " + SpawnerNetworkAddress +
                                    " -NetworkPort " + (StartingNetworkPort + thisPort) +
                                    " -SceneName " + spawnProperties.SceneName +
                                    " -UniqueID " + spawnProperties.UniqueID; //What to do if the UniqueID or any other value is null??

            if (p.Start())
            {
                logger.Log("[ProcessSpawner]: spawning: " + p.StartInfo.FileName + "; args=" + p.StartInfo.Arguments);
            }
            else
            {
                logger.LogError("[ProcessSpawner] - Process Createion Failed.");
                return(false);
            }

            //If registered to a master. Notify it of the current thread utilization
            if (client != null)
            {
                client.Send(new SpawnerStatusMsg()
                {
                    CurrentThreads = GetRunningProcessCount()
                });
            }

            spawnerProcesses[thisPort] = new RunningProcessContainer()
            {
                process = p, pid = p.Id, uniqueID = spawnProperties.UniqueID
            };
            return(true);
        }
Esempio n. 8
0
        private void SendToSpawner(int _connectionId, RequestSpawnStartMsg _message, CallbackHandler _callback = null)
        {
            var message = new RequestSpawnStartToSpawnerMsg(_message);

            if (_connectionId == 0)
            {
                server.InternalSend(message, _callback);
            }
            else
            {
                server.NetworkSend(_connectionId, message, _callback);
            }
        }
Esempio n. 9
0
        //Instead of handling the msg here we will forward it to an available spawner.
        void HandleSpawnRequestMsg(InsightNetworkMessage netMsg)
        {
            if (registeredSpawners.Count == 0)
            {
                logger.LogWarning("[MasterSpawner] - No Spawner Regsitered To Handle Spawn Request");
                return;
            }

            RequestSpawnStartMsg message = netMsg.ReadMessage <RequestSpawnStartMsg>();

            //Get all spawners that have atleast 1 slot free
            List <SpawnerContainer> freeSlotSpawners = new List <SpawnerContainer>();

            foreach (SpawnerContainer spawner in registeredSpawners)
            {
                if (spawner.CurrentThreads < spawner.MaxThreads)
                {
                    freeSlotSpawners.Add(spawner);
                }
            }

            //sort by least busy spawner first
            freeSlotSpawners = freeSlotSpawners.OrderBy(x => x.CurrentThreads).ToList();
            server.SendToClient(freeSlotSpawners[0].connectionId, message, (reader) =>
            {
                RequestSpawnStartMsg callbackResponse = reader.ReadMessage <RequestSpawnStartMsg>();

                if (callbackResponse.Status == CallbackStatus.Success)
                {
                    logger.Log("[Spawn Callback] Game Created on Child Spawner: " + callbackResponse.UniqueID);

                    //If callback from original message is present
                    if (netMsg.callbackId != 0)
                    {
                        netMsg.Reply(callbackResponse);
                    }
                }
                if (callbackResponse.Status == CallbackStatus.Timeout)
                {
                    logger.Log("[Spawn Callback] Createion Timed Out: " + callbackResponse.UniqueID);
                }
                if (callbackResponse.Status == CallbackStatus.Error)
                {
                    logger.Log("[Spawn Callback] Error in SpawnRequest.");
                }
            });
        }
Esempio n. 10
0
        public void InternalSpawnRequest(RequestSpawnStartMsg message)
        {
            //Get all spawners that have atleast 1 slot free
            List <SpawnerContainer> freeSlotSpawners = registeredSpawners.Where(x => (x.CurrentThreads < x.MaxThreads)).ToList();

            if (freeSlotSpawners.Count == 0)
            {
                Debug.LogError("[MasterSpawner] - No Spawners with slots free available to service SpawnRequest.");
                return;
            }

            //sort by least busy spawner first
            freeSlotSpawners = freeSlotSpawners.OrderBy(x => x.CurrentThreads).ToList();

            //Send SpawnRequest to the least busy Spawner
            server.SendToClient(freeSlotSpawners[0].connectionId, (short)MsgId.RequestSpawnStart, message);
        }
Esempio n. 11
0
 //Used by MatchMaker to request a GameServer for a new Match
 public void RequestGameSpawnStart(RequestSpawnStartMsg requestSpawn)
 {
     masterSpawner.InternalSpawnRequest(requestSpawn);
 }
Esempio n. 12
0
 public void SendRequestSpawnStart(RequestSpawnStartMsg requestSpawnStartMsg)
 {
     client.Send(requestSpawnStartMsg);
 }
Esempio n. 13
0
 public void SendRequestSpawnStart(RequestSpawnStartMsg requestSpawnStartMsg)
 {
     client.Send((short)MsgId.RequestSpawnStart, requestSpawnStartMsg);
 }
Esempio n. 14
0
 public RequestSpawnStartToSpawnerMsg(RequestSpawnStartMsg _original) : base(_original)
 {
 }