コード例 #1
0
    public bool StartInstance(InstanceRequestData request)
    {
        var gameConfigs = slaves.Where(x => x.Value.gameNames.Any(u => u == request.gameName)).ToList();

        if (gameConfigs.Count > 0)
        {
            //select a node
            var gameConfig = gameConfigs[UnityEngine.Random.Range(0, gameConfigs.Count)];
            //request the instance.
            gameConfig.Value.networkConnection.Send((short)CustomMessageTypes.InstanceSlaveStartInstanceRequest, request);
        }
        return(false);
    }
コード例 #2
0
    private void HandleStartInstanceRequest(NetworkMessage netMsg)
    {
        StringMessage       msg = netMsg.ReadMessage <StringMessage>();
        InstanceRequestData req = new InstanceRequestData();

        req.gameName   = msg.value;
        req.instanceID = Guid.NewGuid().GetHashCode();
        bool           result        = StartInstance(req);
        IntegerMessage resultMessage = new IntegerMessage();

        resultMessage.value = (result) ? 1 : 0;
        netMsg.conn.Send((short)CustomMessageTypes.StartInstanceResponse, resultMessage);
    }
コード例 #3
0
    private void HandleStartInstanceRequest(NetworkMessage x)
    {
        InstanceRequestData msg = x.ReadMessage <InstanceRequestData>();

        if (!string.IsNullOrEmpty(msg.gameName))
        {
            ProcessStartInfo info = new ProcessStartInfo();
            var instance          = config.instances.FirstOrDefault(u => u.gameName == msg.gameName);
            info.FileName  = instance.path;
            info.Arguments = instance.commandLineArguments;
            var p = Process.Start(info);
            InitializedInstances[p.Id] = new InstanceData();
            var data = InitializedInstances[p.Id];
            data                   = new InstanceData();
            data.gameName          = msg.gameName;
            data.ipAddress         = config.IPAddress;
            data.port              = 0; //will be filled later on when instance responds.
            data.instanceID        = msg.instanceID;
            runningInstances[p.Id] = null;
        }
    }